diff options
author | Ehsan Ghorbannezhad | 2022-05-28 02:16:07 +0430 |
---|---|---|
committer | Ehsan Ghorbannezhad | 2022-05-28 02:16:07 +0430 |
commit | ea19ce2abfc28ff660bd91a2dee73fe07e85ed4d (patch) | |
tree | 415cfefc9dc96c074455125955e0f59f17002d39 | |
parent | 14c6af57bf4a3817b538e27461c12fe1c91b6a6a (diff) | |
download | aur-ea19ce2abfc28ff660bd91a2dee73fe07e85ed4d.tar.gz |
massive improvements
- generate the lists in parallel
- generate the lists using only one install command instead of 3
separate commands
- more sane defaults
- put paclist.sh in /usr/share/libalpm/scripts/paclist instead of
/usr/bin
- add the /etc/paclist/config file to the backup[] array in the PKGBUILD
-rw-r--r-- | .SRCINFO | 12 | ||||
-rw-r--r-- | PKGBUILD | 22 | ||||
-rw-r--r-- | config | 17 | ||||
-rw-r--r-- | paclist.hook | 2 | ||||
-rwxr-xr-x | paclist.sh | 43 |
5 files changed, 57 insertions, 39 deletions
@@ -1,14 +1,14 @@ pkgbase = paclist pkgdesc = pacman hook to make lists of installed packages. - pkgver = r4 - pkgrel = 2 + pkgver = r5 + pkgrel = 1 arch = any - license = GPL + backup = etc/paclist/config source = paclist.sh source = paclist.hook source = config - sha256sums = b2423b71c85c00c5ffccf78dd8ed859edbbacac9f3765fa2ea6cb9662e9736a8 - sha256sums = d63dced7184b8688bcc5e414352d0e436a10f4b5dba1243644f68e7ff277228e - sha256sums = d29a5dd3b799e60312d94819d78ff025e55d72918cd47dd0e5be2b1edbf73d66 + sha256sums = 626d0e3d7ef574ec03a2eba3bb6e026c9ee95d1cd1b3c0ef8f86a3d5edeeef45 + sha256sums = 87ce6f65a9b4a58457beaa0866ec86a1192d668920311969b5b78b5b76491b52 + sha256sums = 470e9b2586fc67d2fde3908e395ce13895100ae1e177f3d6d185cbe4e9d57e15 pkgname = paclist @@ -1,19 +1,17 @@ # Maintainer: Ehsan Ghorbannezad <ehsan at disroot dot org> pkgname=paclist -pkgver=r4 -pkgrel=2 +pkgver=r5 +pkgrel=1 pkgdesc='pacman hook to make lists of installed packages.' arch=(any) -license=(GPL) -source=($pkgname.sh $pkgname.hook config) - -sha256sums=('b2423b71c85c00c5ffccf78dd8ed859edbbacac9f3765fa2ea6cb9662e9736a8' - 'd63dced7184b8688bcc5e414352d0e436a10f4b5dba1243644f68e7ff277228e' - 'd29a5dd3b799e60312d94819d78ff025e55d72918cd47dd0e5be2b1edbf73d66') +backup=(etc/paclist/config) +source=(paclist.sh paclist.hook config) +sha256sums=('626d0e3d7ef574ec03a2eba3bb6e026c9ee95d1cd1b3c0ef8f86a3d5edeeef45' + '87ce6f65a9b4a58457beaa0866ec86a1192d668920311969b5b78b5b76491b52' + '470e9b2586fc67d2fde3908e395ce13895100ae1e177f3d6d185cbe4e9d57e15') package() { - cd "$srcdir" - install -Dm755 $pkgname.sh -t "$pkgdir/usr/bin/" - install -Dm644 config -t "$pkgdir/etc/$pkgname/" - install -Dm644 $pkgname.hook -t "$pkgdir/usr/share/libalpm/hooks/" + install -vDm644 config "$pkgdir"/etc/paclist/config + install -vDm755 paclist.sh "$pkgdir"/usr/share/libalpm/scripts/paclist + install -vDm644 paclist.hook "$pkgdir"/usr/share/libalpm/hooks/paclist.hook } @@ -1,12 +1,17 @@ # paclist's config -# package lists to generate +# package lists to generate. +# the list will be generated using the specified command with +# the specified owner in the specified path. lists=( -# user group path command - root root /etc/paclist/lists/official 'pacman -Qqne' - root root /etc/paclist/lists/aur 'pacman -Qqme' - root root /etc/paclist/lists/all 'pacman -Qq' +# user group path command + root root /etc/paclist/lists/official.list 'pacman -Qqne' + root root /etc/paclist/lists/aur.list 'pacman -Qqme' + root root /etc/paclist/lists/all.list 'pacman -Qq' ) # suffix to add to list names -suffix=-$(cat /etc/hostname) +suffix=-$HOSTNAME + +# wether to print extra info when generating the lists or not +verbose=false diff --git a/paclist.hook b/paclist.hook index e91e591b3ae2..7f5404cd6d8a 100644 --- a/paclist.hook +++ b/paclist.hook @@ -7,4 +7,4 @@ Target = * [Action] Description = Updating package lists... When = PostTransaction -Exec = /bin/sh -c 'paclist.sh <&- >&- 2>&- &' +Exec = /usr/share/libalpm/scripts/paclist diff --git a/paclist.sh b/paclist.sh index 755b251a070f..2ddf30bb71b6 100755 --- a/paclist.sh +++ b/paclist.sh @@ -1,23 +1,38 @@ #!/bin/bash # a script for generating lists of pacman packages. -# add typical bin dirs to PATH -export PATH="${PATH}:/usr/bin:/usr/local/bin" +# config file +conf=/etc/paclist/config -# load and check configuration -. /etc/paclist/config || exit 1 -[ ${#lists[@]} -lt 4 ] && exit 1 -[ $(( ${#lists[@]} % 4 )) -ne 0 ] && exit 1 +# populate the PATH variable with sane defaults +export PATH=$PATH:/usr/bin:/usr/local/bin -for i in $(seq 0 4 $(( ${#lists[@]} - 4 )) ); do +# source the config file +source $conf || { + echo "paclist: failed to source $conf" >&2 + exit 1 +} - user="${lists[$i]}" - group="${lists[$i+1]}" - path="${lists[$i+2]}$suffix" - cmd="${lists[$i+3]}" +# perform sanity checks on the lists array +[[ ${#lists[@]} -lt 4 ]] && { + echo "paclist: the 'lists' array defined in $conf has a size of less than 4" >&2 + exit 1 +} +[[ $(( ${#lists[@]} % 4 )) -ne 0 ]] && { + echo "paclist: the 'lists' array defined in $conf is not divisible by 4" >&2 + exit 1 +} - runuser -u "$user" -g "$group" -- mkdir -p "$(dirname "$path")" - sh -c -- "$cmd" > "$path" - chown "$user":"$group" -- "$path" +[[ $verbose != true ]] && unset verbose +# generate all the lists in parallel +for ((i=0; i<${#lists[@]}; i+=4)); do + user=${lists[$i]} + group=${lists[$i+1]} + path=${lists[$i+2]}$suffix + cmd=${lists[$i+3]} + sh -c -- "${cmd:?}" | install ${verbose:+-v} -Dm644 -o"${user:?}" -g"${group:?}" -- /dev/stdin "${path:?}" & done + +# wait for the lists to be generated +wait |