From 7dc8c9364b9d07519a331b75e50e360ff64c342e Mon Sep 17 00:00:00 2001 From: Molly Lau Date: Sat, 27 May 2023 16:20:36 +0900 Subject: [PATCH] Update 00-header --- Linux_reinstall/updatemotd/00-header | 90 ++++++++-------------------- 1 file changed, 24 insertions(+), 66 deletions(-) diff --git a/Linux_reinstall/updatemotd/00-header b/Linux_reinstall/updatemotd/00-header index b6af3f6..a76b0a4 100644 --- a/Linux_reinstall/updatemotd/00-header +++ b/Linux_reinstall/updatemotd/00-header @@ -1,9 +1,11 @@ -#!/bin/bash +#!/bin/sh # -# 10-sysinfo - generate the system information +# 00-header - create the header of the MOTD # Copyright (c) 2013 Nick Charlton +# Copyright (c) 2009-2010 Canonical Ltd. # # Authors: Nick Charlton &amp;amp;lt;hello@nickcharlton.net&amp;amp;gt; +# Dustin Kirkland &amp;amp;lt;kirkland@canonical.com&amp;amp;gt; # Modified by Oitibs: https://oitibs.com/?s=Debian+Dynamic+MOTD # Modified by Leitbogioro: https://github.com/leitbogioro/ # https://www.zhihu.com/column/originaltechnic @@ -21,72 +23,28 @@ # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -date=`date` -load=`cat /proc/loadavg | awk '{print $1}'` -root_usage=`df -h / | awk '/\// {print $(NF-1)}'` -memory_usage=`free -m | awk '/Mem:/ { total=$2; used=$3 } END { printf("%3.1f%%", used/total*100)}'` -[[ `free -m | awk '/Swap/ {print $2}'` == "0" ]] && swap_usage="0.0%" || swap_usage=`free -m | awk '/Swap/ { printf("%3.1f%%", $3/$2*100) }'` -users=`users | wc -w` -time=`uptime | grep -ohe 'up .*' | sed 's/,/\ hours/g' | awk '{ printf $2" "$3 }'` -processes=`ps aux | wc -l` -localip=`hostname -I | awk '{print $1}'` +#[ -r /etc/lsb-release ] ; /etc/lsb-release -IPv4=`timeout 0.2s dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com | sed 's/\"//g'` -[[ "$IPv4" == "" ]] && IPv4=`timeout 0.2s dig -4 TXT CH +short whoami.cloudflare @1.0.0.1 | sed 's/\"//g'` -IPv6=`timeout 0.2s dig -6 TXT +short o-o.myaddr.l.google.com @ns1.google.com | sed 's/\"//g'` -[[ "$IPv6" == "" ]] && IPv6=`timeout 0.2s dig -6 TXT CH +short whoami.cloudflare @2606:4700:4700::1001 | sed 's/\"//g'` -# IP_Check=$(echo $IPv4 | awk -F. '$1<255&&$2<255&&$3<255&&$4<255{print "isIPv4"}') -IP_Check="$IPv4" -if expr "$IP_Check" : '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' >/dev/null; then - for i in 1 2 3 4; do - if [ $(echo "$IP_Check" | cut -d. -f$i) -gt 255 ]; then - echo "fail ($IP_Check)" - exit 1 - fi - done - IP_Check="isIPv4" +if [ -z "$DISTRIB_DESCRIPTION" ] ; [ -x /usr/bin/lsb_release ]; then + # Fall back to using the very slow lsb_release utility + DISTRIB_DESCRIPTION=$(lsb_release -s -d) fi -[[ ${IPv6: -1} == ":" ]] && IPv6=$(echo "$IPv6" | sed 's/.$/0/') -[[ ${IPv6:0:1} == ":" ]] && IPv6=$(echo "$IPv6" | sed 's/^./0/') -IP6_Check="$IPv6"":" -IP6_Hex_Num=`echo "$IP6_Check" | tr -cd ":" | wc -c` -IP6_Hex_Abbr="0" -if [[ `echo "$IPv6" | grep -i '[[:xdigit:]]' | grep ':'` ]] && [[ "$IP6_Hex_Num" -le "8" ]]; then - for ((i=1; i<="$IP6_Hex_Num"; i++)){ - IP6_Hex=$(echo "$IP6_Check" | cut -d: -f$i) - [[ "$IP6_Hex" == "" ]] && IP6_Hex_Abbr=`expr $IP6_Hex_Abbr + 1` - [[ `echo "$IP6_Hex" | wc -c` -le "4" ]] && { - if [[ `echo "$IP6_Hex" | grep -iE '[^0-9a-f]'` ]] || [[ "$IP6_Hex_Abbr" -gt "1" ]]; then - echo "fail ($IP6_Check)" - exit 1 - fi - } - } - IP6_Check="isIPv6" -fi +figlet `cat /etc/issue | cut -d " " -f1` +printf "\n" -[[ "${IP6_Check}" != "isIPv6" ]] && IPv6="N/A" - -[[ "${IP_Check}" != "isIPv4" ]] && IPv4="N/A" - -if [[ "${localip}" == "${IPv4}" ]] || [[ "${localip}" == "${IPv6}" ]] || [[ -z "${localip}" ]]; then - # localip=`ip -o a show | grep -w "lo" | grep -w "inet" | cut -d ' ' -f7 | awk '{split($1, a, "/"); print $2 "" a[1]}'` - localip=`cat /etc/hosts | grep "localhost" | sed -n 1p | awk '{print $1}'` -fi - -echo " System information as of $date" -echo -printf "%-30s%-15s\n" " System Load:" "$load" -printf "%-30s%-15s\n" " Private IP Address:" "$localip" -printf "%-30s%-15s\n" " Public IPv4 Address:" "$IPv4" -printf "%-30s%-15s\n" " Public IPv6 Address:" "$IPv6" -printf "%-30s%-15s\n" " Memory Usage:" "$memory_usage" -printf "%-30s%-15s\n" " Usage On /:" "$root_usage" -printf "%-30s%-15s\n" " Swap Usage:" "$swap_usage" -printf "%-30s%-15s\n" " Local Users:" "$users" -printf "%-30s%-15s\n" " Processes:" "$processes" -printf "%-30s%-15s\n" " System Uptime:" "$time" -echo +printf "Welcome to %s (%s).\n" "$DISTRIB_DESCRIPTION" "$(uname -r)" +printf "\n" +printf "The programs included with the Debian GNU/Linux system are free software;" +printf "\n" +printf "the exact distribution terms for each program are described in the" +printf "\n" +printf "individual files in /usr/share/doc/*/copyright." +printf "\n" +printf "\n" +printf "Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent" +printf "\n" +printf "permitted by applicable law." +printf "\n" +printf "\n"