summaryrefslogtreecommitdiff
path: root/src/pacman/pacman.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pacman/pacman.c')
-rw-r--r--src/pacman/pacman.c172
1 files changed, 114 insertions, 58 deletions
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 4c556a7d..f4f80449 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -149,6 +149,7 @@ static void usage(int op, const char * const myname)
printf(_(" -r, --root <path> set an alternate installation root\n"));
printf(_(" -b, --dbpath <path> set an alternate database location\n"));
printf(_(" --cachedir <dir> set an alternate package cache location\n"));
+ printf(_(" --arch <arch> set an alternate architecture\n"));
}
}
@@ -195,6 +196,19 @@ static void setuseragent(void)
setenv("HTTP_USER_AGENT", agent, 0);
}
+static void setarch(const char *arch)
+{
+ if (strcmp(arch, "auto") == 0) {
+ struct utsname un;
+ uname(&un);
+ pm_printf(PM_LOG_DEBUG, "config: architecture: %s\n", un.machine);
+ alpm_option_set_arch(un.machine);
+ } else {
+ pm_printf(PM_LOG_DEBUG, "config: architecture: %s\n", arch);
+ alpm_option_set_arch(arch);
+ }
+}
+
/** Free the resources.
*
* @param ret the return value
@@ -364,18 +378,20 @@ static int parseargs(int argc, char *argv[])
{"verbose", no_argument, 0, 'v'},
{"downloadonly", no_argument, 0, 'w'},
{"refresh", no_argument, 0, 'y'},
- {"noconfirm", no_argument, 0, 1000},
- {"config", required_argument, 0, 1001},
- {"ignore", required_argument, 0, 1002},
- {"debug", optional_argument, 0, 1003},
- {"noprogressbar", no_argument, 0, 1004},
- {"noscriptlet", no_argument, 0, 1005},
- {"cachedir", required_argument, 0, 1007},
- {"asdeps", no_argument, 0, 1008},
- {"logfile", required_argument, 0, 1009},
- {"ignoregroup", required_argument, 0, 1010},
- {"needed", no_argument, 0, 1011},
- {"asexplicit", no_argument, 0, 1012},
+ {"noconfirm", no_argument, 0, OP_NOCONFIRM},
+ {"config", required_argument, 0, OP_CONFIG},
+ {"ignore", required_argument, 0, OP_IGNORE},
+ {"debug", optional_argument, 0, OP_DEBUG},
+ {"noprogressbar", no_argument, 0, OP_NOPROGRESSBAR},
+ {"noscriptlet", no_argument, 0, OP_NOSCRIPTLET},
+ {"ask", required_argument, 0, OP_ASK},
+ {"cachedir", required_argument, 0, OP_CACHEDIR},
+ {"asdeps", no_argument, 0, OP_ASDEPS},
+ {"logfile", required_argument, 0, OP_LOGFILE},
+ {"ignoregroup", required_argument, 0, OP_IGNOREGROUP},
+ {"needed", no_argument, 0, OP_NEEDED},
+ {"asexplicit", no_argument, 0, OP_ASEXPLICIT},
+ {"arch", required_argument, 0, OP_ARCH},
{0, 0, 0, 0}
};
@@ -387,21 +403,21 @@ static int parseargs(int argc, char *argv[])
}
switch(opt) {
case 0: break;
- case 1000: config->noconfirm = 1; break;
- case 1001:
+ case OP_NOCONFIRM: config->noconfirm = 1; break;
+ case OP_CONFIG:
if(config->configfile) {
free(config->configfile);
}
config->configfile = strndup(optarg, PATH_MAX);
break;
- case 1002:
+ case OP_IGNORE:
list = strsplit(optarg, ',');
for(item = list; item; item = alpm_list_next(item)) {
alpm_option_add_ignorepkg((char *)alpm_list_getdata(item));
}
FREELIST(list);
break;
- case 1003:
+ case OP_DEBUG:
/* debug levels are made more 'human readable' than using a raw logmask
* here, error and warning are set in config_new, though perhaps a
* --quiet option will remove these later */
@@ -424,32 +440,36 @@ static int parseargs(int argc, char *argv[])
/* progress bars get wonky with debug on, shut them off */
config->noprogressbar = 1;
break;
- case 1004: config->noprogressbar = 1; break;
- case 1005: config->flags |= PM_TRANS_FLAG_NOSCRIPTLET; break;
- case 1007:
+ case OP_NOPROGRESSBAR: config->noprogressbar = 1; break;
+ case OP_NOSCRIPTLET: config->flags |= PM_TRANS_FLAG_NOSCRIPTLET; break;
+ case OP_ASK: config->noask = 1; config->ask = atoi(optarg); break;
+ case OP_CACHEDIR:
if(alpm_option_add_cachedir(optarg) != 0) {
pm_printf(PM_LOG_ERROR, _("problem adding cachedir '%s' (%s)\n"),
optarg, alpm_strerrorlast());
return(1);
}
break;
- case 1008:
+ case OP_ASDEPS:
config->flags |= PM_TRANS_FLAG_ALLDEPS;
break;
- case 1009:
+ case OP_LOGFILE:
config->logfile = strndup(optarg, PATH_MAX);
break;
- case 1010:
+ case OP_IGNOREGROUP:
list = strsplit(optarg, ',');
for(item = list; item; item = alpm_list_next(item)) {
alpm_option_add_ignoregrp((char *)alpm_list_getdata(item));
}
FREELIST(list);
break;
- case 1011: config->flags |= PM_TRANS_FLAG_NEEDED; break;
- case 1012:
+ case OP_NEEDED: config->flags |= PM_TRANS_FLAG_NEEDED; break;
+ case OP_ASEXPLICIT:
config->flags |= PM_TRANS_FLAG_ALLEXPLICIT;
break;
+ case OP_ARCH:
+ setarch(optarg);
+ break;
case 'Q': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_QUERY); break;
case 'R': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_REMOVE); break;
case 'S': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_SYNC); break;
@@ -592,7 +612,7 @@ static char *get_filename(const char *url) {
static char *get_destfile(const char *path, const char *filename) {
char *destfile;
/* len = localpath len + filename len + null */
- int len = strlen(path) + strlen(filename) + 1;
+ size_t len = strlen(path) + strlen(filename) + 1;
destfile = calloc(len, sizeof(char));
snprintf(destfile, len, "%s%s", path, filename);
@@ -602,7 +622,7 @@ static char *get_destfile(const char *path, const char *filename) {
static char *get_tempfile(const char *path, const char *filename) {
char *tempfile;
/* len = localpath len + filename len + '.part' len + null */
- int len = strlen(path) + strlen(filename) + 6;
+ size_t len = strlen(path) + strlen(filename) + 6;
tempfile = calloc(len, sizeof(char));
snprintf(tempfile, len, "%s%s.part", path, filename);
@@ -615,9 +635,7 @@ int download_with_xfercommand(const char *url, const char *localpath,
int ret = 0;
int retval;
int usepart = 0;
- char *ptr1, *ptr2;
- char origCmd[PATH_MAX];
- char parsedCmd[PATH_MAX] = "";
+ char *parsedcmd,*tempcmd;
char cwd[PATH_MAX];
char *destfile, *tempfile, *filename;
@@ -632,28 +650,18 @@ int download_with_xfercommand(const char *url, const char *localpath,
destfile = get_destfile(localpath, filename);
tempfile = get_tempfile(localpath, filename);
- strncpy(origCmd, config->xfercommand, sizeof(origCmd));
+ tempcmd = strdup(config->xfercommand);
/* replace all occurrences of %o with fn.part */
- ptr1 = origCmd;
- while((ptr2 = strstr(ptr1, "%o"))) {
+ if(strstr(tempcmd, "%o")) {
usepart = 1;
- ptr2[0] = '\0';
- strcat(parsedCmd, ptr1);
- strcat(parsedCmd, tempfile);
- ptr1 = ptr2 + 2;
+ parsedcmd = strreplace(tempcmd, "%o", tempfile);
+ free(tempcmd);
+ tempcmd = parsedcmd;
}
- strcat(parsedCmd, ptr1);
/* replace all occurrences of %u with the download URL */
- strncpy(origCmd, parsedCmd, sizeof(origCmd));
- parsedCmd[0] = '\0';
- ptr1 = origCmd;
- while((ptr2 = strstr(ptr1, "%u"))) {
- ptr2[0] = '\0';
- strcat(parsedCmd, ptr1);
- strcat(parsedCmd, url);
- ptr1 = ptr2 + 2;
- }
- strcat(parsedCmd, ptr1);
+ parsedcmd = strreplace(tempcmd, "%u", url);
+ free(tempcmd);
+
/* cwd to the download directory */
getcwd(cwd, PATH_MAX);
if(chdir(localpath)) {
@@ -662,8 +670,8 @@ int download_with_xfercommand(const char *url, const char *localpath,
goto cleanup;
}
/* execute the parsed command via /bin/sh -c */
- pm_printf(PM_LOG_DEBUG, "running command: %s\n", parsedCmd);
- retval = system(parsedCmd);
+ pm_printf(PM_LOG_DEBUG, "running command: %s\n", parsedcmd);
+ retval = system(parsedcmd);
if(retval == -1) {
pm_printf(PM_LOG_WARNING, _("running XferCommand: fork failed!\n"));
@@ -689,6 +697,7 @@ cleanup:
}
free(destfile);
free(tempfile);
+ free(parsedcmd);
return(ret);
}
@@ -749,11 +758,8 @@ static int _parseconfig(const char *file, const char *givensection,
ret = 1;
goto cleanup;
}
- /* if we are not looking at the options section, register a db and also
- * ensure we have set all of our library paths as the library is too stupid
- * at the moment to do lazy opening of the databases */
+ /* if we are not looking at the options section, register a db */
if(strcmp(section, "options") != 0) {
- setlibpaths();
db = alpm_db_register_sync(section);
if(db == NULL) {
pm_printf(PM_LOG_ERROR, _("could not register '%s' database (%s)\n"),
@@ -787,10 +793,7 @@ static int _parseconfig(const char *file, const char *givensection,
}
if(ptr == NULL && strcmp(section, "options") == 0) {
/* directives without settings, all in [options] */
- if(strcmp(key, "NoPassiveFtp") == 0) {
- alpm_option_set_nopassiveftp(1);
- pm_printf(PM_LOG_DEBUG, "config: nopassiveftp\n");
- } else if(strcmp(key, "UseSyslog") == 0) {
+ if(strcmp(key, "UseSyslog") == 0) {
alpm_option_set_usesyslog(1);
pm_printf(PM_LOG_DEBUG, "config: usesyslog\n");
} else if(strcmp(key, "ILoveCandy") == 0) {
@@ -830,6 +833,10 @@ static int _parseconfig(const char *file, const char *givensection,
setrepeatingoption(ptr, "HoldPkg", option_add_holdpkg);
} else if(strcmp(key, "SyncFirst") == 0) {
setrepeatingoption(ptr, "SyncFirst", option_add_syncfirst);
+ } else if(strcmp(key, "Architecture") == 0) {
+ if(!alpm_option_get_arch()) {
+ setarch(ptr);
+ }
} else if(strcmp(key, "DBPath") == 0) {
/* don't overwrite a path specified on the command line */
if(!config->dbpath) {
@@ -878,7 +885,23 @@ static int _parseconfig(const char *file, const char *givensection,
}
} else if(strcmp(key, "Server") == 0) {
/* let's attempt a replacement for the current repo */
- char *server = strreplace(ptr, "$repo", section);
+ char *temp = strreplace(ptr, "$repo", section);
+ /* let's attempt a replacement for the arch */
+ const char *arch = alpm_option_get_arch();
+ char *server;
+ if(arch) {
+ server = strreplace(temp, "$arch", arch);
+ free(temp);
+ } else {
+ if(strstr(temp, "$arch")) {
+ free(temp);
+ pm_printf(PM_LOG_ERROR, _("The mirror '%s' contains the $arch"
+ " variable, but no Architecture is defined.\n"), ptr);
+ ret = 1;
+ goto cleanup;
+ }
+ server = temp;
+ }
if(alpm_db_setserver(db, server) != 0) {
/* pm_errno is set by alpm_db_setserver */
@@ -923,6 +946,29 @@ static int parseconfig(const char *file)
return(_parseconfig(file, NULL, NULL));
}
+/** print commandline to logfile
+ */
+static void cl_to_log(int argc, char* argv[])
+{
+ size_t size = 0;
+ int i;
+ for(i = 0; i<argc; i++) {
+ size += strlen(argv[i]) + 1;
+ }
+ char *cl_text = malloc(size);
+ if(!cl_text)
+ return;
+ char *p = cl_text;
+ for(i = 0; i<argc-1; i++) {
+ strcpy(p, argv[i]);
+ p += strlen(argv[i]);
+ *p++ = ' ';
+ }
+ strcpy(p, argv[i]);
+ alpm_logaction("Running '%s'\n", cl_text);
+ free(cl_text);
+}
+
/** Main function.
* @param argc argc
* @param argv argv
@@ -1018,6 +1064,11 @@ int main(int argc, char *argv[])
alpm_option_set_totaldlcb(cb_dl_total);
}
+ /* noask is meant to be non-interactive */
+ if(config->noask) {
+ config->noconfirm = 1;
+ }
+
#if defined(HAVE_GETEUID) && !defined(CYGWIN)
/* check if we have sufficient permission for the requested operation */
if(myuid > 0 && needs_root()) {
@@ -1049,6 +1100,11 @@ int main(int argc, char *argv[])
cleanup(EXIT_FAILURE);
}
+ /* Log commandline */
+ if(needs_root()) {
+ cl_to_log(argc, argv);
+ }
+
/* start the requested operation */
switch(config->op) {
case PM_OP_REMOVE: