chore(profile_motd): new profile motd script

reformat network print
reformat memory print
This commit is contained in:
lucas committed 2026-11-04 11:29:20 +01:00
1 parent 266cfd5bf9
commit 745503a1ab
2 files changed
+161 -86

No files matched your search

+161
View File
@@ -0,0 +1,161 @@
#!/usr/bin/env bash
[[ -z "$TERM" || "$TERM" == "dumb" ]] && export TERM=xterm-256color
print_line() {
local width
width=$(tput cols 2>/dev/null || echo 80)
printf '%*s\n' "$width" '' | tr ' ' '*'
}
center() {
local width text padding
text="$1"
width=$(tput cols 2>/dev/null || echo 80)
padding=$(( (width - ${#text}) / 2 ))
printf "%*s%s\n" "$padding" "" "$text"
}
tab() {
local target="$1"
local text="$2"
(( $# < 2 )) && {
printf '\t'
return
}
printf "%*s" $(( target - ${#text} > 0 ? target - ${#text} : 1 )) ""
}
#
# Header
#
hour=$(date +%H)
if (( hour < 12 )); then
greeting="Good Morning"
elif (( hour < 19 )); then
greeting="Good Afternoon"
else
greeting="Good Evening"
fi
print_line
center "Server: $HOSTNAME"
print_line
printf "\n%s %s!\n\n" "$greeting" "$(whoami)"
printf "%s\n" "$(date '+%A, %d %B %Y, %T')"
printf "Uptime: %s\n\n" "$(uptime -p)"
#
# Network
#
mapfile -t ifaces < <(
ip -br link |
awk '$1 != "lo" {print $1}'
)
declare -A iface_ips
for iface in "${ifaces[@]}"; do
iface_ips["$iface"]=$(
ip -4 -o addr show "$iface" 2>/dev/null |
awk '{print $4}' |
cut -d/ -f1 |
head -n1
)
[[ -z "${iface_ips[$iface]}" ]] && iface_ips["$iface"]="----------"
done
PUBLIC_IP=$(curl -fsS --max-time 5 ifconfig.co 2>/dev/null)
COUNTRY=$(curl -fsS --max-time 5 ifconfig.co/country 2>/dev/null)
CITY=$(curl -fsS --max-time 5 ifconfig.co/city 2>/dev/null)
PUBLIC_IP=${PUBLIC_IP:-"IP unavailable"}
COUNTRY=${COUNTRY:-"Unknown"}
CITY=${CITY:-"Unknown"}
printf "Network:\n"
# Physical interfaces
for iface in "${ifaces[@]}"; do
[[ "$iface" =~ ^(lo|docker0|br-|veth) ]] && continue
ip="${iface_ips[$iface]}"
[[ "$ip" == "----------" ]] && continue
printf " %-6s %-15s (%s)\n" \
"LAN" \
"$ip" \
"$iface"
done
printf " %-6s %-15s (%s, %s)\n" \
"WAN" \
"$PUBLIC_IP" \
"$CITY" \
"$COUNTRY"
printf " %-6s %s\n" \
"User" \
"$(whoami)"
# Docker networks
docker_found=false
for iface in "${ifaces[@]}"; do
if [[ "$iface" =~ ^(docker0|br-) ]]; then
if ! $docker_found; then
printf "\nDocker:\n"
docker_found=true
fi
printf " %-12s %s\n" \
"${iface:0:12}" \
"${iface_ips[$iface]}"
fi
done
printf "\n"
#
# Memory
#
read -r mem_total mem_used mem_free <<< "$(
free -h |
awk 'NR==2 {print $2, $3, $7}'
)"
printf "%-10s %8s total %8s used %8s free\n" \
"Memory:" "$mem_total" "$mem_used" "$mem_free"
#
# Storage
#
while read -r filesystem size used avail pct mountpoint; do
case "$mountpoint" in
*efi*|*win10*)
continue
;;
/)
label="/root:"
;;
*)
label="/$(basename "$mountpoint"):"
;;
esac
printf "%-10s %8s total %8s used %8s free (%4s)\n" \
"$label" "$size" "$used" "$avail" "$pct"
done < <(
df -h --output=source,size,used,avail,pcent,target |
awk 'NR>1 && $1 ~ /^\/dev\//'
)
printf "\n"
-86
View File
@@ -4,9 +4,6 @@ tab() {
for ((i_tab=${#2};i_tab<$1;i_tab++)); do printf " "; done
}
if [ "$1" != "-o" ]; then
exec 1>/home/lucas/.bash_motd_buff
fi
if [ "$(/sbin/ip -br link | grep bond0)" != "" ];then
if1="bond0"
ip1="$(/sbin/ip -br link bond0 | grep -o "10\.0\.0\.103")"
@@ -46,70 +43,6 @@ if [ "$HOSTNAME" == "quiethost" ]; then
fi
done
fi
if [ "$HOSTNAME" == "raspberry" ]; then
printf "%s:\t%s\t\t" "${ifx[1]}" "${ipx[1]}"
fi
if [ "$HOSTNAME" == "quiethost_dep" ]; then
printf "WallpaperChanger: "
if [ "$(ps -elf | grep -v grep | grep wallpaperChanger.sh)" = "" ]; then
printf "[ OFF ]\t\t"
else
time="$(ps -elf | grep -v grep | grep wallpaperChanger.sh | sed 's/ \+/ /g' | cut -f18 -d' ')"
printf "[ ON ]\t%s min\t" "$time"
fi
printf "\n"
KURS1="$(wget -qO- https://www.fondsprofessionell.at/fonds/details/fondsName/Amundi-Komfort-Invest-traditionell-T/ISIN/AT0000801071/fondsID/FU_80107/)"
KURS2="$(wget -qO- https://www.fondsprofessionell.at/fonds/details/ISIN/AT0000A2L443/fondsID/FU_100076607/)"
KURS3="$(wget -qO- https://www.fondsprofessionell.at/fonds/details/fondsName/Amundi-CPR-Climate-Action-T/ISIN/AT0000A28YU4/fondsID/FU_100070247/)"
DATE1="$(printf "%s\n" "${KURS1}" | sed 's/<\/b>/<\/b>\n/g' | grep -o -P '(?<=<b>NAV am ).*(?= </b>)')"
DATE2="$(printf "%s\n" "${KURS2}" | sed 's/<\/b>/<\/b>\n/g' | grep -o -P '(?<=<b>NAV am ).*(?= </b>)')"
DATE3="$(printf "%s\n" "${KURS3}" | sed 's/<\/b>/<\/b>\n/g' | grep -o -P '(?<=<b>NAV am ).*(?= </b>)')"
KURS_EUR1=$(printf "%s\n" "${KURS1}" | sed 's/<\//\n<\//g' | grep -A2 "NAV am" | grep -o -P '(?<=<td> ).*(?=EUR)' | sed 's/ //g' | sed 's/,/./g')
KURS_PER1=$(printf "%s\n" "${KURS1}" | sed 's/<\//\n<\//g' | grep -A3 "Änderung (%)" | grep -o -P '(?<=<td> ).*(?=%\))')
printf "Traditionell:\t%s EUR" "${KURS_EUR1}"; tab 8 "${KURS_EUR1}"; printf "%s%%)\t${DATE1}\n" "${KURS_PER1}"
KURS_EUR2=$(printf "%s\n" "${KURS2}" | sed 's/<\//\n<\//g' | grep -A2 "NAV am" | grep -o -P '(?<=<td> ).*(?=EUR)' | sed 's/ //g' | sed 's/,/./g')
KURS_PER2=$(printf "%s\n" "${KURS2}" | sed 's/<\//\n<\//g' | grep -A3 "Änderung (%)" | grep -o -P '(?<=<td> ).*(?=%\))')
printf "Dynamisch:\t%s EUR" "${KURS_EUR2}"; tab 8 "${KURS_EUR2}"; printf "%s%%)\t${DATE2}\n" "${KURS_PER2}"
KURS_EUR3=$(printf "%s\n" "${KURS3}" | sed 's/<\//\n<\//g' | grep -A2 "NAV am" | grep -o -P '(?<=<td> ).*(?=EUR)' | sed 's/ //g' | sed 's/,/./g')
KURS_PER3=$(printf "%s\n" "${KURS3}" | sed 's/<\//\n<\//g' | grep -A3 "Änderung (%)" | grep -o -P '(?<=<td> ).*(?=%\))')
printf "Climate:\t%s EUR" "${KURS_EUR3}"; tab 8 "${KURS_EUR3}"; printf "%s%%)\t${DATE3}\n" "${KURS_PER3}"
#bash "/home/lucas/Documents/Dokumente/Projekte/Server/scripts/serverhost/update_BA_Data.sh" "${KURS_EUR1}" "${KURS_EUR2}" "${KURS_EUR3}"
fi
if [ "$HOSTNAME" == "raspberry_dep" ]; then
printf "MoistSens: "
if [ "$(pgrep recieveMS)" = "" ]; then
printf "[ OFF ]\t"
else
printf "[ ON ]\t"
fi
printf "BTServer: "
if [ "$(pgrep BTserver)" = "" ]; then
printf "[ OFF ]\n"
else
printf "[ ON ]\n"
fi
fi
if [[ "$HOSTNAME" = "serverhost" ]] || [[ "$HOSTNAME" = "workhost" ]]; then
printf "OpenVPN: "
if [ "$(pgrep openvpn)" = "" ]; then
printf "[ OFF ]\t"
else
printf "[ ON ] PID: %s" "$(pgrep openvpn | tr '\n' ' ')"
fi
if [[ "$HOSTNAME" = "serverhost" ]]; then
printf "\tUser: deluge-user"; tab 14 "deluge-user";
ip=$(sudo /home/lucas/scripts/serverhost/deluge_user_cmd.sh wget -T 2 -qO- ifconfig.co)
if [ "$ip" != "" ]; then
location=$(sudo /home/lucas/scripts/serverhost/deluge_user_cmd.sh wget -T 2 -qO- ifconfig.co/country)
# city=$(sudo /home/lucas/scripts/serverhost/deluge_user_cmd.sh wget -T 2 -qO- ifconfig.co/city)
printf "$ip"; tab 17 "$ip"; printf "$location\n"
else
printf "No Connection\n"
fi
else
printf "\n"
fi
fi
printf "\n"
SPACE_TAB=18
mem="$(free -h | awk 'NR==2 { printf "Total: %sB,\tUsed: %sB,\tFree: %sB",$2,$3,$7; }')"
@@ -132,22 +65,3 @@ for ((i=0;i<${#data_dev[@]};i++)); do
printf "%s\n" "$osspace"
done
tabs -8
if [[ "$HOSTNAME" = "raspberry" ]]; then
temp="$(/opt/vc/bin/vcgencmd measure_temp | cut -c "6-9") ºC"
temp="Temperature...: $temp"
echo $temp
fi
if [[ "$HOSTNAME" = "workhost" ]] || [[ "$HOSTNAME" = "raspberry" ]] && [[ -f /etc/motd ]]; then
cat /etc/motd
fi
if [[ "$HOSTNAME" = "serverhost" ]] || [[ "$HOSTNAME" = "quiethost" ]]; then
sudo /etc/update-motd.d/90-updates-available
if [ -f /etc/motd ]; then cat /etc/motd; fi
sudo /etc/update-motd.d/91-release-upgrade
sudo /etc/update-motd.d/98-fsck-at-reboot
sudo /etc/update-motd.d/98-reboot-required
fi
if [[ "$1" != "-o" ]] && [[ -f /home/lucas/.bash_motd_buff ]]; then
mv /home/lucas/.bash_motd_buff /home/lucas/.bash_motd
fi