From owner-freebsd-current@FreeBSD.ORG Thu Aug 30 21:28:36 2012 Return-Path: Delivered-To: current@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2A9EA106566B; Thu, 30 Aug 2012 21:28:36 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 0A73D8FC0C; Thu, 30 Aug 2012 21:28:36 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q7ULSZqJ063210; Thu, 30 Aug 2012 21:28:35 GMT (envelope-from bapt@FreeBSD.org) Received: (from bapt@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q7ULSZOI063209; Thu, 30 Aug 2012 21:28:35 GMT (envelope-from bapt@FreeBSD.org) X-Authentication-Warning: freefall.freebsd.org: bapt set sender to bapt@FreeBSD.org using -f Date: Thu, 30 Aug 2012 23:28:33 +0200 From: Baptiste Daroussin To: John Nielsen Message-ID: <20120830212833.GN64447@ithaqua.etoilebsd.net> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="N/GrjenRD+RJfyz+" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Cc: "ports@freebsd.org" , "current@freebsd.org" Subject: Re: Script to set/unset "automatic" status in PKGNG database X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Aug 2012 21:28:36 -0000 --N/GrjenRD+RJfyz+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Thank you, Would you mind adding create a patch against the git tree of pkgng so that = we can include your script into the scripts subdirectory, so that we provide y= our script along with the next pkg 1.0.1 as a contributed script? regards, Bapt On Thu, Aug 30, 2012 at 03:19:59PM -0600, John Nielsen wrote: > I today noticed the "pkg autoremove" command for the first time, which do= es much the same thing as pkg_cutleaves but relies on the "automatic" flag = in the pkgng database rather than user input to determine which "leaf" port= s can be removed. Unfortunately, the pkg2ng utility has no way of knowing w= hich old-style packages it converts were installed automatically as depende= ncies, so they are all marked as non-automatic (i.e. user-requested). In my= case, this was not true for the majority of installed ports. Since I reall= y like this functionality, I decided to update my local package database to= match my preferences. >=20 > Having succeeded, I decided a tool to make doing so easy could well benef= it others (as well as my future self). (Plus I wanted an excuse to play wit= h dialog(1) and "pkg query" a bit.) So here's the result. I'm not too attac= hed to the name. It shouldn't eat your package database or steal your lunch= money, but I'm not responsible if it does. Other than that, feedback is we= lcome. >=20 >=20 > JN > #!/bin/sh >=20 > # Copyright (c) 2012 John Nielsen >=20 > # This script presents a checklist of all PKGNG packages registered on > # the system, showing for each whether or not it is marked as "automatic" > # (i.e. not explicitly requested by the user). Any changes are recorded > # in the PKGNG database. I wrote it to make "pkg autoremove" useful > # following a pkg2ng migration, but other uses are conceivable. >=20 > # The PKGNG database file to use > DB=3D/var/db/pkg/local.sqlite >=20 > # Terminal geometry > sz=3D`stty size` > rows=3D`echo ${sz} | cut -d ' ' -f 1` > cols=3D`echo ${sz} | cut -d ' ' -f 2` > drows=3D$(( ${rows} - 3 )) > dcols=3D$(( ${cols} - 6 )) >=20 > # Dialog results are stored here > tmpfile=3D`mktemp -t set_pkg_auto` >=20 > # We always want the same style checklist > export DIALOGOPTS=3D"--extra-button --extra-label \"Select All\" --cancel= -label \"Deselect All\" --help-button --help-label Exit --separator ," >=20 > # Exit with an error message > die() { > rm -f ${tmpfile} > echo "${1}" > exit 1 > } >=20 > # Don't leave tmpfile behind even if we are killed/interrupted > trap "die \"Interrupt received.\"" 2 15 >=20 > # Run dialog to present the checklist and save the results in tmpfile > run_dialog() { > dialog --checklist "Select packages to consider for auto-removal" ${drow= s} ${dcols} ${drows} $* 2>${tmpfile} > return $? > } >=20 > # Show the current status from the package database in the checklist > select_current() { > run_dialog `pkg query '%n %o %a' | sed -e 's/1$/on/g' -e 's/0$/off/g'` > return $? > } >=20 > # Select all packages in the checklist > select_all() { > run_dialog `pkg query '%n %o' | sed -e 's/$/ on/g'` > return $? > } >=20 > # De-select all packages in the checklist > select_none() { > run_dialog `pkg query '%n %o' | sed -e 's/$/ off/g'` > return $? > } >=20 > # Update the package database to match selections in the specified file > do_update() { > autopkgs=3D`sed -e "s/^,//g" -e "s/\"/'/g" ${1}` > sqlite3 ${DB} "update packages set automatic=3D1 where name in (${autopk= gs});" \ > || die "SQlite error." > sqlite3 ${DB} "update packages set automatic=3D0 where name not in (${au= topkgs});" \ > || die "SQlite error." > } >=20 > # Run select_current for the first checklist > pkgset=3Dcurrent >=20 > # Show the checklist until "OK" or "Exit" is selected > while : ; do > select_${pkgset} > case $? in > 0) # OK, continue with updates > break; > ;; > 3) # Extra (Select all), show the checklist again > pkgset=3Dall > ;; > 1) # Cancel (Deselect all), show the checklist again > pkgset=3Dnone > ;; > *) # 4-Help (Exit) or ESC or error, exit. > die "No changes made." > ;; > esac > done >=20 > # If we got this far then tmpfile has a list of 'automatic' packages > do_update ${tmpfile} >=20 > # Clean up > rm -f ${tmpfile} > echo "Updated successfully." >=20 >=20 > _______________________________________________ > freebsd-ports@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-ports > To unsubscribe, send any mail to "freebsd-ports-unsubscribe@freebsd.org" --N/GrjenRD+RJfyz+ Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (FreeBSD) iEYEARECAAYFAlA/2wEACgkQ8kTtMUmk6ExDPwCfUmDtmvex/QO/hW82E+bIIqc0 nN4An0gA9W9fRW7yq0B33WU+OPEAj3oH =a0Ur -----END PGP SIGNATURE----- --N/GrjenRD+RJfyz+--