dotfiles/zsh/update.zsh

76 lines
1.7 KiB
Bash
Raw Normal View History

2018-09-26 17:12:04 +02:00
pull-dotfiles() {
current_dir=$PWD
echo "\033[32;1m=== Updating dotfiles ===\033[0m"
cd ~/.config/dotfiles && git pull
echo "\033[32;1m=== Updating oh-my-zsh ===\033[0m"
cd ~/.config/oh-my-zsh && git pull
cd $current_dir
}
update() {
echo "\033[32;1m=== Starting the update, please enter your password ===\033[0m"
# Ask for sudo right now
sudo true
if [ $? -ne 0 ]; then
echo "Could not get sudo..."
exit 1
fi
echo "\033[32;1m=== Updating system ===\033[0m"
# Debian based systems
command -v apt > /dev/null 2>&1
if [ $? -eq 0 ]; then
sudo apt update -y
if [ $? -eq 0 ]; then
sudo apt upgrade -y
if [ $? -eq 0 ]; then
sudo apt autoremove -y
fi
fi
fi
# Archlinux based systems
command -v yaourt > /dev/null 2>&1
if [ $? -eq 0 ]; then
yaourt -Syu
else
command -v pacman > /dev/null 2>&1
if [ $? -eq 0 ]; then
sudo pacman -Syu
fi
fi
# Fedora based systems
command -v dnf > /dev/null 2>&1
if [ $? -eq 0 ]; then
dnf upgrade
fi
# Update rust if installed
command -v rustup > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "\033[32;1m=== Updating rustup ===\033[0m"
rustup self update
echo "\033[32;1m=== Updating rust ===\033[0m"
rustup update
cargo install-update --help > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "\033[32;1m=== Updating rust packages ===\033[0m"
cargo install-update -ag
fi
fi
# Update the dotfiles
pull-dotfiles
echo "\033[32;1m=== Update finished ===\033[0m"
}