Skip to content

Commit

Permalink
Cosmetic adjustement of profile.d scripts to align with motd
Browse files Browse the repository at this point in the history
  • Loading branch information
igorpecovnik committed Sep 3, 2024
1 parent 0afe5ec commit d81d52b
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 45 deletions.
2 changes: 1 addition & 1 deletion packages/bsp/common/etc/default/armbian-motd.dpkg-dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

MOTD_DISABLE=""
ONE_WIRE=""
HIDE_IP_PATTERN="^dummy0|^lo"
HIDE_IP_PATTERN="^dummy0|^lo|^docker"
PRIMARY_INTERFACE="$(ip route | grep '^default' | sed "s/.*dev //" | cut -d" " -f1)"
PRIMARY_DIRECTION="rx"
STORAGE=/dev/sda1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ if [ -f "${HOME}/.activate_psd" ]; then
sed -i 's/#USE_OVERLAYFS=.*/USE_OVERLAYFS="yes"/' "${config_file}"
case $(/usr/bin/psd p 2>/dev/null | grep Overlayfs) in
*active*)
echo -e "\nConfigured profile sync daemon with overlayfs."
echo -e "\n Configured profile sync daemon with overlayfs."
;;
*)
echo -e "\nConfigured profile sync daemon."
echo -e "\n Configured profile sync daemon."
sed -i 's/USE_OVERLAYFS="yes"/#USE_OVERLAYFS="no"/' "${config_file}"
;;
esac
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
if [ "$-" != "${-#*i}" ]; then
OutstandingPackages="$(grep -Ev "linux-base|linux-image" /var/run/reboot-required.pkgs 2>/dev/null)"
if [ -f "/var/run/.reboot_required" ]; then
printf "\n[\e[0;91m Kernel was updated, please reboot\x1B[0m ]\n\n"
printf "\n \e[0;91mKernel was updated, please reboot\x1B[0m \n\n"
elif [ "X${OutstandingPackages}" != "X" ]; then
# No kernel update involved, just regular packages like e.g. dbus require a reboot
Packages="$(grep -Ev "linux-base|linux-image" /var/run/reboot-required.pkgs | sort | uniq | tr '\n' ',' | sed -e 's/,/, /g' -e 's/,\ $//')"
OlderThanOneDay=$(find /var/run/reboot-required -mtime +1)
if [ "X${OlderThanOneDay}" = "X" ]; then
printf "\n[\e[0;92m some packages require a reboot (${Packages})\x1B[0m ]\n\n"
printf "\n\e[0;92m Some packages require a reboot (${Packages})\x1B[0m\n\n"
else
printf "\n[\e[0;91m some packages require a reboot since more than 1 day (${Packages})\x1B[0m ]\n\n"
printf "\n\e[0;91m Some packages require a reboot since more than 1 day (${Packages})\x1B[0m\n\n"
fi
fi
fi
30 changes: 14 additions & 16 deletions packages/bsp/common/etc/update-motd.d/10-armbian-header
Original file line number Diff line number Diff line change
Expand Up @@ -47,49 +47,47 @@ done
KERNELID=$(uname -r)

# Display software vendor logo
echo -e "\e[0;91m$(figlet -f small " $VENDOR")\e[0m";
echo -e "\e[1;91m$(figlet -f small " $VENDOR")\e[0m";

# 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"
echo -e " \e[0;92mv${VERSION}\x1B[0m for $BOARD_NAME running Armbian Linux \e[0;92m${KERNELID^}\x1B[0m"

# render image and board type
if [[ "$IMAGE_TYPE" != "stable" ]]; then
[[ "$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)"
[[ "$IMAGE_TYPE" == "user-built" ]] && HARDWARE_STATUS="\e[0;91mDIY\x1B[0m (custom image)\x1B[0m"
[[ "$IMAGE_TYPE" == "nightly" ]] && HARDWARE_STATUS="\e[0;91mfor advanced users\x1B[0m (rolling release)\x1B[0m"
else
[[ "$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"
[[ "$BOARD_TYPE" == "csc" || "$BOARD_TYPE" == "tvb" ]] && HARDWARE_STATUS="\e[0;91mDIY (community maintained)\x1B[0m"
[[ "$BOARD_TYPE" == "wip" ]] && HARDWARE_STATUS="\e[0;91mfor advanced users\x1B[0m (work in progress)\x1B[0m"
[[ "$BOARD_TYPE" == "eos" ]] && HARDWARE_STATUS="\e[0;91mend of life\x1B[0m"
fi

# render distribution status
if [[ $DISTRIBUTION_STATUS == supported ]]; then
DISTRO_STATUS="\e[1;92mstable\e[0m ($DISTRIBUTION_CODENAME)"
DISTRO_STATUS="\e[0;92mstable\e[0m ($DISTRIBUTION_CODENAME)"
elif [[ $DISTRIBUTION_STATUS == eos ]]; then
DISTRO_STATUS="\e[1;91mend of life\e[0m ($DISTRIBUTION_CODENAME)"
DISTRO_STATUS="\e[0;91mend of life\e[0m ($DISTRIBUTION_CODENAME)"
else
DISTRO_STATUS="\e[1;93mrolling\e[0m ($DISTRIBUTION_CODENAME)"
DISTRO_STATUS="\e[0;93mrolling\e[0m ($DISTRIBUTION_CODENAME)"
fi

# 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"
if [[ $NUM_UPDATES -gt 0 ]]; then
if apt-mark showhold | grep -q linux-image 2>/dev/null; then
UPDATE_STATUS="Kernel upgrade \e[0;91mdisabled\e[0m"
else
UPDATE_STATUS="FW upgrade \e[1;92menabled\e[0m"
UPDATE_STATUS="Kernel upgrade \e[0;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
Expand Down
39 changes: 25 additions & 14 deletions packages/bsp/common/etc/update-motd.d/30-armbian-sysinfo
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ MOTD_DISABLE=""
PRIMARY_INTERFACE="eth0"
PRIMARY_DIRECTION="rx"
STORAGE=/dev/sda1
HIDE_IP_PATTERN="^dummy0|^lo"
HIDE_IP_PATTERN="^dummy0|^lo|^docker"
CPU_TEMP_LIMIT=60
# Temperature offset in Celcius degrees
CPU_TEMP_OFFSET=0
Expand Down Expand Up @@ -53,6 +53,10 @@ function display() {
fi
} # display

function get_wan_address(){
curl -s http://whatismyip.akamai.com/
}

function get_ip_addresses() {
local ips=()
for f in /sys/class/net/*; do
Expand Down Expand Up @@ -91,6 +95,7 @@ function storage_info() {
# Works only with ambienttemp and batteryinfo since A20 is slow enough :)
amb_temp=$(ambienttemp &)
ip_address=$(get_ip_addresses &)
wan_ip_address=$(get_wan_address &)
batteryinfo
storage_info
getboardtemp
Expand Down Expand Up @@ -126,9 +131,15 @@ swap_total=$(awk '{print $(2)}' <<<${swap_info})

# draw a line to start this section

#printf "\e[0;90m Sysinfo "; printf '%.s─' $(seq 1 71); echo -e " \x1B[0m"
#echo ""
echo -en " IP addresses: \x1B[93m(LAN)\x1B[0m \x1B[92m$ip_address\x1B[0m "
if [[ -n $wan_ip_address ]]; then
echo -e "\x1B[93m(WAN)\x1B[0m $wan_ip_address"
fi
echo ""
printf "\e[0;90m Performance: \x1B[0m"
echo "" # fixed newline
echo ""

display " Load" "${load%% *}" "${critical_load}" "0" "%" ""

printf "Up time: \x1B[92m%s\x1B[0m\t" "$time"
Expand All @@ -148,8 +159,6 @@ fi

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 "Ambient temp" "$amb_temp" $AMB_TEMP_LIMIT "0" "°C" ""
Expand All @@ -164,21 +173,23 @@ display "Battery" "$battery_percent" "20" "1" "%" "$status_battery_text" ; a=$((
line=0
if [[ -n "$PRIMARY_INTERFACE" ]] && vnstat -i "$PRIMARY_INTERFACE" &> /dev/null; then
traffic=$(vnstat -i $PRIMARY_INTERFACE --oneline | cut -d";" -f4,5)
traffic_rx=$(echo $traffic | cut -d";" -f1,1 | sed -r 's/([0-9]+\.[0-9]{1})[0-9]*/\1/')
traffic_tx=$(echo $traffic | cut -d";" -f2,2 | sed -r 's/([0-9]+\.[0-9]{1})[0-9]*/\1/')
traffic_rx=$(echo $traffic | cut -d";" -f1,1 | sed -r 's/([0-9]+\.[0-9]{1})[0-9]*/\1/' | cut -d" " -f1 | cut -d"," -f1)
traffic_rx_unit=$(echo $traffic | cut -d";" -f1,1 | sed -r 's/([0-9]+\.[0-9]{1})[0-9]*/\1/' | cut -d" " -f2)
traffic_tx=$(echo $traffic | cut -d";" -f2,2 | sed -r 's/([0-9]+\.[0-9]{1})[0-9]*/\1/' | cut -d" " -f1 | cut -d"," -f1)
traffic_tx_unit=$(echo $traffic | cut -d";" -f2,2 | sed -r 's/([0-9]+\.[0-9]{1})[0-9]*/\1/' | cut -d" " -f2)
[[ "$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"
display " TX today" "$traffic_tx" 500 0 " $traffic_tx_unit" ""
line=$((line+1))
;;
rx)
printf " RX today: \x1B[92m%s\x1B[0m \t" "$traffic_rx"
display " RX today" "$traffic_rx" 500 0 " $traffic_rx_unit" ""
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"
display " TX today" "$traffic_tx" 500 0 " $traffic_tx_unit" ""
display "RX today" "$traffic_rx" 500 0 " $traffic_rx_unit" ""
line=$((line+1))
;;
*) #off or whatever
Expand All @@ -191,15 +202,15 @@ 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
Expand Down
4 changes: 2 additions & 2 deletions packages/bsp/common/etc/update-motd.d/35-armbian-tips
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +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
# 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"
printf "\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/^/ /'
echo ""
fi
fi
29 changes: 22 additions & 7 deletions packages/bsp/common/etc/update-motd.d/41-commands
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,29 @@ for f in $MOTD_DISABLE; do
[[ $f == $THIS_SCRIPT ]] && exit 0
done

printf "\e[0;90m Commands: \x1B[0m\n" #; printf '%.s─' $(seq 1 39); echo -e "\x1B[0m"
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"

list=(
"System config ","sudo ","armbian-config"
"System monitor ","","htop"
)

# just for easier coloring
yellow() { printf '%s' $'\e[1;33m' "$*" $'\e[0m'; }

for l in "${list[@]}"
do
name=$(echo $l | cut -d"," -f1)
sudo=$(echo $l | cut -d"," -f2)
command=$(echo $l | cut -d"," -f3)

if command -v $command &> /dev/null
then
printf "$(yellow " %-26s %-0s"): $sudo$command\n" "$name"
fi
done

echo -e "\033[0m"
#printf "\e[0;90m www.armbian.com/donate "; printf '%.s─' $(seq 1 21); echo -e "\x1B[0m"
#echo ""

exit 0

0 comments on commit d81d52b

Please sign in to comment.