From owner-svn-src-stable@FreeBSD.ORG Mon Nov 4 13:01:30 2013 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id C6D92C36; Mon, 4 Nov 2013 13:01:30 +0000 (UTC) (envelope-from bdrewery@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id B31062416; Mon, 4 Nov 2013 13:01:30 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rA4D1UBp074112; Mon, 4 Nov 2013 13:01:30 GMT (envelope-from bdrewery@svn.freebsd.org) Received: (from bdrewery@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id rA4D1Ukn074109; Mon, 4 Nov 2013 13:01:30 GMT (envelope-from bdrewery@svn.freebsd.org) Message-Id: <201311041301.rA4D1Ukn074109@svn.freebsd.org> From: Bryan Drewery Date: Mon, 4 Nov 2013 13:01:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r257632 - stable/10/usr.sbin/pkg X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Nov 2013 13:01:30 -0000 Author: bdrewery (ports committer) Date: Mon Nov 4 13:01:29 2013 New Revision: 257632 URL: http://svnweb.freebsd.org/changeset/base/257632 Log: MFC r257505: Add -f support to 'pkg bootstrap' and 'pkg add' to force installation of pkg(8) even if already installed. This is useful if you somehow messup pkg(8) and need to reinstall from remote with it already being registered in the pkg(8) /var/db/pkg database. Also add some sanity checks to 'pkg add'. Approved by: bapt Approved by: re (glebius) Modified: stable/10/usr.sbin/pkg/pkg.7 stable/10/usr.sbin/pkg/pkg.c Directory Properties: stable/10/usr.sbin/pkg/ (props changed) Modified: stable/10/usr.sbin/pkg/pkg.7 ============================================================================== --- stable/10/usr.sbin/pkg/pkg.7 Mon Nov 4 11:59:44 2013 (r257631) +++ stable/10/usr.sbin/pkg/pkg.7 Mon Nov 4 13:01:29 2013 (r257632) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd October 30, 2013 +.Dd November 1, 2013 .Dt PKG 7 .Os .Sh NAME @@ -35,11 +35,13 @@ .Ao Ar command Ac .Nm add +.Op Fl f .Ao Pa pkg.txz Ac .Nm .Fl N .Nm bootstrap +.Op Fl f .Sh DESCRIPTION .Nm is the package management tool. @@ -55,7 +57,7 @@ The first time invoked, will bootstrap the real .Xr pkg 8 from a remote repository. -.Bl -tag -width "pkg add xxxxxxx" +.Bl -tag -width "pkg bootstrap" .It Nm Ao Ar command Ac If .Xr pkg 8 @@ -63,7 +65,7 @@ is not installed yet, it will be fetched installed, and then have the original command forwarded to it. If already installed, the command requested will be forwarded to the real .Xr pkg 8 . -.It Nm Li add Ao Pa pkg.txz Ac +.It Nm Li add Oo Fl f Oc Ao Pa pkg.txz Ac Install .Xr pkg 8 from a local package instead of fetching from remote. @@ -72,16 +74,26 @@ If a file exists and signature checking is enabled, then the signature will be verified before installing the package. +If the +.Fl f +flag is specified, then +.Xr pkg 8 +will be installed regardless if it is already installed. .It Nm Fl N Do not bootstrap, just determine if .Xr pkg 8 is actually installed or not. Returns 0 and the number of packages installed if it is, otherwise 1. -.It Nm Li bootstrap +.It Nm Li bootstrap Op Fl f Attempt to bootstrap and do not forward anything to .Xr pkg 8 after it is installed. +If the +.Fl f +flag is specified, then +.Xr pkg 8 +will be fetched and installed regardless if it is already installed. .El .Sh CONFIGURATION Configuration varies in whether it is in a repository configuration file Modified: stable/10/usr.sbin/pkg/pkg.c ============================================================================== --- stable/10/usr.sbin/pkg/pkg.c Mon Nov 4 11:59:44 2013 (r257631) +++ stable/10/usr.sbin/pkg/pkg.c Mon Nov 4 13:01:29 2013 (r257632) @@ -135,7 +135,7 @@ cleanup: } static int -install_pkg_static(const char *path, const char *pkgpath) +install_pkg_static(const char *path, const char *pkgpath, bool force) { int pstat; pid_t pid; @@ -144,7 +144,12 @@ install_pkg_static(const char *path, con case -1: return (-1); case 0: - execl(path, "pkg-static", "add", pkgpath, (char *)NULL); + if (force) + execl(path, "pkg-static", "add", "-f", pkgpath, + (char *)NULL); + else + execl(path, "pkg-static", "add", pkgpath, + (char *)NULL); _exit(1); default: break; @@ -740,7 +745,7 @@ cleanup: } static int -bootstrap_pkg(void) +bootstrap_pkg(bool force) { FILE *config; int fd_pkg, fd_sig; @@ -801,7 +806,7 @@ bootstrap_pkg(void) } if ((ret = extract_pkg_static(fd_pkg, pkgstatic, MAXPATHLEN)) == 0) - ret = install_pkg_static(pkgstatic, tmppkg); + ret = install_pkg_static(pkgstatic, tmppkg, force); snprintf(conf, MAXPATHLEN, "%s/etc/pkg.conf", getenv("LOCALBASE") ? getenv("LOCALBASE") : _LOCALBASE); @@ -866,7 +871,7 @@ pkg_query_yes_no(void) } static int -bootstrap_pkg_local(const char *pkgpath) +bootstrap_pkg_local(const char *pkgpath, bool force) { char path[MAXPATHLEN]; char pkgstatic[MAXPATHLEN]; @@ -898,7 +903,7 @@ bootstrap_pkg_local(const char *pkgpath) } if ((ret = extract_pkg_static(fd_pkg, pkgstatic, MAXPATHLEN)) == 0) - ret = install_pkg_static(pkgstatic, pkgpath); + ret = install_pkg_static(pkgstatic, pkgpath, force); cleanup: close(fd_pkg); @@ -912,12 +917,24 @@ int main(__unused int argc, char *argv[]) { char pkgpath[MAXPATHLEN]; - bool yes = false; + const char *pkgarg; + bool bootstrap_only, force, yes; + + bootstrap_only = false; + force = false; + pkgarg = NULL; + yes = false; snprintf(pkgpath, MAXPATHLEN, "%s/sbin/pkg", getenv("LOCALBASE") ? getenv("LOCALBASE") : _LOCALBASE); - if (access(pkgpath, X_OK) == -1) { + if (argc > 1 && strcmp(argv[1], "bootstrap") == 0) { + bootstrap_only = true; + if (argc == 3 && strcmp(argv[2], "-f") == 0) + force = true; + } + + if ((bootstrap_only && force) || access(pkgpath, X_OK) == -1) { /* * To allow 'pkg -N' to be used as a reliable test for whether * a system is configured to use pkg, don't bootstrap pkg @@ -928,9 +945,21 @@ main(__unused int argc, char *argv[]) config_init(); - if (argc > 2 && strcmp(argv[1], "add") == 0 && - access(argv[2], R_OK) == 0) { - if (bootstrap_pkg_local(argv[2]) != 0) + if (argc > 1 && strcmp(argv[1], "add") == 0) { + if (argc > 2 && strcmp(argv[2], "-f") == 0) { + force = true; + pkgarg = argv[3]; + } else + pkgarg = argv[2]; + if (pkgarg == NULL) { + fprintf(stderr, "Path to pkg.txz required\n"); + exit(EXIT_FAILURE); + } + if (access(pkgarg, R_OK) == -1) { + fprintf(stderr, "No such file: %s\n", pkgarg); + exit(EXIT_FAILURE); + } + if (bootstrap_pkg_local(pkgarg, force) != 0) exit(EXIT_FAILURE); exit(EXIT_SUCCESS); } @@ -948,18 +977,15 @@ main(__unused int argc, char *argv[]) if (pkg_query_yes_no() == 0) exit(EXIT_FAILURE); } - if (bootstrap_pkg() != 0) + if (bootstrap_pkg(force) != 0) exit(EXIT_FAILURE); config_finish(); - if (argv[1] != NULL && strcmp(argv[1], "bootstrap") == 0) + if (bootstrap_only) exit(EXIT_SUCCESS); - } else { - if (argv[1] != NULL && strcmp(argv[1], "bootstrap") == 0) { - printf("pkg already bootstrapped at %s\n", - pkgpath); - exit(EXIT_SUCCESS); - } + } else if (bootstrap_only) { + printf("pkg already bootstrapped at %s\n", pkgpath); + exit(EXIT_SUCCESS); } execv(pkgpath, argv);