#!/bin/bash { #//////////////////////////////////// # DietPi Banner Script # #//////////////////////////////////// # Created by Daniel Knight / daniel.knight@dietpi.com / dietpi.com # #//////////////////////////////////// # # Info: # - 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 #//////////////////////////////////// # Grab input [[ $1 == [01] ]] && INPUT=$1 || INPUT=2 # Import DietPi-Globals -------------------------------------------------------------- . /boot/dietpi/func/dietpi-globals # - Allow concurrent banner prints but a single menu call only if [[ $INPUT == 2 ]] then readonly G_PROGRAM_NAME='DietPi-Banner' G_CHECK_ROOT_USER # Required to store settings G_INIT else # Apply safe locale in non-menu mode (where G_INIT does it) export LC_ALL='C.UTF-8' LANG='C.UTF-8' fi # Import DietPi-Globals -------------------------------------------------------------- #///////////////////////////////////////////////////////////////////////////////////// # Globals #///////////////////////////////////////////////////////////////////////////////////// readonly FP_SAVEFILE='/boot/dietpi/.dietpi-banner' readonly FP_CUSTOM='/boot/dietpi/.dietpi-banner_custom' aDESCRIPTION=( 'Device model' 'Uptime' 'CPU temp' 'FQDN/hostname' 'NIS domainname' 'LAN IP' 'WAN IP' 'Disk usage (RootFS)' 'Disk usage (userdata)' 'Weather (wttr.in)' 'Custom banner entry' 'Display DietPi useful commands?' 'MOTD' 'VPN status' 'Large hostname' 'Print credits' 'Let'\''s Encrypt cert status' 'RAM usage' 'Load average' ) # Set defaults: Disable CPU temp by default in VMs if (( $G_HW_MODEL == 20 )) then aENABLED=(1 0 0 0 0 1 0 1 0 0 0 1 1 0 0 1 0 0 0) else aENABLED=(1 0 1 0 0 1 0 0 0 0 0 1 1 0 0 1 0 0 0) fi COLOUR_RESET='\e[0m' aCOLOUR=( '\e[38;5;154m' # DietPi green | Lines, bullets and separators '\e[1m' # Bold white | Main descriptions '\e[90m' # Grey | Credits '\e[91m' # Red | Update notifications ) # Load settings here, to have chosen ${aCOLOUR[0]} applied to below strings # shellcheck disable=SC1090 [[ -f $FP_SAVEFILE ]] && . "$FP_SAVEFILE" GREEN_LINE=" ${aCOLOUR[0]}─────────────────────────────────────────────────────$COLOUR_RESET" GREEN_BULLET=" ${aCOLOUR[0]}-$COLOUR_RESET" GREEN_SEPARATOR="${aCOLOUR[0]}:$COLOUR_RESET" DIETPI_VERSION="$G_DIETPI_VERSION_CORE.$G_DIETPI_VERSION_SUB.$G_DIETPI_VERSION_RC" [[ $G_GITBRANCH == 'master' ]] || DIETPI_VERSION+=" ($G_GITBRANCH)" # DietPi update available? AVAILABLE_UPDATE= # value = version string Check_DietPi_Update() { [[ -f '/run/dietpi/.update_available' ]] || return 1 AVAILABLE_UPDATE=$(&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)" # 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"%)"}')" # Load average (( ${aENABLED[18]} == 1 )) && 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 $(&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)" # DietPi-VPN connection status (( ${aENABLED[13]} == 1 )) && 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)" # 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)" # Weather (( ${aENABLED[9]} == 1 )) && 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 )) then echo -en "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[16]} $GREEN_SEPARATOR " if [[ $EUID == 0 ]] then # Running as root Print_Cert_Status 2>&1 else # Running as non-root: Fail silently without NOPASSWD to avoid password prompt, but print info instead sudo -n dash -c "$(declare -f Print_Cert_Status); Print_Cert_Status 2>&1" 2> /dev/null || echo 'NOPASSWD sudo required to obtain cert status' fi fi # Custom (( ${aENABLED[10]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[10]} $GREEN_SEPARATOR $(bash "$FP_CUSTOM" 2>&1)" # MOTD if (( ${aENABLED[12]} == 1 )) then local motd fp_motd='/run/dietpi/.dietpi_motd' [[ -f $fp_motd ]] || curl -sSfLm 3 'https://dietpi.com/motd' -o "$fp_motd" # shellcheck disable=SC1090 [[ -f $fp_motd ]] && . "$fp_motd" &> /dev/null && [[ $motd ]] && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[12]} $GREEN_SEPARATOR $motd" fi echo -e "$GREEN_LINE\n" (( ${aENABLED[15]} == 1 )) && Print_Credits Print_Updates (( ${aENABLED[11]} == 1 )) && Print_Useful_Commands } Menu_Main() { G_WHIP_CHECKLIST_ARRAY=() for i in "${!aDESCRIPTION[@]}" do local state='off' (( ${aENABLED[$i]:=0} == 1 )) && state='on' G_WHIP_CHECKLIST_ARRAY+=("$i" "${aDESCRIPTION[$i]}" "$state") done G_WHIP_CHECKLIST "Please (de)select options via spacebar to be shown in the $G_PROGRAM_NAME:" || return 0 for i in "${!aDESCRIPTION[@]}" do aENABLED[$i]=0 done for i in $G_WHIP_RETURNED_VALUE do aENABLED[$i]=1 # Custom entry (( $i == 10 )) || continue [[ -f $FP_CUSTOM ]] && 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. For multi-line or non-bash scripts, keep it separate and only add the script call here.' || continue echo "$G_WHIP_RETURNED_VALUE" > "$FP_CUSTOM" G_WHIP_DEFAULT_ITEM=${aDESCRIPTION[10]} G_WHIP_INPUTBOX 'Please enter a meaningful name to be shown in front of your custom command output:' && aDESCRIPTION[10]=$G_WHIP_RETURNED_VALUE done [[ -f $FP_CUSTOM ]] || aENABLED[10]=0 Save > "$FP_SAVEFILE" } #///////////////////////////////////////////////////////////////////////////////////// # 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 fi #----------------------------------------------------------------------------------- exit 0 #----------------------------------------------------------------------------------- }