From e3893a851143b5584e0174b8c82525534cffa7bf Mon Sep 17 00:00:00 2001 From: yutent Date: Sun, 7 Jan 2024 17:33:13 +0800 Subject: [PATCH] update --- src/fetch | 66 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/src/fetch b/src/fetch index a135f5e..b632d7c 100755 --- a/src/fetch +++ b/src/fetch @@ -14,10 +14,13 @@ _cwh=$(tput setaf 7) # 白色 _cbd=$(tput bold) # 加粗 _cnc=$(tput sgr0) # 重置(结束) -# vars +# 一些变量 FULL=─ EMPTY=─ +IN_DOCKER='N' + +ARCH_NAME='amd64' name=$USER 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 //') +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() { + model="" if [[ -d /system/app/ && -d /system/priv-app ]]; then model="$(getprop ro.product.brand) $(getprop ro.product.model)" @@ -44,12 +58,26 @@ get_model() { elif [[ -f /tmp/sysinfo/model ]]; then model=$(< /tmp/sysinfo/model) fi + + if [[ $model == "" ]]; then + if [ $IN_DOCKER == "Y" ]; then + model="docker container" + else + model="@${host}" + fi + else + model="@${model}" + fi } # 获取debian的内核版本 get_kernel() { - IFS=" " read -ra kver <<< "$(uname -v)" - kernel_version="${kver[4]}-amd64" + if [ $IN_DOCKER == "Y" ]; then + kernel_version="$(uname -r)-${ARCH_NAME}" + else + IFS=" " read -ra kver <<< "$(uname -v)" + kernel_version="${kver[4]}-${ARCH_NAME}" + fi } get_shell(){ @@ -90,33 +118,15 @@ free() { 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_kernel get_shell -ram=$(free | awk '/Mem:/ {print int($3/$2 * 100.0)}') -PADXX=$((PADX - 3)) -for ((i = 0; i < PADXX; ++i)); do - PADCC="$PADCC " -done +ram=$(free | awk '/Mem:/ {print int($3/$2 * 100.0)}') block_1=" ▓▓ " @@ -137,6 +147,10 @@ deb_3=" / _\` |/ _ \ '_ \| |/ _\` | '_ \ " deb_4=" | (_| | __/ |_) | | (_| | | | |" deb_5=" \__,_|\___|_.__/|_|\__,_|_| |_|" + +# 输出前清屏 +clear + cat <