From patchwork Wed Apr 24 17:44: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: 1089 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 C333CD9E81E9 for ; Wed, 24 Apr 2019 17:45:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on apollo X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIMWL_WL_HIGH=-0.001, 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=unavailable autolearn_force=no version=3.4.2 X-Spam-BL-Results: [127.0.9.2] Received: from orion.archlinux.org (orion.archlinux.org [88.198.91.70]) by apollo.archlinux.org (Postfix) with ESMTPS for ; Wed, 24 Apr 2019 17:45:18 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id CEB06121A1B787; Wed, 24 Apr 2019 17:45:16 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [IPv6:2a01:4f8:160:3033::2]) (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, 24 Apr 2019 17:45:16 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id BAF8E288FB; Wed, 24 Apr 2019 17:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=luna2; t=1556127916; bh=0tOau+sOsd0ft/ZZV1YqvNJqKnS+NaRYReDSGYbmzQs=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe; b=VfN0+TUIUgiI7lxZOGbs1fA7A4u+r/MY+h1XPQy+YYPEIHEhMMfiPIRxSe4DTU1oy awWsjWwkT/PM68056Q8feVc7ym3hSQJQsudIoiDKG85mJ2vc/p3bkjLdBog629HrgB n9MWXh5uOQbc9tc7ggydaqiFtQ6vJCzBkbKzHeeC8FR5xRI4M+FNYDHM6/rqP9thgj XjOls8ft0ykF6Wz+eRZdDJl6ZE9f5XFrpR6ZflHMRP5iLEZB4UsjccUykkIBLq12h/ hmfrAInOGUhYhPjiPYhXCTTnbl5yXO4VWyKBlIlND1fQhOXE2By7fmg1iPH2+cSd61 LkDPm79yUAkxsMNcfYzWduimfQJ9i25Tl4pZsyW9AdhNlqpFzuRMJ3Ev4Lr7vacukS UOBBc9bsorYpn9sTr+wUrsARBfH95y1ysuhG8Q0ZdgpKAYwR9tfxbM0viKtXv54yho Xk5yNgLtCWx77ve48uKe3qTKnNlIZGiqy1WZxnWZySM7obL2hZCWLUZ2Mbdaz6nu1n iFmih6pt4zsD0EIOVsAQgsfRnFLK4iETdpDmKtlRG0N/AtH6Da4TLdb1Amu5m4GiZg AvKWzcWlzAPb4jkZxZPv7mQM1Ly+0Dje2jWcp1raRsx7jh/VzY+yNr9DiF9m4RR9As S9onLgbnMyciY+WSYvj7UULk= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id AA3EA2354B for ; Wed, 24 Apr 2019 17:45:13 +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, 24 Apr 2019 17:45:13 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 55707121A1B785; Wed, 24 Apr 2019 17:45:05 +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 AA176121A1B784; Wed, 24 Apr 2019 17:45:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=orion; t=1556127905; bh=0tOau+sOsd0ft/ZZV1YqvNJqKnS+NaRYReDSGYbmzQs=; h=From:To:Subject:Date:In-Reply-To:References; b=CSQdOc4UlUV6P3ZMmN/2LI6sPOCtYT8RUHjf5E2unKFYQZAnkz8mnaLmzuvyX3JI+ irxVNj5KVMOmjXVlifgVwonXASgnQRl257laa8XdgVUYY0qbPejSjibzgkeLQbHB31 gJiOwB3/6hKU2QOAjDs/MZlh8WQNMs4w0iwbZE0LsbCrUEw65REnV+olfpee3OpBXs EUJiIZWLkFzz4DN0aWXmWJhMvsn9gJFLjc7rShq0ULXh1AxFDKJBL0mT1vZErR3w7D oFwQKiSQ27ezUwQx4CC2tjKFsi4LjwaMrKNThE+ihWvwlYU5CcspiJT5Kz6lQA9tj6 9mhwSLNMl0zkcnxiiyTnyyL5TZl/wbGfsHgo03nQV0lT2pMPh0UwXBD7YXp20QFzxl WYoOq9jVocmarq/nzFTI1iQf0G4j/dfB9q11yfJtguVTD7drHwz2bFtwx7mRnflXzi Uvb/SyYV08x3vSEAFK5pSiHPNvKhMITUTjS5SON9XSLYuW3smqt1msByKov87q6fCh 91ugcXk2RF1TC48KyodE/WoztdRW2nG5RMKO0y4s3F6ktggZ8viBsGw6ru3jl7tZnD LAdA+cwE8g8NW/qO27LV7CgaJrgvzSo4Kk9JYumtpweruZSGArWRJ+eQOGfspNWd7/ a2XgxMccS2DfjLaCdJDhPX70= From: Eli Schwartz To: pacman-contrib@lists.archlinux.org Subject: [pacman-contrib] [PATCH v2] checkupdates: add option to download updates using -Swu Date: Wed, 24 Apr 2019 13:44:43 -0400 Message-Id: <20190424174444.25275-1-eschwartz@archlinux.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190417175643.17431-1-eschwartz@archlinux.org> References: <20190417175643.17431-1-eschwartz@archlinux.org> 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 --- v2: do not rely on libmakepkg, yet -- cf. discussion re: datarootdir vs. getting libmakepkgdir from pkg-config. src/checkupdates.sh.in | 61 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/src/checkupdates.sh.in b/src/checkupdates.sh.in index 1d01fda..8eb6e21 100644 --- a/src/checkupdates.sh.in +++ b/src/checkupdates.sh.in @@ -21,19 +21,51 @@ declare -r myname='checkupdates' declare -r myver='@PACKAGE_VERSION@' +DOWNLOAD_CACHE=0 + m4_include(../lib/output_format.sh) m4_include(../lib/term_colors.sh) +m4_include(../lib/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 +89,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: