diff --git a/usr.sbin/pkg_install/create/main.c b/usr.sbin/pkg_install/create/main.c index 0ff82342919e..b98b21ee9db1 100644 --- a/usr.sbin/pkg_install/create/main.c +++ b/usr.sbin/pkg_install/create/main.c @@ -1,259 +1,263 @@ /* * FreeBSD install - a package for the installation and maintainance * of non-core utilities. * * Jordan K. Hubbard * 18 July 1993 * * This is the create module. * */ #include __FBSDID("$FreeBSD$"); #include #include #include "lib.h" #include "create.h" match_t MatchType = MATCH_GLOB; char *Prefix = NULL; char *Comment = NULL; char *Desc = NULL; char *SrcDir = NULL; char *BaseDir = NULL; char *Display = NULL; char *Install = NULL; char *PostInstall = NULL; char *DeInstall = NULL; char *PostDeInstall = NULL; char *Contents = NULL; char *Require = NULL; char *ExcludeFrom = NULL; char *Mtree = NULL; char *Pkgdeps = NULL; char *Conflicts = NULL; char *Origin = NULL; char *InstalledPkg = NULL; char PlayPen[FILENAME_MAX]; int Dereference = FALSE; int PlistOnly = FALSE; int Recursive = FALSE; int Regenerate = TRUE; int Help = FALSE; enum zipper Zipper = BZIP2; static void usage(void); static char opts[] = "EGYNnORhjvxyzf:p:P:C:c:d:i:I:k:K:r:t:X:D:m:s:S:o:b:"; static struct option longopts[] = { { "backup", required_argument, NULL, 'b' }, { "extended", no_argument, NULL, 'E' }, { "help", no_argument, &Help, TRUE }, { "no", no_argument, NULL, 'N' }, { "no-glob", no_argument, NULL, 'G' }, { "origin", required_argument, NULL, 'o' }, { "plist-only", no_argument, NULL, 'O' }, { "prefix", required_argument, NULL, 'p' }, { "recursive", no_argument, NULL, 'R' }, { "regex", no_argument, NULL, 'x' }, { "template", required_argument, NULL, 't' }, { "verbose", no_argument, NULL, 'v' }, { "yes", no_argument, NULL, 'Y' }, { NULL, 0, NULL, 0 }, }; int main(int argc, char **argv) { int ch; char **pkgs, **start, *tmp; pkgs = start = argv; while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1) switch(ch) { case 'v': Verbose++; break; case 'x': MatchType = MATCH_REGEX; break; case 'E': MatchType = MATCH_EREGEX; break; case 'G': MatchType = MATCH_EXACT; break; case 'N': AutoAnswer = NO; break; case 'Y': AutoAnswer = YES; break; case 'O': PlistOnly = TRUE; break; case 'p': Prefix = optarg; break; case 's': SrcDir = optarg; break; case 'S': BaseDir = optarg; break; case 'f': Contents = optarg; break; case 'C': Conflicts = optarg; break; case 'c': Comment = optarg; break; case 'd': Desc = optarg; break; case 'i': Install = optarg; break; case 'I': PostInstall = optarg; break; case 'k': DeInstall = optarg; break; case 'K': PostDeInstall = optarg; break; case 'r': Require = optarg; break; case 't': strlcpy(PlayPen, optarg, sizeof(PlayPen)); break; case 'X': ExcludeFrom = optarg; break; case 'h': Dereference = TRUE; break; case 'D': Display = optarg; break; case 'm': Mtree = optarg; break; case 'P': Pkgdeps = optarg; break; case 'o': Origin = optarg; break; case 'y': case 'j': Zipper = BZIP2; break; case 'z': Zipper = GZIP; break; case 'b': InstalledPkg = optarg; while ((tmp = strrchr(optarg, (int)'/')) != NULL) { *tmp++ = '\0'; /* * If character after the '/' is alphanumeric, then we've * found the package name. Otherwise we've come across * a trailing '/' and need to continue our quest. */ if (isalpha(*tmp)) { InstalledPkg = tmp; break; } } break; case 'R': Recursive = TRUE; break; + case 'n': + Regenerate = FALSE; + break; + case 0: if (Help) usage(); break; default: usage(); break; } argc -= optind; argv += optind; /* Get all the remaining package names, if any */ while (*argv) *pkgs++ = *argv++; /* If no packages, yelp */ if ((pkgs == start) && (InstalledPkg == NULL)) warnx("missing package name"), usage(); *pkgs = NULL; if ((start[0] != NULL) && (start[1] != NULL)) { warnx("only one package name allowed ('%s' extraneous)", start[1]); usage(); } if (start[0] == NULL) start[0] = InstalledPkg; if (!pkg_perform(start)) { if (Verbose) warnx("package creation failed"); return 1; } else return 0; } static void usage() { fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n", "usage: pkg_create [-YNOhjnvyz] [-C conflicts] [-P pkgs] [-p prefix]", " [-i iscript] [-I piscript] [-k dscript] [-K pdscript]", " [-r rscript] [-s srcdir] [-S basedir]", " [-t template] [-X excludefile]", " [-D displayfile] [-m mtreefile] [-o originpath]", " -c comment -d description -f packlist pkg-filename", " pkg_create [-EGYNRhnvxy] -b pkg-name [pkg-filename]"); exit(1); } diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h index 545cd3c9e5bb..d4632577c87c 100644 --- a/usr.sbin/pkg_install/lib/lib.h +++ b/usr.sbin/pkg_install/lib/lib.h @@ -1,248 +1,248 @@ /* $FreeBSD$ */ /* * FreeBSD install - a package for the installation and maintainance * of non-core utilities. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Jordan K. Hubbard * 18 July 1993 * * Include and define various things wanted by the library routines. * */ #ifndef _INST_LIB_LIB_H_ #define _INST_LIB_LIB_H_ /* Includes */ #include #include #include #include #include #include #include #include #include #include #include /* Macros */ #define SUCCESS (0) #define FAIL (-1) #ifndef TRUE #define TRUE (1) #endif #ifndef FALSE #define FALSE (0) #endif #define YES 2 #define NO 1 /* Usually "rm", but often "echo" during debugging! */ #define REMOVE_CMD "/bin/rm" /* Usually "rm", but often "echo" during debugging! */ #define RMDIR_CMD "/bin/rmdir" /* Where the ports lives by default */ #define DEF_PORTS_DIR "/usr/ports" /* just in case we change the environment variable name */ #define PORTSDIR "PORTSDIR" /* macro to get name of directory where the ports lives */ #define PORTS_DIR (getenv(PORTSDIR) ? getenv(PORTSDIR) : DEF_PORTS_DIR) /* Where we put logging information by default, else ${PKG_DBDIR} if set */ #define DEF_LOG_DIR "/var/db/pkg" /* just in case we change the environment variable name */ #define PKG_DBDIR "PKG_DBDIR" /* macro to get name of directory where we put logging information */ #define LOG_DIR (getenv(PKG_DBDIR) ? getenv(PKG_DBDIR) : DEF_LOG_DIR) /* The names of our "special" files */ #define CONTENTS_FNAME "+CONTENTS" #define COMMENT_FNAME "+COMMENT" #define DESC_FNAME "+DESC" #define INSTALL_FNAME "+INSTALL" #define POST_INSTALL_FNAME "+POST-INSTALL" #define DEINSTALL_FNAME "+DEINSTALL" #define POST_DEINSTALL_FNAME "+POST-DEINSTALL" #define REQUIRE_FNAME "+REQUIRE" #define REQUIRED_BY_FNAME "+REQUIRED_BY" #define DISPLAY_FNAME "+DISPLAY" #define MTREE_FNAME "+MTREE_DIRS" #if defined(__FreeBSD_version) && __FreeBSD_version >= 800000 #define INDEX_FNAME "INDEX-8" #elif defined(__FreeBSD_version) && __FreeBSD_version >= 700000 #define INDEX_FNAME "INDEX-7" #elif defined(__FreeBSD_version) && __FreeBSD_version >= 600000 #define INDEX_FNAME "INDEX-6" #elif defined(__FreeBSD_version) && __FreeBSD_version >= 500036 #define INDEX_FNAME "INDEX-5" #else #define INDEX_FNAME "INDEX" #endif #define CMD_CHAR '@' /* prefix for extended PLIST cmd */ /* The name of the "prefix" environment variable given to scripts */ #define PKG_PREFIX_VNAME "PKG_PREFIX" /* * Version of the package tools - increase only when some * functionality used by bsd.port.mk is changed, added or removed */ -#define PKG_INSTALL_VERSION 20080612 +#define PKG_INSTALL_VERSION 20080708 #define PKG_WRAPCONF_FNAME "/var/db/pkg_install.conf" #define main(argc, argv) real_main(argc, argv) /* Version numbers to assist with changes in package file format */ #define PLIST_FMT_VER_MAJOR 1 #define PLIST_FMT_VER_MINOR 1 enum _plist_t { PLIST_FILE, PLIST_CWD, PLIST_CMD, PLIST_CHMOD, PLIST_CHOWN, PLIST_CHGRP, PLIST_COMMENT, PLIST_IGNORE, PLIST_NAME, PLIST_UNEXEC, PLIST_SRC, PLIST_DISPLAY, PLIST_PKGDEP, PLIST_CONFLICTS, PLIST_MTREE, PLIST_DIR_RM, PLIST_IGNORE_INST, PLIST_OPTION, PLIST_ORIGIN, PLIST_DEPORIGIN, PLIST_NOINST }; typedef enum _plist_t plist_t; enum _match_t { MATCH_ALL, MATCH_EXACT, MATCH_GLOB, MATCH_NGLOB, MATCH_EREGEX, MATCH_REGEX }; typedef enum _match_t match_t; /* Types */ typedef unsigned int Boolean; struct _plist { struct _plist *prev, *next; char *name; Boolean marked; plist_t type; }; typedef struct _plist *PackingList; struct _pack { struct _plist *head, *tail; const char *name; const char *origin; int fmtver_maj, fmtver_mnr; }; typedef struct _pack Package; struct reqr_by_entry { STAILQ_ENTRY(reqr_by_entry) link; char pkgname[PATH_MAX]; }; STAILQ_HEAD(reqr_by_head, reqr_by_entry); /* Prototypes */ /* Misc */ int vsystem(const char *, ...); char *vpipe(const char *, ...); void cleanup(int); char *make_playpen(char *, off_t); char *where_playpen(void); void leave_playpen(void); off_t min_free(const char *); /* String */ char *get_dash_string(char **); char *copy_string(const char *); char *copy_string_adds_newline(const char *); Boolean suffix(const char *, const char *); void nuke_suffix(char *); void str_lowercase(char *); char *strconcat(const char *, const char *); char *get_string(char *, int, FILE *); /* File */ Boolean fexists(const char *); Boolean isdir(const char *); Boolean isemptydir(const char *fname); Boolean isemptyfile(const char *fname); Boolean isfile(const char *); Boolean isempty(const char *); Boolean issymlink(const char *); Boolean isURL(const char *); char *fileGetURL(const char *, const char *, int); char *fileFindByPath(const char *, const char *); char *fileGetContents(const char *); void write_file(const char *, const char *); void copy_file(const char *, const char *, const char *); void move_file(const char *, const char *, const char *); void copy_hierarchy(const char *, const char *, Boolean); int delete_hierarchy(const char *, Boolean, Boolean); int unpack(const char *, const char *); void format_cmd(char *, int, const char *, const char *, const char *); /* Msg */ void upchuck(const char *); void barf(const char *, ...); void whinge(const char *, ...); Boolean y_or_n(Boolean, const char *, ...); /* Packing list */ PackingList new_plist_entry(void); PackingList last_plist(Package *); PackingList find_plist(Package *, plist_t); char *find_plist_option(Package *, const char *name); void plist_delete(Package *, Boolean, plist_t, const char *); void free_plist(Package *); void mark_plist(Package *); void csum_plist_entry(char *, PackingList); void add_plist(Package *, plist_t, const char *); void add_plist_top(Package *, plist_t, const char *); void delete_plist(Package *pkg, Boolean all, plist_t type, const char *name); void write_plist(Package *, FILE *); void read_plist(Package *, FILE *); int plist_cmd(const char *, char **); int delete_package(Boolean, Boolean, Package *); Boolean make_preserve_name(char *, int, const char *, const char *); /* For all */ int pkg_perform(char **); int real_main(int, char **); /* Query installed packages */ char **matchinstalled(match_t, char **, int *); char **matchbyorigin(const char *, int *); char ***matchallbyorigin(const char **, int *); int isinstalledpkg(const char *name); int pattern_match(match_t MatchType, char *pattern, const char *pkgname); /* Dependencies */ int sortdeps(char **); int chkifdepends(const char *, const char *); int requiredby(const char *, struct reqr_by_head **, Boolean, Boolean); /* Version */ int verscmp(Package *, int, int); int version_cmp(const char *, const char *); /* Externs */ extern Boolean Quiet; extern Boolean Fake; extern Boolean Force; extern int AutoAnswer; extern int Verbose; #endif /* _INST_LIB_LIB_H_ */