master
yutent 2024-01-07 17:33:13 +08:00
parent fba8878dbe
commit e3893a8511
1 changed files with 40 additions and 26 deletions

View File

@ -14,10 +14,13 @@ _cwh=$(tput setaf 7) # 白色
_cbd=$(tput bold) # 加粗 _cbd=$(tput bold) # 加粗
_cnc=$(tput sgr0) # 重置(结束) _cnc=$(tput sgr0) # 重置(结束)
# vars # 一些变量
FULL=─ FULL=─
EMPTY=─ EMPTY=─
IN_DOCKER='N'
ARCH_NAME='amd64'
name=$USER name=$USER
host=$(uname -n) host=$(uname -n)
@ -29,8 +32,19 @@ term=$(ps -o sid= -p "$$" | xargs ps -o ppid= -p | xargs ps -o comm= -p)
uptm=$(uptime -p | sed -e 's/up //') uptm=$(uptime -p | sed -e 's/up //')
check_is_docker(){
if [ -f /.dockerenv ]; then
IN_DOCKER="Y"
elif [ -f /proc/cmdline ]; then
if cat /proc/cmdline | grep -q docker; then
IN_DOCKER="Y"
fi
fi
}
# 获取设备信息 # 获取设备信息
get_model() { get_model() {
model=""
if [[ -d /system/app/ && -d /system/priv-app ]]; then if [[ -d /system/app/ && -d /system/priv-app ]]; then
model="$(getprop ro.product.brand) $(getprop ro.product.model)" model="$(getprop ro.product.brand) $(getprop ro.product.model)"
@ -44,12 +58,26 @@ get_model() {
elif [[ -f /tmp/sysinfo/model ]]; then elif [[ -f /tmp/sysinfo/model ]]; then
model=$(< /tmp/sysinfo/model) model=$(< /tmp/sysinfo/model)
fi fi
if [[ $model == "" ]]; then
if [ $IN_DOCKER == "Y" ]; then
model="docker container"
else
model="@${host}"
fi
else
model="@${model}"
fi
} }
# 获取debian的内核版本 # 获取debian的内核版本
get_kernel() { get_kernel() {
if [ $IN_DOCKER == "Y" ]; then
kernel_version="$(uname -r)-${ARCH_NAME}"
else
IFS=" " read -ra kver <<< "$(uname -v)" IFS=" " read -ra kver <<< "$(uname -v)"
kernel_version="${kver[4]}-amd64" kernel_version="${kver[4]}-${ARCH_NAME}"
fi
} }
get_shell(){ get_shell(){
@ -90,33 +118,15 @@ free() {
printf "0" printf "0"
} }
# 清屏
clear
# find the center of the screen
COL=$(tput cols)
ROW=$(tput lines)
((PADY = ROW / 2 - 10 - 22 / 2))
((PADX = COL / 2 - 34 / 2))
for ((i = 0; i < PADX; ++i)); do
PADC="$PADC "
done
for ((i = 0; i < PADY; ++i)); do
PADR="$PADR\n"
done
check_is_docker
get_model get_model
get_kernel get_kernel
get_shell get_shell
ram=$(free | awk '/Mem:/ {print int($3/$2 * 100.0)}')
PADXX=$((PADX - 3)) ram=$(free | awk '/Mem:/ {print int($3/$2 * 100.0)}')
for ((i = 0; i < PADXX; ++i)); do
PADCC="$PADCC "
done
block_1=" ▓▓ " block_1=" ▓▓ "
@ -137,6 +147,10 @@ deb_3=" / _\` |/ _ \ '_ \| |/ _\` | '_ \ "
deb_4=" | (_| | __/ |_) | | (_| | | | |" deb_4=" | (_| | __/ |_) | | (_| | | | |"
deb_5=" \__,_|\___|_.__/|_|\__,_|_| |_|" deb_5=" \__,_|\___|_.__/|_|\__,_|_| |_|"
# 输出前清屏
clear
cat <<EOF cat <<EOF
┌──────────────────────────┬──────────────────────────────────────────────────┐ ┌──────────────────────────┬──────────────────────────────────────────────────┐
│ │ ${deb_1} │ │ │ ${deb_1} │
@ -148,7 +162,7 @@ cat <<EOF
│ │ │ │ │ │
│ ${logo_4} ├──────────────┬───────────────────────────────────┤ │ ${logo_4} ├──────────────┬───────────────────────────────────┤
│ │ │ │ │ │ │ │
│ ${logo_5} │ Host │ @${host} │ │ ${logo_5} │ Host │ ${model} │
│ │ OS │ │ │ │ OS │ │
│ ${logo_6} │ Uptime │ ${uptm} │ │ ${logo_6} │ Uptime │ ${uptm} │
│ │ │ │ │ │ │ │
@ -171,9 +185,9 @@ EOF
# hide the cursor and wait for user input # 隐藏光标并监听输入
tput civis tput civis
read -n 1 read -n 1
# give the cursor back # 任意输入,恢复光标
tput cnorm tput cnorm