114 lines
		
	
	
	
		
			2.4 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			114 lines
		
	
	
	
		
			2.4 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
| #!/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 -conf-rebase=confrebase
 | |
| 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() {
 | |
| 	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
 | |
| 	# 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
 | |
| }
 | |
| 
 | |
| 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 $auto
 | |
| 	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..."
 | |
| 	config-update $confrebase
 | |
| fi
 | |
| 
 | |
| echo "Running configured extra updaters..."
 | |
| misc-update $auto
 | 
