From 0afe5ec2dc6eec55e0b672ef817b1ef89e6e34fc Mon Sep 17 00:00:00 2001 From: Igor Pecovnik Date: Sat, 31 Aug 2024 15:50:18 +0200 Subject: [PATCH] Refactor welcome screen to improve user experience --- .../etc/update-motd.d/10-armbian-header | 77 +++++++++++++++---- .../etc/update-motd.d/30-armbian-sysinfo | 29 ++++--- .../common/etc/update-motd.d/35-armbian-tips | 4 +- .../etc/update-motd.d/40-armbian-updates | 39 ---------- .../{41-armbian-config => 41-commands} | 17 ++-- .../update-motd.d/98-armbian-autoreboot-warn | 4 +- 6 files changed, 91 insertions(+), 79 deletions(-) delete mode 100755 packages/bsp/common/etc/update-motd.d/40-armbian-updates rename packages/bsp/common/etc/update-motd.d/{41-armbian-config => 41-commands} (58%) diff --git a/packages/bsp/common/etc/update-motd.d/10-armbian-header b/packages/bsp/common/etc/update-motd.d/10-armbian-header index 9d8ac46633..1aeefe41d7 100755 --- a/packages/bsp/common/etc/update-motd.d/10-armbian-header +++ b/packages/bsp/common/etc/update-motd.d/10-armbian-header @@ -22,11 +22,19 @@ VENDORTEMP="${VENDOR}" # Keep the VENDOR from image if its defined there [[ -n "${VENDORTEMP}" && "${VENDORTEMP}" != "${VENDOR}" ]] && VENDOR="${VENDORTEMP}" +# If VENDORPRETTYNAME is defined, used that +[[ -n $VENDORPRETTYNAME ]] && VENDOR="$VENDORPRETTYNAME" + if [[ -f /etc/armbian-distribution-status ]]; then . /etc/armbian-distribution-status + # Fina a way that works [[ -f /etc/lsb-release ]] && DISTRIBUTION_CODENAME=$(grep CODENAME /etc/lsb-release | cut -d"=" -f2) + [[ -f /etc/lsb-release ]] && DISTRIBUTION_ID=$(grep DISTRIB_ID /etc/lsb-release | cut -d"=" -f2) [[ -z "$DISTRIBUTION_CODENAME" && -f /etc/os-release ]] && DISTRIBUTION_CODENAME=$(grep VERSION_CODENAME /etc/os-release | cut -d"=" -f2) + [[ -z "$DISTRIBUTION_ID" && -f /etc/os-release ]] && DISTRIBUTION_ID=$(grep "^ID" /etc/os-release | cut -d"=" -f2) [[ -z "$DISTRIBUTION_CODENAME" && -x /usr/bin/lsb_release ]] && DISTRIBUTION_CODENAME=$(/usr/bin/lsb_release -c | cut -d":" -f2 | tr -d "\t") + [[ -z "$DISTRIBUTION_ID" && -x /usr/bin/lsb_release ]] && DISTRIBUTION_ID=$(/usr/bin/lsb_release -i | cut -d":" -f2 | tr -d "\t") + # Read Armbian distribution status DISTRIBUTION_STATUS=$(grep "$DISTRIBUTION_CODENAME" /etc/armbian-distribution-status | cut -d"=" -f2) fi [[ -f /etc/default/armbian-motd ]] && . /etc/default/armbian-motd @@ -35,31 +43,66 @@ for f in $MOTD_DISABLE; do [[ $f == $THIS_SCRIPT ]] && exit 0 done - +# Read Armbian kernel version KERNELID=$(uname -r) -# Odroid N2 exception -[[ -f /proc/device-tree/model ]] && [[ -n $(tr -d '\000' < /proc/device-tree/model | grep ODROID | grep Plus) ]] && BOARD_NAME+="+" +# Display software vendor logo +echo -e "\e[0;91m$(figlet -f small " $VENDOR")\e[0m"; -TERM=linux toilet -f standard -F metal $(echo $BOARD_NAME | sed 's/Orange Pi/OPi/' | sed 's/NanoPi/NPi/' | sed 's/Banana Pi/BPi/') -echo -e "Welcome to \e[0;91m${VENDOR} ${VERSION} ${DISTRIBUTION_CODENAME^}\x1B[0m with $([[ $BRANCH == edge ]] && echo -e "\e[0;91mbleeding\x1B[0m edge " )\e[0;91mLinux $KERNELID\x1B[0m\n" - -# displaying status warnings +# Display version, board, and kernel version +echo -e " \e[1;91mv${VERSION}\x1B[0m for \e[1;93m$BOARD_NAME \x1B[0mrunning \e[1;91mArmbian Linux\x1B[0m \e[1;93m${KERNELID^}\x1B[0m" +# render image and board type if [[ "$IMAGE_TYPE" != "stable" ]]; then - [[ "$IMAGE_TYPE" == "user-built" ]] && UNSUPPORTED_TEXT="built from trunk" - [[ "$IMAGE_TYPE" == "nightly" ]] && UNSUPPORTED_TEXT="untested automated build" + [[ "$IMAGE_TYPE" == "user-built" ]] && HARDWARE_STATUS="\e[1;91mnot supported\x1B[0m (custom image)" + [[ "$IMAGE_TYPE" == "nightly" ]] && HARDWARE_STATUS="\e[1;91mfor advanced users\x1B[0m (rolling release)" else - [[ "$BOARD_TYPE" == "csc" || "$BOARD_TYPE" == "tvb" ]] && UNSUPPORTED_TEXT="community creations" - [[ "$BOARD_TYPE" == "wip" ]] && UNSUPPORTED_TEXT="work in progress" - [[ "$BOARD_TYPE" == "eos" ]] && UNSUPPORTED_TEXT="end of life" + [[ "$BOARD_TYPE" == "csc" || "$BOARD_TYPE" == "tvb" ]] && HARDWARE_STATUS="Community maintained" + [[ "$BOARD_TYPE" == "wip" ]] && HARDWARE_STATUS="\e[1;91mfor advanced users\x1B[0m (work in progress)" + [[ "$BOARD_TYPE" == "eos" ]] && HARDWARE_STATUS="\e[1;91mend of life\x1B[0m" fi -if [[ -n $DISTRIBUTION_STATUS && $DISTRIBUTION_STATUS != supported ]]; then - [[ -n $UNSUPPORTED_TEXT ]] && UNSUPPORTED_TEXT+=" & " - UNSUPPORTED_TEXT+="unsupported ($DISTRIBUTION_CODENAME) userspace!" +# render distribution status +if [[ $DISTRIBUTION_STATUS == supported ]]; then + DISTRO_STATUS="\e[1;92mstable\e[0m ($DISTRIBUTION_CODENAME)" +elif [[ $DISTRIBUTION_STATUS == eos ]]; then + DISTRO_STATUS="\e[1;91mend of life\e[0m ($DISTRIBUTION_CODENAME)" +else + DISTRO_STATUS="\e[1;93mrolling\e[0m ($DISTRIBUTION_CODENAME)" fi -if [[ -n $UNSUPPORTED_TEXT ]]; then - echo -e "\e[0;91mNo end-user support: \x1B[0m$UNSUPPORTED_TEXT\n" +# read packages update status +NUM_UPDATES=0 +NUM_UPDATES_ONHOLD=0 +NUM_SECURITY_UPDATES=0 +[[ -f /var/cache/apt/archives/updates.number ]] && . /var/cache/apt/archives/updates.number +if [[ $NUM_UPDATES -gt 0 ]] && grep -q linux /var/cache/apt/archives/updates.list 2>/dev/null; then + if [[ $NUM_UPDATES_ONHOLD -gt 0 ]]; then + UPDATE_STATUS="FW upgrade \e[1;91mdisabled\e[0m" + else + UPDATE_STATUS="FW upgrade \e[1;92menabled\e[0m" + fi + UPDATE_STATUS+=" and \e[1;92m$NUM_UPDATES\e[0m package" + # Cosmetic is important + [[ $NUM_UPDATES -gt 1 ]] && UPDATE_STATUS+="s" + UPDATE_STATUS+=" available for upgrade\e[0m " +fi + +# draw a line to start this section +#printf "\e[0;90m OS "; printf '%.s─' $(seq 1 76); echo -e " \x1B[0m" +echo "" + +# Display packages status +if [[ -n $DISTRO_STATUS ]]; then + echo -e " Packages: ${DISTRIBUTION_ID^} ${DISTRO_STATUS}" +fi + +# Display available updates +if [[ -n $UPDATE_STATUS ]]; then + echo -e " Updates: $UPDATE_STATUS" +fi + +# Display hardware support status +if [[ -n $HARDWARE_STATUS ]]; then + echo -e " Support: $HARDWARE_STATUS" fi diff --git a/packages/bsp/common/etc/update-motd.d/30-armbian-sysinfo b/packages/bsp/common/etc/update-motd.d/30-armbian-sysinfo index abd85bab7a..9d8f4fe82b 100755 --- a/packages/bsp/common/etc/update-motd.d/30-armbian-sysinfo +++ b/packages/bsp/common/etc/update-motd.d/30-armbian-sysinfo @@ -123,7 +123,13 @@ swap_usage=$( (awk '/Swap/ { printf("%3.0f", $3/$2*100) }' <<<${swap_info} 2>/de swap_total=$(awk '{print $(2)}' <<<${swap_info}) # display info -display "System load" "${load%% *}" "${critical_load}" "0" "%" "" + +# draw a line to start this section + +#printf "\e[0;90m Sysinfo "; printf '%.s─' $(seq 1 71); echo -e " \x1B[0m" +echo "" + +display " Load" "${load%% *}" "${critical_load}" "0" "%" "" printf "Up time: \x1B[92m%s\x1B[0m\t" "$time" display "Local users" "${users##* }" "3" "2" "" @@ -140,12 +146,12 @@ else swap_total+="M" fi -display "Memory usage" "$memory_usage" "70" "0" "%" " of ${memory_total}" +display " Memory usage" "$memory_usage" "70" "0" "%" " of ${memory_total}" display "Zram usage" "$swap_usage" "75" "0" "%" " of ${swap_total}" printf "IP: " printf "\x1B[92m%s\x1B[0m" "$ip_address" echo "" # fixed newline -display "CPU temp" "$board_temp" $CPU_TEMP_LIMIT "0" "°C" "" +display " CPU temp" "$board_temp" $CPU_TEMP_LIMIT "0" "°C" "" display "Ambient temp" "$amb_temp" $AMB_TEMP_LIMIT "0" "°C" "" display "Usage of /" "$root_usage" "90" "1" "%" " of $root_total" echo "" # fixed newline @@ -163,16 +169,16 @@ if [[ -n "$PRIMARY_INTERFACE" ]] && vnstat -i "$PRIMARY_INTERFACE" &> /dev/null; [[ "$traffic" == *"Not enough"* ]] && { traffic_tx="n/a "; traffic_rx="n/a "; } case $PRIMARY_DIRECTION in tx) - printf "TX today: \x1B[92m%s\x1B[0m \t" "$traffic_tx" + printf " TX today: \x1B[92m%s\x1B[0m \t" "$traffic_tx" line=$((line+1)) ;; rx) - printf "RX today: \x1B[92m%s\x1B[0m \t" "$traffic_rx" + printf " RX today: \x1B[92m%s\x1B[0m \t" "$traffic_rx" line=$((line+1)) ;; both) - printf "TX today: \x1B[92m%s\x1B[0m \t" "$traffic_tx" - printf "RX today: \x1B[92m%s\x1B[0m \t" "$traffic_rx" + printf " TX today: \x1B[92m%s\x1B[0m \t" "$traffic_tx" + printf " RX today: \x1B[92m%s\x1B[0m \t" "$traffic_rx" line=$((line+1)) ;; *) #off or whatever @@ -185,18 +191,17 @@ if [[ $(command -v zpool) ]]; then if [[ -n $(echo $zpoolstatus | grep 'not loaded') ]]; then : elif [[ -n $(echo $zpoolstatus | grep 'degraded\|OFFLINE') ]]; then - printf "ZFS pool: " + printf " ZFS pool: " echo -ne "\e[0;91mDegraded\x1B[0m" line=$((line+1)) elif [[ -n $(echo $zpoolstatus | grep 'no pools available') ]]; then - printf "ZFS pool: " + printf " ZFS pool: " echo -ne "n/a" line=$((line+1)) else - printf "ZFS pool: " + printf " ZFS pool: " echo -ne "\e[0;92mOnline\x1B[0m" line=$((line+1)) fi fi -[[ $line -ne 0 ]] && echo "" -echo "" +if [[ $line -ne 0 ]]; then echo ""; fi diff --git a/packages/bsp/common/etc/update-motd.d/35-armbian-tips b/packages/bsp/common/etc/update-motd.d/35-armbian-tips index 0b54c9c3fa..6afe203ba8 100755 --- a/packages/bsp/common/etc/update-motd.d/35-armbian-tips +++ b/packages/bsp/common/etc/update-motd.d/35-armbian-tips @@ -25,6 +25,8 @@ if [[ -f $quotes && $(( $RANDOM % 1 )) == 0 ]]; then DUE_DATE=$(echo $quote | cut -d"|" -f1) SELECTED_QUOTE=$(echo $quote | cut -d"|" -f2) if [[ -n $SELECTED_QUOTE && $(date +'%Y-%m-%d') < $(date -d $DUE_DATE +"%Y-%m-%d") ]]; then - echo -e "\e[93mTip of the day:\e[39m $SELECTED_QUOTE\n" + # draw a line to start this section + printf "\n\e[0;90m Tips:\x1B[0m\n " #; printf '%.s─' $(seq 1 5); echo -e " \x1B[0m" + echo -e "\n$SELECTED_QUOTE" | fold -w 79 -s | sed 's/^/ /' fi fi diff --git a/packages/bsp/common/etc/update-motd.d/40-armbian-updates b/packages/bsp/common/etc/update-motd.d/40-armbian-updates deleted file mode 100755 index 1321d54d7a..0000000000 --- a/packages/bsp/common/etc/update-motd.d/40-armbian-updates +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -# -# Copyright (c) Authors: https://www.armbian.com/authors -# -# This file is licensed under the terms of the GNU General Public -# License version 2. This program is licensed "as is" without any -# warranty of any kind, whether express or implied. - -# DO NOT EDIT THIS FILE but add config options to /etc/default/armbian-motd -# any changes will be lost on board support package update - -THIS_SCRIPT="updates" -MOTD_DISABLE="" - -[[ -f /etc/default/armbian-motd ]] && . /etc/default/armbian-motd - -for f in $MOTD_DISABLE; do - [[ $f == $THIS_SCRIPT ]] && exit 0 -done - -NUM_UPDATES=0 -NUM_UPDATES_ONHOLD=0 - -[[ -f /var/cache/apt/archives/updates.number ]] && . /var/cache/apt/archives/updates.number - -if [[ $NUM_UPDATES -gt 0 ]]; then - echo -en "[\e[31m $NUM_SECURITY_UPDATES security updates available, $NUM_UPDATES updates total\e[0m: \e[1mapt upgrade\e[0m " -fi - -if [[ $NUM_UPDATES_ONHOLD -gt 0 ]] && grep -q linux /var/cache/apt/archives/updates.list 2>/dev/null; then - [[ $NUM_UPDATES -gt 0 ]] && echo -en "| " || echo -en "[ " - echo -en "\e[31mKernel and firmware upgrades disabled:\e[0m \e[1marmbian-config\e[0m " -fi - -if [[ $NUM_UPDATES -gt 0 ]] || [[ $NUM_UPDATES_ONHOLD -gt 0 ]]; then - echo -e "]" - echo -e "Last check: \e[92m$DATE\e[0m" - echo -fi diff --git a/packages/bsp/common/etc/update-motd.d/41-armbian-config b/packages/bsp/common/etc/update-motd.d/41-commands similarity index 58% rename from packages/bsp/common/etc/update-motd.d/41-armbian-config rename to packages/bsp/common/etc/update-motd.d/41-commands index 8cad023e3d..e5ae79de2c 100755 --- a/packages/bsp/common/etc/update-motd.d/41-armbian-config +++ b/packages/bsp/common/etc/update-motd.d/41-commands @@ -9,7 +9,7 @@ # DO NOT EDIT THIS FILE but add config options to /etc/default/armbian-motd # any changes will be lost on board support package update -THIS_SCRIPT="config" +THIS_SCRIPT="commands" MOTD_DISABLE="" [[ -f /etc/default/armbian-motd ]] && . /etc/default/armbian-motd @@ -18,13 +18,14 @@ for f in $MOTD_DISABLE; do [[ $f == $THIS_SCRIPT ]] && exit 0 done -if [[ $(( $RANDOM % 2 )) == 0 ]]; then - if [[ -f /usr/sbin/armbian-config ]]; then - echo -e "[\e[31m General system configuration (beta)\e[0m: \e[1marmbian-config\e[0m ]\n" - else - echo -e "[\e[31m Menu-driven system configuration (beta)\e[0m: \e[1msudo apt update && sudo apt install armbian-config\e[0m ]\n" - fi -fi +echo "" +printf "\e[0;90m Commands: \e[0;90m\n" #; printf '%.s─' $(seq 1 39); echo -e "\x1B[0m" +echo "" +echo -e " \e[1;93mUpdate\e[1;39m: sudo apt update ; sudo apt upgrade" +echo -e " \e[1;93mSystem config\e[1;39m: sudo armbian-config" +echo -e "\033[0m" +#printf "\e[0;90m www.armbian.com/donate "; printf '%.s─' $(seq 1 21); echo -e "\x1B[0m" +#echo "" exit 0 diff --git a/packages/bsp/common/etc/update-motd.d/98-armbian-autoreboot-warn b/packages/bsp/common/etc/update-motd.d/98-armbian-autoreboot-warn index 2e6036fd69..c248a8be2f 100755 --- a/packages/bsp/common/etc/update-motd.d/98-armbian-autoreboot-warn +++ b/packages/bsp/common/etc/update-motd.d/98-armbian-autoreboot-warn @@ -10,6 +10,6 @@ # any changes will be lost on board support package update if [[ -f /var/run/resize2fs-reboot ]]; then - printf "\e[0;91mWarning: a reboot is needed to finish resizing the filesystem \x1B[0m \n" - printf "\e[0;91mPlease reboot the system as soon as possible \x1B[0m \n" + printf "\e[0;91m Warning: a reboot is needed to finish resizing the filesystem \x1B[0m \n" + printf "\e[0;91m Please reboot the system as soon as possible \x1B[0m \n" fi