Created
January 10, 2018 15:02
-
-
Save lspg/6e3d5beb27ab7e74d777787412921484 to your computer and use it in GitHub Desktop.
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 | |
| # Colors | |
| c1="\e[39m" # Normal | |
| c2="\e[91m" # Red | |
| c3="\e[92m" # Light Green | |
| c4="\e[36m" # Cyan | |
| c5="\e[31m" # Light Red | |
| c6="\e[93m" # Yellow | |
| c7="\e[32m" # Green | |
| c8="\e[97m" # White | |
| function tst { | |
| echo -e "${c5} => $*${c4}" | |
| if ! $*; then | |
| echo -e "${c6}Exiting script due to error from: $*${c1}" | |
| exit 1 | |
| fi | |
| echo -en "${c1}" | |
| } | |
| function out { | |
| if [ ! $CNT ]; then CNT=0; fi | |
| CNT=$((CNT+1)) | |
| printf -v NUM "%02d" $CNT | |
| echo -e "${c2}${NUM} => $*${c1}" | |
| } | |
| function check_sha256() { | |
| echo "> Checking SHAs..." | |
| local=$1 | |
| remote=$2 | |
| # Local file | |
| if [ -f ${local} ]; then | |
| sha_local=$(sha256sum ${local} | cut -d " " -f 1) | |
| echo $(sha256sum ${local}) > ${local}.sha256 | |
| fi | |
| if [ -z "${sha_local}" ]; then | |
| if [ -f ${local}.sha256 ]; then | |
| sha_local=$(cat ${local}.sha256 | cut -d " " -f 1) | |
| fi | |
| fi | |
| echo "> local file sha256 : ${sha_local}" | |
| # Remote file | |
| sha_remote=$(wget -qnv -O - ${remote} | cut -d ' ' -f 1) | |
| echo -e "> remote file sha256 : ${sha_remote}" | |
| if [ ${sha_local} == ${sha_remote} ]; then | |
| SHACHK=true | |
| else | |
| SHACHK=false | |
| fi | |
| } | |
| function sysupgrade() { | |
| out "Upgrading system..." | |
| while true; do | |
| read -p "Upgrade system ? [y/N] " yn | |
| case $yn in | |
| y|Y) | |
| tst sudo apt-get -yqq update | |
| tst sudo apt-get -y upgrade | |
| tst sudo apt-get -yqq autoremove --purge | |
| tst apt-get clean -qy | |
| tst rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/* | |
| break;; | |
| n|N|"") | |
| break;; | |
| esac | |
| done | |
| } | |
| # FIND ABSOLUTE SCRIPT PATH | |
| SOURCE="${BASH_SOURCE[0]}" | |
| while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink | |
| ROOT="$( cd -P "$( dirname "$SOURCE" )" && pwd )" | |
| SOURCE="$(readlink "$SOURCE")" | |
| [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located | |
| done | |
| ROOT="$(readlink -f $( cd -P "$( dirname "$SOURCE" )" && pwd )/..)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment