Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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 )/..)"
Add Comment
Please, Sign In to add comment