30 require_once(
"$MODDIR/lib/php/common-cli.php");
34 error_reporting(E_NOTICE & E_STRICT);
36 $Usage =
"Usage: " . basename($argv[0]) .
" [options] [archives] 38 -h = this help message 39 -v = enable verbose debugging 40 --username string = user name 41 --groupname string = group name 42 --password string = password 43 -c string = Specify the directory for the system configuration 44 -P number = set the permission to public on this upload or not. 1: yes; 0: no 45 -s = Run synchronously. Don't return until archive already in FOSSology repository. 46 If the archive is a file (see below), then the file can be safely removed. 48 Upload from version control system options(you have to specify which type of vcs you are using): 49 -S = upload from subversion repo 50 -G = upload from git repo 51 --user string = user name 52 --pass string = password 54 FOSSology storage options: 55 -f path = folder path for placing files (e.g., -f 'Fedora/ISOs/Disk 1') 56 You do not need to specify your top level folder. 57 All paths are under your top level folder. 58 -A = alphabet folders; organize uploads into folder a-c, d-f, etc. 59 -AA num = specify the number of letters per folder (default: 3); implies -A 60 -n name = (optional) name for the upload (default: name it after the file) 61 -d desc = (optional) description for the update 63 FOSSology processing queue options: 64 -Q = list all available processing agents 65 -q = specify a comma-separated list of agents, or 'all' 66 NOTE: By default, no analysis agents are queued up. 67 -T = TEST. No database or repository updates are performed. 68 Test mode enables verbose mode. 69 -I = ignore scm data scanning 71 FOSSology source options: 72 archive = file, directory, or URL to the archive. 73 If the archive is a URL, then it is retrieved and added. 74 If the archive is a file, then it is used as the source to add. 75 If the archive is a directory, then ALL files under it are 77 The archive support globbing - '*', all the matched files will be added. 78 Note: have to put it in single/double quotes, e.g. '*.php' 79 - = a single hyphen means the archive list will come from stdin. 80 -X path = item to exclude when archive is a directory 81 You can specify more than one -X. For example, to exclude 82 all svn and cvs directories, include the following before the 83 archive's directory path: 86 If you use -n, then -n must be set BEFORE each archive. 87 If you specify a directory, then -n and -d are ignored. 88 Multiple archives can be specified after each storage option. 90 One example, to load a file into one path: 92 --username USER --password PASSWORD \\ 93 -f path -d 'the file' /tmp/file 94 One example, to upload all the php files in /tmp: 95 cp2foss --username USER --password PASSWORD -f path -d 'the file' '/tmp/*.php' 98 -a archive = (deprecated) see archive 99 -e addr = (deprecated and ignored) 100 -p path = (deprecated) see -f 101 -R = (deprecated and ignored) 102 -w = (deprecated and ignored) 103 -W = (deprecated and ignored) 109 $fossjobs_command =
"";
120 $Letters =
"abcdefghijklmnopqrstuvwxyz";
121 $Numbers =
"0123456789";
122 if (empty($UploadName)) {
125 $Name = strtolower(substr($UploadName, 0, 1));
127 if (empty($BucketGroupSize) || ($BucketGroupSize < 1)) {
128 $BucketGroupSize = 3;
130 for ($i = 0;$i < 26;$i+= $BucketGroupSize) {
131 $Range = substr($Letters, $i, $BucketGroupSize);
132 $Find = strpos($Range, $Name);
133 if ($Find !==
false) {
134 if (($BucketGroupSize <= 1) || (strlen($Range) <= 1)) {
137 return (substr($Range, 0, 1) .
'-' . substr($Range, -1, 1));
141 $Find = strpos($Numbers, $Name);
142 if ($Find !==
false) {
162 $dbManager = $GLOBALS[
'container']->get(
'db.manager');
165 if (empty($Parent)) {
169 if ($FolderPath ==
'/') {
172 if (empty($FolderPath)) {
175 list($folderHead, $folderTail) = explode(
'/', $FolderPath, 2);
176 if (empty($folderHead)) {
177 return (
GetFolder($folderTail, $Parent));
180 $SQL =
"SELECT folder_pk FROM folder 181 INNER JOIN foldercontents ON child_id = folder_pk 182 AND foldercontents_mode = '1' 183 WHERE foldercontents.parent_fk = $1 AND folder_name = $2";
185 print
"SQL=\n$SQL\n$1=$Parent\n$2=$folderHead\n";
188 $row = $dbManager->getSingleRow($SQL, array($Parent, $folderHead), __METHOD__.
".GetFolder.exists");
192 $P = & $Plugins[plugin_find_id(
"folder_create") ];
194 print
"FATAL: Unable to find folder_create plugin.\n";
198 print
"Folder not found: Creating $folderHead\n";
201 $P->create($Parent, $folderHead,
"");
202 $row = $dbManager->getSingleRow($SQL, array($Parent, $folderHead), __METHOD__.
".GetFolder.exists");
205 $Parent = $row[
'folder_pk'];
206 return (
GetFolder($folderTail, $Parent));
219 function UploadOne($FolderPath, $UploadArchive, $UploadName, $UploadDescription, $TarSource = null)
221 $dbManager = $GLOBALS[
'container']->get(
'db.manager');
225 global $fossjobs_command;
231 global $TarExcludeList;
235 if (empty($UploadName)) {
236 $text =
"UploadName is empty\n";
241 $user_pk = $SysConf[
'auth'][
'UserId'];
242 $group_pk = $SysConf[
'auth'][
'GroupId'];
244 $UsersRow =
GetSingleRec(
"users",
"where user_pk=$user_pk");
246 print
"You have no permission to upload files into FOSSology\n";
251 $root_folder_fk = $UsersRow[
"root_folder_fk"];
257 $FolderPk =
GetFolder($FolderPath, $root_folder_fk);
258 if ($FolderPk == 1) {
259 print
" Uploading to folder: 'Software Repository'\n";
261 print
" Uploading to folder: '$FolderPath'\n";
263 print
" Uploading as '$UploadName'\n";
264 if (!empty($UploadDescription)) {
265 print
" Upload description: '$UploadDescription'\n";
272 print
"JobAddUpload($user_pk, $group_pk, $UploadName,$UploadArchive,$UploadDescription,$Mode,$FolderPk, $public_flag);\n";
275 $Src = $UploadArchive;
276 if (!empty($TarSource)) {
279 $UploadPk =
JobAddUpload($user_pk, $group_pk, $UploadName, $Src, $UploadDescription, $Mode, $FolderPk, $public_flag);
280 print
" UploadPk is: '$UploadPk'\n";
281 print
" FolderPk is: '$FolderPk'\n";
286 print
"JobAddJob($user_pk, $group_pk, wget, $UploadPk);\n";
289 $jobpk = JobAddJob($user_pk, $group_pk,
"wget", $UploadPk);
290 if (empty($jobpk) || ($jobpk < 0)) {
291 $text = _(
"Failed to insert job record");
297 $jq_args =
"$UploadPk - $Src";
298 if ($TarExcludeList) {
299 $jq_args .=
" " . $TarExcludeList;
302 $jq_args .=
" " . $VCS;
304 if ($vcsuser && $vcspass) {
305 $jq_args .=
" --username $vcsuser --password $vcspass ";
308 print
"JobQueueAdd($jobpk, wget_agent, $jq_args, no, NULL);\n";
311 $jobqueuepk =
JobQueueAdd($jobpk,
"wget_agent", $jq_args,
"no", NULL);
312 if (empty($jobqueuepk)) {
313 $text = _(
"Failed to insert task 'wget' into job queue");
321 print
"AgentAdd wget_agent and dj2nest.\n";
324 $unpackplugin = &$Plugins[plugin_find_id(
"agent_unpack") ];
325 $ununpack_jq_pk = $unpackplugin->AgentAdd($jobpk, $UploadPk, $ErrorMsg, array(
"wget_agent"), $scmarg);
326 if ($ununpack_jq_pk < 0) {
331 $adj2nestplugin = &$Plugins[plugin_find_id(
"agent_adj2nest") ];
332 $adj2nest_jq_pk = $adj2nestplugin->AgentAdd($jobpk, $UploadPk, $ErrorMsg, array());
333 if ($adj2nest_jq_pk < 0) {
338 if (!empty($QueueList)) {
339 switch ($QueueList) {
342 $Cmd =
"$fossjobs_command -U '$UploadPk'";
345 $Cmd =
"$fossjobs_command -U '$UploadPk' -A '$QueueList'";
361 while ($working && ($waitCount++ < 30)) {
363 $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'";
365 $row = $dbManager->getSingleRow($SQL, array($UploadPk), __METHOD__.
".UploadOne");
372 echo
"Gave up waiting for copy completion. Is the scheduler running?";
384 $UploadDescription =
"";
387 $TarExcludeList =
"";
393 $user = $passwd =
"";
395 $vcsuser = $vcspass=
"";
397 for ($i = 1; $i < $argc; $i ++) {
420 $vcsuser = $argv[$i];
424 $vcspass = $argv[$i];
432 $bucket_size = intval($argv[$i]);
433 if ($bucket_size < 1) {
440 $FolderPath = $argv[$i];
444 $FolderPath = preg_replace(
'@^/*@',
"", $FolderPath);
445 $FolderPath = preg_replace(
'@/*$@',
"", $FolderPath);
450 $FolderPath = preg_replace(
"@^S.*? Repository@",
"", $FolderPath);
451 $FolderPath = preg_replace(
'@//*@',
"/", $FolderPath);
452 $FolderPath =
'/' . $FolderPath;
464 $UploadDescription = $argv[$i];
468 $UploadName = $argv[$i];
475 $QueueList = $argv[$i];
490 if (!empty($TarExcludeList)) {
491 $TarExcludeList .=
" ";
494 $TarExcludeList .=
"--exclude '" . $argv[$i] .
"'";
504 if (1 == $argv[$i]) {
520 if (substr($argv[$i], 0, 1) ==
'-') {
521 print
"Unknown parameter: '" . $argv[$i] .
"'\n";
526 $UploadArchive = $argv[$i];
533 if (!$Test && $OptionQ) {
534 $Cmd =
"fossjobs --username $user --groupname $group --password $passwd -c $SYSCONFDIR -a";
541 $Fin = fopen(
"php://stdin",
"r");
543 $UploadArchive =
trim(fgets($Fin));
550 $fossjobs_command =
"fossjobs --username $user --groupname $group --password $passwd -c $SYSCONFDIR -v ";
552 $fossjobs_command =
"fossjobs --username $user --groupname $group --password $passwd -c $SYSCONFDIR ";
557 if (!$UploadArchive) {
558 print
"FATAL: No files to upload were specified.\n";
567 if (filter_var($UploadArchive, FILTER_VALIDATE_URL)) {
568 }
else if (strchr($UploadArchive,
'*')) {
569 $file_number_cmd =
"ls $UploadArchive > /dev/null";
570 system($file_number_cmd, $return_val);
574 if (
"/" != $UploadArchive[0]) {
575 $UploadArchive = getcwd().
"/".$UploadArchive;
578 print
"Note: it seems that what you want to upload '$UploadArchive' does not exist. \n";
585 if (strlen($UploadArchive) > 0 && empty($UploadName)) {
586 $UploadName = basename($UploadArchive);
589 if ($vcsuser && $vcspass) {
590 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";
593 print
"Loading '$UploadArchive'\n";
594 print
" Calling UploadOne in 'main': '$FolderPath'\n";
595 $res =
UploadOne($FolderPath, $UploadArchive, $UploadName, $UploadDescription);
account_check(&$user, &$passwd, &$group="")
check if this account is correct
JobQueueAdd($job_pk, $jq_type, $jq_args, $jq_runonpfile, $Depends, $host=NULL, $jq_cmd_args=NULL)
Insert a jobqueue + jobdepends records.
GetSingleRec($Table, $Where="")
Retrieve a single database record.
FolderGetTop()
DEPRECATED! Find the top-of-tree folder_pk for the current user.
cli_Init()
Initialize the fossology environment for CLI use. This routine loads the plugins so they can be use b...
UploadOne($FolderPath, $UploadArchive, $UploadName, $UploadDescription, $TarSource=null)
Given one object (file or URL), upload it.
GetFolder($FolderPath, $Parent=null)
Given a folder path, return the folder_pk.
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
if(!$UploadArchive) $UploadArchiveTmp
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).
GetBucketFolder($UploadName, $BucketGroupSize)
Given an upload name and the number of letters per bucket, return the bucket folder name...
JobAddUpload($userId, $groupId, $job_name, $filename, $desc, $UploadMode, $folder_pk, $public_perm=Auth::PERM_NONE)
Insert a new upload record, and update the foldercontents table.
char * trim(char *ptext)
Trimming whitespace.