20 require_once(
"$MODDIR/lib/php/common-cli.php");
24 error_reporting(E_NOTICE & E_STRICT);
26 $Usage =
"Usage: " . basename($argv[0]) .
" [options] [archives]
28 -h = this help message
29 -v = enable verbose debugging
30 --username string = user name
31 --groupname string = group name
32 --password string = password
33 -c string = Specify the directory for the system configuration
34 -g number = set the global decisions from previous uploads or not. 1: yes; 0: no
35 -P number = set the permission to public on this upload or not. 1: yes; 0: no
36 -s = Run synchronously. Don't return until archive already in FOSSology repository.
37 If the archive is a file (see below), then the file can be safely removed.
39 Upload from version control system options(you have to specify which type of vcs you are using):
40 -S = upload from subversion repo
41 -G = upload from git repo
42 --user string = user name
43 --pass string = password
45 FOSSology storage options:
46 -f path = folder path for placing files (e.g., -f 'Fedora/ISOs/Disk 1')
47 You do not need to specify your top level folder.
48 All paths are under your top level folder.
49 -A = alphabet folders; organize uploads into folder a-c, d-f, etc.
50 -AA num = specify the number of letters per folder (default: 3); implies -A
51 -n name = (optional) name for the upload (default: name it after the file)
52 -d desc = (optional) description for the update
54 FOSSology processing queue options:
55 -Q = list all available processing agents
56 -q = specify a comma-separated list of agents, or 'all'
57 NOTE: By default, no analysis agents are queued up.
58 -T = TEST. No database or repository updates are performed.
59 Test mode enables verbose mode.
60 -I = ignore scm data scanning
62 FOSSology source options:
63 archive = file, directory, or URL to the archive.
64 If the archive is a URL, then it is retrieved and added.
65 If the archive is a file, then it is used as the source to add.
66 If the archive is a directory, then ALL files under it are
68 The archive support globbing - '*', all the matched files will be added.
69 Note: have to put it in single/double quotes, e.g. '*.php'
70 - = a single hyphen means the archive list will come from stdin.
71 -X path = item to exclude when archive is a directory
72 You can specify more than one -X. For example, to exclude
73 all svn and cvs directories, include the following before the
74 archive's directory path:
77 If you use -n, then -n must be set BEFORE each archive.
78 If you specify a directory, then -n and -d are ignored.
79 Multiple archives can be specified after each storage option.
81 One example, to load a file into one path:
83 --username USER --password PASSWORD \\
84 -f path -d 'the file' /tmp/file
85 One example, to upload all the php files in /tmp:
86 cp2foss --username USER --password PASSWORD -f path -d 'the file' '/tmp/*.php'
89 -a archive = (deprecated) see archive
90 -e addr = (deprecated and ignored)
91 -p path = (deprecated) see -f
92 -R = (deprecated and ignored)
93 -w = (deprecated and ignored)
94 -W = (deprecated and ignored)
100 $fossjobs_command =
"";
111 $Letters =
"abcdefghijklmnopqrstuvwxyz";
112 $Numbers =
"0123456789";
113 if (empty($UploadName)) {
116 $Name = strtolower(substr($UploadName, 0, 1));
118 if (empty($BucketGroupSize) || ($BucketGroupSize < 1)) {
119 $BucketGroupSize = 3;
121 for ($i = 0;$i < 26;$i+= $BucketGroupSize) {
122 $Range = substr($Letters, $i, $BucketGroupSize);
123 $Find = strpos($Range, $Name);
124 if ($Find !==
false) {
125 if (($BucketGroupSize <= 1) || (strlen($Range) <= 1)) {
128 return (substr($Range, 0, 1) .
'-' . substr($Range, -1, 1));
132 $Find = strpos($Numbers, $Name);
133 if ($Find !==
false) {
153 $dbManager = $GLOBALS[
'container']->get(
'db.manager');
156 if (empty($Parent)) {
160 if ($FolderPath ==
'/') {
163 if (empty($FolderPath)) {
166 list($folderHead, $folderTail) = explode(
'/', $FolderPath, 2);
167 if (empty($folderHead)) {
168 return (
GetFolder($folderTail, $Parent));
171 $SQL =
"SELECT folder_pk FROM folder
172 INNER JOIN foldercontents ON child_id = folder_pk
173 AND foldercontents_mode = '1'
174 WHERE foldercontents.parent_fk = $1 AND folder_name = $2";
176 print
"SQL=\n$SQL\n$1=$Parent\n$2=$folderHead\n";
179 $row = $dbManager->getSingleRow($SQL, array($Parent, $folderHead), __METHOD__.
".GetFolder.exists");
183 $P = & $Plugins[plugin_find_id(
"folder_create") ];
185 print
"FATAL: Unable to find folder_create plugin.\n";
189 print
"Folder not found: Creating $folderHead\n";
192 $P->create($Parent, $folderHead,
"");
193 $row = $dbManager->getSingleRow($SQL, array($Parent, $folderHead), __METHOD__.
".GetFolder.exists");
196 $Parent = $row[
'folder_pk'];
197 return (
GetFolder($folderTail, $Parent));
210 function UploadOne($FolderPath, $UploadArchive, $UploadName, $UploadDescription, $TarSource =
null)
212 $dbManager = $GLOBALS[
'container']->get(
'db.manager');
216 global $fossjobs_command;
223 global $TarExcludeList;
227 if (empty($UploadName)) {
228 $text =
"UploadName is empty\n";
233 $user_pk = $SysConf[
'auth'][
'UserId'];
234 $group_pk = $SysConf[
'auth'][
'GroupId'];
236 $UsersRow =
GetSingleRec(
"users",
"where user_pk=$user_pk");
238 print
"You have no permission to upload files into FOSSology\n";
243 $root_folder_fk = $UsersRow[
"root_folder_fk"];
249 $FolderPk =
GetFolder($FolderPath, $root_folder_fk);
250 if ($FolderPk == 1) {
251 print
" Uploading to folder: 'Software Repository'\n";
253 print
" Uploading to folder: '$FolderPath'\n";
255 print
" Uploading as '$UploadName'\n";
256 if (!empty($UploadDescription)) {
257 print
" Upload description: '$UploadDescription'\n";
264 print
"JobAddUpload($user_pk, $group_pk, $UploadName,$UploadArchive,$UploadDescription,$Mode,$FolderPk, $public_flag, $global_flag);\n";
267 $Src = $UploadArchive;
268 if (!empty($TarSource)) {
271 $UploadPk =
JobAddUpload($user_pk, $group_pk, $UploadName, $Src, $UploadDescription, $Mode, $FolderPk, $public_flag, $global_flag);
272 print
" UploadPk is: '$UploadPk'\n";
273 print
" FolderPk is: '$FolderPk'\n";
278 print
"JobAddJob($user_pk, $group_pk, wget, $UploadPk);\n";
281 $jobpk = JobAddJob($user_pk, $group_pk,
"wget", $UploadPk);
282 if (empty($jobpk) || ($jobpk < 0)) {
283 $text = _(
"Failed to insert job record");
289 $jq_args =
"$UploadPk - $Src";
290 if ($TarExcludeList) {
291 $jq_args .=
" " . $TarExcludeList;
294 $jq_args .=
" " . $VCS;
296 if ($vcsuser && $vcspass) {
297 $jq_args .=
" --username $vcsuser --password $vcspass ";
300 print
"JobQueueAdd($jobpk, wget_agent, $jq_args, no, NULL);\n";
303 $jobqueuepk =
JobQueueAdd($jobpk,
"wget_agent", $jq_args,
"no", NULL);
304 if (empty($jobqueuepk)) {
305 $text = _(
"Failed to insert task 'wget' into job queue");
313 print
"AgentAdd wget_agent and dj2nest.\n";
316 $unpackplugin = &$Plugins[plugin_find_id(
"agent_unpack") ];
317 $ununpack_jq_pk = $unpackplugin->AgentAdd($jobpk, $UploadPk, $ErrorMsg, array(
"wget_agent"), $scmarg);
318 if ($ununpack_jq_pk < 0) {
323 $adj2nestplugin = &$Plugins[plugin_find_id(
"agent_adj2nest") ];
324 $adj2nest_jq_pk = $adj2nestplugin->AgentAdd($jobpk, $UploadPk, $ErrorMsg, array());
325 if ($adj2nest_jq_pk < 0) {
330 if (!empty($QueueList)) {
331 switch ($QueueList) {
334 $Cmd =
"$fossjobs_command -U '$UploadPk'";
337 $Cmd =
"$fossjobs_command -U '$UploadPk' -A '$QueueList'";
353 while ($working && ($waitCount++ < 30)) {
355 $SQL =
"select 1 from jobqueue inner join job on job.job_pk = jobqueue.jq_job_fk where job_upload_fk = $1 and jq_end_bits = 0 and jq_type = 'wget_agent'";
357 $row = $dbManager->getSingleRow($SQL, array($UploadPk), __METHOD__.
".UploadOne");
364 echo
"Gave up waiting for copy completion. Is the scheduler running?";
376 $UploadDescription =
"";
379 $TarExcludeList =
"";
386 $user = $passwd =
"";
388 $vcsuser = $vcspass=
"";
390 for ($i = 1; $i < $argc; $i ++) {
401 $user = escapeshellarg($argv[$i]);
405 $group = escapeshellarg($argv[$i]);
409 $passwd = escapeshellarg($argv[$i]);
413 $vcsuser = $argv[$i];
417 $vcspass = $argv[$i];
425 $bucket_size = intval($argv[$i]);
426 if ($bucket_size < 1) {
433 $FolderPath = $argv[$i];
437 $FolderPath = preg_replace(
'@^/*@',
"", $FolderPath);
438 $FolderPath = preg_replace(
'@/*$@',
"", $FolderPath);
443 $FolderPath = preg_replace(
"@^S.*? Repository@",
"", $FolderPath);
444 $FolderPath = preg_replace(
'@//*@',
"/", $FolderPath);
445 $FolderPath =
'/' . $FolderPath;
457 $UploadDescription = escapeshellarg($argv[$i]);
461 $UploadName = escapeshellarg($argv[$i]);
468 $QueueList = escapeshellarg($argv[$i]);
483 if (!empty($TarExcludeList)) {
484 $TarExcludeList .=
" ";
487 $TarExcludeList .=
"--exclude '" . $argv[$i] .
"'";
497 if (1 == $argv[$i]) {
505 if (1 == $argv[$i]) {
521 if (substr($argv[$i], 0, 1) ==
'-') {
522 print
"Unknown parameter: '" . $argv[$i] .
"'\n";
527 $UploadArchive = escapeshellarg($argv[$i]);
534 if (!$Test && $OptionQ) {
535 $Cmd =
"fossjobs --username $user --groupname $group --password $passwd -c $SYSCONFDIR -a";
542 $Fin = fopen(
"php://stdin",
"r");
544 $UploadArchive =
trim(fgets($Fin));
551 $fossjobs_command =
"fossjobs --username $user --groupname $group --password $passwd -c $SYSCONFDIR -v ";
553 $fossjobs_command =
"fossjobs --username $user --groupname $group --password $passwd -c $SYSCONFDIR ";
558 if (!$UploadArchive) {
559 print
"FATAL: No files to upload were specified.\n";
568 if (filter_var($UploadArchive, FILTER_VALIDATE_URL)) {
569 }
else if (strchr($UploadArchive,
'*')) {
570 $file_number_cmd =
"ls $UploadArchive > /dev/null";
571 system($file_number_cmd, $return_val);
575 if (
"/" != $UploadArchive[0]) {
576 $UploadArchive = getcwd().
"/".$UploadArchive;
579 print
"Note: it seems that what you want to upload '$UploadArchive' does not exist. \n";
586 if (strlen($UploadArchive) > 0 && empty($UploadName)) {
587 $UploadName = basename($UploadArchive);
590 if ($vcsuser && $vcspass) {
591 print
"Warning: usernames and passwords on the command line are visible to system users with a shell account. To avoid this you can download your source, then upload.\n";
594 print
"Loading '$UploadArchive'\n";
595 print
" Calling UploadOne in 'main': '$FolderPath'\n";
596 $res =
UploadOne($FolderPath, $UploadArchive, $UploadName, $UploadDescription);
account_check(&$user, &$passwd, &$group="")
check if this account is correct
cli_Init()
Initialize the fossology environment for CLI use. This routine loads the plugins so they can be use b...
GetSingleRec($Table, $Where="")
Retrieve a single database record.
FolderGetTop()
DEPRECATED! Find the top-of-tree folder_pk for the current user.
JobQueueAdd($job_pk, $jq_type, $jq_args, $jq_runonpfile, $Depends, $host=NULL, $jq_cmd_args=NULL)
Insert a jobqueue + jobdepends records.
JobAddUpload($userId, $groupId, $job_name, $filename, $desc, $UploadMode, $folder_pk, $public_perm=Auth::PERM_NONE, $setGlobal=0)
Insert a new upload record, and update the foldercontents table.
if(! $UploadArchive) $UploadArchiveTmp
GetFolder($FolderPath, $Parent=null)
Given a folder path, return the folder_pk.
UploadOne($FolderPath, $UploadArchive, $UploadName, $UploadDescription, $TarSource=null)
Given one object (file or URL), upload it.
GetBucketFolder($UploadName, $BucketGroupSize)
Given an upload name and the number of letters per bucket, return the bucket folder name.
char * trim(char *ptext)
Trimming whitespace.
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
list_t type structure used to keep various lists. (e.g. there are multiple lists).