Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## ROUTINES
- ## Here at the beginning, a load of useful routines - see further down
- # Get time as a UNIX timestamp (seconds elapsed since Jan 1, 1970 0:00 UTC)
- startTime="$(date +%s)"
- columns=$(tput cols)
- user_response=""
- # High Intensity
- IGreen='\e[0;92m' # Green
- IYellow='\e[0;93m' # Yellow
- IBlue='\e[0;94m' # Blue
- ICyan='\e[0;96m' # Cyan
- IWhite='\e[0;97m' # White
- # Bold High Intensity
- BIRed='\e[1;91m' # Red
- BIGreen='\e[1;92m' # Green
- BIYellow='\e[1;93m' # Yellow
- BIPurple='\e[1;95m' # Purple
- BIMagenta='\e[1;95m' # Purple
- BICyan='\e[1;96m' # Cyan
- BIWhite='\e[1;97m' # White
- skip=0
- other=0
- clean_stdin()
- {
- while read -r -t 0; do
- read -n 256 -r -s
- done
- }
- # Permanent loop until both passwords are the same..
- function user_input {
- local VARIABLE_NAME=${1}
- local VARIABLE_NAME_1="A"
- local VARIABLE_NAME_2="B"
- while true; do
- printf "${BICyan}$2: ${BIWhite}";
- if [ "$3" = "hide" ] ; then
- stty -echo;
- fi
- read VARIABLE_NAME_1;
- stty echo;
- if [ "$3" = "hide" ] ; then
- printf "\n${BICyan}$2 (again) : ${BIWhite}";
- stty -echo;
- read VARIABLE_NAME_2;
- stty echo;
- else
- VARIABLE_NAME_2=$VARIABLE_NAME_1;
- fi
- if [ $VARIABLE_NAME_1 != $VARIABLE_NAME_2 ] ; then
- printf "\n${BIRed}Sorry, did not match!${BIWhite}\n";
- else
- break;
- fi
- done
- readonly ${VARIABLE_NAME}=$VARIABLE_NAME_1;
- if [ "$3" == "hide" ] ; then
- printf "\n";
- fi
- }
- stopit=0
- other=0
- yes=0
- nohelp=0
- hideother=0
- timecount(){
- sec=30
- while [ $sec -ge 0 ]; do
- if [ $nohelp -eq 1 ]; then
- if [ $hideother -eq 1 ]; then
- printf "${BIPurple}Continue ${BIWhite}y${BIPurple}(es)/${BIWhite}n${BIPurple}(o)/${BIWhite}a${BIPurple}(ll)/${BIWhite}e${BIPurple}(nd)- ${BIGreen}00:0$min:$sec${BIPurple} remaining\033[0K\r${BIWhite}"
- else
- printf "${BIPurple}Continue ${BIWhite}y${BIPurple}(es)/${BIWhite}o${BIPurple}(ther)/${BIWhite}e${BIPurple}(nd)- ${BIGreen}00:0$min:$sec${BIPurple} remaining\033[0K\r${BIWhite}"
- fi
- else
- printf "${BIPurple}Continue ${BIWhite}y${BIPurple}(es)/${BIWhite}h${BIPurple}(elp)- ${BIGreen}00:0$min:$sec${BIPurple} remaining\033[0K\r${BIWhite}"
- fi
- sec=$((sec-1))
- trap '' 2
- stty -echo
- read -t 1 -n 1 user_response
- stty echo
- trap - 2
- if [ -n "$user_response" ]; then
- break
- fi
- done
- }
- task_start(){
- printf "\r\n"
- printf "${BIGreen}%*s\n" $columns | tr ' ' -
- printf "$1"
- clean_stdin
- skip=0
- printf "\n${BIGreen}%*s${BIWhite}\n" $columns | tr ' ' -
- elapsedTime="$(($(date +%s)-startTime))"
- printf "Elapsed: %02d hrs %02d mins %02d secs\n" "$((elapsedTime/3600%24))" "$((elapsedTime/60%60))" "$((elapsedTime%60))"
- clean_stdin
- if [ "$user_response" != "a" ]; then
- timecount
- fi
- echo -e " \033[0K\r"
- if [ "$user_response" = "e" ]; then
- printf "${BIWhite}"
- exit 1
- fi
- if [ "$user_response" = "n" ]; then
- skip=1
- fi
- if [ "$user_response" = "o" ]; then
- other=1
- fi
- if [ "$user_response" = "h" ]; then
- stopit=1
- fi
- if [ "$user_response" = "y" ]; then
- yes=1
- fi
- if [ -n "$2" ]; then
- if [ $skip -eq 0 ]; then
- printf "${BIYellow}$2${BIWhite}\n"
- else
- printf "${BICyan}%*s${BIWhite}\n" $columns '[SKIPPED]'
- fi
- fi
- }
- task_end(){
- printf "${BICyan}%*s${BIWhite}\n" $columns '[OK]'
- }
- # credits to DietPi
- CPU_TEMP_CURRENT='Unknown'
- CPU_TEMP_PRINT='Unknown'
- ACTIVECORES=$(grep -c processor /proc/cpuinfo)
- #Array to store possible locations for temp read.
- aFP_TEMPERATURE=(
- '/sys/class/thermal/thermal_zone0/temp'
- '/sys/devices/virtual/thermal/thermal_zone1/temp'
- '/sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/temp1_input'
- '/sys/class/hwmon/hwmon0/device/temp_label'
- )
- Obtain_Cpu_Temp(){
- for ((i=0; i<${#aFP_TEMPERATURE[@]}; i++))
- do
- if [ -f "${aFP_TEMPERATURE[$i]}" ]; then
- CPU_TEMP_CURRENT=$(cat "${aFP_TEMPERATURE[$i]}")
- # - Some devices (pine) provide 2 digit output, some provide a 5 digit ouput.
- # So, If the value is over 1000, we can assume it needs converting to 1'c
- if (( $CPU_TEMP_CURRENT == 0 )); then
- continue
- fi
- if (( $CPU_TEMP_CURRENT >= 1000 )); then
- CPU_TEMP_CURRENT=$( echo -e "$CPU_TEMP_CURRENT" | awk '{print $1/1000}' | xargs printf "%0.0f" )
- fi
- if (( $CPU_TEMP_CURRENT >= 70 )); then
- CPU_TEMP_PRINT="\e[91mWarning: $CPU_TEMP_CURRENT'c\e[0m"
- elif (( $CPU_TEMP_CURRENT >= 60 )); then
- CPU_TEMP_PRINT="\e[38;5;202m$CPU_TEMP_CURRENT'c\e[0m"
- elif (( $CPU_TEMP_CURRENT >= 50 )); then
- CPU_TEMP_PRINT="\e[93m$CPU_TEMP_CURRENT'c\e[0m"
- elif (( $CPU_TEMP_CURRENT >= 40 )); then
- CPU_TEMP_PRINT="\e[92m$CPU_TEMP_CURRENT'c\e[0m"
- elif (( $CPU_TEMP_CURRENT >= 30 )); then
- CPU_TEMP_PRINT="\e[96m$CPU_TEMP_CURRENT'c\e[0m"
- else
- CPU_TEMP_PRINT="\e[96m$CPU_TEMP_CURRENT'c\e[0m"
- fi
- break
- fi
- done
- }
- LOGFILE=$HOME/$0-`date +%Y-%m-%d_%Hh%Mm`.log
- printl() {
- printf $1
- echo -e $1 >> $LOGFILE
- }
- printstatus() {
- Obtain_Cpu_Temp
- h=$(($SECONDS/3600));
- m=$((($SECONDS/60)%60));
- s=$(($SECONDS%60));
- printf "\r\n${BIGreen}==\r\n== ${BIYellow}$1"
- printf "\r\n${BIGreen}== ${IBlue}Total: %02dh:%02dm:%02ds Cores: $ACTIVECORES Temperature: $CPU_TEMP_PRINT \r\n${BIGreen}==${IWhite}\r\n\r\n" $h $m $s;
- echo -e "############################################################" >> $LOGFILE
- echo -e $1 >> $LOGFILE
- }
- ############################################################################
- ##
- ## MAIN SECTION OF SCRIPT - action begins here
- ##
- #############################################################################
- ##
- printstatus "Welcome to THE SCRIPT!"
- AQUIET=""
- NQUIET=""
- # install sudo on devices without it
- [ ! -x /usr/bin/sudo ] && apt-get $AQUIET -y update > /dev/null 2>&1 && apt-get $AQUIET -y install sudo 2>&1 | tee -a $LOGFILE
- # Whiptail menu may already be installed by default, on the other hand maybe not.
- sudo apt-get $AQUIET -y install whiptail ccze 2>&1 | tee -a $LOGFILE
- # Another way - Xenial should come up in upper case in $DISTRO
- . /etc/os-release
- OPSYS=${ID^^}
- echo -e OPSYS: $OPSYS >> $LOGFILE
- printstatus "Grabbing some preliminaries..."
- # test internet connection
- sudo chmod u+s /bin/ping
- if [[ "$(ping -c 1 23.1.68.60 | grep '100%' )" != "" ]]; then
- printl "${IRed}!!!! No internet connection available, aborting! ${IWhite}\r\n"
- exit 0
- fi
- # install lsb_release on devices without it
- [ ! -x /usr/bin/lsb_release ] && apt-get $AQUIET -y update > /dev/null 2>&1 && apt-get $AQUIET -y install lsb-release 2>&1 | tee -a $LOGFILE
- DISTRO=$(/usr/bin/lsb_release -rs)
- CHECK64=$(uname -m)
- echo -e DISTRO: $DISTRO >> $LOGFILE
- echo -e CHECK64: $CHECK64 >> $LOGFILE
- printstatus "Installing Nodes (could take some time)"
- for addonnodes in
- moment node-red-contrib-config node-red-contrib-grove node-red-contrib-diode node-red-contrib-bigtimer \
- node-red-contrib-esplogin node-red-contrib-timeout node-red-node-openweathermap node-red-node-google node-red-contrib-advanced-ping \
- node-red-node-sqlite node-red-node-emoncms node-red-node-geofence node-red-contrib-moment node-red-contrib-particle \
- node-red-contrib-web-worldmap node-red-contrib-sqldbs node-red-contrib-ramp-thermostat node-red-contrib-graphs \
- node-red-contrib-isonline node-red-node-ping node-red-node-random node-red-node-smooth node-red-contrib-npm node-red-node-arduino \
- node-red-contrib-file-function node-red-contrib-boolean-logic node-red-contrib-blynk-ws node-red-contrib-telegrambot \
- node-red-dashboard node-red-node-darksky node-red-contrib-owntracks node-red-contrib-alexa-local node-red-contrib-heater-controller ;
- do
- printstatus "Installing node \"${addonnodes}\""
- npm $NQUIET install --save ${addonnodes} 2>&1 | tee -a $LOGFILE
- done
Advertisement
Add Comment
Please, Sign In to add comment