dotfiles/zsh/update.zsh

165 lines
4.3 KiB
Bash
Raw Normal View History

2019-01-07 14:25:56 +01:00
update-system() {
2019-01-08 11:16:43 +01:00
# Ask for sudo right now
sudoresult=$(sudo -nv 2>&1)
if [ $? -eq 0 ]; then
# Nothing to do
elif echo $sudoresult | grep -q '^sudo:'; then
echo "\033[32;1m=== Starting system update, please enter your password ===\033[0m"
sudo true
if [ $? -ne 0 ]; then
echo "Could not get sudo..."
return 1
fi
else
echo "\033[33;1m=== You are not a sudoer, skipping system update... ===\033[0m"
return 1
fi
2018-09-26 17:12:04 +02:00
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
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"
2019-01-07 14:25:56 +01:00
}
2018-11-19 09:59:36 +01:00
2019-01-07 14:25:56 +01:00
update-rust() {
# Update rust if installed
command -v rustup > /dev/null 2>&1
2019-01-09 11:02:32 +01:00
if [ $? -ne 0 ]; then
return
fi
2019-01-07 14:25:56 +01:00
2019-01-09 11:02:32 +01:00
start_rust_update=`date +%s`
echo "\033[32;1m=== Updating rustup ===\033[0m"
rustup self update
2018-09-26 17:12:04 +02:00
2019-01-09 11:02:32 +01:00
echo "\033[32;1m=== Updating rust ===\033[0m"
rustup update
2018-09-26 17:12:04 +02:00
2019-01-09 11:02:32 +01:00
cargo install-update --help > /dev/null 2>&1
2018-09-26 17:12:04 +02:00
2019-01-09 11:02:32 +01:00
if [ $? -ne 0 ]; then
2018-09-26 18:30:54 +02:00
2019-01-09 11:02:32 +01:00
pkg-config --libs --cflags openssl > /dev/null 2>&1
2019-01-08 11:16:43 +01:00
2019-01-09 11:02:32 +01:00
# We need to install openssl
if [ $? -ne 0 ]; then
2018-09-26 18:30:54 +02:00
2019-01-09 11:02:32 +01:00
# Ask for sudo right now
sudoresult=$(sudo -nv 2>&1)
2018-09-26 18:30:54 +02:00
2019-01-09 11:02:32 +01:00
if [ $? -eq 0 ]; then
command -v apt > /dev/null 2>&1
2018-09-26 18:30:54 +02:00
if [ $? -eq 0 ]; then
2019-01-09 11:02:32 +01:00
sudo apt install -y libssl-dev
2018-09-26 18:30:54 +02:00
fi
2019-01-09 11:02:32 +01:00
# For fedora
command -v dnf > /dev/null 2>&1
if [ $? -eq 0 ]; then
sudo dnf install openssl-devel
fi
elif echo $sudoresult | grep -q '^sudo:'; then
echo "\033[32;1m=== libssl-dev is needed to update rust packages, please enter your password ===\033[0m"
sudo true
if [ $? -ne 0 ]; then
echo "Could not get sudo..."
return 1
fi
else
echo "\033[33;1m=== You are not a sudoer, cannot install cargo-update... ===\033[0m"
return 1
2018-09-26 18:30:54 +02:00
fi
2018-09-26 17:12:04 +02:00
fi
2018-09-26 18:11:42 +02:00
2019-01-09 11:02:32 +01:00
echo "\033[32;1m=== Installing rust packages updater ===\033[0m"
cargo install cargo-update
2018-09-26 17:12:04 +02:00
fi
2019-01-09 11:02:32 +01:00
echo "\033[32;1m=== Updating rust packages ===\033[0m"
cargo install-update -ag
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"
2019-01-07 14:25:56 +01:00
}
update-dotfiles() {
2018-11-19 09:59:36 +01:00
start_dotfiles_update=`date +%s`
2019-01-07 14:25:56 +01:00
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
2018-09-26 17:12:04 +02:00
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"
2019-01-07 14:25:56 +01:00
}
update() {
start=`date +%s`
2019-01-08 11:16:43 +01:00
echo "\033[32;1m=== Starting update ===\033[0m"
2019-01-07 14:25:56 +01:00
# Update the system
update-system
# Update rust and rust packages
update-rust
# Update the dotfiles
update-dotfiles
2018-11-19 09:59:36 +01:00
2019-01-09 11:05:40 +01:00
seconds=$((`date +%s` - $start ))
2018-11-19 09:59:36 +01:00
formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'`
echo "\033[32;1m=== Update finished in $formatted ===\033[0m"
2019-01-07 14:25:56 +01:00
2018-09-26 17:12:04 +02:00
}