2005-03-14 20:51:43 -05:00
|
|
|
/*
|
|
|
|
* pacman.c
|
|
|
|
*
|
2006-01-02 14:55:35 -05:00
|
|
|
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
|
2005-03-14 20:51:43 -05:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
|
|
* USA.
|
|
|
|
*/
|
|
|
|
|
2005-10-06 03:28:30 -04:00
|
|
|
#include "config.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <signal.h>
|
2006-12-05 01:55:52 -05:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2005-10-07 19:29:49 -04:00
|
|
|
#include <unistd.h>
|
2006-05-14 22:19:57 -04:00
|
|
|
#include <libintl.h>
|
2006-06-28 01:37:15 -04:00
|
|
|
#include <locale.h>
|
2006-10-15 15:34:52 -04:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
#include <malloc/malloc.h>
|
|
|
|
#elif defined(__OpenBSD__) || defined(__APPLE__)
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#elif defined(CYGWIN)
|
2005-10-06 03:28:30 -04:00
|
|
|
#include <libgen.h> /* basename */
|
2006-10-15 15:34:52 -04:00
|
|
|
#else
|
|
|
|
#include <mcheck.h> /* debug */
|
2005-10-06 03:28:30 -04:00
|
|
|
#endif
|
2006-10-15 15:34:52 -04:00
|
|
|
#include <time.h>
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
#include <alpm.h>
|
|
|
|
/* pacman */
|
|
|
|
#include "list.h"
|
|
|
|
#include "util.h"
|
2005-03-19 04:00:40 -05:00
|
|
|
#include "log.h"
|
2006-11-14 02:58:42 -05:00
|
|
|
#include "downloadprog.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
#include "conf.h"
|
|
|
|
#include "package.h"
|
|
|
|
#include "add.h"
|
|
|
|
#include "remove.h"
|
|
|
|
#include "upgrade.h"
|
|
|
|
#include "query.h"
|
|
|
|
#include "sync.h"
|
2006-01-06 17:19:14 -05:00
|
|
|
#include "deptest.h"
|
2006-03-13 15:34:47 -05:00
|
|
|
|
|
|
|
#define PACCONF "/etc/pacman.conf"
|
|
|
|
|
2006-10-15 15:34:52 -04:00
|
|
|
#if defined(__OpenBSD__) || defined(__APPLE__)
|
|
|
|
#define BSD
|
|
|
|
#endif
|
|
|
|
|
2006-03-13 15:34:47 -05:00
|
|
|
/* Operations */
|
|
|
|
enum {
|
|
|
|
PM_OP_MAIN = 1,
|
|
|
|
PM_OP_ADD,
|
|
|
|
PM_OP_REMOVE,
|
|
|
|
PM_OP_UPGRADE,
|
|
|
|
PM_OP_QUERY,
|
|
|
|
PM_OP_SYNC,
|
|
|
|
PM_OP_DEPTEST
|
|
|
|
};
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2005-10-29 03:00:56 -04:00
|
|
|
config_t *config = NULL;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2006-11-20 04:10:23 -05:00
|
|
|
pmdb_t *db_local;
|
2005-03-14 20:51:43 -05:00
|
|
|
/* list of (sync_t *) structs for sync locations */
|
|
|
|
list_t *pmc_syncs = NULL;
|
|
|
|
/* list of targets specified on command line */
|
|
|
|
list_t *pm_targets = NULL;
|
|
|
|
|
2006-10-15 15:34:52 -04:00
|
|
|
unsigned int maxcols = 80;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2006-02-01 13:20:13 -05:00
|
|
|
extern int neednl;
|
|
|
|
|
2006-03-13 15:34:47 -05:00
|
|
|
/* Display usage/syntax for the specified operation.
|
|
|
|
* op: the operation code requested
|
|
|
|
* myname: basename(argv[0])
|
|
|
|
*/
|
|
|
|
static void usage(int op, char *myname)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2006-03-13 15:34:47 -05:00
|
|
|
if(op == PM_OP_MAIN) {
|
2006-05-14 22:19:57 -04:00
|
|
|
printf(_("usage: %s {-h --help}\n"), myname);
|
|
|
|
printf(_(" %s {-V --version}\n"), myname);
|
|
|
|
printf(_(" %s {-A --add} [options] <file>\n"), myname);
|
|
|
|
printf(_(" %s {-R --remove} [options] <package>\n"), myname);
|
|
|
|
printf(_(" %s {-U --upgrade} [options] <file>\n"), myname);
|
|
|
|
printf(_(" %s {-F --freshen} [options] <file>\n"), myname);
|
|
|
|
printf(_(" %s {-Q --query} [options] [package]\n"), myname);
|
|
|
|
printf(_(" %s {-S --sync} [options] [package]\n"), myname);
|
|
|
|
printf(_("\nuse '%s --help' with other options for more syntax\n"), myname);
|
2006-03-13 15:34:47 -05:00
|
|
|
} else {
|
|
|
|
if(op == PM_OP_ADD) {
|
2006-05-14 22:19:57 -04:00
|
|
|
printf(_("usage: %s {-A --add} [options] <file>\n"), myname);
|
|
|
|
printf(_("options:\n"));
|
|
|
|
printf(_(" -d, --nodeps skip dependency checks\n"));
|
|
|
|
printf(_(" -f, --force force install, overwrite conflicting files\n"));
|
2006-03-13 15:34:47 -05:00
|
|
|
} else if(op == PM_OP_REMOVE) {
|
2006-05-14 22:19:57 -04:00
|
|
|
printf(_("usage: %s {-R --remove} [options] <package>\n"), myname);
|
|
|
|
printf(_("options:\n"));
|
|
|
|
printf(_(" -c, --cascade remove packages and all packages that depend on them\n"));
|
|
|
|
printf(_(" -d, --nodeps skip dependency checks\n"));
|
|
|
|
printf(_(" -k, --dbonly only remove database entry, do not remove files\n"));
|
|
|
|
printf(_(" -n, --nosave remove configuration files as well\n"));
|
|
|
|
printf(_(" -s, --recursive remove dependencies also (that won't break packages)\n"));
|
2006-03-13 15:34:47 -05:00
|
|
|
} else if(op == PM_OP_UPGRADE) {
|
|
|
|
if(config->flags & PM_TRANS_FLAG_FRESHEN) {
|
2006-05-14 22:19:57 -04:00
|
|
|
printf(_("usage: %s {-F --freshen} [options] <file>\n"), myname);
|
2006-03-13 15:34:47 -05:00
|
|
|
} else {
|
2006-05-14 22:19:57 -04:00
|
|
|
printf(_("usage: %s {-U --upgrade} [options] <file>\n"), myname);
|
2006-03-13 15:34:47 -05:00
|
|
|
}
|
2006-05-14 22:19:57 -04:00
|
|
|
printf(_("options:\n"));
|
|
|
|
printf(_(" -d, --nodeps skip dependency checks\n"));
|
|
|
|
printf(_(" -f, --force force install, overwrite conflicting files\n"));
|
2006-03-13 15:34:47 -05:00
|
|
|
} else if(op == PM_OP_QUERY) {
|
2006-05-14 22:19:57 -04:00
|
|
|
printf(_("usage: %s {-Q --query} [options] [package]\n"), myname);
|
|
|
|
printf(_("options:\n"));
|
2006-10-15 15:34:52 -04:00
|
|
|
printf(_(" -c, --changelog view the changelog of a package\n"));
|
|
|
|
printf(_(" -e, --orphans list all packages that were installed as a dependency\n"));
|
2006-05-14 22:19:57 -04:00
|
|
|
printf(_(" and are not required by any other packages\n"));
|
|
|
|
printf(_(" -g, --groups view all members of a package group\n"));
|
|
|
|
printf(_(" -i, --info view package information\n"));
|
|
|
|
printf(_(" -l, --list list the contents of the queried package\n"));
|
2006-10-15 15:34:52 -04:00
|
|
|
printf(_(" -m, --foreign list all packages that were not found in the sync db(s)\n"));
|
2006-05-14 22:19:57 -04:00
|
|
|
printf(_(" -o, --owns <file> query the package that owns <file>\n"));
|
|
|
|
printf(_(" -p, --file pacman will query the package file [package] instead of\n"));
|
|
|
|
printf(_(" looking in the database\n"));
|
|
|
|
printf(_(" -s, --search search locally-installed packages for matching strings\n"));
|
2006-03-13 15:34:47 -05:00
|
|
|
} else if(op == PM_OP_SYNC) {
|
2006-05-14 22:19:57 -04:00
|
|
|
printf(_("usage: %s {-S --sync} [options] [package]\n"), myname);
|
|
|
|
printf(_("options:\n"));
|
|
|
|
printf(_(" -c, --clean remove old packages from cache directory (use -cc for all)\n"));
|
|
|
|
printf(_(" -d, --nodeps skip dependency checks\n"));
|
2006-10-15 15:34:52 -04:00
|
|
|
printf(_(" -e, --dependsonly install dependencies only\n"));
|
2006-05-14 22:19:57 -04:00
|
|
|
printf(_(" -f, --force force install, overwrite conflicting files\n"));
|
|
|
|
printf(_(" -g, --groups view all members of a package group\n"));
|
2006-12-01 04:32:29 -05:00
|
|
|
printf(_(" -i, --info view package information\n"));
|
2006-05-14 22:19:57 -04:00
|
|
|
printf(_(" -p, --print-uris print out URIs for given packages and their dependencies\n"));
|
|
|
|
printf(_(" -s, --search search remote repositories for matching strings\n"));
|
|
|
|
printf(_(" -u, --sysupgrade upgrade all packages that are out of date\n"));
|
|
|
|
printf(_(" -w, --downloadonly download packages but do not install/upgrade anything\n"));
|
|
|
|
printf(_(" -y, --refresh download fresh package databases from the server\n"));
|
|
|
|
printf(_(" --ignore <pkg> ignore a package upgrade (can be used more than once)\n"));
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2006-05-14 22:19:57 -04:00
|
|
|
printf(_(" --config <path> set an alternate configuration file\n"));
|
|
|
|
printf(_(" --noconfirm do not ask for anything confirmation\n"));
|
2006-10-15 15:34:52 -04:00
|
|
|
printf(_(" --ask <number> pre-specify answers for questions (see manpage)\n"));
|
2006-05-14 22:19:57 -04:00
|
|
|
printf(_(" --noprogressbar do not show a progress bar when downloading files\n"));
|
|
|
|
printf(_(" --noscriptlet do not execute the install scriptlet if there is any\n"));
|
|
|
|
printf(_(" -v, --verbose be verbose\n"));
|
|
|
|
printf(_(" -r, --root <path> set an alternate installation root\n"));
|
|
|
|
printf(_(" -b, --dbpath <path> set an alternate database location\n"));
|
2006-02-01 13:20:13 -05:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2006-10-15 15:34:52 -04:00
|
|
|
/* Version
|
|
|
|
*/
|
|
|
|
static void version()
|
|
|
|
{
|
|
|
|
printf("\n");
|
|
|
|
printf(" .--. Pacman v%s - libalpm v%s\n", PACKAGE_VERSION, PM_VERSION);
|
|
|
|
printf("/ _.-' .-. .-. .-. Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>\n");
|
|
|
|
printf("\\ '-. '-' '-' '-' & Frugalware developers <frugalware-devel@frugalware.org>\n");
|
|
|
|
printf(" '--' \n");
|
|
|
|
printf(_(" This program may be freely redistributed under\n"));
|
|
|
|
printf(_(" the terms of the GNU General Public License\n"));
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cleanup(int signum)
|
|
|
|
{
|
|
|
|
list_t *lp;
|
|
|
|
|
|
|
|
if(signum==SIGSEGV)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Internal pacman error: Segmentation fault\n"
|
2006-10-15 17:06:08 -04:00
|
|
|
"Please submit a full bug report, with the given package if appropriate.\n");
|
2006-10-15 15:34:52 -04:00
|
|
|
exit(signum);
|
2006-11-14 02:58:42 -05:00
|
|
|
} else if((signum == SIGINT) && (alpm_trans_release() == -1)
|
|
|
|
&& (pm_errno == PM_ERR_TRANS_COMMITING)) {
|
2006-10-15 15:34:52 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(signum != 0 && config->op_d_vertest == 0) {
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free alpm library resources */
|
|
|
|
if(alpm_release() == -1) {
|
|
|
|
ERR(NL, "%s\n", alpm_strerror(pm_errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free memory */
|
|
|
|
for(lp = pmc_syncs; lp; lp = lp->next) {
|
|
|
|
sync_t *sync = lp->data;
|
|
|
|
FREE(sync->treename);
|
|
|
|
}
|
|
|
|
FREELIST(pmc_syncs);
|
|
|
|
FREELIST(pm_targets);
|
|
|
|
FREECONF(config);
|
|
|
|
|
|
|
|
if(neednl) {
|
|
|
|
putchar('\n');
|
|
|
|
}
|
2006-10-31 01:41:42 -05:00
|
|
|
|
|
|
|
/* restore the cursor
|
|
|
|
printf("\033[?25h\033[?0c");
|
2006-10-15 15:34:52 -04:00
|
|
|
fflush(stdout);
|
2006-10-31 01:41:42 -05:00
|
|
|
*/
|
2006-10-15 15:34:52 -04:00
|
|
|
|
|
|
|
exit(signum);
|
|
|
|
}
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
/* Parse command-line arguments for each operation
|
|
|
|
* argc: argc
|
|
|
|
* argv: argv
|
|
|
|
*
|
|
|
|
* Returns: 0 on success, 1 on error
|
|
|
|
*/
|
2006-03-13 15:34:47 -05:00
|
|
|
static int parseargs(int argc, char *argv[])
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
|
|
|
int opt;
|
|
|
|
int option_index = 0;
|
|
|
|
static struct option opts[] =
|
|
|
|
{
|
|
|
|
{"add", no_argument, 0, 'A'},
|
2005-03-25 17:37:13 -05:00
|
|
|
{"resolve", no_argument, 0, 'D'}, /* used by 'makepkg -s' */
|
2005-03-14 20:51:43 -05:00
|
|
|
{"freshen", no_argument, 0, 'F'},
|
|
|
|
{"query", no_argument, 0, 'Q'},
|
2005-03-25 17:37:13 -05:00
|
|
|
{"remove", no_argument, 0, 'R'},
|
2005-03-14 20:51:43 -05:00
|
|
|
{"sync", no_argument, 0, 'S'},
|
2005-03-25 17:37:13 -05:00
|
|
|
{"deptest", no_argument, 0, 'T'}, /* used by makepkg */
|
|
|
|
{"upgrade", no_argument, 0, 'U'},
|
2005-03-14 20:51:43 -05:00
|
|
|
{"version", no_argument, 0, 'V'},
|
2005-03-25 17:37:13 -05:00
|
|
|
{"vertest", no_argument, 0, 'Y'}, /* does the same as the 'vercmp' binary */
|
|
|
|
{"dbpath", required_argument, 0, 'b'},
|
|
|
|
{"cascade", no_argument, 0, 'c'},
|
2006-10-15 15:34:52 -04:00
|
|
|
{"changelog", no_argument, 0, 'c'},
|
2005-03-14 20:51:43 -05:00
|
|
|
{"clean", no_argument, 0, 'c'},
|
|
|
|
{"nodeps", no_argument, 0, 'd'},
|
2006-10-15 15:34:52 -04:00
|
|
|
{"dependsonly",no_argument, 0, 'e'},
|
2005-03-14 20:51:43 -05:00
|
|
|
{"orphans", no_argument, 0, 'e'},
|
2005-03-25 17:37:13 -05:00
|
|
|
{"force", no_argument, 0, 'f'},
|
|
|
|
{"groups", no_argument, 0, 'g'},
|
|
|
|
{"help", no_argument, 0, 'h'},
|
|
|
|
{"info", no_argument, 0, 'i'},
|
|
|
|
{"dbonly", no_argument, 0, 'k'},
|
|
|
|
{"list", no_argument, 0, 'l'},
|
2005-03-14 20:51:43 -05:00
|
|
|
{"nosave", no_argument, 0, 'n'},
|
2005-12-13 21:23:14 -05:00
|
|
|
{"foreign", no_argument, 0, 'm'},
|
2005-03-14 20:51:43 -05:00
|
|
|
{"owns", no_argument, 0, 'o'},
|
|
|
|
{"file", no_argument, 0, 'p'},
|
2005-04-13 15:16:32 -04:00
|
|
|
{"print-uris", no_argument, 0, 'p'},
|
2005-03-25 17:37:13 -05:00
|
|
|
{"root", required_argument, 0, 'r'},
|
|
|
|
{"recursive", no_argument, 0, 's'},
|
|
|
|
{"search", no_argument, 0, 's'},
|
2005-03-14 20:51:43 -05:00
|
|
|
{"sysupgrade", no_argument, 0, 'u'},
|
2005-03-25 17:37:13 -05:00
|
|
|
{"verbose", no_argument, 0, 'v'},
|
2005-03-14 20:51:43 -05:00
|
|
|
{"downloadonly", no_argument, 0, 'w'},
|
|
|
|
{"refresh", no_argument, 0, 'y'},
|
|
|
|
{"noconfirm", no_argument, 0, 1000},
|
|
|
|
{"config", required_argument, 0, 1001},
|
2005-03-25 17:37:13 -05:00
|
|
|
{"ignore", required_argument, 0, 1002},
|
2005-05-02 03:37:55 -04:00
|
|
|
{"debug", required_argument, 0, 1003},
|
2006-01-28 00:07:50 -05:00
|
|
|
{"noprogressbar", no_argument, 0, 1004},
|
2006-03-07 13:17:03 -05:00
|
|
|
{"noscriptlet", no_argument, 0, 1005},
|
2006-10-15 15:34:52 -04:00
|
|
|
{"ask", required_argument, 0, 1006},
|
2005-03-14 20:51:43 -05:00
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
2005-05-02 03:37:55 -04:00
|
|
|
char root[PATH_MAX];
|
2006-12-05 01:55:52 -05:00
|
|
|
struct stat st = {0};
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2005-12-13 21:23:14 -05:00
|
|
|
while((opt = getopt_long(argc, argv, "ARUFQSTDYr:b:vkhscVfmnoldepiuwyg", opts, &option_index))) {
|
2005-03-14 20:51:43 -05:00
|
|
|
if(opt < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch(opt) {
|
2006-01-07 05:01:19 -05:00
|
|
|
case 0: break;
|
2005-10-28 08:20:40 -04:00
|
|
|
case 1000: config->noconfirm = 1; break;
|
2005-03-25 17:37:13 -05:00
|
|
|
case 1001:
|
2005-10-28 08:20:40 -04:00
|
|
|
if(config->configfile) {
|
|
|
|
free(config->configfile);
|
2005-04-13 15:16:32 -04:00
|
|
|
}
|
2006-10-15 15:34:52 -04:00
|
|
|
#if defined(__OpenBSD__) || defined(__APPLE__)
|
|
|
|
config->configfile = strdup(optarg);
|
|
|
|
#else
|
2005-10-28 08:20:40 -04:00
|
|
|
config->configfile = strndup(optarg, PATH_MAX);
|
2006-10-15 15:34:52 -04:00
|
|
|
#endif
|
2006-01-07 05:01:19 -05:00
|
|
|
break;
|
2005-10-28 08:20:40 -04:00
|
|
|
case 1002: config->op_s_ignore = list_add(config->op_s_ignore, strdup(optarg)); break;
|
2006-01-07 05:01:19 -05:00
|
|
|
case 1003: config->debug = atoi(optarg); break;
|
2006-01-28 00:07:50 -05:00
|
|
|
case 1004: config->noprogressbar = 1; break;
|
2006-03-07 13:17:03 -05:00
|
|
|
case 1005: config->flags |= PM_TRANS_FLAG_NOSCRIPTLET; break;
|
2006-10-15 15:34:52 -04:00
|
|
|
case 1006: config->noask = 1; config->ask = atoi(optarg); break;
|
2006-01-07 05:01:19 -05:00
|
|
|
case 'A': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_ADD); break;
|
|
|
|
case 'D':
|
|
|
|
config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_DEPTEST);
|
|
|
|
config->op_d_resolve = 1;
|
2006-01-10 13:45:32 -05:00
|
|
|
config->flags |= PM_TRANS_FLAG_ALLDEPS;
|
2006-01-07 05:01:19 -05:00
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_UPGRADE);
|
|
|
|
config->flags |= PM_TRANS_FLAG_FRESHEN;
|
|
|
|
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;
|
2005-10-28 08:20:40 -04:00
|
|
|
case 'T': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_DEPTEST); break;
|
|
|
|
case 'U': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_UPGRADE); break;
|
|
|
|
case 'V': config->version = 1; break;
|
2006-01-07 05:01:19 -05:00
|
|
|
case 'Y':
|
|
|
|
config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_DEPTEST);
|
|
|
|
config->op_d_vertest = 1;
|
|
|
|
break;
|
2005-03-25 17:37:13 -05:00
|
|
|
case 'b':
|
2006-12-05 01:55:52 -05:00
|
|
|
if(stat(optarg, &st) == -1 || !S_ISDIR(st.st_mode)) {
|
|
|
|
pm_fprintf(stderr, NL, _("error: '%s' is not a valid db path\n"), optarg);
|
|
|
|
exit(1);
|
|
|
|
}
|
2006-11-20 04:10:23 -05:00
|
|
|
alpm_option_set_dbpath(optarg);
|
|
|
|
config->dbpath = alpm_option_get_dbpath(optarg);
|
2005-03-25 17:37:13 -05:00
|
|
|
break;
|
2006-01-07 05:01:19 -05:00
|
|
|
case 'c':
|
|
|
|
config->op_s_clean++;
|
|
|
|
config->flags |= PM_TRANS_FLAG_CASCADE;
|
2006-10-15 15:34:52 -04:00
|
|
|
config->op_q_changelog = 1;
|
2006-01-07 05:01:19 -05:00
|
|
|
break;
|
2005-10-28 08:20:40 -04:00
|
|
|
case 'd': config->flags |= PM_TRANS_FLAG_NODEPS; break;
|
2006-10-15 15:34:52 -04:00
|
|
|
case 'e': config->op_q_orphans = 1; config->flags |= PM_TRANS_FLAG_DEPENDSONLY; break;
|
2005-10-28 08:20:40 -04:00
|
|
|
case 'f': config->flags |= PM_TRANS_FLAG_FORCE; break;
|
2006-01-13 16:27:25 -05:00
|
|
|
case 'g': config->group++; break;
|
2005-10-28 08:20:40 -04:00
|
|
|
case 'h': config->help = 1; break;
|
2006-01-07 05:01:19 -05:00
|
|
|
case 'i':
|
|
|
|
config->op_q_info++;
|
|
|
|
config->op_s_info++;
|
|
|
|
break;
|
2005-10-28 08:20:40 -04:00
|
|
|
case 'k': config->flags |= PM_TRANS_FLAG_DBONLY; break;
|
|
|
|
case 'l': config->op_q_list = 1; break;
|
2005-12-13 21:23:14 -05:00
|
|
|
case 'm': config->op_q_foreign = 1; break;
|
2005-10-28 08:20:40 -04:00
|
|
|
case 'n': config->flags |= PM_TRANS_FLAG_NOSAVE; break;
|
|
|
|
case 'o': config->op_q_owns = 1; break;
|
2006-01-07 05:01:19 -05:00
|
|
|
case 'p':
|
|
|
|
config->op_q_isfile = 1;
|
2006-10-15 15:34:52 -04:00
|
|
|
config->flags |= PM_TRANS_FLAG_PRINTURIS;
|
2006-01-07 05:01:19 -05:00
|
|
|
break;
|
2005-03-14 20:51:43 -05:00
|
|
|
case 'r':
|
2006-12-08 03:17:41 -05:00
|
|
|
printf("setting root path=%s\n", optarg);
|
2005-03-14 20:51:43 -05:00
|
|
|
if(realpath(optarg, root) == NULL) {
|
2006-05-14 22:19:57 -04:00
|
|
|
perror(_("bad root path"));
|
2005-03-25 17:37:13 -05:00
|
|
|
return(1);
|
|
|
|
}
|
2006-12-08 03:17:41 -05:00
|
|
|
config->root = strdup(root);
|
2005-03-14 20:51:43 -05:00
|
|
|
break;
|
2006-01-07 05:01:19 -05:00
|
|
|
case 's':
|
|
|
|
config->op_s_search = 1;
|
|
|
|
config->op_q_search = 1;
|
|
|
|
config->flags |= PM_TRANS_FLAG_RECURSE;
|
|
|
|
break;
|
2005-10-28 08:20:40 -04:00
|
|
|
case 'u': config->op_s_upgrade = 1; break;
|
|
|
|
case 'v': config->verbose++; break;
|
2006-03-04 10:33:44 -05:00
|
|
|
case 'w':
|
|
|
|
config->op_s_downloadonly = 1;
|
2006-10-15 15:34:52 -04:00
|
|
|
config->flags |= PM_TRANS_FLAG_DOWNLOADONLY;
|
2006-03-04 10:33:44 -05:00
|
|
|
config->flags |= PM_TRANS_FLAG_NOCONFLICTS;
|
|
|
|
break;
|
2006-01-17 16:30:02 -05:00
|
|
|
case 'y': config->op_s_sync++; break;
|
2005-03-14 20:51:43 -05:00
|
|
|
case '?': return(1);
|
2006-01-07 05:01:19 -05:00
|
|
|
default: return(1);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-13 15:34:47 -05:00
|
|
|
if(config->op == 0) {
|
2006-05-14 22:19:57 -04:00
|
|
|
ERR(NL, _("only one operation may be used at a time\n"));
|
2006-03-13 15:34:47 -05:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(config->help) {
|
|
|
|
usage(config->op, basename(argv[0]));
|
|
|
|
return(2);
|
|
|
|
}
|
|
|
|
if(config->version) {
|
|
|
|
version();
|
|
|
|
return(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
while(optind < argc) {
|
|
|
|
/* add the target to our target array */
|
|
|
|
pm_targets = list_add(pm_targets, strdup(argv[optind]));
|
|
|
|
optind++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int ret = 0;
|
2006-11-20 04:10:23 -05:00
|
|
|
char *lang = NULL;
|
2006-03-13 15:34:47 -05:00
|
|
|
#ifndef CYGWIN
|
|
|
|
uid_t myuid;
|
|
|
|
#endif
|
|
|
|
list_t *lp;
|
|
|
|
|
2006-11-07 11:32:48 -05:00
|
|
|
#if defined(PACMAN_DEBUG) && !defined(CYGWIN) && !defined(BSD)
|
2006-11-14 02:58:42 -05:00
|
|
|
/*setenv("MALLOC_TRACE","pacman.mtrace", 0);*/
|
2006-11-09 14:27:10 -05:00
|
|
|
mtrace();
|
2006-03-13 15:34:47 -05:00
|
|
|
#endif
|
2006-11-20 04:10:23 -05:00
|
|
|
maxcols = getcols();
|
2006-03-13 15:34:47 -05:00
|
|
|
|
|
|
|
/* set signal handlers */
|
|
|
|
signal(SIGINT, cleanup);
|
|
|
|
signal(SIGTERM, cleanup);
|
2006-10-15 15:34:52 -04:00
|
|
|
signal(SIGSEGV, cleanup);
|
2006-03-13 15:34:47 -05:00
|
|
|
|
2006-10-31 01:41:42 -05:00
|
|
|
/* hide the cursor, prevent flicker during fancy graphics
|
|
|
|
printf("\033[?25l\033[?1c");
|
|
|
|
*/
|
|
|
|
|
2006-06-28 01:37:15 -04:00
|
|
|
/* i18n init */
|
|
|
|
lang=getenv("LC_ALL");
|
|
|
|
if(lang==NULL || lang[0]=='\0')
|
|
|
|
lang=getenv("LC_MESSAGES");
|
|
|
|
if (lang==NULL || lang[0]=='\0')
|
|
|
|
lang=getenv("LANG");
|
|
|
|
|
|
|
|
setlocale(LC_ALL, lang);
|
2006-10-15 15:34:52 -04:00
|
|
|
// workaround for tr_TR
|
|
|
|
if(lang && !strcmp(lang, "tr_TR"))
|
|
|
|
setlocale(LC_CTYPE, "C");
|
2006-06-28 01:37:15 -04:00
|
|
|
bindtextdomain("pacman", "/usr/share/locale");
|
|
|
|
textdomain("pacman");
|
|
|
|
|
2006-03-13 15:34:47 -05:00
|
|
|
/* init config data */
|
|
|
|
config = config_new();
|
|
|
|
config->op = PM_OP_MAIN;
|
2006-11-02 22:56:02 -05:00
|
|
|
config->debug |= PM_LOG_ERROR;
|
2006-03-13 15:34:47 -05:00
|
|
|
config->debug |= PM_LOG_WARNING;
|
|
|
|
/* disable progressbar if the output is redirected */
|
|
|
|
if(!isatty(1)) {
|
|
|
|
config->noprogressbar = 1;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2006-03-13 15:34:47 -05:00
|
|
|
/* parse the command line */
|
|
|
|
ret = parseargs(argc, argv);
|
|
|
|
if(ret != 0) {
|
|
|
|
config_free(config);
|
|
|
|
exit(ret);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2006-03-13 15:34:47 -05:00
|
|
|
#ifndef CYGWIN
|
|
|
|
/* see if we're root or not */
|
|
|
|
myuid = geteuid();
|
|
|
|
#ifndef FAKEROOT
|
|
|
|
if(!myuid && getenv("FAKEROOTKEY")) {
|
|
|
|
/* fakeroot doesn't count, we're non-root */
|
|
|
|
myuid = 99;
|
|
|
|
}
|
|
|
|
#endif
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2006-03-13 15:34:47 -05:00
|
|
|
/* check if we have sufficient permission for the requested operation */
|
|
|
|
if(myuid > 0) {
|
|
|
|
if(config->op != PM_OP_MAIN && config->op != PM_OP_QUERY && config->op != PM_OP_DEPTEST) {
|
|
|
|
if((config->op == PM_OP_SYNC && !config->op_s_sync &&
|
2006-11-10 15:09:59 -05:00
|
|
|
(config->op_s_search || config->group || config->op_q_list || config->op_q_info
|
|
|
|
|| config->flags & PM_TRANS_FLAG_PRINTURIS))
|
2006-10-15 15:34:52 -04:00
|
|
|
|| (config->op == PM_OP_DEPTEST && !config->op_d_resolve)
|
|
|
|
|| (config->root != NULL)) {
|
|
|
|
/* special case: PM_OP_SYNC can be used w/ config->op_s_search by any user */
|
|
|
|
/* special case: ignore root user check if -r is specified, fall back on
|
|
|
|
* normal FS checking */
|
2005-03-14 20:51:43 -05:00
|
|
|
} else {
|
2006-05-14 22:19:57 -04:00
|
|
|
ERR(NL, _("you cannot perform this operation unless you are root.\n"));
|
2006-03-13 15:34:47 -05:00
|
|
|
config_free(config);
|
|
|
|
exit(1);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-03-13 15:34:47 -05:00
|
|
|
#endif
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2006-03-13 15:34:47 -05:00
|
|
|
if(config->root == NULL) {
|
2006-12-08 03:17:41 -05:00
|
|
|
config->root = strdup(PM_ROOT);
|
2006-03-13 15:34:47 -05:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2006-03-13 15:34:47 -05:00
|
|
|
/* initialize pm library */
|
2006-11-20 17:15:26 -05:00
|
|
|
if(alpm_initialize(config->root) == -1) {
|
2006-05-14 22:19:57 -04:00
|
|
|
ERR(NL, _("failed to initilize alpm library (%s)\n"), alpm_strerror(pm_errno));
|
2006-03-13 15:34:47 -05:00
|
|
|
cleanup(1);
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2006-10-15 15:34:52 -04:00
|
|
|
/* Setup logging as soon as possible, to print out maximum debugging info */
|
2006-11-20 04:10:23 -05:00
|
|
|
alpm_option_set_logmask(config->debug);
|
|
|
|
alpm_option_set_logcb(cb_log);
|
2006-10-15 15:34:52 -04:00
|
|
|
|
2006-03-13 15:34:47 -05:00
|
|
|
if(config->configfile == NULL) {
|
|
|
|
config->configfile = strdup(PACCONF);
|
|
|
|
}
|
2006-10-15 15:34:52 -04:00
|
|
|
if(alpm_parse_config(config->configfile, cb_db_register, "") != 0) {
|
|
|
|
ERR(NL, _("failed to parse config (%s)\n"), alpm_strerror(pm_errno));
|
2006-03-13 15:34:47 -05:00
|
|
|
cleanup(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set library parameters */
|
2006-11-20 04:10:23 -05:00
|
|
|
alpm_option_set_dlcb(log_progress);
|
|
|
|
|
|
|
|
config->dbpath = alpm_option_get_dbpath();
|
|
|
|
config->cachedir = alpm_option_get_cachedir();
|
2006-03-13 15:34:47 -05:00
|
|
|
|
|
|
|
for(lp = config->op_s_ignore; lp; lp = lp->next) {
|
2006-11-20 04:10:23 -05:00
|
|
|
alpm_option_add_ignorepkg(lp->data);
|
2006-03-13 15:34:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if(config->verbose > 0) {
|
2006-10-15 15:34:52 -04:00
|
|
|
printf("Root : %s\n", config->root);
|
|
|
|
printf("DBPath: %s\n", config->dbpath);
|
2006-05-14 22:19:57 -04:00
|
|
|
list_display(_("Targets:"), pm_targets);
|
2006-03-13 15:34:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Opening local database */
|
2006-10-20 02:26:55 -04:00
|
|
|
db_local = alpm_db_register("local");
|
2006-03-13 15:34:47 -05:00
|
|
|
if(db_local == NULL) {
|
2006-05-14 22:19:57 -04:00
|
|
|
ERR(NL, _("could not register 'local' database (%s)\n"), alpm_strerror(pm_errno));
|
2006-03-13 15:34:47 -05:00
|
|
|
cleanup(1);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2006-03-13 15:34:47 -05:00
|
|
|
|
|
|
|
if(list_count(pm_targets) == 0 && !(config->op == PM_OP_QUERY || (config->op == PM_OP_SYNC
|
|
|
|
&& (config->op_s_sync || config->op_s_upgrade || config->op_s_clean || config->group
|
|
|
|
|| config->op_q_list)))) {
|
2006-05-14 22:19:57 -04:00
|
|
|
ERR(NL, _("no targets specified (use -h for help)\n"));
|
2006-03-13 15:34:47 -05:00
|
|
|
cleanup(1);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2006-03-13 15:34:47 -05:00
|
|
|
|
|
|
|
/* start the requested operation */
|
|
|
|
switch(config->op) {
|
|
|
|
case PM_OP_ADD: ret = pacman_add(pm_targets); break;
|
|
|
|
case PM_OP_REMOVE: ret = pacman_remove(pm_targets); break;
|
|
|
|
case PM_OP_UPGRADE: ret = pacman_upgrade(pm_targets); break;
|
|
|
|
case PM_OP_QUERY: ret = pacman_query(pm_targets); break;
|
|
|
|
case PM_OP_SYNC: ret = pacman_sync(pm_targets); break;
|
|
|
|
case PM_OP_DEPTEST: ret = pacman_deptest(pm_targets); break;
|
|
|
|
default:
|
2006-05-14 22:19:57 -04:00
|
|
|
ERR(NL, _("no operation specified (use -h for help)\n"));
|
2006-03-13 15:34:47 -05:00
|
|
|
ret = 1;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2006-03-13 15:34:47 -05:00
|
|
|
cleanup(ret);
|
|
|
|
/* not reached */
|
|
|
|
return(0);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set ts=2 sw=2 noet: */
|