diff --git a/bin/update b/bin/update index 5795623..87a4361 100755 --- a/bin/update +++ b/bin/update @@ -60,30 +60,30 @@ _check_date_file() { } _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=("." "!" "...") + local subject0=("Your" "The" "This") + local subject1=("system" "machine" "pc" "computer") + local adjective=("awesome" "incredible" "amazing" "brave" "hard working" "loyal" "nice" "polite" "powerful" "pro-active" "reliable" "fabulous" "fantastic" "incredible" "outstanding" "remarkable" "spectacular" "splendid" "super" "happy" "cheerful") + local verb=("is" "seems" "looks" "appears to be") + local no_verb=("is not" "doesn't seem" "doesn't look" "appears not to be") + local adverb=("up-to-date" "ready" "updated") + local dot=("." "!" "...") - 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` + local n_subject0=`shuf -i0-"$((${#subject0[@]}-1))" -n1` + local n_subject1=`shuf -i0-"$((${#subject1[@]}-1))" -n1` + local n_adjective=`shuf -i0-"$((${#adjective[@]}-1))" -n1` + local n_adverb=`shuf -i0-"$((${#adverb[@]}-1))" -n1` + local n_dot=`shuf -i0-"$((${#dot[@]}-1))" -n1` if [ $1 = "updated" ]; then - color="32" - n_verb=`shuf -i0-"$((${#verb[@]}-1))" -n1` - s_verb=${verb[$n_verb]} - end="" + local color="32" + local n_verb=`shuf -i0-"$((${#verb[@]}-1))" -n1` + local s_verb=${verb[$n_verb]} + local end="" elif [ $1 = "not_updated" ]; then - color="31" - n_verb=`shuf -i0-"$((${#no_verb[@]}-1))" -n1` - s_verb=${no_verb[$n_verb]} - end="Run \`update\` to update your system." + local color="31" + local n_verb=`shuf -i0-"$((${#no_verb[@]}-1))" -n1` + local s_verb=${no_verb[$n_verb]} + local end="Run \`update\` to update your system." fi echo -e "\033[$color;1m${subject0[$n_subject0]} ${adjective[$n_adjective]} ${subject1[$n_subject1]} $s_verb ${adverb[$n_adverb]}${dot[$n_dot]} ${end}\033[0m" @@ -93,8 +93,8 @@ _check_date() { _check_date_file - old_date=`cat ~/.config/dotfiles/.data/update_date` - new_date=`date $1` + local old_date=`cat ~/.config/dotfiles/.data/update_date` + local new_date=`date $1` if [ "$new_date" != "$old_date" ]; then _sentence not_updated @@ -119,7 +119,7 @@ update-system() { fi echo -e "\033[32;1m=== Updating system ===\033[0m" - start_system_update=`date +%s` + local start=`date +%s` # Debian based systems command -v apt > /dev/null 2>&1 @@ -153,8 +153,8 @@ update-system() { sudo dnf upgrade fi - seconds=$((`date +%s` - $start_system_update )) - formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` + local seconds=$((`date +%s` - $start)) + local formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` echo -e "\033[32;1m=== System updated in $formatted ===\033[0m" } @@ -166,7 +166,7 @@ update-rust() { return fi - start_rust_update=`date +%s` + local start=`date +%s` echo -e "\033[32;1m=== Updating rustup ===\033[0m" rustup self update @@ -180,7 +180,7 @@ update-rust() { # This program requires openssl, so check that it is installed pkg-config --libs --cflags openssl > /dev/null 2>&1 - installed_openssl=$? + local installed_openssl=$? # We need to install openssl if [ $installed_openssl -ne 0 ]; then @@ -227,8 +227,8 @@ update-rust() { cargo install-update -ag fi - seconds=$((`date +%s` - $start_rust_update )) - formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` + local seconds=$((`date +%s` - $start)) + local formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` echo -e "\033[32;1m=== Rust updated in $formatted ===\033[0m" } @@ -240,12 +240,12 @@ update-wasm() { fi echo -e "\033[32;1m=== Updating wasmer ===\033[0m" - start_wasm_update=`date +%s` + local start=`date +%s` wasmer self-update - seconds=$((`date +%s` - $start_wasm_update )) - formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` + local seconds=$((`date +%s` - $start)) + local formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` echo -e "\033[32;1m=== Wasm updated in $formatted ===\033[0m" } @@ -261,19 +261,19 @@ update-npm() { return fi - start_npm_update=`date +%s` + local start=`date +%s` echo -e "\033[32;1m=== Updating node packages ===\033[0m" npm update -g - seconds=$((`date +%s` - $start_npm_update )) - formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` + local seconds=$((`date +%s` - $start)) + local formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` echo -e "\033[32;1m=== Node packages updated in $formatted ===\033[0m" } update-dotfiles() { - start_dotfiles_update=`date +%s` + local start=`date +%s` - current_dir=$PWD + local current_dir=$PWD echo -e "\033[32;1m=== Updating dotfiles ===\033[0m" cd ~/.config/dotfiles && git pull @@ -290,8 +290,8 @@ update-dotfiles() { cd $current_dir - seconds=$((`date +%s` - $start_dotfiles_update )) - formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` + local seconds=$((`date +%s` - $start)) + local formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` echo -e "\033[32;1m=== Dotfiles updated in $formatted ===\033[0m" } @@ -301,13 +301,13 @@ update-neovim() { return fi - start_neovim_update=`date +%s` + local start=`date +%s` echo -e "\033[32;1m=== Updating neovim packages ===\033[0m" nvim +PlugUpdate +qall - seconds=$((`date +%s` - $start_neovim_update )) - formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` + local seconds=$((`date +%s` - $start)) + local formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` echo -e "\033[32;1m=== Neovim updated in $formatted ===\033[0m" } @@ -402,7 +402,7 @@ main() { return $? fi - start=`date +%s` + local start=`date +%s` echo -e "\033[32;1m=== Starting full update ===\033[0m" # Update the system @@ -433,8 +433,8 @@ main() { update-postpone _check_running - seconds=$((`date +%s` - $start )) - formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` + local seconds=$((`date +%s` - $start )) + local formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` echo -e "\033[32;1m=== Update finished in $formatted ===\033[0m" _check_running