WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/bsp/common/etc/cron.daily/armbian-quotes
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

curl --max-time 2 -L -s -o "/tmp/quotes.txt" "https://github.armbian.com/quotes.txt"
curl --max-time 2 -L -s -o "/etc/update-motd.d/quotes.txt" "https://github.armbian.com/quotes.txt"
16 changes: 13 additions & 3 deletions packages/bsp/common/etc/update-motd.d/00-clear
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@
THIS_SCRIPT="clear"
MOTD_DISABLE=""

[[ -f /etc/default/armbian-motd ]] && . /etc/default/armbian-motd
# Clear runtime MOTD state
MOTD_RUN_DIR="/run/armbian-motd"
if [[ -d "$MOTD_RUN_DIR" ]]; then
rm -f "${MOTD_RUN_DIR}/".*.printed 2>/dev/null
else
mkdir -p "$MOTD_RUN_DIR" 2>/dev/null
fi

safe_source() { [[ -f "$1" ]] && . "$1"; }

for f in $MOTD_DISABLE; do
[[ $f == $THIS_SCRIPT ]] && exit 0
# Optional overrides
safe_source /etc/default/armbian-motd
for f in ${MOTD_DISABLE}; do
[[ "${f}" == "${THIS_SCRIPT}" ]] && exit 0
done

# Clear screen
Expand Down
317 changes: 123 additions & 194 deletions packages/bsp/common/etc/update-motd.d/10-armbian-header
Original file line number Diff line number Diff line change
Expand Up @@ -2,237 +2,166 @@
#
# 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.
# Licensed under the GNU General Public License, version 2.
# Distributed “as is” without any warranty of any kind.

# DO NOT EDIT THIS FILE but add config options to /etc/default/armbian-motd
# any changes will be lost on board support package update
# DO NOT EDIT THIS FILE.
# To customize behavior, override options in /etc/default/armbian-motd.
# Any local edits here will be lost during board support package updates.

set -o pipefail

THIS_SCRIPT="header"
MOTD_DISABLE=""
HIDE_IP_PATTERN="^dummy0|^lo|^docker|^hassio|^br-|^veth|^vnet|^virbr"
HIDE_LOCAL_IPV6="true"

# Read image configuration
[[ -f /etc/armbian-image-release ]] && . /etc/armbian-image-release
VENDORTEMP="${VENDOR}"
_motd_mark_after_header() {
local base="/run/armbian-motd"
mkdir -p "$base" 2>/dev/null || base="${XDG_RUNTIME_DIR:-/tmp}/armbian-motd"
mkdir -p "$base" 2>/dev/null || return 0
local stamp="${base}/.after_header.printed"
[[ -e "$stamp" ]] || { echo ""; : >"$stamp"; }
}

# Read update configuration
[[ -f /etc/armbian-release ]] && . /etc/armbian-release
safe_source() { [[ -f "$1" ]] && . "$1"; }

# Keep the VENDOR from image if its defined there
[[ -n "${VENDORTEMP}" && "${VENDORTEMP}" != "${VENDOR}" ]] && VENDOR="${VENDORTEMP}"
# --- Load metadata from image and release files ---
safe_source /etc/armbian-image-release
VENDORTEMP="${VENDOR:-}"
safe_source /etc/armbian-release
[[ -n "${VENDORTEMP}" && "${VENDORTEMP}" != "${VENDOR:-}" ]] && VENDOR="${VENDORTEMP}"
[[ -n "${VENDORPRETTYNAME:-}" ]] && VENDOR="${VENDORPRETTYNAME}"

# If VENDORPRETTYNAME is defined, used that
[[ -n ${VENDORPRETTYNAME} ]] && VENDOR="${VENDORPRETTYNAME}"
# --- Distribution and upgrade information ---
DISTRIBUTION_CODENAME=""
DISTRIBUTION_ID=""
upgrade=""

if [[ -f /etc/armbian-distribution-status ]]; then
. /etc/armbian-distribution-status
# Find 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 | cut -d";" -f1)

# Read upgrade possibilities on stable channel
filter=$(grep "supported" /etc/armbian-distribution-status | cut -d"=" -f1)
upgrade=$(for j in ${filter}; do
for i in $(grep "^${DISTRIBUTION_CODENAME}" /etc/armbian-distribution-status | cut -d";" -f2 | cut -d"=" -f2 | sed "s/,/ /g"); do
if [[ "${i}" == "${j}" ]]; then
echo "${i}"
fi
# Prefer lsb-release (safe to source; no VERSION conflict)
if [[ -f /etc/lsb-release ]]; then
# shellcheck disable=SC1091
. /etc/lsb-release
DISTRIBUTION_CODENAME="${DISTRIB_CODENAME:-${DISTRIBUTION_CODENAME}}"
DISTRIBUTION_ID="${DISTRIB_ID:-${DISTRIBUTION_ID}}"
fi

# If still missing, read only the keys we need from os-release (do NOT source it)
if [[ -z "${DISTRIBUTION_CODENAME}" || -z "${DISTRIBUTION_ID}" ]]; then
if [[ -f /etc/os-release ]]; then
DISTRIBUTION_CODENAME="$(awk -F= '/^VERSION_CODENAME=/{sub(/^"/,"",$2); sub(/"$/,"",$2); print $2}' /etc/os-release)"
DISTRIBUTION_ID="$(awk -F= '/^ID=/{sub(/^"/,"",$2); sub(/"$/,"",$2); print $2}' /etc/os-release)"
fi
fi

# If still missing, fallback to lsb_release command
if [[ -z "${DISTRIBUTION_CODENAME}" || -z "${DISTRIBUTION_ID}" ]]; then
if command -v lsb_release >/dev/null 2>&1; then
DISTRIBUTION_CODENAME="$(lsb_release -c | awk -F: '{gsub(/\t/,"",$2); print $2}')"
DISTRIBUTION_ID="$(lsb_release -i | awk -F: '{gsub(/\t/,"",$2); print $2}')"
fi
fi

DISTRIBUTION_STATUS="$(awk -F'[=;]' -v c="${DISTRIBUTION_CODENAME}" '$1==c{print $2; exit}' /etc/armbian-distribution-status)"
filter=$(awk -F= '/supported/{print $1}' /etc/armbian-distribution-status)
current_line="$(awk -F';' -v c="${DISTRIBUTION_CODENAME}" '$1==c{print $2; exit}' /etc/armbian-distribution-status)"
candidates="$(printf '%s\n' "${current_line#*=}" | tr ',' ' ')"
for j in $filter; do
for i in $candidates; do
if [[ "$i" == "$j" ]]; then upgrade="$i"; fi
done
done | tail -1)
done
fi

[[ -f /etc/default/armbian-motd ]] && . /etc/default/armbian-motd
safe_source /etc/default/armbian-motd
for f in ${MOTD_DISABLE}; do
[[ "${f}" == "${THIS_SCRIPT}" ]] && exit 0
done

function get_wan_address() {
curl -4 --max-time 2 -s https://ipv4.whatismyip.akamai.com/
} # get wan ip address

function get_wan6_address() {
curl -6 --max-time 2 -s https://ipv6.whatismyip.akamai.com/
} # get wan ip6 address

function get_ip_addresses() {
local ipv4s=()
local ipv4
local address4
local ipv6s=()
local ipv6
local address6
local intf
local f

for f in /sys/class/net/*; do
intf=$(basename "${f}")
# match only interface names
if [[ ${intf} =~ ${HIDE_IP_PATTERN} ]]; then
continue
else
# List all IP addresses without reordering or duplicates
ipv4=$(ip -4 addr show dev "${intf}")
ipv4=$(echo "${ipv4}" | grep -v "${intf}:avahi")
ipv4=$(echo "${ipv4}" | awk '/inet/ {print $2}')
ipv4=$(echo "${ipv4}" | cut -d'/' -f1)
ipv4=$(echo "${ipv4}" | awk '!x[$0]++')
ipv6=$(ip -6 addr show dev "${intf}")
if [[ "${HIDE_LOCAL_IPV6}" == true ]]; then
ipv6=$(ip -6 addr show dev "${intf}" | grep -v fe80)
fi
ipv6=$(echo "${ipv6}" | grep -v "${intf}:avahi")
ipv6=$(echo "${ipv6}" | awk '/inet6/ {print $2}')
ipv6=$(echo "${ipv6}" | cut -d'/' -f1)
ipv6=$(echo "${ipv6}" | awk '!x[$0]++')

for address4 in ${ipv4}; do
ipv4s+=("${address4}")
done
for address6 in ${ipv6}; do
ipv6s+=("${address6}")
done
fi
done

echo "${ipv4s[*]}|${ipv6s[*]}"
} # get_ip_addresses
# --- Kernel and system info ---
KERNELID="$(uname -r)"

# Read Armbian kernel version
KERNELID=$(uname -r)
# Get other variables
ip_address=$(get_ip_addresses &)
wan_ip_address=$(get_wan_address &)
wan_ip6_address=$(get_wan6_address &)
_motd_mark_after_header

# Get access point info
if systemctl is-active --quiet service hostapd && [[ -f /etc/hostapd/hostapd.conf ]]; then
. /etc/hostapd/hostapd.conf
# --- Vendor banner ---
if [[ -n "${VENDORCOLOR:-}" ]]; then
if command -v figlet >/dev/null 2>&1; then
printf '\e[38;2;%sm%s\e[0m\n' "${VENDORCOLOR}" "$(figlet -f small " ${VENDOR}")"
else
printf '\e[38;2;%sm### %s ###\e[0m\n' "${VENDORCOLOR}" "${VENDOR}"
fi
else
if command -v figlet >/dev/null 2>&1; then
printf '\e[1;91m%s\e[0m\n' "$(figlet -f small " ${VENDOR}")"
else
printf '\e[1;91m### %s ###\e[0m\n' "${VENDOR}"
fi
fi

# Display software vendor logo
if [[ -n "${VENDORCOLOR}" ]]; then
echo -e "\e[38;2;${VENDORCOLOR}m$(figlet -f small " ${VENDOR}")\e[0m"
else
echo -e "\e[1;91m$(figlet -f small " ${VENDOR}")\e[0m"
# --- Board name and version line ---
# Keep BOARD_NAME from Armbian files; only special-case RPi4 model tweak.
if [[ "${BOARD:-}" == "rpi4b" ]]; then
BOARD_NAME="$(tr '\0' '\n' < /proc/device-tree/model | sed -E 's/ Rev [0-9.]+$//')"
fi

# Read RPI model from cpuinfo
if [[ ${BOARD:-} == rpi4b ]]; then
BOARD_NAME=$(tr '\0' '\n' < /proc/device-tree/model | sed -E 's/ Rev [0-9.]+$//')
# Preserve Armbian VERSION; if it ends with "trunk", show "rolling"
if [[ "${VERSION:-}" == *trunk* ]]; then
VERSION="$(printf '%s' "${VERSION}" | cut -d'.' -f1-2)"
VERSION="${VERSION} rolling"
fi

# Display version, board, and kernel version
[[ ${VERSION} == *trunk* ]] && VERSION=$(echo -e ${VERSION} | cut -d"." -f1-2 | sed "s/\$/ rolling/")
echo -e " \e[0;92mv${VERSION}\x1B[0m for ${BOARD_NAME} running Armbian Linux \e[0;92m${KERNELID^}\x1B[0m"
printf ' \e[0;92mv%s\x1B[0m for %s running Armbian Linux \e[0;92m%s\x1B[0m\n' \
"${VERSION}" "${BOARD_NAME}" "${KERNELID}"

# render image and board type
# --- Hardware support status ---
HARDWARE_STATUS=""
if [[ "${IMAGE_TYPE:-}" != "stable" ]]; then
[[ "${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="\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[0;92mstable\e[0m (${DISTRIBUTION_CODENAME})"
elif [[ ${DISTRIBUTION_STATUS} == eos ]]; then
DISTRO_STATUS="\e[0;91mend of life\e[0m (${DISTRIBUTION_CODENAME})"
case "${IMAGE_TYPE:-}" in
"user-built") HARDWARE_STATUS=$'\e[0;91mDIY\x1B[0m (custom image)\x1B[0m' ;;
"nightly") HARDWARE_STATUS=$'\e[0;91mfor advanced users\x1B[0m (rolling release)\x1B[0m' ;;
esac
else
DISTRO_STATUS="\e[0;93mrolling\e[0m (${DISTRIBUTION_CODENAME})"
fi

# read packages update status
[[ -f /var/cache/apt/archives/updates.number ]] && . /var/cache/apt/archives/updates.number
if [[ ${NUM_UPDATES:-} -gt 0 ]]; then
if apt-mark showhold | grep -q linux-image 2> /dev/null; then
case "${BOARD_TYPE:-}" in
"csc"|"tvb") HARDWARE_STATUS=$'\e[0;91mDIY (community maintained)\x1B[0m' ;;
"wip") HARDWARE_STATUS=$'\e[0;91mfor advanced users\x1B[0m (work in progress)\x1B[0m' ;;
"eos") HARDWARE_STATUS=$'\e[0;91mend of life\x1B[0m' ;;
esac
fi

# --- Distribution status line ---
case "${DISTRIBUTION_STATUS:-}" in
supported) DISTRO_STATUS=$'\e[0;92mstable\e[0m' ;;
eos) DISTRO_STATUS=$'\e[0;91mend of life\e[0m' ;;
*) DISTRO_STATUS=$'\e[0;93mrolling\e[0m' ;;
esac
[[ -n "${DISTRIBUTION_CODENAME}" ]] && DISTRO_STATUS+=" (${DISTRIBUTION_CODENAME})"

# --- Updates status ---
if [[ -f /var/cache/apt/archives/updates.number ]]; then
# shellcheck disable=SC1091
. /var/cache/apt/archives/updates.number
fi
UPDATE_STATUS=""
if [[ "${NUM_UPDATES:-0}" -gt 0 ]]; then
if apt-mark showhold 2>/dev/null | grep -q '^linux-image'; then
UPDATE_STATUS="Kernel upgrade \e[0;91mdisabled\e[0m"
else
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"
[[ "${NUM_UPDATES}" -gt 1 ]] && UPDATE_STATUS+="s"
UPDATE_STATUS+=" available for upgrade\e[0m "
fi

# read running Docker containers if any
if systemctl is-active docker > /dev/null; then
CONTAINERS_STATUS=$(docker ps --format "{{.Names}}" | tr '\n' ',' | sed 's/,/, /g' | sed 's/, $//')
fi

echo ""

# Display packages status
if [[ -n ${DISTRO_STATUS} ]]; then
if [[ -n "${upgrade}" ]]; then
DISTRO_STATUS+=", possible distro upgrade (${upgrade})"
fi
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

# Display IP addresses
IFS='|' read -r ipv4s ipv6s <<< "${ip_address}"
# remove WAN IPv4 from the list of all IPv4
if [[ "${ipv4s}" == *${wan_ip_address}* ]]; then
ipv4s=$(echo $ipv4s | sed "s/"${wan_ip_address}"//g" | xargs )
fi
if [[ -n ${ipv4s} || -n ${wan_ip_address} ]]; then
all_ip_address=" IPv4: "
if [[ -n ${ipv4s} ]]; then
all_ip_address+=" \x1B[93m(LAN)\x1B[0m "
fi
all_ip_address+="\x1B[92m${ipv4s// /, }\x1B[0m "
if [[ -n ${wan_ip_address} ]]; then
all_ip_address+="\x1B[93m(WAN)\x1B[0m \x1B[95m${wan_ip_address}\x1B[0m "
fi
echo -e "${all_ip_address}"
fi
# remove WAN IPv6 from the list of all IPv6
if [[ -n "${wan_ip6_address}" && "${ipv6s}" == *${wan_ip6_address}* ]]; then
ipv6s=$(echo $ipv6s | sed "s/"${wan_ip6_address}"//g" | xargs )
fi
printf '\n'

if [[ -n ${ipv6s} || -n ${wan_ip6_address} ]]; then
all_ip6_address=" IPv6: "
if [[ -n ${ipv6s} ]]; then
all_ip6_address+="\x1B[96m${ipv6s// /, }\x1B[0m "
fi
if [[ -n ${wan_ip6_address} ]]; then
all_ip6_address+="\x1B[93m(WAN)\x1B[0m \x1B[95m${wan_ip6_address}\x1B[0m "
fi
echo -e "${all_ip6_address}"
# --- Display summary ---
if [[ -n "${DISTRO_STATUS:-}" ]]; then
[[ -n "${upgrade}" ]] && DISTRO_STATUS+=", possible distro upgrade (${upgrade})"
printf ' Packages: %s %b\n' "${DISTRIBUTION_ID^}" "${DISTRO_STATUS}"
fi

# Display running docker containers
if [[ -n "${CONTAINERS_STATUS}" ]]; then
echo -e " Containers: \x1B[92m${CONTAINERS_STATUS}\x1B[0m"
fi

# Display hostapd
if [[ -n ${ssid} ]]; then
echo -e " WiFi AP: SSID: (\x1B[91m${ssid}\x1B[0m), $(iw dev "${interface:-}" info | grep channel | xargs)"
fi
[[ -n "${UPDATE_STATUS}" ]] && printf ' Updates: %b\n' "${UPDATE_STATUS}"
[[ -n "${HARDWARE_STATUS}" ]] && printf ' Support: %b\n' "${HARDWARE_STATUS}"

echo ""
# ensure zero exit when executed directly
(return 0 2>/dev/null) || exit 0
Loading