From patchwork Wed Oct 23 06:13:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eli Schwartz X-Patchwork-Id: 1292 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 80BFF149A1503 for ; Wed, 23 Oct 2019 06:14:27 +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,SPF_HELO_NONE=0.001, 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 [IPv6:2a01:4f8:160:6087::1]) by apollo.archlinux.org (Postfix) with ESMTPS for ; Wed, 23 Oct 2019 06:14:26 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 67AD91609AECEC; Wed, 23 Oct 2019 06:14:25 +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, 23 Oct 2019 06:14:25 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 5850F2CF59; Wed, 23 Oct 2019 06:14:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=luna2; t=1571811265; bh=jsgXPXw1s/UPFYTLz5l0hYBVlLU98d2zwdTcZhrHCeE=; h=From:To:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe; b=nvgHKt/YnOiOyIaOAUofDjQG+SnCLiaspjwnZhl0TsXni0yXsVD/myj7nrl5dfNet 8YMfKySt4D2g/1ke8T8/2zNFAbPaC/qx4AMy2srnUt0dmhPtrQCj4M0TeF52VOT6RK pXnJCziR/FqcRywchcnGcT9/l3Vn79kh7STwxcf62JFnU66rzNSCbCAC8WtjVW02Ki JNpxqDy9M8qoonDYAkki9JdkALJBi+QkEt74IyFb7RvVM6ponZMtMC/W0sBs8hmdIM dNbn8jGcQNSvKHBhM7kbpxBMxKJ3zfmgams32WyOTvgD/lhcgcfGdxmg3gS/xkkBJv 6H/w8XJOV9JBlXf9zIIdtwR2qKXGNS02yqvZlq5iguE8vwOn5GhSYbDbxpiqFwkw+j dWgf3Ngp9SBS7rWb3fHTXa82CinMGZ0KQaB/lyDP7LsGo/1TG4xbDf6aBGLKpG3/0u jL4teNP7K8Ann4fHG2UZvSrN/TlziieGTthCFOMbFiPIscS82ejwiNJDMErVQS7MBh icsUlM2WDEZ2S+qu7bJEwNn4aLfEgC7dg5yZpMR0F+6Qo1RfbvfNTS8hCWgwU9C0AX uZlTQkr08izVY0kCDA3+QahBzomZLQB1xCLYNaySQW8Zsle01eurdrIuvArRYqyF3P qZL5cr00XCO7sX2KSsVGn568= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 1B2982CF59 for ; Wed, 23 Oct 2019 06:14:21 +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, 23 Oct 2019 06:14:21 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id D05091609AECD7; Wed, 23 Oct 2019 06:14:16 +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 0413A1609AECD6; Wed, 23 Oct 2019 06:14:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=orion; t=1571811256; bh=jsgXPXw1s/UPFYTLz5l0hYBVlLU98d2zwdTcZhrHCeE=; h=From:To:Subject:Date; b=VOv17u8/culmjASaXZTXdtcfceicDkvd64hDrCqZknizKRdqfquLCJQOPN/GbUlV9 C0wT5+IrRK6L2xF9GFF3QlPcj3V6b7oxgxuuee+SBVddByMPDaG84HDk66QhoLdL9a 3qnS6E9MdDmbGU1zyk5WY8rORUEauRaaM+hKmN/FFwti2L10SC0M+ODhMQvcHgBBOs KCOat/Kx94vwqqb5Ef533Ny9Wbq/LyEa1f1OjH1UQXqszvc0bDIKDKLwDoV+1bmQRR 8zbcSo+S2AdlkPtZNc8bPP7O07Uww5vTbFWLjQVuH1/SAknsWTm9xOXflBqvLGOlig JpVwjaWDpI9JYkOa8n64vqMuewGxeTDuO/gRNeGPzeVyAnyGp0QGoZaZYgB3hnml+Q XrqkI4MnRv9A3NeR43LAwe8fuS3OqIoP7QMMdfjMAa2uSCY+RtNZANm+ktSniUUjfZ zb666Z1UR86dwubxA1Qxs6yFBA2LP/Rk+t2lVhMNNpOt9i6rtDc39jbillN+n+740T 44hdCyW7oAdyN1dDF9kJ3331uCLeTR+ZIbXOjzJL2gjNTsmo6XcM6dcmxPX3kzweOB lM3yeO5oYcGQoQ8OMGJqIN5dawMm+Xn5SBmI/oJisTcNyovkUuNHyFBFj76Xt3XHh3 Bzw+Zs6oiSjQwNnya6MdrKpI= From: Eli Schwartz To: pacman-contrib@lists.archlinux.org Subject: [pacman-contrib] [PATCH 1/4] Port to libmakepkg Date: Wed, 23 Oct 2019 02:13:56 -0400 Message-Id: <20191023061359.820902-1-eschwartz@archlinux.org> X-Mailer: git-send-email 2.23.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" Replace m4 macros with use of libmakepkg extensions. Signed-off-by: Eli Schwartz --- configure.ac | 5 ++ lib/Makefile.am | 5 +- lib/output_format.sh | 32 ---------- lib/parseopts.sh | 137 ----------------------------------------- lib/term_colors.sh | 21 ------- src/Makefile.am | 9 +-- src/checkupdates.sh.in | 20 ++++-- src/paccache.sh.in | 14 ++++- src/pacdiff.sh.in | 12 +++- 9 files changed, 48 insertions(+), 207 deletions(-) delete mode 100644 lib/output_format.sh delete mode 100644 lib/parseopts.sh delete mode 100644 lib/term_colors.sh diff --git a/configure.ac b/configure.ac index ecb34db..82c16b3 100644 --- a/configure.ac +++ b/configure.ac @@ -65,6 +65,10 @@ PKG_CHECK_MODULES(LIBARCHIVE, [libarchive >= 2.8.0], , PKG_CHECK_MODULES(LIBALPM, [libalpm], , AC_MSG_ERROR([*** libalpm is needed to build pacman-contrib!])) +PKG_CHECK_VAR(LIBMAKEPKGDIR, [libmakepkg], [libmakepkgdir], , + AC_MSG_ERROR([*** libmakepkg is needed to build pacman-contrib!])) +AC_SUBST(LIBMAKEPKGDIR) + # Enable or disable use of git version in version string AC_MSG_CHECKING(whether to use git version if available) if test "x$wantgitver" = "xyes" ; then @@ -173,6 +177,7 @@ ${PACKAGE_NAME}: localstatedir : $(eval echo ${localstatedir}) database dir : $(eval echo ${localstatedir})/lib/pacman/ cache dir : $(eval echo ${localstatedir})/cache/pacman/pkg/ + libmakepkg dir : $(eval echo ${LIBMAKEPKGDIR}) compiler : ${CC} compiler flags : ${WARNING_CFLAGS} ${CFLAGS} diff --git a/lib/Makefile.am b/lib/Makefile.am index 8b18cb5..c7a1385 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -3,9 +3,6 @@ SUBDIRS= DIST_SUBDIRS = $(SUBDIRS) EXTRA_DIST = \ - output_format.sh \ - parseopts.sh \ - size_to_human.sh \ - term_colors.sh + size_to_human.sh # vim:set noet: diff --git a/lib/output_format.sh b/lib/output_format.sh deleted file mode 100644 index 9f02c00..0000000 --- a/lib/output_format.sh +++ /dev/null @@ -1,32 +0,0 @@ -plain() { - (( QUIET )) && return - local mesg=$1; shift - printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&1 -} - -msg() { - (( QUIET )) && return - local mesg=$1; shift - printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&1 -} - -msg2() { - (( QUIET )) && return - local mesg=$1; shift - printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&1 -} - -ask() { - local mesg=$1; shift - printf "${BLUE}::${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}" "$@" >&1 -} - -warning() { - local mesg=$1; shift - printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - -error() { - local mesg=$1; shift - printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} diff --git a/lib/parseopts.sh b/lib/parseopts.sh deleted file mode 100644 index cf6aa6c..0000000 --- a/lib/parseopts.sh +++ /dev/null @@ -1,137 +0,0 @@ -# getopt-like parser -parseopts() { - local opt= optarg= i= shortopts=$1 - local -a longopts=() unused_argv=() - - shift - while [[ $1 && $1 != '--' ]]; do - longopts+=("$1") - shift - done - shift - - longoptmatch() { - local o longmatch=() - for o in "${longopts[@]}"; do - if [[ ${o%:} = "$1" ]]; then - longmatch=("$o") - break - fi - [[ ${o%:} = "$1"* ]] && longmatch+=("$o") - done - - case ${#longmatch[*]} in - 1) - # success, override with opt and return arg req (0 == none, 1 == required) - opt=${longmatch%:} - if [[ $longmatch = *: ]]; then - return 1 - else - return 0 - fi ;; - 0) - # fail, no match found - return 255 ;; - *) - # fail, ambiguous match - printf "@SCRIPTNAME@: $(gettext "option '%s' is ambiguous; possibilities:")" "--$1" - printf " '%s'" "${longmatch[@]%:}" - printf '\n' - return 254 ;; - esac >&2 - } - - while (( $# )); do - case $1 in - --) # explicit end of options - shift - break - ;; - -[!-]*) # short option - for (( i = 1; i < ${#1}; i++ )); do - opt=${1:i:1} - - # option doesn't exist - if [[ $shortopts != *$opt* ]]; then - printf "@SCRIPTNAME@: $(gettext "invalid option") -- '%s'\n" "$opt" >&2 - OPTRET=(--) - return 1 - fi - - OPTRET+=("-$opt") - # option requires optarg - if [[ $shortopts = *$opt:* ]]; then - # if we're not at the end of the option chunk, the rest is the optarg - if (( i < ${#1} - 1 )); then - OPTRET+=("${1:i+1}") - break - # if we're at the end, grab the the next positional, if it exists - elif (( i == ${#1} - 1 )) && [[ $2 ]]; then - OPTRET+=("$2") - shift - break - # parse failure - else - printf "@SCRIPTNAME@: $(gettext "option requires an argument") -- '%s'\n" "$opt" >&2 - OPTRET=(--) - return 1 - fi - fi - done - ;; - --?*=*|--?*) # long option - IFS='=' read -r opt optarg <<< "${1#--}" - longoptmatch "$opt" - case $? in - 0) - # parse failure - if [[ $optarg ]]; then - printf "@SCRIPTNAME@: $(gettext "option '%s' does not allow an argument")\n" "--$opt" >&2 - OPTRET=(--) - return 1 - # --longopt - else - OPTRET+=("--$opt") - fi - ;; - 1) - # --longopt=optarg - if [[ $optarg ]]; then - OPTRET+=("--$opt" "$optarg") - # --longopt optarg - elif [[ $2 ]]; then - OPTRET+=("--$opt" "$2" ) - shift - # parse failure - else - printf "@SCRIPTNAME@: $(gettext "option '%s' requires an argument")\n" "--$opt" >&2 - OPTRET=(--) - return 1 - fi - ;; - 254) - # ambiguous option -- error was reported for us by longoptmatch() - OPTRET=(--) - return 1 - ;; - 255) - # parse failure - printf "@SCRIPTNAME@: $(gettext "invalid option") '--%s'\n" "$opt" >&2 - OPTRET=(--) - return 1 - ;; - esac - ;; - *) # non-option arg encountered, add it as a parameter - unused_argv+=("$1") - ;; - esac - shift - done - - # add end-of-opt terminator and any leftover positional parameters - OPTRET+=('--' "${unused_argv[@]}" "$@") - unset longoptmatch - - return 0 -} diff --git a/lib/term_colors.sh b/lib/term_colors.sh deleted file mode 100644 index 87e95ee..0000000 --- a/lib/term_colors.sh +++ /dev/null @@ -1,21 +0,0 @@ -# check if messages are to be printed using color -unset ALL_OFF BOLD BLUE GREEN RED YELLOW -if [[ -t 2 && ! $USE_COLOR = "n" && ! $TERM = "dumb" ]]; then - # prefer terminal safe colored and bold text when tput is supported - if tput setaf 0 &>/dev/null; then - ALL_OFF="$(tput sgr0)" - BOLD="$(tput bold)" - BLUE="${BOLD}$(tput setaf 4)" - GREEN="${BOLD}$(tput setaf 2)" - RED="${BOLD}$(tput setaf 1)" - YELLOW="${BOLD}$(tput setaf 3)" - else - ALL_OFF="\e[1;0m" - BOLD="\e[1;1m" - BLUE="${BOLD}\e[1;34m" - GREEN="${BOLD}\e[1;32m" - RED="${BOLD}\e[1;31m" - YELLOW="${BOLD}\e[1;33m" - fi -fi -readonly ALL_OFF BOLD BLUE GREEN RED YELLOW diff --git a/src/Makefile.am b/src/Makefile.am index 08dde4b..2efd416 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -92,10 +92,11 @@ AM_CFLAGS = \ $(LIBALPM_CFLAGS) edit = sed \ - -e 's|@bindir[@]|${bindir}|g' \ + -e 's|@bindir[@]|$(bindir)|g' \ -e 's|@sysconfdir[@]|$(sysconfdir)|g' \ -e 's|@localstatedir[@]|$(localstatedir)|g' \ -e 's|@PACKAGE_VERSION[@]|$(REAL_PACKAGE_VERSION)|g' \ + -e 's|@libmakepkgdir[@]|$(LIBMAKEPKGDIR)|g' \ -e 's|@SIZECMD[@]|$(SIZECMD)|g' \ -e 's|@SCRIPTNAME[@]|$@|g' \ -e '1s|!/bin/bash|!$(BASH_SHELL)|g' \ @@ -121,9 +122,9 @@ $(OURFILES): Makefile all-am: $(OURSCRIPTS) $(OURFILES) -checkupdates: $(srcdir)/checkupdates.sh.in $(top_srcdir)/lib/output_format.sh $(top_srcdir)/lib/term_colors.sh -paccache: $(srcdir)/paccache.sh.in $(top_srcdir)/lib/output_format.sh $(top_srcdir)/lib/parseopts.sh $(top_srcdir)/lib/size_to_human.sh $(top_srcdir)/lib/term_colors.sh -pacdiff: $(srcdir)/pacdiff.sh.in $(top_srcdir)/lib/output_format.sh $(top_srcdir)/lib/term_colors.sh +checkupdates: $(srcdir)/checkupdates.sh.in +paccache: $(srcdir)/paccache.sh.in +pacdiff: $(srcdir)/pacdiff.sh.in paclist: $(srcdir)/paclist.sh.in paclog-pkglist: $(srcdir)/paclog-pkglist.sh.in pacscripts: $(srcdir)/pacscripts.sh.in diff --git a/src/checkupdates.sh.in b/src/checkupdates.sh.in index 0885983..eecb4a7 100644 --- a/src/checkupdates.sh.in +++ b/src/checkupdates.sh.in @@ -21,11 +21,14 @@ declare -r myname='checkupdates' declare -r myver='@PACKAGE_VERSION@' +LIBRARY=${LIBRARY:-'@libmakepkgdir@'} + DOWNLOAD_CACHE=0 +USE_COLOR=0 -m4_include(../lib/output_format.sh) -m4_include(../lib/term_colors.sh) -m4_include(../lib/parseopts.sh) +# Import libmakepkg +source "$LIBRARY"/util/message.sh +source "$LIBRARY"/util/parseopts.sh usage() { cat << __EOF__ @@ -45,7 +48,7 @@ __EOF__ } OPT_SHORT='dh' -OPT_LONG=('download' 'help') +OPT_LONG=('download' 'help' 'nocolor') if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then exit 1 @@ -60,6 +63,8 @@ while :; do -h|--help) usage exit 0 ;; + --nocolor) + USE_COLOR='n';; --) shift break ;; @@ -67,6 +72,13 @@ while :; do shift done +# check if messages are to be printed using color +if [[ -t 2 && $USE_COLOR != "n" ]]; then + colorize +else + unset ALL_OFF BOLD BLUE GREEN RED YELLOW +fi + if ! type -P fakeroot >/dev/null; then error 'Cannot find the fakeroot binary.' exit 1 diff --git a/src/paccache.sh.in b/src/paccache.sh.in index c7265ba..af901f4 100644 --- a/src/paccache.sh.in +++ b/src/paccache.sh.in @@ -25,6 +25,8 @@ shopt -s extglob declare -r myname='paccache' declare -r myver='@PACKAGE_VERSION@' +LIBRARY=${LIBRARY:-'@libmakepkgdir@'} + declare -a cachedirs=() candidates=() cmdopts=() whitelist=() blacklist=() declare -i delete=0 dryrun=0 filecount=0 move=0 needsroot=0 totalsaved=0 verbose=0 declare -i min_atime=0 min_mtime=0 @@ -33,8 +35,9 @@ declare delim=$'\n' keep=3 movedir= scanarch= QUIET=0 USE_COLOR='y' -m4_include(../lib/output_format.sh) -m4_include(../lib/parseopts.sh) +# Import libmakepkg +source "$LIBRARY"/util/message.sh +source "$LIBRARY"/util/parseopts.sh die() { error "$@" @@ -310,7 +313,12 @@ while :; do shift done -m4_include(../lib/term_colors.sh) +# check if messages are to be printed using color +if [[ -t 2 && $USE_COLOR != "n" ]]; then + colorize +else + unset ALL_OFF BOLD BLUE GREEN RED YELLOW +fi # setting default cachedirs if [[ -z $cachedirs ]]; then diff --git a/src/pacdiff.sh.in b/src/pacdiff.sh.in index 8a70d4e..e3b8f8c 100644 --- a/src/pacdiff.sh.in +++ b/src/pacdiff.sh.in @@ -23,13 +23,16 @@ shopt -s extglob declare -r myname='pacdiff' declare -r myver='@PACKAGE_VERSION@' +LIBRARY=${LIBRARY:-'@libmakepkgdir@'} + diffprog=${DIFFPROG:-'vim -d'} diffsearchpath=${DIFFSEARCHPATH:-/etc} USE_COLOR='y' declare -a oldsaves declare -i USE_FIND=0 USE_LOCATE=0 USE_PACDB=0 OUTPUTONLY=0 -m4_include(../lib/output_format.sh) +# Import libmakepkg +source "$LIBRARY"/util/message.sh usage() { cat </dev/null && (( ! OUTPUTONLY )); then error "Cannot find the $diffprog binary required for viewing differences."