Skip to content

Instantly share code, notes, and snippets.

@PCouaillier
Last active August 24, 2022 13:11
Show Gist options
  • Save PCouaillier/46294a1127e2a9161418b912f7df5da0 to your computer and use it in GitHub Desktop.
Save PCouaillier/46294a1127e2a9161418b912f7df5da0 to your computer and use it in GitHub Desktop.
simple script to keep a system up to date
#!/usr/bin/env sh
if command -v apt-fast > /dev/null 2>&1
then
sudo apt-fast update && sudo apt-fast upgrade -y
else
if command -v apt > /dev/null 2>&1
then
sudo apt update && sudo apt upgrade -y
fi
fi
if command -v zypper > /dev/null 2>&1
then
sudo zypper ref && sudo zypper up -y && test "production" != "$ENVIRONMENT" && sudo zypper dup -y
fi
if command -v rustup > /dev/null 2>&1
then
rustup update
fi
if command -v flatpak > /dev/null 2>&1
then
flatpak update
fi
function _upgrade_opt() {
current_path=$(pwd)
if test -z "$SSH_AUTH_SOCK" -o -z "$SSH_AGENT_PID"
then
eval $(ssh-agent) ; ssh-add or true
fi
for p in $(find ~/.local/opt/ -mindepth 1 -maxdepth 1 -type d)
do
cd "$p"
if command -v git > /dev/null 2>&1
then
if test -d ".git"
then
git pull --rebase --autostash
if test 0 -eq "$?" -a -f "Cargo.toml"
then
cargo build --release
fi
fi
fi
done
cd "$current_path"
}
while getopts ':oh' options; do
case ${options} in
h)
echo " -h shows this message "
echo " -o upgrades .local/opt/"
;;
o)
_upgrade_opt
;;
?)
echo "Invalid option: -${OPTARG}."
exit 1
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment