From 732b81139f96b9d546c88564bfc214326f31d5dc Mon Sep 17 00:00:00 2001 From: Alexander Gehrke Date: Sun, 18 Jun 2023 17:40:21 +0200 Subject: [PATCH] new script: update --- misc/update | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100755 misc/update diff --git a/misc/update b/misc/update new file mode 100755 index 0000000..036eb80 --- /dev/null +++ b/misc/update @@ -0,0 +1,94 @@ +#!/bin/zsh + +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 +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() { + git -C "$1" pull --autostash && git -C "$1" push +} + +if [[ ! $skip ]] then + # update scripts + check "Updating scripts..." + local result=$(gitupdate "$SCRIPTS_DIR" 2>&1) + if [[ $? == 0 ]]; then + succeed + exec "$0" "${ALL_ARGS[@]}" --skip-scripts + else + 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 +} + + +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 + elif [[ "$ID" == ubuntu ]] || command -v apt-get &>/dev/null; then + info "Ubuntu Linux detected" + sudo apt-get $auto update + 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 + 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 +fi