misc/update: add rebase option

This commit is contained in:
Alexander Gehrke 2024-04-04 13:40:49 +02:00
parent 71f44d3ac7
commit 65377655af

View file

@ -3,7 +3,7 @@
source ${$(realpath "$0"):h:h}/lib/common.zsh
ALL_ARGS=("$@")
zparseopts -D -E -- -help=help h=help c=confs -conf=confs -skip-scripts=skip y=auto -yes=auto
zparseopts -D -E -- -help=help h=help c=confs -conf=confs -skip-scripts=skip y=auto -yes=auto -conf-rebase=confrebase
SCRIPTS_DIR=${$(realpath "$0"):h}
if [[ $help ]]; then
@ -21,7 +21,12 @@ if [[ $help ]]; then
fi
gitupdate() {
git -C "$1" pull --autostash && git -C "$1" push
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
}
if [[ ! $skip ]] then
@ -29,9 +34,9 @@ if [[ ! $skip ]] then
check "Updating scripts..."
local result=$(gitupdate "$SCRIPTS_DIR" 2>&1)
if [[ $? == 0 ]]; then
succeed
succeed
exec "$0" "${ALL_ARGS[@]}" --skip-scripts
else
else
fail "error during script updates"
echo $result
exit 1
@ -58,16 +63,37 @@ xbps-update () {
fi
}
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
}
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"
xbps-update
xbps-update $auto
elif [[ "$ID" == ubuntu ]] || command -v apt-get &>/dev/null; then
info "Ubuntu Linux detected"
sudo apt-get $auto update
sudo apt-get $auto update
sudo apt-get $auto upgrade
else
error "Unsupoorted distro, skipping update."
@ -80,15 +106,9 @@ if command -v flatpak &> /dev/null; then
fi
if [[ $confs ]]; then
echo Updating configs...
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
echo "Updating configs..."
config-update $confrebase
fi
echo "Running configured extra updaters..."
misc-update $auto