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() {
|
|
|
|
|
2018-11-19 09:59:36 +01:00
|
|
|
start=`date +%s`
|
2018-09-26 17:12:04 +02:00
|
|
|
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..."
|
2018-10-11 11:05:21 +02:00
|
|
|
return 1
|
2018-09-26 17:12:04 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "\033[32;1m=== Updating system ===\033[0m"
|
2018-11-19 09:59:36 +01:00
|
|
|
start_system_update=`date +%s`
|
2018-09-26 17:12:04 +02:00
|
|
|
|
|
|
|
# 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
|
2018-09-26 18:30:54 +02:00
|
|
|
sudo dnf upgrade
|
2018-09-26 17:12:04 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Update rust if installed
|
|
|
|
command -v rustup > /dev/null 2>&1
|
2018-11-19 09:59:36 +01:00
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
start_rust_update=`date +%s`
|
2018-09-26 17:12:04 +02:00
|
|
|
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
|
|
|
|
|
2018-09-26 18:11:42 +02:00
|
|
|
if [ $? -ne 0 ]; then
|
2018-09-26 18:30:54 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-09-26 18:11:42 +02:00
|
|
|
echo "\033[32;1m=== Installing rust packages updater ===\033[0m"
|
|
|
|
cargo install cargo-update
|
2018-09-26 17:12:04 +02:00
|
|
|
fi
|
2018-09-26 18:11:42 +02:00
|
|
|
|
|
|
|
echo "\033[32;1m=== Updating rust packages ===\033[0m"
|
|
|
|
cargo install-update -ag
|
2018-09-26 17:12:04 +02:00
|
|
|
fi
|
|
|
|
|
2018-11-19 09:59:36 +01:00
|
|
|
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"
|
|
|
|
|
2018-09-26 17:12:04 +02:00
|
|
|
# Update the dotfiles
|
2018-11-19 09:59:36 +01:00
|
|
|
start_dotfiles_update=`date +%s`
|
2018-09-26 17:12:04 +02:00
|
|
|
pull-dotfiles
|
|
|
|
|
2018-11-19 09:59:36 +01:00
|
|
|
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"
|
|
|
|
|
|
|
|
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"
|
2018-09-26 17:12:04 +02:00
|
|
|
}
|