Skip to content

Commit

Permalink
v9.10
Browse files Browse the repository at this point in the history
- DietPi-Banner | Remove support for legacy "2" input, print error message and usage info in case of invalid input, and some coding enhancements
  • Loading branch information
MichaIng committed Jan 21, 2025
1 parent 4ff6d78 commit 77511bd
Showing 1 changed file with 34 additions and 42 deletions.
76 changes: 34 additions & 42 deletions dietpi/func/dietpi-banner
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
# - Location: /boot/dietpi/func/dietpi-banner
# - Checks /run/dietpi/.update_available, /run/dietpi/.live_patches, /run/dietpi/.apt_updates, /run/dietpi/.dietpi_motd and /boot/dietpi/.prep_info
#
# Usage:
# - dietpi-banner = banner customisation menu
# - dietpi-banner 0 = top section + LAN IP
# - dietpi-banner 1 = clear terminal + top section + chosen entries + credits
#////////////////////////////////////
USAGE='
- dietpi-banner = banner customisation menu
- dietpi-banner 0 = top section + LAN IP
- dietpi-banner 1 = clear terminal + top section + chosen entries + credits
' #////////////////////////////////////

# Grab input
[[ $1 == [01] ]] && INPUT=$1 || INPUT=2
INPUT=$*

# Import DietPi-Globals --------------------------------------------------------------
. /boot/dietpi/func/dietpi-globals
Expand Down Expand Up @@ -97,7 +97,7 @@
Check_DietPi_Update()
{
[[ -f '/run/dietpi/.update_available' ]] || return 1
AVAILABLE_UPDATE=$(</run/dietpi/.update_available)
read -r AVAILABLE_UPDATE < /run/dietpi/.update_available
return 0
}

Expand All @@ -115,7 +115,7 @@
Check_APT_Updates()
{
[[ -f '/run/dietpi/.apt_updates' ]] || return 1
PACKAGE_COUNT=$(</run/dietpi/.apt_updates)
read -r PACKAGE_COUNT < /run/dietpi/.apt_updates
return 0
}

Expand Down Expand Up @@ -177,7 +177,7 @@ $GREEN_LINE"

Print_Local_Ip()
{
[[ ${aENABLED[5]} == 1 ]] || return 0
(( ${aENABLED[5]} )) || return 0
local iface=$(G_GET_NET -q iface)
local ip=$(G_GET_NET -q ip)
echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[5]} $GREEN_SEPARATOR ${ip:-Use dietpi-config to setup a connection} (${iface:-NONE})"
Expand All @@ -204,7 +204,7 @@ $GREEN_LINE"
[[ -f '/boot/dietpi/.prep_info' ]] && mawk 'NR==1 {sub(/^0$/,"DietPi Core Team");a=$0} NR==2 {print " Image by : "a" (pre-image: "$0")"}' /boot/dietpi/.prep_info

echo -e " Patreon Legends : Chris Gelatt, ADSB.im
Website : https://dietpi.com/ | https://twitter.com/DietPi_
Website : https://dietpi.com/ | https://x.com/DietPi_
Contribute : https://dietpi.com/contribute.html
Web Hosting by : https://myvirtualserver.com$COLOUR_RESET\n"
}
Expand Down Expand Up @@ -249,35 +249,35 @@ $GREEN_LINE"

# Large Format Hostname
# shellcheck disable=SC1091
(( ${aENABLED[14]} == 1 )) && . /boot/dietpi/func/dietpi-print_large "$(</etc/hostname)" && echo
(( ${aENABLED[14]} )) && . /boot/dietpi/func/dietpi-print_large "$(</etc/hostname)" && echo
# Device model
(( ${aENABLED[0]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[0]} $GREEN_SEPARATOR $G_HW_MODEL_NAME"
(( ${aENABLED[0]} )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[0]} $GREEN_SEPARATOR $G_HW_MODEL_NAME"
# Uptime
(( ${aENABLED[1]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[1]} $GREEN_SEPARATOR $(uptime -p 2>&1)"
(( ${aENABLED[1]} )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[1]} $GREEN_SEPARATOR $(uptime -p 2>&1)"
# CPU temp
(( ${aENABLED[2]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[2]} $GREEN_SEPARATOR $(print_full_info=1 G_OBTAIN_CPU_TEMP 2>&1)"
(( ${aENABLED[2]} )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[2]} $GREEN_SEPARATOR $(print_full_info=1 G_OBTAIN_CPU_TEMP 2>&1)"
# RAM usage
(( ${aENABLED[17]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[17]} $GREEN_SEPARATOR $(free -b | mawk 'NR==2 {CONVFMT="%.0f"; print $3/1024^2" of "$2/1024^2" MiB ("$3/$2*100"%)"}')"
(( ${aENABLED[17]} )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[17]} $GREEN_SEPARATOR $(free -b | mawk 'NR==2 {CONVFMT="%.0f"; print $3/1024^2" of "$2/1024^2" MiB ("$3/$2*100"%)"}')"
# Load average
(( ${aENABLED[18]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[18]} $GREEN_SEPARATOR $(mawk '{print $1 ", " $2 ", " $3}' /proc/loadavg) ($(nproc) cores)"
(( ${aENABLED[18]} )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[18]} $GREEN_SEPARATOR $(mawk '{print $1 ", " $2 ", " $3}' /proc/loadavg) ($(nproc) cores)"
# Hostname
(( ${aENABLED[3]} == 1 && ${aENABLED[14]} != 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[3]} $GREEN_SEPARATOR $(</etc/hostname)"
(( ${aENABLED[3]} && ! ${aENABLED[14]} )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[3]} $GREEN_SEPARATOR $(</etc/hostname)"
# NIS/YP domainname
(( ${aENABLED[4]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[4]} $GREEN_SEPARATOR $(hostname -y 2>&1)"
(( ${aENABLED[4]} )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[4]} $GREEN_SEPARATOR $(hostname -y 2>&1)"
# LAN IP
Print_Local_Ip
# WAN IP + location info
(( ${aENABLED[6]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[6]} $GREEN_SEPARATOR $(G_GET_WAN_IP 2>&1)"
(( ${aENABLED[6]} )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[6]} $GREEN_SEPARATOR $(G_GET_WAN_IP 2>&1)"
# DietPi-VPN connection status
(( ${aENABLED[13]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[13]} $GREEN_SEPARATOR $(/boot/dietpi/dietpi-vpn status 2>&1)"
(( ${aENABLED[13]} )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[13]} $GREEN_SEPARATOR $(/boot/dietpi/dietpi-vpn status 2>&1)"
# Disk usage (RootFS)
(( ${aENABLED[7]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[7]} $GREEN_SEPARATOR $(df -h --output=used,size,pcent / | mawk 'NR==2 {print $1" of "$2" ("$3")"}' 2>&1)"
(( ${aENABLED[7]} )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[7]} $GREEN_SEPARATOR $(df -h --output=used,size,pcent / | mawk 'NR==2 {print $1" of "$2" ("$3")"}' 2>&1)"
# Disk usage (DietPi userdata)
(( ${aENABLED[8]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[8]} $GREEN_SEPARATOR $(df -h --output=used,size,pcent /mnt/dietpi_userdata | mawk 'NR==2 {print $1" of "$2" ("$3")"}' 2>&1)"
(( ${aENABLED[8]} )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[8]} $GREEN_SEPARATOR $(df -h --output=used,size,pcent /mnt/dietpi_userdata | mawk 'NR==2 {print $1" of "$2" ("$3")"}' 2>&1)"
# Weather
(( ${aENABLED[9]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[9]} $GREEN_SEPARATOR $(curl -sSfLm 3 'https://wttr.in/?format=4' 2>&1)"
(( ${aENABLED[9]} )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[9]} $GREEN_SEPARATOR $(curl -sSfLm 3 'https://wttr.in/?format=4' 2>&1)"
# Let's Encrypt cert status
if (( ${aENABLED[16]} == 1 ))
if (( ${aENABLED[16]} ))
then
echo -en "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[16]} $GREEN_SEPARATOR "
if [[ $EUID == 0 ]]
Expand All @@ -290,9 +290,9 @@ $GREEN_LINE"
fi
fi
# Custom
(( ${aENABLED[10]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[10]} $GREEN_SEPARATOR $(bash "$FP_CUSTOM" 2>&1)"
(( ${aENABLED[10]} )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[10]} $GREEN_SEPARATOR $(bash "$FP_CUSTOM" 2>&1)"
# MOTD
if (( ${aENABLED[12]} == 1 ))
if (( ${aENABLED[12]} ))
then
local motd fp_motd='/run/dietpi/.dietpi_motd'
[[ -f $fp_motd ]] || curl -sSfLm 3 'https://dietpi.com/motd' -o "$fp_motd"
Expand All @@ -301,9 +301,9 @@ $GREEN_LINE"
fi
echo -e "$GREEN_LINE\n"

(( ${aENABLED[15]} == 1 )) && Print_Credits
(( ${aENABLED[15]} )) && Print_Credits
Print_Updates
(( ${aENABLED[11]} == 1 )) && Print_Useful_Commands
(( ${aENABLED[11]} )) && Print_Useful_Commands
}

Menu_Main()
Expand All @@ -330,7 +330,7 @@ $GREEN_LINE"
# Custom entry
(( $i == 10 )) || continue

[[ -f $FP_CUSTOM ]] && G_WHIP_DEFAULT_ITEM=$(<"$FP_CUSTOM") || G_WHIP_DEFAULT_ITEM="echo 'Hello World!'"
[[ -f $FP_CUSTOM ]] && read -r G_WHIP_DEFAULT_ITEM < "$FP_CUSTOM" || G_WHIP_DEFAULT_ITEM='echo '\''Hello World!\'
G_WHIP_INPUTBOX 'You have chosen to show a custom entry in the banner.
Please enter the desired command here.\n
NB: It is executed as bash script, so it needs to be in bash compatible syntax.
Expand All @@ -350,19 +350,11 @@ NB: It is executed as bash script, so it needs to be in bash compatible syntax.
#/////////////////////////////////////////////////////////////////////////////////////
# Main Loop
#/////////////////////////////////////////////////////////////////////////////////////
if (( $INPUT == 0 ))
then
Print_Header
Print_Local_Ip

elif (( $INPUT == 1 ))
then
Print_Banner

elif (( $INPUT == 2 ))
then
Menu_Main
Print_Banner
case $INPUT in
0) Print_Header; Print_Local_Ip;;
1) Print_Banner;;
'') Menu_Main; Print_Banner;;
*) G_DIETPI-NOTIFY 1 "Invalid input \"$*\"\n\nUsage:$USAGE"; exit 1;;
fi

#-----------------------------------------------------------------------------------
Expand Down

0 comments on commit 77511bd

Please sign in to comment.