Skip to content

Commit

Permalink
v6.15
Browse files Browse the repository at this point in the history
+ Apply screen blanking disable during init on tty1 always.
+ code improvements

https://github.com/Fourdee/DietPi/issues/2066
  • Loading branch information
Daniel (Fourdee) committed Sep 12, 2018
1 parent 7060775 commit bb0a7eb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 46 deletions.
66 changes: 23 additions & 43 deletions dietpi/dietpi-cloudshell
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
DIETPI_CLOUDSHELL_VERSION=9

#/tmp/.* files used throughout this script.
FP_TEMP='/tmp/dietpi-cloudshell'
FP_TEMP="/tmp/$G_PROGRAM_NAME/.tmp"

BLANK_SCREEN_ACTIVE=0
BLANK_SCREEN_AT_SPECIFIC_TIME_ENABLED=0
Expand All @@ -59,15 +59,21 @@
#Turn screen on
elif (( $BLANK_SCREEN_TIME_HOUR_END == $current_hour )); then

setterm --blank poke &> /dev/tty1
setterm --reset &> /dev/tty1
setterm --blank 0 --powersave off &> /dev/tty1
BLANK_SCREEN_ACTIVE=0
Disable_Screen_Blanking

fi

}

Disable_Screen_Blanking(){

setterm --blank poke &> /dev/tty1
setterm --reset &> /dev/tty1
setterm --blank 0 --powersave off &> /dev/tty1
BLANK_SCREEN_ACTIVE=0

}

#BC does not allow for printing leading zeros.
BC_ADD_LEADING_ZERO(){

Expand Down Expand Up @@ -158,8 +164,7 @@

}

#Apply fonts
Enable_Term_Options(){
Init_Term_Options(){

# - Set large font 1st (480x320+)
setfont /usr/share/consolefonts/Uni3-TerminusBold32x16
Expand All @@ -171,6 +176,9 @@

fi

#Disable screen blanking on tty1 initially
Disable_Screen_Blanking

}

#/////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -419,16 +427,14 @@
fi

CPU_USAGE=0
FP_TEMP='/tmp/.cpu_usage'

# PS (inaccurate)
ps -axo %cpu | sed '1d' | sed 's/ //' > $FP_TEMP
while read -r line
do

CPU_USAGE=$( echo "scale=1;$CPU_USAGE + $line" | bc -l )

done < $FP_TEMP
done <<< "$(ps -axo %cpu | sed '1d' | sed 's/ //')"

#ps returns usage of each core, so we devide the total by #n cores
CPU_USAGE=$(echo "scale=0;$CPU_USAGE / $G_HW_CPU_CORES" | bc -l )
Expand Down Expand Up @@ -498,29 +504,26 @@
local index_start=$1
local index_end=$2

FP_TEMP='/tmp/.df'
rm $FP_TEMP

#df will endless hang when NFS server is down: https://github.com/Fourdee/DietPi/issues/395
# - So lets run it as another thread so we can kill it if it hangs.
local df_failed=0
rm $FP_TEMP
df -Ph > $FP_TEMP &
local pid=$(echo $!)

# - Wait X seconds before terminating the df thread
local max_seconds=4
local current_seconds=0
while ps aux | awk '{print $2}' | grep -q "$pid\$" # ! -f may exist, but no data at time of scrape, causing 'mount not found'. so lets wait for process to exit.
while [[ ! -f $FP_TEMP ]]
do

#kill
if (( $current_seconds >= $max_seconds )); then

#kill

G_DIETPI-NOTIFY 1 'DF failed, unable to obtain drive data'
sleep 2

kill $pid
killall -w df

df_failed=1

Expand Down Expand Up @@ -562,24 +565,11 @@
Percent_To_Graph ${STORAGE_PERCENT[$i]}
STORAGE_PERCENT[$i]=$C_PERCENT_GRAPH

#DEBUG John:
echo -e 'Results success:\n' >> /var/log/dietpi-cloudshell.log
echo -e " - Index = $i" >> /var/log/dietpi-cloudshell.log
echo -e " - Path = ${STORAGE_PATH[$i]}" >> /var/log/dietpi-cloudshell.log
echo -e " - Total = ${STORAGE_TOTAL[$i]}" >> /var/log/dietpi-cloudshell.log

else

STORAGE_PERCENT[$i]="${STORAGE_PATH[$i]}"
STORAGE_FREE[$i]='Mount not active'

#DEBUG John:
echo -e "$(date) | Mount not found:\n" >> /var/log/dietpi-cloudshell.log
echo -e " - Index = $i" >> /var/log/dietpi-cloudshell.log
echo -e " - Path = ${STORAGE_PATH[$i]}\n" >> /var/log/dietpi-cloudshell.log
cat $FP_TEMP >> /var/log/dietpi-cloudshell.log
echo -e '\n' >> /var/log/dietpi-cloudshell.log

fi

done
Expand Down Expand Up @@ -634,8 +624,6 @@
NETWORK_DETAILS_MODE=0 #1=dhcp, 0=static
Obtain_NETWORK_DETAILS(){

FP_TEMP='/tmp/.ip_address'

#Hostname
NETWORK_DETAILS_HOSTNAME=$(hostname)

Expand Down Expand Up @@ -763,7 +751,6 @@
Obtain_MEMORY(){

#Write to temp
FP_TEMP='/tmp/.mem'
free -m > $FP_TEMP

#RAM MB
Expand Down Expand Up @@ -1359,7 +1346,7 @@ _EOF_

Run_Cloudshell(){

Enable_Term_Options
Init_Term_Options

#Start Intro
if (( $RUN_INTRO )); then
Expand Down Expand Up @@ -1614,15 +1601,6 @@ _EOF_
#Return to main menu
TARGETMENUID=0

#Colour array
#0 WHITE
#1 RED
#2 GREEN
#3 YELLOW
#4 BLUE
#5 PURPLE
#6 CYAN

G_WHIP_MENU_ARRAY=(

'0' 'White'
Expand Down Expand Up @@ -1754,6 +1732,7 @@ _EOF_

)

G_WHIP_BUTTON_CANCEL_TEXT='Back'
G_WHIP_MENU 'Automatically power down the screen and disable DietPi-Cloudshell processing during a specific time.\n\nNB: This feature will only work if DietPi-Cloudshell was launched with the DietPi-Autostart option, or, launched from the main screen (tty1).'
if (( $? == 0 )); then

Expand Down Expand Up @@ -1825,6 +1804,7 @@ _EOF_

done

G_WHIP_BUTTON_CANCEL_TEXT='Back'
G_WHIP_MENU 'Storage Device Mount Location:\n\nDietPi-Cloudshell pulls the storage stats from the drive mount location. If you have custom drives/mounts, please set them here to be displayed during storage scene updates.\n\n - Drive 1 = Displayed during main storage scene\n - Drive 2/3 = Displayed during additional storage scene\n - Drive 4/5 = Displayed during additional storage scene'
if (( $? == 0 )); then

Expand Down
3 changes: 0 additions & 3 deletions dietpi/dietpi-software
Original file line number Diff line number Diff line change
Expand Up @@ -9080,16 +9080,13 @@ StandardOutput=tty
TTYPath=/dev/tty1
ExecStartPre=/usr/bin/setterm --term linux --blank 0 --powersave off --cursor off
ExecStart=/bin/bash -c '/DietPi/dietpi/dietpi-cloudshell 1'
ExecStop=/usr/bin/setterm --reset
ExecStop=/bin/bash -c 'G_DIETPI-NOTIFY 0 DietPi-Cloudshell terminated, have a nice day!'
[Install]
WantedBy=multi-user.target
_EOF_
systemctl daemon-reload

fi

Expand Down

0 comments on commit bb0a7eb

Please sign in to comment.