Guest User

Untitled

a guest
Jan 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Colors
  4. c1="\e[39m" # Normal
  5. c2="\e[91m" # Red
  6. c3="\e[92m" # Light Green
  7. c4="\e[36m" # Cyan
  8. c5="\e[31m" # Light Red
  9. c6="\e[93m" # Yellow
  10. c7="\e[32m" # Green
  11. c8="\e[97m" # White
  12.  
  13. function tst {
  14. echo -e "${c5} => $*${c4}"
  15. if ! $*; then
  16. echo -e "${c6}Exiting script due to error from: $*${c1}"
  17. exit 1
  18. fi
  19. echo -en "${c1}"
  20. }
  21.  
  22. function out {
  23. if [ ! $CNT ]; then CNT=0; fi
  24. CNT=$((CNT+1))
  25. printf -v NUM "%02d" $CNT
  26. echo -e "${c2}${NUM} => $*${c1}"
  27. }
  28.  
  29. function check_sha256() {
  30. echo "> Checking SHAs..."
  31. local=$1
  32. remote=$2
  33. # Local file
  34. if [ -f ${local} ]; then
  35. sha_local=$(sha256sum ${local} | cut -d " " -f 1)
  36. echo $(sha256sum ${local}) > ${local}.sha256
  37. fi
  38. if [ -z "${sha_local}" ]; then
  39. if [ -f ${local}.sha256 ]; then
  40. sha_local=$(cat ${local}.sha256 | cut -d " " -f 1)
  41. fi
  42. fi
  43. echo "> local file sha256 : ${sha_local}"
  44.  
  45. # Remote file
  46. sha_remote=$(wget -qnv -O - ${remote} | cut -d ' ' -f 1)
  47. echo -e "> remote file sha256 : ${sha_remote}"
  48.  
  49. if [ ${sha_local} == ${sha_remote} ]; then
  50. SHACHK=true
  51. else
  52. SHACHK=false
  53. fi
  54. }
  55.  
  56. function sysupgrade() {
  57. out "Upgrading system..."
  58. while true; do
  59. read -p "Upgrade system ? [y/N] " yn
  60. case $yn in
  61. y|Y)
  62. tst sudo apt-get -yqq update
  63. tst sudo apt-get -y upgrade
  64. tst sudo apt-get -yqq autoremove --purge
  65. tst apt-get clean -qy
  66. tst rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/*
  67. break;;
  68. n|N|"")
  69. break;;
  70. esac
  71. done
  72. }
  73.  
  74. # FIND ABSOLUTE SCRIPT PATH
  75. SOURCE="${BASH_SOURCE[0]}"
  76.  
  77. while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
  78. ROOT="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
  79. SOURCE="$(readlink "$SOURCE")"
  80. [[ $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
  81. done
  82. ROOT="$(readlink -f $( cd -P "$( dirname "$SOURCE" )" && pwd )/..)"
Add Comment
Please, Sign In to add comment