Created
April 17, 2015 17:46
-
-
Save rhoconlinux/e71fc38582cdc5240643 to your computer and use it in GitHub Desktop.
ninja-apt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Author: rhoconlinux, http://rhoconlinux.wordpress.com | |
| # ------ | |
| # Credit for the spinner > Tasos Latsas https://github.com/tlatsas/bash-spinner | |
| ##########################spinner funcion starts | |
| function _spinner() { | |
| # $1 start/stop | |
| # | |
| # on start: $2 display message | |
| # on stop : $2 process exit status | |
| # $3 spinner function pid (supplied from stop_spinner) | |
| local on_success="DONE" | |
| local on_fail="FAIL" | |
| local white="\e[1;37m" | |
| local green="\e[1;32m" | |
| local red="\e[1;31m" | |
| local nc="\e[0m" | |
| case $1 in | |
| start) | |
| # calculate the column where spinner and status msg will be displayed | |
| let COLS=$(tput cols) | |
| let column=${#2} | |
| # display message and position the cursor in $column column | |
| echo -ne ${2} | |
| printf "\n%${column}s" | |
| #printf "%$1" | |
| # start spinner | |
| i=1 | |
| sp='\|/-' | |
| delay=0.15 | |
| while : | |
| do | |
| printf "\b${sp:i++%${#sp}:1}" | |
| sleep $delay | |
| done | |
| ;; | |
| stop) | |
| if [[ -z ${3} ]]; then | |
| echo "spinner is not running.." | |
| exit 1 | |
| fi | |
| kill $3 > /dev/null 2>&1 | |
| # inform the user uppon success or failure | |
| echo -en "\b[" | |
| if [[ $2 -eq 0 ]]; then | |
| echo -en "${green}${on_success}${nc}" | |
| else | |
| echo -en "${red}${on_fail}${nc}" | |
| fi | |
| echo -e "]" | |
| ;; | |
| *) | |
| echo "invalid argument, try {start/stop}" | |
| exit 1 | |
| ;; | |
| esac | |
| } | |
| function start_spinner { | |
| # $1 : msg to display | |
| _spinner "start" "${1}" & | |
| # set global spinner pid | |
| _sp_pid=$! | |
| disown | |
| } | |
| function stop_spinner { | |
| # $1 : command exit status | |
| _spinner "stop" $1 $_sp_pid | |
| unset _sp_pid | |
| } | |
| ##########################spinner funcion ends | |
| clear | |
| echo "Grant root access to update and upgrade your system:" | |
| echo "" | |
| echo " ***LET FINISH THE SCRIPT, BE PATIENT***" | |
| echo "" | |
| sudo echo "The last software upgrade was carried at:" | |
| ls -lt --time-style="long-iso" /var/log/apt | grep -o '\([0-9]\{2,4\}[- ]\)\{3\}[0-9]\{2\}:[0-9]\{2\}' -m 1 | |
| echo "" | |
| # Checking pack health | |
| echo 'Checking and solving eventual integrity faults of the package system...' | |
| echo "Running dpkg integrity check..." | |
| start_spinner | |
| sudo dpkg --configure -a | |
| stop_spinner $? | |
| echo "" | |
| echo 'Running apt-get to fix eventual errors...' | |
| start_spinner | |
| sudo apt-get install -f -y -qq | |
| stop_spinner $? | |
| echo "" | |
| # update | |
| start_spinner 'Downloading and Updating sources...' | |
| # use sleep to give spinner time to fork and run | |
| # because cp fails instantly | |
| sudo apt-get update -qq | |
| sleep 1 | |
| stop_spinner $? | |
| echo "" | |
| # upgrade | |
| start_spinner 'Downloading upgrades...' | |
| # use sleep to give spinner time to fork and run | |
| # because cp fails instantly | |
| sudo apt-get dist-upgrade -y -qq; sleep 1; stop_spinner $? | |
| echo "" | |
| # removing garbage | |
| start_spinner 'Cleaning obsolete packages from the system...' | |
| sudo apt-get autoremove -y -qq | |
| sudo apt-get install -f -y -qq; sleep 1; stop_spinner $? | |
| echo "" | |
| echo "Your system is now up-to-date." | |
| echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment