mirror of
https://github.com/moparisthebest/pkgsync
synced 2024-12-21 15:18:52 -05:00
Few changes and fixes to address feedback
This commit is contained in:
parent
c7229488cb
commit
67dfcc1722
@ -1,6 +1,9 @@
|
|||||||
# pkgsync
|
# pkgsync
|
||||||
A simple script to sync installed packages across Arch installs
|
A simple script to sync installed packages across Arch installs
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
Configure pkgsync by modifying /etc/default/pkgsync, follow instructions in comments. Then just run pkgsync on each system to sync packages.
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
This script is only for Linux distros that use pacman for package management. All dependencies are included in the Arch Linux base group but are listed out here for general info:
|
This script is only for Linux distros that use pacman for package management. All dependencies are included in the Arch Linux base group but are listed out here for general info:
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
# this is the configuration for pkgsync
|
# this is the configuration for pkgsync
|
||||||
# it uses these defaults, but you can change them
|
# it uses these defaults, but you can change them
|
||||||
|
|
||||||
|
# list files can have comments starting with #, and do not need to be sorted
|
||||||
|
|
||||||
# packages on this system to exclude from shared install list
|
# packages on this system to exclude from shared install list
|
||||||
#EXCLUSION_LIST=/etc/pkgsync/pkg_exclude.list
|
#EXCLUSION_LIST=/etc/pkgsync/pkg_exclude.list
|
||||||
|
|
||||||
@ -13,6 +15,11 @@
|
|||||||
# packages to install on all systems, you must sync it between systems
|
# packages to install on all systems, you must sync it between systems
|
||||||
#INSTALL_LIST=/etc/pkgsync/pkg_install.list
|
#INSTALL_LIST=/etc/pkgsync/pkg_install.list
|
||||||
|
|
||||||
|
# scripts must be executable and have non-zero exit status for pkgsync to continue
|
||||||
|
|
||||||
|
# script that is ran before pkgsync calculations start, can be used to sync various lists
|
||||||
|
#PRESTART_SCRIPT=/etc/pkgsync/pkg_prestart.sh
|
||||||
|
|
||||||
# script that is ran when INSTALL_LIST is changed, can be used to sync it
|
# script that is ran when INSTALL_LIST is changed, can be used to sync it
|
||||||
#FINISH_SCRIPT=/etc/pkgsync/pkg_finish.sh
|
#FINISH_SCRIPT=/etc/pkgsync/pkg_finish.sh
|
||||||
|
|
||||||
|
62
pkgsync
62
pkgsync
@ -8,17 +8,20 @@ EXCLUSION_LIST="${EXCLUSION_LIST:-/etc/pkgsync/pkg_exclude.list}"
|
|||||||
BLACKLIST_LIST="${BLACKLIST_LIST:-/etc/pkgsync/pkg_blacklist.list}"
|
BLACKLIST_LIST="${BLACKLIST_LIST:-/etc/pkgsync/pkg_blacklist.list}"
|
||||||
REMOVE_LIST="${REMOVE_LIST:-/etc/pkgsync/pkg_remove.list}"
|
REMOVE_LIST="${REMOVE_LIST:-/etc/pkgsync/pkg_remove.list}"
|
||||||
INSTALL_LIST="${INSTALL_LIST:-/etc/pkgsync/pkg_install.list}"
|
INSTALL_LIST="${INSTALL_LIST:-/etc/pkgsync/pkg_install.list}"
|
||||||
FINISH_SCRIPT="${INSTALL_LIST:-/etc/pkgsync/pkg_finish.sh}"
|
PRESTART_SCRIPT="${PRESTART_SCRIPT:-/etc/pkgsync/pkg_prestart.sh}"
|
||||||
|
FINISH_SCRIPT="${FINISH_SCRIPT:-/etc/pkgsync/pkg_finish.sh}"
|
||||||
TMP_DIR="${TMP_DIR:-/tmp}"
|
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
|
# 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 > "$TMP_DIR/pkg_exclude.list" || true
|
grep -v '^#' "$EXCLUSION_LIST" 2>/dev/null | sort -u > "$TMP_DIR/pkg_exclude.list" || true
|
||||||
grep -v '^#' "$BLACKLIST_LIST" 2>/dev/null > "$TMP_DIR/pkg_blacklist.list" || true
|
grep -v '^#' "$BLACKLIST_LIST" 2>/dev/null | sort -u > "$TMP_DIR/pkg_blacklist.list" || true
|
||||||
grep -v '^#' "$REMOVE_LIST" 2>/dev/null > "$TMP_DIR/pkg_remove.list" || true
|
grep -v '^#' "$REMOVE_LIST" 2>/dev/null | sort -u > "$TMP_DIR/pkg_remove.list" || true
|
||||||
[ ! -e "$INSTALL_LIST" ] && touch "$INSTALL_LIST"
|
grep -v '^#' "$INSTALL_LIST" 2>/dev/null | sort -u > "$TMP_DIR/pkg_install.list" || true
|
||||||
|
|
||||||
# get our explicitly installed packages, minus hardware-specific exclusions
|
# get our explicitly installed packages, minus hardware-specific exclusions
|
||||||
pacman -Qe | awk '{print $1}' | sort | comm -23 - "$TMP_DIR/pkg_exclude.list" > "$TMP_DIR/mypkgs_with_exclusions.txt"
|
pacman -Q | awk '{print $1}' | sort | comm -23 - "$TMP_DIR/pkg_exclude.list" > "$TMP_DIR/mypkgs_with_exclusions.txt"
|
||||||
|
|
||||||
# exclude packages to remove
|
# 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"
|
comm -23 "$TMP_DIR/mypkgs_with_exclusions.txt" "$TMP_DIR/pkg_remove.list" > "$TMP_DIR/mypkgs_with_exclusions_without_remove.txt"
|
||||||
@ -27,24 +30,55 @@ comm -23 "$TMP_DIR/mypkgs_with_exclusions.txt" "$TMP_DIR/pkg_remove.list" > "$TM
|
|||||||
comm -12 "$TMP_DIR/mypkgs_with_exclusions.txt" "$TMP_DIR/pkg_remove.list" > "$TMP_DIR/pkg_toremove.list"
|
comm -12 "$TMP_DIR/mypkgs_with_exclusions.txt" "$TMP_DIR/pkg_remove.list" > "$TMP_DIR/pkg_toremove.list"
|
||||||
|
|
||||||
# combine our packages with shared installed list, excluding remove
|
# combine our packages with shared installed list, excluding remove
|
||||||
sort -u "$TMP_DIR/mypkgs_with_exclusions_without_remove.txt" "$INSTALL_LIST" | comm -23 - "$TMP_DIR/pkg_remove.list" > "$TMP_DIR/pkg_installed.list"
|
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
|
# 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"
|
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
|
# offer to install missing packages
|
||||||
xargs -p --no-run-if-empty pacman -S --needed --noconfirm < "$TMP_DIR/pkg_toinstall.list"
|
if [ -s "$TMP_DIR/pkg_toinstall.list" ]
|
||||||
|
then
|
||||||
|
yn=l
|
||||||
|
while [[ ! "$yn" =~ ^[YyNnAa]$ ]]
|
||||||
|
do
|
||||||
|
read -p "Install new packages? (yes/no/list/abort)..." -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" =~ ^[Aa]$ ]] && exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# offer to remove packages
|
# offer to remove packages
|
||||||
xargs -p --no-run-if-empty pacman -Ru --noconfirm < "$TMP_DIR/pkg_toremove.list"
|
if [ -s "$TMP_DIR/pkg_toremove.list" ]
|
||||||
|
then
|
||||||
|
yn=l
|
||||||
|
while [[ ! "$yn" =~ ^[YyNnAa]$ ]]
|
||||||
|
do
|
||||||
|
read -p "Remove packages? (yes/no/list/abort)..." -n 1 yn
|
||||||
|
echo
|
||||||
|
[[ "$yn" =~ ^[Ll]$ ]] && cat "$TMP_DIR/pkg_toremove.list"
|
||||||
|
done
|
||||||
|
[[ "$yn" =~ ^[Yy]$ ]] && pacman -Ru --confirm - < "$TMP_DIR/pkg_toremove.list"
|
||||||
|
[[ "$yn" =~ ^[Aa]$ ]] && exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# offer to update install list, if it changed
|
# offer to update install list, if it changed
|
||||||
if [ "$(comm -3 "$TMP_DIR/pkg_installed.list" "$INSTALL_LIST")" != "" ]
|
if [ -s "$TMP_DIR/pkg_ourinstall.list" ]
|
||||||
then
|
then
|
||||||
read -p "Overwrite '$INSTALL_LIST' with new package list and run finish script?..." -n 1 yn
|
yn=l
|
||||||
[[ $yn =~ ^[Yy]$ ]] && cp "$TMP_DIR/pkg_installed.list" "$INSTALL_LIST"
|
while [[ ! "$yn" =~ ^[YyNnAa]$ ]]
|
||||||
echo
|
do
|
||||||
|
read -p "Append packages unique to this computer to install list and run finish script? (yes/no/list/abort)..." -n 1 yn
|
||||||
|
echo
|
||||||
|
[[ "$yn" =~ ^[Ll]$ ]] && cat "$TMP_DIR/pkg_ourinstall.list"
|
||||||
|
done
|
||||||
|
[[ "$yn" =~ ^[Yy]$ ]] && cat "$TMP_DIR/pkg_ourinstall.list" >> "$INSTALL_LIST"
|
||||||
|
[[ "$yn" =~ ^[Aa]$ ]] && exit 1
|
||||||
[ -x "$FINISH_SCRIPT" ] && "$FINISH_SCRIPT"
|
[ -x "$FINISH_SCRIPT" ] && "$FINISH_SCRIPT"
|
||||||
fi
|
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"
|
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"
|
||||||
|
Loading…
Reference in New Issue
Block a user