scripts/misc/update

115 lines
2.4 KiB
Plaintext
Raw Normal View History

2023-06-18 15:40:21 +00:00
#!/bin/zsh
source ${$(realpath "$0"):h:h}/lib/common.zsh
ALL_ARGS=("$@")
2024-04-04 11:40:49 +00:00
zparseopts -D -E -- -help=help h=help c=confs -conf=confs -skip-scripts=skip y=auto -yes=auto -conf-rebase=confrebase
2023-06-18 15:40:21 +00:00
SCRIPTS_DIR=${$(realpath "$0"):h}
if [[ $help ]]; then
<<-HELP
usage: update [-h] [-c] [-y]
Update the system, scripts directory, flatpaks, and optionally configs.
Options:
-h, --help Show this help message and exit.
-c, --confs Update configs.
-y, --yes Automatically answer yes to all prompts.
HELP
exit 0
fi
gitupdate() {
2024-04-04 11:40:49 +00:00
zparseopts -D -E -- -conf-rebase=confrebase
if [[ $confrebase ]]; then
git -C "$1" pull --autostash --rebase && git -C "$1" push
else
git -C "$1" pull --autostash --rebase=false --ff-only && git -C "$1" push
fi
2023-06-18 15:40:21 +00:00
}
if [[ ! $skip ]] then
# update scripts
check "Updating scripts..."
local result=$(gitupdate "$SCRIPTS_DIR" 2>&1)
if [[ $? == 0 ]]; then
2024-04-04 11:40:49 +00:00
succeed
2023-06-18 15:40:21 +00:00
exec "$0" "${ALL_ARGS[@]}" --skip-scripts
2024-04-04 11:40:49 +00:00
else
2023-06-18 15:40:21 +00:00
fail "error during script updates"
echo $result
exit 1
fi
fi
xbps-update () {
zparseopts -D -E -- y=auto -yes=auto
if [[ -z "$@" ]]
then
sudo xbps-install -Su $auto
if [[ $? == 16 ]]
then
sudo xbps-install -Syu xbps
xupdate $auto
fi
else
sudo xbps-install -SA "$@"
fi
if command -v xrestricted &> /dev/null; then
xrestricted $auto update
xcheckupdates
fi
}
2024-04-04 11:40:49 +00:00
misc-update() {
for i in ${XDG_CONFIG_HOME}/update.d/*; do
if [[ -x $i ]]; then
info "Running updater: ${i:t}"
$i $auto
fi
done
}
config-update() {
for confgit in ${XDG_CONFIG_HOME:-$HOME/.config}/*/.git; do
check "Updating \"${confgit:h}\"..."
local result=$(gitupdate "$@" "${confgit:h}" 2>&1)
if [[ $? == 0 ]]; then
succeed
else
fail "Could not update \"${confgit:h}\""
echo $result
fi
done
}
2023-06-18 15:40:21 +00:00
if [[ -e /etc/os-release ]]; then
info "Updating OS... "
source /etc/os-release
if [[ "$ID" == void ]] || command -v xbps-install &>/dev/null; then
info "Void Linux detected"
2024-04-04 11:40:49 +00:00
xbps-update $auto
2023-06-18 15:40:21 +00:00
elif [[ "$ID" == ubuntu ]] || command -v apt-get &>/dev/null; then
info "Ubuntu Linux detected"
2024-04-04 11:40:49 +00:00
sudo apt-get $auto update
2023-06-18 15:40:21 +00:00
sudo apt-get $auto upgrade
else
error "Unsupoorted distro, skipping update."
fi
fi
if command -v flatpak &> /dev/null; then
info "Updating Flatpaks... "
flatpak update ${auto:+--noninteractive}
fi
if [[ $confs ]]; then
2024-04-04 11:40:49 +00:00
echo "Updating configs..."
config-update $confrebase
2023-06-18 15:40:21 +00:00
fi
2024-04-04 11:40:49 +00:00
echo "Running configured extra updaters..."
misc-update $auto