From patchwork Wed Apr 17 17:56:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eli Schwartz X-Patchwork-Id: 1084 Return-Path: Delivered-To: patchwork@archlinux.org Received: from apollo.archlinux.org (localhost [127.0.0.1]) by apollo.archlinux.org (Postfix) with ESMTP id 95544D62BC34 for ; Wed, 17 Apr 2019 17:57:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on apollo X-Spam-Level: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00=-1, DKIMWL_WL_HIGH=-0.024,DKIM_SIGNED=0.1,DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_MED=-2.3, T_DMARC_POLICY_NONE=0.01 autolearn=ham autolearn_force=no version=3.4.2 X-Spam-BL-Results: [127.0.9.2] Received: from orion.archlinux.org (orion.archlinux.org [IPv6:2a01:4f8:160:6087::1]) by apollo.archlinux.org (Postfix) with ESMTPS for ; Wed, 17 Apr 2019 17:57:04 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 385BC11FD894EF; Wed, 17 Apr 2019 17:57:03 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [5.9.250.164]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits)) (No client certificate requested) by orion.archlinux.org (Postfix) with ESMTPS; Wed, 17 Apr 2019 17:57:03 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 269BF20867; Wed, 17 Apr 2019 17:57:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=luna2; t=1555523823; bh=hokofDgD7sHdikkck1DAINexSzCocqcf8ZD+EUrJmZM=; h=From:To:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe; b=IlUEa5Bu/eTyU7D6/fMVSNfZQl50TtR5u2KZkFbUpOl0ggjsRfnMBdy99Ctp6Cl2G 0wkRIJsMF2+i13qbsrMJyLaLeSDkYyU0Svec7EcK5eJtKKhrVk92PBQXycj2SvX8GG M2KwqS3TnfUTMyriMNnoea6jn1u98SnSpiVldhKs9HWFy4uPWHvzaXaA5zWneUEnj8 TzMfAus/kfQzvNGPhs9qN69kobhT3/WwiFKEwe+T72mgdBvJ43DssKN7ffQjlFrool lH2wroS5cy3BqTXt6btH90dT1rGPXXjSHGz64WO61Yd+AxqvHcNhz/IK3orsgg8ThR 9lL07krMzCjtObQmm1tVncAU8iU8c3xUHofCGyUYN7J1diFIm18t9mnM/F1lF20yd5 r3ZJCt3Nn88OPI27OzLd4xn473P5+Lc8U6EUybF72NGg2c/R0nvtVw8hoLEyHb0DNG DdE57QRz5i3ie56XcAxI+8w1UKkj0LoQ//SjNRfjR16FYW7weVW1i7i67En59gb3oO dyL1F6hrJy6FH2P98QHLxFucAWb1nJ+Uj7AuxH5IyA2u/P8DbeoRLFLBnMLluXUb4p g3JbRl4o2glQDLoNfSfDywovW2VaP+l53OYAd7W/hcC3wdENS4JsEkrBvUwABgWV+O elxoaMWGLNa3Uy51egZdjVXE= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 40853207DC for ; Wed, 17 Apr 2019 17:57:01 +0000 (UTC) Received: from orion.archlinux.org (orion.archlinux.org [IPv6:2a01:4f8:160:6087::1]) by luna.archlinux.org (Postfix) with ESMTPS for ; Wed, 17 Apr 2019 17:57:01 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 4AAB011FD894D6; Wed, 17 Apr 2019 17:56:59 +0000 (UTC) Received: from didactylos.attlocal.net (unknown [IPv6:2600:1700:57f0:ca20:763a:c795:fcf6:91ea]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: eschwartz) by orion.archlinux.org (Postfix) with ESMTPSA id B39FC11FD894CE; Wed, 17 Apr 2019 17:56:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=orion; t=1555523819; bh=hokofDgD7sHdikkck1DAINexSzCocqcf8ZD+EUrJmZM=; h=From:To:Subject:Date; b=kq4pcEBkNXdZuE1DvctvNDHHxd5768OuWDv6kw0ajRgfIFSM9XWIDIlMyMEWLhNIp hclWhIJLuSRlztbFqcGG9cv1yTs8MpOuYbog8OXvvI4cfx6s2DvgHzzcfTE4HrN1R9 w2N3rvg0NQSxgLZdrl35JWls6SXWakgweK1Lfua8wRl4ABIPFFx5QrRdl22KYJZJ3d 1MuzLl9rzf1HACeO1jWEF/qyq19eBsnQk0wc7itbJ5nsw920eSBiUtbH8bfRB9fity IB9OgNm3foFF0ZA2NnV7GLyTmphVOyAbDn4myo7UqhtmEcXG5GnJynrvc3K4Txm6Vv dN1M4Ey1DMQvUCIVijQsJ/ZgE+dY2gplidQTRbV9tKE+UMnCzz6OOSDVP8W+6eRRx4 O4pKxBy2ooZrfyMoS5R2FDJxikW9h/eVReDguW0L+YrmRjaZ286A4SSquPI16M/tCR fsL+N4/ID6t36GI8Df+kTddENxFdfRhyZtVRCvulYVHcDroO7btGHs5jMcpm921NQd gAdbsau3kWyYsNZYcdlOCsfIuciZW5AwN/cTkFA+QGsWqDXSj7x/NVUBDOFtqYXk66 pevol7JJWZIQ0ngEBsrC6Jc8Eq2jsWgNvpF95WMxz+nTuhryGC2nlq22n+l8gFgi3x QVtY/KFzmLSku8M4jTm/9ZrU= From: Eli Schwartz To: pacman-contrib@lists.archlinux.org Subject: [pacman-contrib] [PATCH] checkupdates: add option to download updates using -Swu Date: Wed, 17 Apr 2019 13:56:43 -0400 Message-Id: <20190417175643.17431-1-eschwartz@archlinux.org> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-BeenThere: pacman-contrib@lists.archlinux.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for pacman-contrib development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: pacman-contrib-bounces@lists.archlinux.org Sender: "pacman-contrib" This is safer than -Sywu, and should be included here for the same reason we wish to encourage people not to use -Sy && -Qu. Since an option was added, we now need option parsing, so I converted over to using parseopts. Signed-off-by: Eli Schwartz --- requires libmakepkg port src/checkupdates.sh.in | 64 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 11 deletions(-) diff --git a/src/checkupdates.sh.in b/src/checkupdates.sh.in index 1d01fda..ed7cf28 100644 --- a/src/checkupdates.sh.in +++ b/src/checkupdates.sh.in @@ -21,19 +21,54 @@ declare -r myname='checkupdates' declare -r myver='@PACKAGE_VERSION@' +LIBRARY=${LIBRARY:-'@datarootdir@/makepkg'} + +DOWNLOAD_CACHE=0 + m4_include(../lib/output_format.sh) m4_include(../lib/term_colors.sh) +# Import libmakepkg +source "$LIBRARY"/util/parseopts.sh + +usage() { + cat << __EOF__ +${myname} v${myver} + +Safely print a list of pending updates + +Usage: ${myname} [options] + + Options: + -d, --download download pending updates to the pacman cache. + -h, --help display this help message and exit. + +Note: Export the "CHECKUPDATES_DB" variable to change the path of the temporary database. -if (( $# > 0 )); then - echo "${myname} v${myver}" - echo - echo "Safely print a list of pending updates" - echo - echo "Usage: ${myname}" - echo - echo 'Note: Export the "CHECKUPDATES_DB" variable to change the path of the temporary database.' - exit 0 +__EOF__ +} + +OPT_SHORT='dh' +OPT_LONG=('download' 'help') + +if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then + exit 1 fi +set -- "${OPTRET[@]}" +unset OPT_SHORT OPT_LONG OPTRET + +while :; do + case $1 in + -d|--download) + DOWNLOAD_CACHE=1 ;; + -h|--help) + usage + exit 0 ;; + --) + shift + break ;; + esac + shift +done if ! type -P fakeroot >/dev/null; then error 'Cannot find the fakeroot binary.' @@ -57,8 +92,15 @@ if ! fakeroot -- pacman -Sy --dbpath "$CHECKUPDATES_DB" --logfile /dev/null &> / error 'Cannot fetch updates' exit 1 fi -pacman -Qu --dbpath "$CHECKUPDATES_DB" 2> /dev/null | grep -v '\[.*\]' +mapfile -t updates < <(pacman -Qu --dbpath "$CHECKUPDATES_DB" 2> /dev/null | grep -v '\[.*\]') -exit 0 +if (( ${#updates[@]} )); then + printf '%s\n' "${updates[@]}" + if (( DOWNLOAD_CACHE )); then + sudo pacman -Sw --noconfirm "${updates[@]%% *}" --dbpath "$CHECKUPDATES_DB" --logfile /dev/null + fi +else + exit 1 +fi # vim: set noet: