Last active
September 26, 2017 06:23
-
-
Save Zerophase/caa9b52374c678b67d3c4f48c45ea277 to your computer and use it in GitHub Desktop.
Record explicitly installed packages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Trigger] | |
Operation = Install | |
Type = Package | |
Target = * | |
[Action] | |
When = PostTransaction | |
Exec = /etc/pacman.d/scripts/record-installedpkgs.sh -u | |
NeedsTargets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Trigger] | |
Operation = Remove | |
Type = Package | |
Target = * | |
[Action] | |
When = PreTransaction | |
Exec = /etc/pacman.d/scripts/record-installedpkgs.sh -r | |
NeedsTargets | |
AbortOnFail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -e | |
set -x | |
set -o nounset # Treat unset variables as an error | |
set -o pipefail | |
usage() | |
{ | |
cat <<EOF | |
usage: ${0##*/} [options] | |
Options: | |
-i initialize installed package list. | |
-u update installed package list | |
-r remove package from installed package list | |
-h print this help message | |
EOF | |
} | |
mountdir="/run/media/zerophase/PortableStorage" | |
mounted() | |
{ | |
if grep -qs $mountdir /proc/mounts; then | |
return 0; | |
else | |
return 1; | |
fi | |
} | |
if ! mounted; then | |
mkdir -p $mountdir | |
mount -L PortableStorage $mountdir | |
fi | |
reinstalldir=$mountdir/reinstall_arch/ | |
# 1. switch for updating lists of installed packages and initial list | |
case $1 in | |
"-u"*) | |
input=( $(cat) ) | |
if native=$(pacman -Qenq "${input[@]}"); then | |
echo "$native" >> "${reinstalldir}nativepackages.txt" | |
sort "${reinstalldir}nativepackages.txt" -o "${reinstalldir}nativepackages.txt" | |
else | |
foreign=$(pacman -Qemq "${input[@]}") | |
echo "$foreign" >> "${reinstalldir}foreignpackages.txt" | |
sort "${reinstalldir}foreignpackages.txt" -o "${reinstalldir}foreignpackages.txt" | |
fi | |
;; | |
"-r"*) | |
input=( $(cat) ) | |
if native=( $(pacman -Qenq "${input[@]}") ); then | |
for i in "${native[@]}"; do | |
sed -i "/$i/d" "${reinstalldir}nativepackages.txt" | |
done | |
else | |
foreign=( $(pacman -Qemq "${input[@]}") ) || true | |
for i in "${foreign[@]}"; do | |
sed -i "/$i/d" "${reinstalldir}foreignpackages.txt" | |
done | |
fi | |
;; | |
"-i"*) | |
pacman -Qenq > "${reinstalldir}nativepackages.txt" | |
pacman -Qemq > "${reinstalldir}foreignpackages.txt" | |
;; | |
"-h"*) | |
usage | |
# TODO fix flow so mounted doesn't run for this option | |
;; | |
*) | |
;; | |
esac | |
if mounted; then | |
umount $mountdir | |
rm -d $mountdir | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment