From fcd68426c802f0d357a7f48f90a261c1d23aaec3 Mon Sep 17 00:00:00 2001 From: Mateus Auler Date: Mon, 2 May 2022 03:51:46 -0300 Subject: [PATCH 1/2] Add option to set alternative pacman command This patch introduces the ability to pick a different pacman command to run when searching for installed packages and installing the meta-package. This is mainly useful for using aur helpers. The option to provide an alternative pacman command is -p or --pacman, followed by the command name or its path. With the use of aur helpers in mind, it also adds the following options: - --not-as-root: Run installation command as unpriviledged user - --depends-first: Run a separate instance of pacman (or the provided alternative) to install the dependencies before installing the meta-package itself. Signed-off-by: Mateus Auler --- makepkg-meta.sh | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/makepkg-meta.sh b/makepkg-meta.sh index 8b37fc7..0219359 100644 --- a/makepkg-meta.sh +++ b/makepkg-meta.sh @@ -12,13 +12,16 @@ RMDEPENDS=() PKGGROUPS=('meta') ADDGROUPS=() RMGROUPS=() +PACMAN='pacman' +ASROOT=1 +DEPENDSFIRST=0 error() { printf "$@" >&2 exit 1 } -usage () { +usage() { cat < [options] @@ -58,6 +61,17 @@ Options: times. Packages are automatically in the "meta" group. Overrides groups loaded from an existing package. + -p, --pacman= + Command or path of alternative pacman binary. (Must be compatible with + pacman sub-commands.) + + --not-as-root + Run the pacman command as the current user on package installation. + + --depends-first + Install dependencies in a separate call to pacman before installing + the meta-package. + --no-update Do not search for an existing package to load information. @@ -104,32 +118,33 @@ dump_pkginfo() { } load_pkg_data() { - pacman -Q "$PKGNAME" &> /dev/null || return - [[ $PKGVER != 0 ]] || PKGVER=`LC_ALL=C pacman -Qi "$PKGNAME" \ + $PACMAN -Q "$PKGNAME" &> /dev/null || return + [[ $PKGVER != 0 ]] || PKGVER=`LC_ALL=C $PACMAN -Qi "$PKGNAME" \ | sed -ne 's/^Version\s*: //p' \ | awk 'BEGIN {FS="-"} {print $1}'` - [[ -n $PKGDESC ]] || PKGDESC=`LC_ALL=C pacman -Qi "$PKGNAME" \ + [[ -n $PKGDESC ]] || PKGDESC=`LC_ALL=C $PACMAN -Qi "$PKGNAME" \ | sed -ne 's/^Description\s*: //p'` - [[ -n $DEPENDS ]] || DEPENDS=(`LC_ALL=C pacman -Qi "$PKGNAME" \ + [[ -n $DEPENDS ]] || DEPENDS=(`LC_ALL=C $PACMAN -Qi "$PKGNAME" \ | awk 'BEGIN {FS=" : "} $1 ~ /^Depends/ {print $2}' \ | awk 'BEGIN {RS=" "} {print}'`) - [[ -n $PKGGROUPS ]] || PKGGROUPS=(`LC_ALL=C pacman -Qi "$PKGNAME" \ + [[ -n $PKGGROUPS ]] || PKGGROUPS=(`LC_ALL=C $PACMAN -Qi "$PKGNAME" \ | awk 'BEGIN {FS=" : "} $1 ~ /^Groups/ {print $2}' \ | awk 'BEGIN {RS=" "} {print}'`) } OPTS=`getopt --name makepkg-meta \ - --options 'a:,r:' \ + --options 'a:,r:,p:' \ --long 'help,version,no-update,description:' \ - --long 'pkgbuild,pkginfo' \ + --long 'pkgbuild,pkginfo,not-as-root,depends-first' \ --long 'depends:,add-depends:,rm-depends:' \ - --long 'groups:,add-groups:,rm-groups:' \ + --long 'groups:,add-groups:,rm-groups:,pacman:' \ -- "$@"` [[ $? != 0 ]] && exit 1 eval set -- "$OPTS" while true; do case "$1" in --description) shift; PKGDESC=$1 ;; + -p|--pacman) shift; PACMAN=$1 ;; --depends) shift; IFS=, read -ra d <<<"$1"; DEPENDS+=("${d[@]}"); unset d ;; -a|--add-depends) shift; IFS=, read -ra d <<<"$1"; ADDDEPENDS+=("${d[@]}"); unset d ;; -r|--rm-depends) shift; IFS=, read -ra d <<<"$1"; RMDEPENDS+=("${d[@]}"); unset d ;; @@ -139,6 +154,8 @@ while true; do --no-update) UPDATE=0 ;; --pkgbuild) DUMPPKGBUILD=1 ;; --pkginfo) DUMPPKGINFO=1 ;; + --not-as-root) ASROOT=0 ;; + --depends-first) DEPENDSFIRST=1 ;; --help) usage; exit 0 ;; --version) version; exit 0 ;; --) shift; break ;; @@ -189,7 +206,10 @@ mkdir "$TMPDIR" dump_pkginfo > "$PKGINFO" bsdtar -c -C "$TMPDIR" -f "$PKGFILE" .PKGINFO -sudo pacman -U "$PKGFILE" + +[[ $ASROOT == 1 ]] && PACMAN="sudo $PACMAN" +[[ $DEPENDSFIRST == 1 ]] && $PACMAN -S --needed --asdeps "${DEPENDS[@]}" || `exit 0` +[[ $? == 0 ]] && $PACMAN -U "$PKGFILE" rm "$PKGFILE" "$PKGINFO" rmdir "$TMPDIR" From 60fb112ce26c99b0fb91fcb3ec563ac77a216aab Mon Sep 17 00:00:00 2001 From: Mateus Auler Date: Mon, 2 May 2022 04:07:50 -0300 Subject: [PATCH 2/2] Update README with the new options --- README.pod | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.pod b/README.pod index cd5b19b..4136353 100644 --- a/README.pod +++ b/README.pod @@ -48,6 +48,20 @@ Comma-separated list of package groups. May be specified multiple times. Packages are automatically in the C group. Overrides groups loaded from an existing package. +=item B<-p>, B<--pacman>=I + +Command or path of alternative pacman binary. (Must be compatible with +pacman sub-commands.) + +=item B<--not-as-root> + +Run the pacman command as the current user on package installation. + +=item B<--depends-first> + +Install dependencies in a separate call to pacman before installing +the meta-package. + =item B<--no-update> Do not search for an existing package to load information.