updater script
This commit is contained in:
parent
f02c609c70
commit
d960b99cbe
2 changed files with 129 additions and 1 deletions
128
scripts/mgr
Executable file
128
scripts/mgr
Executable file
|
@ -0,0 +1,128 @@
|
||||||
|
#!/bin/sh
|
||||||
|
TASKS="$@"
|
||||||
|
|
||||||
|
PACMAN_UPDATE='yay -Sy && yay -Sy archlinux-keyring --needed --noconfirm'
|
||||||
|
PACMAN_UPGRADE='yay -Syu --noconfirm'
|
||||||
|
FLATPAK_UPDATE='/usr/bin/flatpak update -y --noninteractive'
|
||||||
|
DISTROBOX_UPDATE='/usr/bin/distrobox-upgrade -a'
|
||||||
|
PIP_UPDATE='/usr/bin/pipx upgrade-all'
|
||||||
|
PASSMGR_UPDATE='/usr/bin/pass git pull'
|
||||||
|
|
||||||
|
success() {
|
||||||
|
PROMPT="$1"
|
||||||
|
notify-send " $PROMPT"
|
||||||
|
printf "\033[32m %s\033[0m\n" "$PROMPT"
|
||||||
|
}
|
||||||
|
|
||||||
|
warn() {
|
||||||
|
PROMPT="$1"
|
||||||
|
printf "\033[33mWarning: %s\033[0m\n" "$PROMPT"
|
||||||
|
}
|
||||||
|
|
||||||
|
error() {
|
||||||
|
PROMPT="$1"
|
||||||
|
notify-send "Error: $PROMPT"
|
||||||
|
printf "\033[31mError: %s\033[0m\n" "$PROMPT"
|
||||||
|
}
|
||||||
|
|
||||||
|
pacman_update() {
|
||||||
|
if [ -d "/var/lib/pacman" ] ; then
|
||||||
|
$PACMAN_UPDATE && success "Updated pacman package index" && return 0
|
||||||
|
error "Could not update pacman index"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
warn "pacman not installed"
|
||||||
|
}
|
||||||
|
|
||||||
|
apt_update() {
|
||||||
|
[ -z "$sudopass" ] && sudopass="$(< /dev/null | menu "sudo:" pass)"
|
||||||
|
if [ -d "/var/lib/dpkg" ] && [ -e "/usr/bin/apt-get" ] ; then
|
||||||
|
printf '%s' "$sudopass" | sudo -S apt update && status="success"
|
||||||
|
[ "$status" != "success" ] && error "Could not update apt index" && return 1
|
||||||
|
upgradable="$(apt list --upgradable)"
|
||||||
|
[ "$upgradable" != "Listing..." ] && success "Updates available"
|
||||||
|
success "Updated apt package index" && return 0
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
warn "apt not installed"
|
||||||
|
}
|
||||||
|
|
||||||
|
pacman_upgrade() {
|
||||||
|
pacman_update
|
||||||
|
if [ -d "/var/lib/pacman" ] ; then
|
||||||
|
$PACMAN_UPGRADE && success "Updated pacman packages" && return 0
|
||||||
|
error "Could not update pacman packages"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
apt_upgrade() {
|
||||||
|
[ -z "$sudopass" ] && sudopass="$(< /dev/null | menu "sudo:" pass)"
|
||||||
|
apt_update
|
||||||
|
if [ -d "/var/lib/dpkg" ] && [ -e "/usr/bin/apt-get" ] ; then
|
||||||
|
mkdir -p /tmp/apt-updater
|
||||||
|
dpkg-query -l --no-pager | gzip > /tmp/apt-updater/previous
|
||||||
|
printf '%s' "$sudopass" | sudo apt upgrade -y || status="$(echo 'error')"
|
||||||
|
[ "$status" = "error" ] && error "Could not update apt packages"
|
||||||
|
dpkg-query -l --no-pager | gzip > /tmp/apt-updater/current
|
||||||
|
if [ -z "$(diff /tmp/apt-updater/current /tmp/apt-updater/previous)" ] ; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
success "Updated apt packages"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
rm -rf /tmp/apt-updater
|
||||||
|
error "Could not update apt packages"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
flatpak_update() {
|
||||||
|
if [ -e "/usr/bin/flatpak" ] ; then
|
||||||
|
$FLATPAK_UPDATE
|
||||||
|
success "Updated flatpak packages"
|
||||||
|
else
|
||||||
|
warn "flatpak not installed"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
distrobox_update() {
|
||||||
|
if [ -e "/usr/bin/distrobox" ] ; then
|
||||||
|
$DISTROBOX_UPDATE
|
||||||
|
success "Updated distrobox containers"
|
||||||
|
else
|
||||||
|
warn "distrobox not installed"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
pip_update() {
|
||||||
|
if [ -e "/usr/bin/pipx" ] ; then
|
||||||
|
status="$($PIP_UPDATE)"
|
||||||
|
[ "$status" = "Versions did not change after running 'pipx upgrade' for each package 😴" ] && return 0
|
||||||
|
success "Updated pipx packages"
|
||||||
|
else
|
||||||
|
warn "pipx not installed"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
configs() {
|
||||||
|
for homecfg in /home/*/.config ; do
|
||||||
|
status="$(/usr/bin/git -C $homecfg pull || echo 'error')"
|
||||||
|
[ "$status" = "error" ] && error "Updating configs failed" && return 1
|
||||||
|
if [ "$status" != "Already up to date." ] ; then
|
||||||
|
success "Updated configs"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
passmgr() {
|
||||||
|
if [ -e "/usr/bin/pass" ] ; then
|
||||||
|
status="$($PASSMGR_UPDATE || echo 'error')"
|
||||||
|
[ "$status" = "error" ] && error "Updating passwords failed" && return 1
|
||||||
|
if [ "$status" != "Already up to date." ] ; then success "Updated passwords" ; fi
|
||||||
|
else
|
||||||
|
warn "pass not installed"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
for TASK in $TASKS ; do $TASK ; done
|
||||||
|
|
||||||
|
sudopass=""
|
|
@ -30,7 +30,7 @@ alias \
|
||||||
|
|
||||||
# Command shortcuts
|
# Command shortcuts
|
||||||
alias \
|
alias \
|
||||||
apt-upgrade="sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y" \
|
mgr-all="mgr pacman_upgrade apt_upgrade flatpak_update distrobox_update pip_update configs passmgr" \
|
||||||
df-short="df -h | grep -v '\s/dev.*$\|\s/run.*$\|\s/boot.*$'" \
|
df-short="df -h | grep -v '\s/dev.*$\|\s/run.*$\|\s/boot.*$'" \
|
||||||
wacom-setup-menu="wacom-setup menu" \
|
wacom-setup-menu="wacom-setup menu" \
|
||||||
swayimg="swayimg -s fit -w 000000 -m" \
|
swayimg="swayimg -s fit -w 000000 -m" \
|
||||||
|
|
Loading…
Reference in a new issue