Skip to content

Commit

Permalink
v6.29
Browse files Browse the repository at this point in the history
+ DietPi-Banner | Always load DietPi-Globals: #3313
+ DietPi-Banner | Run G_INIT only on menu calls to allow concurrent banner prints but a single menu call only
+ DietPi-Banner | Menu calls require root permissions to write to settings files
+ DietPi-Banner | Only re-obtain network details if resulting file does not exist instead of if it exist
  • Loading branch information
MichaIng authored Jan 4, 2020
1 parent a9b9216 commit c77812d
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions dietpi/func/dietpi-banner
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,30 @@
#////////////////////////////////////
#
# Info:
# - filename /DietPi/dietpi/func/dietpi-banner
# - Filename: /{DietPi,boot}/dietpi/func/dietpi-banner
# - Checks /DietPi/dietpi/.update_available
#
# Usage:
# - dietpi-banner 0 = top section + LAN IP
# - dietpi-banner 1 = top section + chosen entries + credits + clear
# - dietpi-banner 1 = clear terminal + top section + chosen entries + credits
# - dietpi-banner 2 = banner customisation menu
#////////////////////////////////////

# Grab input
[[ $1 == [12] ]] && INPUT=$1 || INPUT=0

# Import DietPi-Globals --------------------------------------------------------------
. /DietPi/dietpi/func/dietpi-globals
# - Allow cuncurrent banner prints but a single menu call only
if [[ $1 == 2 ]]; then

G_PROGRAM_NAME='DietPi-Banner'
G_CHECK_ROOT_USER # Required to store settings
G_INIT

fi
# Import DietPi-Globals --------------------------------------------------------------

#/////////////////////////////////////////////////////////////////////////////////////
# Globals
#/////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -64,13 +77,12 @@
GREEN_BULLET=" ${aCOLOUR[0]}-$COLOUR_RESET"
GREEN_SEPARATOR="${aCOLOUR[0]}:$COLOUR_RESET"

. /DietPi/dietpi/.version
DIETPI_VERSION="$G_DIETPI_VERSION_CORE.$G_DIETPI_VERSION_SUB.$G_DIETPI_VERSION_RC"
[[ $G_GITBRANCH != 'master' ]] && DIETPI_VERSION+=" ($G_GITBRANCH)"
[[ $G_GITBRANCH == 'master' ]] || DIETPI_VERSION+=" ($G_GITBRANCH)"

# Update available?
UPDATE_AVAILABLE=0
UPDATE_AVAILABLE_VERSION='' # -1 = image required, other value = latest version
UPDATE_AVAILABLE_VERSION= # -1 = image required, other value = latest version
Obtain_Update_Available(){

if [[ -f '/DietPi/dietpi/.update_available' ]]; then
Expand Down Expand Up @@ -107,23 +119,22 @@

# Update Available?
Obtain_Update_Available
local text_update_available_date
if (( $UPDATE_AVAILABLE )); then

if [[ $UPDATE_AVAILABLE_VERSION == '-1' ]]; then

text_update_available_date="${aCOLOUR[3]}Image available"
local text_update_available_date="${aCOLOUR[3]}Image available"

else

text_update_available_date="${aCOLOUR[3]}Update available"
local text_update_available_date="${aCOLOUR[3]}Update available"

fi

else

local locale_current=$(sed -n '/^[[:blank:]]*AUTO_SETUP_LOCALE=/{s/^[^=]*=//p;q}' /DietPi/dietpi.txt)
text_update_available_date=$(LC_ALL=${locale_current:-en_GB.UTF-8} date +"%R - %a %x")
local text_update_available_date=$(LC_ALL=${locale_current:-en_GB.UTF-8} date +"%R - %a %x")

fi

Expand All @@ -136,8 +147,8 @@ $GREEN_LINE"
Print_Local_Ip(){

[[ ${aENABLED[5]} == 1 ]] || return
[[ -f '/DietPi/dietpi/.network' ]] && /DietPi/dietpi/func/obtain_network_details
echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[5]} $GREEN_SEPARATOR $(mawk 'NR==3 {dev=$0} NR==4 {print $0" ("dev")"}' /DietPi/dietpi/.network 2>&1)" # 5: LAN IP (adapter)
[[ -f '/DietPi/dietpi/.network' ]] || /DietPi/dietpi/func/obtain_network_details
echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[5]} $GREEN_SEPARATOR $(mawk 'NR==3 {dev=$0} NR==4 {print $0" ("dev")"}' /DietPi/dietpi/.network 2>&1)"

}

Expand All @@ -147,14 +158,14 @@ $GREEN_LINE"

[[ -f '/DietPi/dietpi/.prep_info' ]] && mawk 'NR==1 {sub(/^0$/,"DietPi Core Team");a=$0} NR==2 {print " Image : "a" (pre-image: "$0")"}' /DietPi/dietpi/.prep_info

echo ' Web : https://DietPi.com | https://twitter.com/dietpi_
echo ' Web : https://dietpi.com | https://twitter.com/dietpi_
Patreon Legends : PINE64 community | oct8l
Donate : https://DietPi.com/#donate'
Donate : https://dietpi.com/#donate'

local image_additional_credits=$(mawk 'NR==8 {print}' /DietPi/dietpi/.hw_model 2>&1)
local image_additional_credits=$(mawk 'NR==8' /DietPi/dietpi/.hw_model 2>&1)
[[ $image_additional_credits ]] && echo " Device image possible thanks to: $image_additional_credits"

echo -e " DietPi Hosting : Powered by https://MyVirtualServer.com$COLOUR_RESET\n"
echo -e " DietPi Hosting : Powered by https://myvirtualserver.com$COLOUR_RESET\n"

# Update available?
if (( $UPDATE_AVAILABLE )); then
Expand All @@ -175,7 +186,7 @@ $GREEN_LINE"

Print_Useful_Commands(){

echo -e "${aCOLOUR[1]} dietpi-launcher$COLOUR_RESET $GREEN_SEPARATOR All the DietPi programs in one place.
echo -e " ${aCOLOUR[1]}dietpi-launcher$COLOUR_RESET $GREEN_SEPARATOR All the DietPi programs in one place.
${aCOLOUR[1]}dietpi-config$COLOUR_RESET $GREEN_SEPARATOR Feature rich configuration tool for your device.
${aCOLOUR[1]}dietpi-software$COLOUR_RESET $GREEN_SEPARATOR Select optimized software for installation.
${aCOLOUR[1]}htop$COLOUR_RESET $GREEN_SEPARATOR Resource monitor.
Expand All @@ -185,13 +196,10 @@ $GREEN_LINE"

Print_Banner(){

# Source DietPi-Globals if not yet sourced from main menu and CPU temp chosen
[[ ${aENABLED[2]} != 1 && ${aENABLED[12]} != 1 || $G_PROGRAM_NAME ]] || . /DietPi/dietpi/func/dietpi-globals

G_TERM_CLEAR
Print_Header

(( ${aENABLED[0]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[0]} $GREEN_SEPARATOR $(mawk 'NR==2 {print}' /DietPi/dietpi/.hw_model 2>&1)" # 0: Device model
(( ${aENABLED[0]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[0]} $GREEN_SEPARATOR $(mawk 'NR==2' /DietPi/dietpi/.hw_model 2>&1)" # 0: Device model
(( ${aENABLED[1]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[1]} $GREEN_SEPARATOR $(uptime -p 2>&1)" # 1: Uptime
(( ${aENABLED[2]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[2]} $GREEN_SEPARATOR $(print_full_info=1 G_OBTAIN_CPU_TEMP 2>&1)" # 2: CPU temp
(( ${aENABLED[3]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[3]} $GREEN_SEPARATOR $(hostname -f 2>&1)" # 3: Hostname
Expand All @@ -202,7 +210,7 @@ $GREEN_LINE"
(( ${aENABLED[7]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[7]} $GREEN_SEPARATOR $(df -h --output=avail / | mawk 'NR==2 {print $1}' 2>&1)" # 7: Freespace (RootFS)
(( ${aENABLED[8]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[8]} $GREEN_SEPARATOR $(df -h --output=avail /mnt/dietpi_userdata | mawk 'NR==2 {print $1}' 2>&1)" # 8: Freespace (DietPi userdata)
(( ${aENABLED[9]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[9]} $GREEN_SEPARATOR $(curl -sSfLm 2 https://wttr.in/?format=4 2>&1)" # 9: Weather
(( ${aENABLED[10]} == 1 )) && [[ -x $FP_CUSTOM ]] && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[10]} $GREEN_SEPARATOR $(bash $FP_CUSTOM 2>&1)" # 10: Custom
[[ ${aENABLED[10]} == 1 && -x $FP_CUSTOM ]] && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[10]} $GREEN_SEPARATOR $(bash $FP_CUSTOM 2>&1)" # 10: Custom
if (( ${aENABLED[12]} == 1 )); then

local fp_motd='/tmp/.dietpi_motd'
Expand Down Expand Up @@ -231,12 +239,7 @@ $GREEN_LINE"

Menu_Main(){

. /DietPi/dietpi/func/dietpi-globals
G_PROGRAM_NAME='DietPi-Banner'
G_INIT

G_WHIP_CHECKLIST_ARRAY=()

for i in ${!aDESCRIPTION[@]}
do

Expand Down Expand Up @@ -264,15 +267,15 @@ $GREEN_LINE"

[[ -f $FP_CUSTOM ]] && G_WHIP_DEFAULT_ITEM=$(<$FP_CUSTOM) || G_WHIP_DEFAULT_ITEM="echo 'Hello World!'"
if G_WHIP_INPUTBOX 'You have chosen to show a custom entry in the banner.
Please enter/verify the desired command here.\n
Please enter the desired command here.\n
NB: It is executed as bash script, so it needs to be in bash compatible syntax.
For complex or non-bash scripts keep it separate and add its execution command here.'; then
For multi-line or non-bash scripts, keep it separate and only add the script call here.'; then

echo "$G_WHIP_RETURNED_VALUE" > $FP_CUSTOM
chmod +x $FP_CUSTOM

G_WHIP_DEFAULT_ITEM=${aDESCRIPTION[10]}
G_WHIP_INPUTBOX 'Please enter a meaningful name/description to be shown in front of your custom command output:' && aDESCRIPTION[10]=$G_WHIP_RETURNED_VALUE
G_WHIP_INPUTBOX 'Please enter a meaningful name to be shown in front of your custom command output:' && aDESCRIPTION[10]=$G_WHIP_RETURNED_VALUE

fi

Expand Down

0 comments on commit c77812d

Please sign in to comment.