94 lines
2.9 KiB
Bash
Executable file
94 lines
2.9 KiB
Bash
Executable file
#!/bin/sh
|
|
# Upgrade script for
|
|
# some GNU/Linux distros
|
|
|
|
# Clean previous logs
|
|
rm -rf "$XDG_STATE_HOME"/upgrade_logs_*
|
|
|
|
# Get pkgmanager name
|
|
[ -d "/var/lib/pacman" ] && pkgmanager="pacman"
|
|
[ -d "/var/lib/dpkg" ] && pkgmanager="apt"
|
|
[ -d "/var/db/xbps" ] && pkgmanager="xbps"
|
|
|
|
# Prompts
|
|
printf "Update repository index? ($pkgmanager) [y/N]: "
|
|
read -r ind # Repository index
|
|
printf "Update packages? ($pkgmanager & flatpak) [y/N]: "
|
|
read -r pkg # Packages
|
|
printf "Update configs? (~/.config/) [y/N]: "
|
|
read -r cfg # Configs
|
|
printf "Update source-built? (~/.local/src/) [y/N]: "
|
|
read -r src # Source built
|
|
printf "Update password vault? [y/N]: "
|
|
read -r pss # Passwords
|
|
|
|
# Functions for each pkgmanager (missing xbps)
|
|
update() {
|
|
case $pkgmanager in
|
|
"pacman") yay -Sy && yay -Sy archlinux-keyring --needed --noconfirm >> "$XDG_STATE_HOME"/upgrade_logs_pkg ;;
|
|
"apt") sudo apt-get update >> "$XDG_STATE_HOME"/upgrade_logs_pkg ;;
|
|
"xbps") echo "TBD" ;;
|
|
esac
|
|
}
|
|
|
|
upgrade() {
|
|
case $pkgmanager in
|
|
"pacman") yay -Syu --noconfirm ;;
|
|
"apt") sudo apt-get upgrade -y ;;
|
|
"xbps") echo "TBD" ;;
|
|
esac
|
|
}
|
|
|
|
# Script steps
|
|
index() {
|
|
printf "\n\033[1m"Updating"\033[0m \033[1m"package"\033[0m \033[1m"index..."\033[0m\n"
|
|
update
|
|
}
|
|
|
|
packages() {
|
|
printf "\n\033[1m"Upgrading"\033[0m \033[1m"packages..."\033[0m\n"
|
|
upgrade
|
|
flatpak update -y --noninteractive >> "$XDG_STATE_HOME"/upgrade_logs_pkg
|
|
}
|
|
|
|
configs() {
|
|
printf "\n\033[1m"Updating"\033[0m \033[1m"configs..."\033[0m\n"
|
|
git -C ~/.config pull >> "$XDG_STATE_HOME"/upgrade_logs_git
|
|
}
|
|
|
|
sources() {
|
|
printf "\n\033[1m"Getting"\033[0m \033[1m"and"\033[0m \033[1m"building"\033[0m \033[1m"source..."\033[0m\n"
|
|
for dir in ~/.local/src/* ; do
|
|
git -C $dir pull >> "$XDG_STATE_HOME"/upgrade_logs_git
|
|
if [ "$(diff $dir/config.h $dir/config.def.h)" != "" ] ; then
|
|
printf "Found diffs in $dir/config.def.h, apply? [y/N]: "
|
|
read -r diff
|
|
[ "$diff" = "y" ] && rm -rf "$dir"/config.h
|
|
fi
|
|
sudo make clean install -C "$dir" >> "$XDG_STATE_HOME"/upgrade_logs_src
|
|
done
|
|
}
|
|
|
|
passwords() {
|
|
printf "\n\033[1m"Getting"\033[0m \033[1m"passwords..."\033[0m\n"
|
|
pass git pull >> "$XDG_STATE_HOME"/upgrade_logs_git
|
|
}
|
|
|
|
# Error control
|
|
[ "$ind" = "y" ] && index &&
|
|
notify-send " Repositories" "Updated repository index" || notify-send " Repositories" "Couldn't complete"
|
|
|
|
[ "$pkg" = "y" ] && packages &&
|
|
notify-send " Packages" "Updated package base" || notify-send " Packages" "Couldn't complete"
|
|
|
|
[ "$cfg" = "y" ] && configs &&
|
|
notify-send " Configs" "Updated configs" || notify-send " Configs" "Coudn't complete"
|
|
|
|
[ "$src" = "y" ] && sources &&
|
|
notify-send " Source" "Updated source builds" || notify-send " Source" "Coudn't complete"
|
|
|
|
[ "$pss" = "y" ] && passwords &&
|
|
notify-send " Passwords" "Updated password vault" || notify-send " Passwords" "Coudn't complete"
|
|
|
|
printf "\n\033[1m"Done!"\033[0m\n"
|
|
notify-send " Upgrade complete"
|