sh 忍者容易
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 忍者容易相关的知识,希望对你有一定的参考价值。
#!/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 --force-yes -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 ""
以上是关于sh 忍者容易的主要内容,如果未能解决你的问题,请参考以下文章