88 lines
4.1 KiB
Bash
Executable File
88 lines
4.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
[ -e /etc/default/pkgsync ] && . /etc/default/pkgsync
|
|
|
|
EXCLUSION_LIST="${EXCLUSION_LIST:-/etc/pkgsync/pkg_exclude.list}"
|
|
BLACKLIST_LIST="${BLACKLIST_LIST:-/etc/pkgsync/pkg_blacklist.list}"
|
|
REMOVE_LIST="${REMOVE_LIST:-/etc/pkgsync/pkg_remove.list}"
|
|
INSTALL_LIST="${INSTALL_LIST:-/etc/pkgsync/pkg_install.list}"
|
|
PRESTART_SCRIPT="${PRESTART_SCRIPT:-/etc/pkgsync/pkg_prestart.sh}"
|
|
FINISH_SCRIPT="${FINISH_SCRIPT:-/etc/pkgsync/pkg_finish.sh}"
|
|
TMP_DIR="${TMP_DIR:-/tmp}"
|
|
|
|
[ -x "$PRESTART_SCRIPT" ] && "$PRESTART_SCRIPT"
|
|
|
|
# we really don't care if these exist or not or are empty, we just want empty files if so
|
|
grep -v '^#' "$EXCLUSION_LIST" 2>/dev/null | sort -u > "$TMP_DIR/pkg_exclude.list" || true
|
|
grep -v '^#' "$BLACKLIST_LIST" 2>/dev/null | sort -u > "$TMP_DIR/pkg_blacklist.list" || true
|
|
grep -v '^#' "$REMOVE_LIST" 2>/dev/null | sort -u > "$TMP_DIR/pkg_remove.list" || true
|
|
grep -v '^#' "$INSTALL_LIST" 2>/dev/null | sort -u > "$TMP_DIR/pkg_install.list" || true
|
|
|
|
# get our explicitly installed packages, minus hardware-specific exclusions
|
|
pacman -Qq | sort | comm -23 - "$TMP_DIR/pkg_exclude.list" > "$TMP_DIR/mypkgs_with_exclusions.txt"
|
|
|
|
# exclude packages to remove
|
|
comm -23 "$TMP_DIR/mypkgs_with_exclusions.txt" "$TMP_DIR/pkg_remove.list" > "$TMP_DIR/mypkgs_with_exclusions_without_remove.txt"
|
|
|
|
# list of packages to remove, with our blacklist excluded
|
|
comm -12 "$TMP_DIR/mypkgs_with_exclusions.txt" "$TMP_DIR/pkg_remove.list" | comm -23 - "$TMP_DIR/pkg_blacklist.list" > "$TMP_DIR/pkg_toremove.list"
|
|
|
|
# combine our packages with shared installed list, excluding remove
|
|
sort -u "$TMP_DIR/mypkgs_with_exclusions_without_remove.txt" "$TMP_DIR/pkg_install.list" | comm -23 - "$TMP_DIR/pkg_remove.list" > "$TMP_DIR/pkg_installed.list"
|
|
|
|
# list of packages to install, with our blacklist excluded
|
|
comm -13 "$TMP_DIR/mypkgs_with_exclusions_without_remove.txt" "$TMP_DIR/pkg_installed.list" | comm -23 - "$TMP_DIR/pkg_blacklist.list" > "$TMP_DIR/pkg_toinstall.list"
|
|
|
|
# packages already on this computer not in the shared install list we need to put in there
|
|
comm -23 "$TMP_DIR/pkg_installed.list" "$TMP_DIR/pkg_install.list" > "$TMP_DIR/pkg_ourinstall.list"
|
|
|
|
# offer to install missing packages
|
|
if [ -s "$TMP_DIR/pkg_toinstall.list" ]
|
|
then
|
|
yn=l
|
|
while [[ ! "$yn" =~ ^[YyNnAaQqBb]$ ]]
|
|
do
|
|
read -p "Install new packages? (yes/no/list/abort/blacklist)..." -n 1 yn
|
|
echo
|
|
[[ "$yn" =~ ^[Ll]$ ]] && cat "$TMP_DIR/pkg_toinstall.list"
|
|
done
|
|
[[ "$yn" =~ ^[Yy]$ ]] && pacman -S --needed --confirm - < "$TMP_DIR/pkg_toinstall.list"
|
|
[[ "$yn" =~ ^[Bb]$ ]] && cat "$TMP_DIR/pkg_toinstall.list" >> "$BLACKLIST_LIST"
|
|
[[ "$yn" =~ ^[AaQq]$ ]] && exit 1
|
|
fi
|
|
|
|
# offer to remove packages
|
|
if [ -s "$TMP_DIR/pkg_toremove.list" ]
|
|
then
|
|
yn=l
|
|
while [[ ! "$yn" =~ ^[YyNnAaQqBb]$ ]]
|
|
do
|
|
read -p "Remove packages? (yes/no/list/abort/blacklist)..." -n 1 yn
|
|
echo
|
|
[[ "$yn" =~ ^[Ll]$ ]] && cat "$TMP_DIR/pkg_toremove.list"
|
|
done
|
|
[[ "$yn" =~ ^[Yy]$ ]] && pacman -Ru --confirm - < "$TMP_DIR/pkg_toremove.list"
|
|
[[ "$yn" =~ ^[Bb]$ ]] && cat "$TMP_DIR/pkg_toremove.list" >> "$BLACKLIST_LIST"
|
|
[[ "$yn" =~ ^[AaQq]$ ]] && exit 1
|
|
fi
|
|
|
|
# offer to update install list, if it changed
|
|
if [ -s "$TMP_DIR/pkg_ourinstall.list" ]
|
|
then
|
|
yn=l
|
|
while [[ ! "$yn" =~ ^[YyNnAaQqEe]$ ]]
|
|
do
|
|
read -p "Append packages unique to this computer to install list and run finish script? (yes/no/list/abort/exclude)..." -n 1 yn
|
|
echo
|
|
[[ "$yn" =~ ^[Ll]$ ]] && cat "$TMP_DIR/pkg_ourinstall.list"
|
|
done
|
|
[[ "$yn" =~ ^[Yy]$ ]] && cat "$TMP_DIR/pkg_ourinstall.list" >> "$INSTALL_LIST"
|
|
[[ "$yn" =~ ^[Ee]$ ]] && cat "$TMP_DIR/pkg_ourinstall.list" >> "$EXCLUSION_LIST"
|
|
[[ "$yn" =~ ^[AaQq]$ ]] && exit 1
|
|
[ -x "$FINISH_SCRIPT" ] && "$FINISH_SCRIPT"
|
|
fi
|
|
|
|
rm -f "$TMP_DIR/pkg_exclude.list" "$TMP_DIR/pkg_blacklist.list" "$TMP_DIR/pkg_remove.list" "$TMP_DIR/mypkgs_with_exclusions.txt" "$TMP_DIR/mypkgs_with_exclusions_without_remove.txt" "$TMP_DIR/pkg_toremove.list" "$TMP_DIR/pkg_installed.list" "$TMP_DIR/pkg_toinstall.list" "$TMP_DIR/pkg_ourinstall.list"
|