2019-05-03 09:45:06 +02:00
|
|
|
#!/usr/bin/env bash
|
2019-02-11 17:40:33 +01:00
|
|
|
|
|
|
|
_check_date_if_format() {
|
|
|
|
local format=`_date_format`
|
|
|
|
|
|
|
|
if [ "$format" != "" ]; then
|
2019-04-17 10:04:40 +02:00
|
|
|
_check_date $format $1
|
2019-02-11 17:40:33 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-02-01 15:18:33 +01:00
|
|
|
_date_format() {
|
|
|
|
|
|
|
|
case $UPDATE_CHECK in
|
|
|
|
"daily") echo +%d/%m/%Y;;
|
|
|
|
"weekly") echo +%V/%Y;;
|
|
|
|
"monthly") echo +%m/%Y;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-02-01 11:54:10 +01:00
|
|
|
_check_date_file() {
|
|
|
|
mkdir -p ~/.config/dotfiles/.data
|
|
|
|
touch ~/.config/dotfiles/.data/update_date
|
|
|
|
}
|
|
|
|
|
|
|
|
_sentence() {
|
|
|
|
subject0=("Your" "The" "This")
|
|
|
|
subject1=("system" "machine" "pc" "computer")
|
|
|
|
adjective=("awesome" "incredible" "amazing" "brave" "hard working" "loyal" "nice" "polite" "powerful" "pro-active" "reliable" "fabulous" "fantastic" "incredible" "outstanding" "remarkable" "spectacular" "splendid" "super" "happy" "cheerful")
|
|
|
|
verb=("is" "seems" "looks" "appears to be")
|
|
|
|
no_verb=("is not" "doesn't seem" "doesn't look" "appears not to be")
|
|
|
|
adverb=("up-to-date" "ready" "updated")
|
|
|
|
dot=("." "!" "...")
|
|
|
|
|
2019-05-03 09:45:06 +02:00
|
|
|
n_subject0=`shuf -i0-"$((${#subject0[@]}-1))" -n1`
|
|
|
|
n_subject1=`shuf -i0-"$((${#subject1[@]}-1))" -n1`
|
|
|
|
n_adjective=`shuf -i0-"$((${#adjective[@]}-1))" -n1`
|
|
|
|
n_adverb=`shuf -i0-"$((${#adverb[@]}-1))" -n1`
|
|
|
|
n_dot=`shuf -i0-"$((${#dot[@]}-1))" -n1`
|
2019-02-01 11:54:10 +01:00
|
|
|
|
|
|
|
if [ $1 = "updated" ]; then
|
|
|
|
color="32"
|
2019-05-03 09:45:06 +02:00
|
|
|
n_verb=`shuf -i0-"$((${#verb[@]}-1))" -n1`
|
|
|
|
s_verb=${verb[$n_verb]}
|
2019-02-01 11:54:10 +01:00
|
|
|
elif [ $1 = "not_updated" ]; then
|
|
|
|
color="31"
|
2019-05-03 09:45:06 +02:00
|
|
|
n_verb=`shuf -i0-"$((${#no_verb[@]}-1))" -n1`
|
|
|
|
s_verb=${no_verb[$n_verb]}
|
2019-02-01 11:54:10 +01:00
|
|
|
fi
|
|
|
|
|
2019-05-03 09:45:06 +02:00
|
|
|
echo -e "\033[$color;1m${subject0[$n_subject0]} ${adjective[$n_adjective]} ${subject1[$n_subject1]} $s_verb ${adverb[$n_adverb]}${dot[$n_dot]}\033[0m"
|
2019-02-01 11:54:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_check_date() {
|
2019-02-01 15:18:33 +01:00
|
|
|
|
2019-02-01 11:54:10 +01:00
|
|
|
_check_date_file
|
|
|
|
|
|
|
|
old_date=`cat ~/.config/dotfiles/.data/update_date`
|
2019-02-01 15:18:33 +01:00
|
|
|
new_date=`date $1`
|
2019-02-01 11:54:10 +01:00
|
|
|
|
|
|
|
if [ "$new_date" != "$old_date" ]; then
|
|
|
|
_sentence not_updated
|
2019-04-17 10:04:40 +02:00
|
|
|
elif [ "$UPDATE_CHECK_ALWAYS" = "true" ] || [ "$2" = "force" ]; then
|
2019-02-01 11:54:10 +01:00
|
|
|
_sentence updated
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-01-07 14:25:56 +01:00
|
|
|
update-system() {
|
2019-01-08 11:16:43 +01:00
|
|
|
|
2019-05-03 09:45:06 +02:00
|
|
|
echo -e "\033[32;1m=== Starting system update, please enter your password ===\033[0m"
|
2019-04-22 10:03:25 +02:00
|
|
|
sudo true
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Could not get sudo..."
|
2019-01-08 11:16:43 +01:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2019-05-03 09:45:06 +02:00
|
|
|
echo -e "\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
|
2019-03-13 10:46:24 +01:00
|
|
|
command -v yay > /dev/null 2>&1
|
|
|
|
|
2018-09-26 17:12:04 +02:00
|
|
|
if [ $? -eq 0 ]; then
|
2019-04-16 14:48:47 +02:00
|
|
|
yay -Syu --noconfirm
|
2019-03-15 20:42:03 +01:00
|
|
|
yay -Syua --noconfirm
|
2018-09-26 17:12:04 +02:00
|
|
|
else
|
2019-03-13 10:46:24 +01:00
|
|
|
command -v pacman > /dev/null 2>&1
|
2018-09-26 17:12:04 +02:00
|
|
|
|
|
|
|
if [ $? -eq 0 ]; then
|
2019-03-15 20:42:03 +01:00
|
|
|
sudo pacman -Syu --noconfirm
|
2018-09-26 17:12:04 +02:00
|
|
|
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'`
|
2019-05-03 09:45:06 +02:00
|
|
|
echo -e "\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`
|
2019-05-03 09:45:06 +02:00
|
|
|
echo -e "\033[32;1m=== Updating rustup ===\033[0m"
|
2019-01-09 11:02:32 +01:00
|
|
|
rustup self update
|
2018-09-26 17:12:04 +02:00
|
|
|
|
2019-05-03 09:45:06 +02:00
|
|
|
echo -e "\033[32;1m=== Updating rust ===\033[0m"
|
2019-01-09 11:02:32 +01:00
|
|
|
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
|
2019-05-03 09:45:06 +02:00
|
|
|
echo -e "\033[32;1m=== libssl-dev is needed to update rust packages, please enter your password ===\033[0m"
|
2019-01-09 11:02:32 +01:00
|
|
|
sudo true
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Could not get sudo..."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
else
|
2019-05-03 09:45:06 +02:00
|
|
|
echo -e "\033[33;1m=== You are not a sudoer, cannot install cargo-update... ===\033[0m"
|
2019-01-09 11:02:32 +01:00
|
|
|
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-05-03 09:45:06 +02:00
|
|
|
echo -e "\033[32;1m=== Installing rust packages updater ===\033[0m"
|
2019-01-09 11:02:32 +01:00
|
|
|
cargo install cargo-update
|
2018-09-26 17:12:04 +02:00
|
|
|
fi
|
|
|
|
|
2019-05-03 09:45:06 +02:00
|
|
|
echo -e "\033[32;1m=== Updating rust packages ===\033[0m"
|
2019-01-09 11:02:32 +01:00
|
|
|
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'`
|
2019-05-03 09:45:06 +02:00
|
|
|
echo -e "\033[32;1m=== Rust updated in $formatted ===\033[0m"
|
2018-11-19 09:59:36 +01:00
|
|
|
|
2019-01-07 14:25:56 +01:00
|
|
|
}
|
|
|
|
|
2019-03-15 15:32:54 +01:00
|
|
|
update-npm() {
|
|
|
|
|
|
|
|
# Update node packages if installed
|
|
|
|
command -v npm > /dev/null 2>&1
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2019-03-21 17:56:49 +01:00
|
|
|
if [ ! -d ~/.npmbin ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2019-03-15 15:32:54 +01:00
|
|
|
start_npm_update=`date +%s`
|
2019-05-03 09:45:06 +02:00
|
|
|
echo -e "\033[32;1m=== Updating node packages ===\033[0m"
|
2019-03-15 15:32:54 +01:00
|
|
|
|
|
|
|
for package in $(npm -g outdated --parseable --depth=0 | cut -d: -f3)
|
|
|
|
do
|
|
|
|
npm -g install "$package"
|
|
|
|
done
|
|
|
|
|
2019-03-17 22:37:40 +01:00
|
|
|
seconds=$((`date +%s` - $start_npm_update ))
|
2019-03-15 15:32:54 +01:00
|
|
|
formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'`
|
2019-05-03 09:45:06 +02:00
|
|
|
echo -e "\033[32;1m=== Node packages updated in $formatted ===\033[0m"
|
2019-03-15 15:32:54 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2019-05-03 09:45:06 +02:00
|
|
|
echo -e "\033[32;1m=== Updating dotfiles ===\033[0m"
|
2019-01-07 14:25:56 +01:00
|
|
|
cd ~/.config/dotfiles && git pull
|
|
|
|
|
2019-05-03 10:22:50 +02:00
|
|
|
if [ -d ~/.config/oh-my-zsh ]; then
|
|
|
|
echo -e "\033[32;1m=== Updating oh-my-zsh ===\033[0m"
|
|
|
|
cd ~/.config/oh-my-zsh && git pull
|
|
|
|
fi
|
|
|
|
|
2019-01-07 14:25:56 +01:00
|
|
|
if [ -d ~/.config/awesome/.git ]; then
|
2019-05-03 09:45:06 +02:00
|
|
|
echo -e "\033[32;1m=== Updating awesome config ===\033[0m"
|
2019-01-07 14:25:56 +01:00
|
|
|
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'`
|
2019-05-03 09:45:06 +02:00
|
|
|
echo -e "\033[32;1m=== Dotfiles updated in $formatted ===\033[0m"
|
2019-01-07 14:25:56 +01:00
|
|
|
}
|
|
|
|
|
2019-04-03 18:26:51 +02:00
|
|
|
update-neovim() {
|
2019-04-03 18:32:56 +02:00
|
|
|
command -v nvim > /dev/null 2>&1
|
2019-04-03 18:26:51 +02:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
start_neovim_update=`date +%s`
|
2019-05-03 09:45:06 +02:00
|
|
|
echo -e "\033[32;1m=== Updating neovim packages ===\033[0m"
|
2019-04-03 18:26:51 +02:00
|
|
|
|
|
|
|
nvim +PlugUpdate +qall
|
|
|
|
|
|
|
|
seconds=$((`date +%s` - $start_neovim_update ))
|
|
|
|
formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'`
|
2019-05-03 09:45:06 +02:00
|
|
|
echo -e "\033[32;1m=== Neovim updated in $formatted ===\033[0m"
|
2019-04-03 18:26:51 +02:00
|
|
|
}
|
|
|
|
|
2019-04-17 10:04:40 +02:00
|
|
|
_print_help() {
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
2019-04-17 16:46:15 +02:00
|
|
|
partial-test() {
|
2019-05-03 09:45:06 +02:00
|
|
|
case $1 in
|
2019-04-17 16:46:15 +02:00
|
|
|
"system") return 0;;
|
|
|
|
"rust") return 0;;
|
|
|
|
"npm") return 0;;
|
|
|
|
"dotfiles") return 0;;
|
|
|
|
"neovim") return 0;;
|
|
|
|
"check") return 0;;
|
|
|
|
"startup") return 0;;
|
|
|
|
*) return 1;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
partial-update() {
|
2019-05-03 09:45:06 +02:00
|
|
|
case $1 in
|
2019-04-17 16:46:15 +02:00
|
|
|
"system") update-system;;
|
|
|
|
"rust") update-rust;;
|
|
|
|
"npm") update-npm;;
|
|
|
|
"dotfiles") update-dotfiles;;
|
|
|
|
"neovim") update-neovim;;
|
|
|
|
"check") _check_date_if_format force;;
|
|
|
|
"startup") _check_date_if_format;;
|
|
|
|
*) return 1
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2019-02-11 17:40:33 +01:00
|
|
|
main() {
|
2019-01-07 14:25:56 +01:00
|
|
|
|
2019-02-11 17:40:33 +01:00
|
|
|
if [ $# -eq 0 ]; then
|
2019-01-07 14:25:56 +01:00
|
|
|
|
2019-02-11 17:40:33 +01:00
|
|
|
start=`date +%s`
|
2019-05-03 09:45:06 +02:00
|
|
|
echo -e "\033[32;1m=== Starting full update ===\033[0m"
|
2019-01-07 14:25:56 +01:00
|
|
|
|
2019-02-11 17:40:33 +01:00
|
|
|
# Update the system
|
|
|
|
update-system
|
2019-01-07 14:25:56 +01:00
|
|
|
|
2019-02-11 17:40:33 +01:00
|
|
|
# Update rust and rust packages
|
|
|
|
update-rust
|
2018-11-19 09:59:36 +01:00
|
|
|
|
2019-03-15 15:32:54 +01:00
|
|
|
# Update npm and npm packages
|
|
|
|
update-npm
|
|
|
|
|
2019-02-11 17:40:33 +01:00
|
|
|
# Update the dotfiles
|
|
|
|
update-dotfiles
|
2019-01-07 14:25:56 +01:00
|
|
|
|
2019-04-03 18:26:51 +02:00
|
|
|
# Update the neovim packages
|
|
|
|
update-neovim
|
|
|
|
|
2019-02-11 17:40:33 +01:00
|
|
|
format=`_date_format`
|
2019-02-01 15:18:33 +01:00
|
|
|
|
2019-02-11 17:40:33 +01:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
_check_date_file
|
|
|
|
date $format > ~/.config/dotfiles/.data/update_date
|
|
|
|
fi
|
2019-02-01 15:18:33 +01:00
|
|
|
|
2019-02-11 17:40:33 +01:00
|
|
|
seconds=$((`date +%s` - $start ))
|
|
|
|
formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'`
|
2019-05-03 09:45:06 +02:00
|
|
|
echo -e "\033[32;1m=== Update finished in $formatted ===\033[0m"
|
2019-02-11 17:40:33 +01:00
|
|
|
|
2019-04-17 10:04:40 +02:00
|
|
|
_check_date_if_format force
|
|
|
|
|
2019-02-11 17:40:33 +01:00
|
|
|
else
|
|
|
|
|
2019-04-17 16:46:15 +02:00
|
|
|
for part in $@; do
|
|
|
|
partial-test $part
|
|
|
|
if [ $? -ne 0 ]; then
|
2019-05-03 09:45:06 +02:00
|
|
|
echo -e "\033[1;31merror:\033[0m unrocognized update command \"$part\""
|
2019-04-17 16:46:15 +02:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
done
|
2019-02-11 17:40:33 +01:00
|
|
|
|
2019-04-17 16:46:15 +02:00
|
|
|
for part in $@; do
|
|
|
|
partial-update $part
|
2019-04-17 10:04:40 +02:00
|
|
|
done
|
2019-02-01 15:18:33 +01:00
|
|
|
|
|
|
|
fi
|
2019-02-11 17:40:33 +01:00
|
|
|
|
2018-09-26 17:12:04 +02:00
|
|
|
}
|
2019-02-11 17:40:33 +01:00
|
|
|
|
|
|
|
main $@
|