#!/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