dotfiles/zsh/update.zsh

138 lines
3.4 KiB
Bash

update-system() {
echo "\033[32;1m=== Updating system ===\033[0m"
start_system_update=`date +%s`
# 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
sudo dnf upgrade
fi
seconds=$((`date +%s` - $start_system_update ))
formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'`
echo "\033[32;1m=== System updated in $formatted ===\033[0m"
}
update-rust() {
# Update rust if installed
command -v rustup > /dev/null 2>&1
if [ $? -eq 0 ]; then
start_rust_update=`date +%s`
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 [ $? -ne 0 ]; then
pkg-config --libs --cflags openssl > /dev/null 2>&1
if [ $? -ne 0 ]; then
# We need to install openssl
command -v apt > /dev/null 2>&1
if [ $? -eq 0 ]; then
sudo apt install -y libssl-dev
fi
# For fedora
command -v dnf > /dev/null 2>&1
if [ $? -eq 0 ]; then
sudo dnf install openssl-devel
fi
fi
echo "\033[32;1m=== Installing rust packages updater ===\033[0m"
cargo install cargo-update
fi
echo "\033[32;1m=== Updating rust packages ===\033[0m"
cargo install-update -ag
fi
seconds=$((`date +%s` - $start_rust_update ))
formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'`
echo "\033[32;1m=== Rust updated in $formatted ===\033[0m"
}
update-dotfiles() {
start_dotfiles_update=`date +%s`
current_dir=$PWD
echo "\033[32;1m=== Updating oh-my-zsh ===\033[0m"
cd ~/.config/oh-my-zsh && git pull
echo "\033[32;1m=== Updating dotfiles ===\033[0m"
cd ~/.config/dotfiles && git pull
if [ -d ~/.config/awesome/.git ]; then
echo "\033[32;1m=== Updating awesome config ===\033[0m"
cd ~/.config/awesome/ && git pull
fi
cd $current_dir
seconds=$((`date +%s` - $start_dotfiles_update ))
formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'`
echo "\033[32;1m=== Dotfiles updated in $formatted ===\033[0m"
}
update() {
start=`date +%s`
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..."
return 1
fi
# Update the system
update-system
# Update rust and rust packages
update-rust
# Update the dotfiles
update-dotfiles
seconds=$((`date +%s` - $start_system_update ))
formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'`
echo "\033[32;1m=== Update finished in $formatted ===\033[0m"
}