X-OpenWrt/CustomFiles/Depends/profile

118 lines
3.8 KiB
Plaintext
Raw Normal View History

Sysinfo() {
2022-05-06 13:20:04 +00:00
TARGET_PROFILE=$(getinf TARGET_PROFILE /rom/etc/autoupdate/default)
TARGET_BOARD=$(getinf TARGET_BOARD /rom/etc/autoupdate/default)
2022-03-22 15:09:04 +00:00
[ -z "${TARGET_PROFILE}" ] && echo
2021-09-05 07:50:11 +00:00
if [ "${TARGET_BOARD}" == x86 ]
then
2022-01-14 11:48:27 +00:00
[ -d /sys/firmware/efi ] && TARGET_BOOTABLE="UEFI" || TARGET_BOOTABLE="BIOS"
2021-09-05 07:50:11 +00:00
fi
[ -f /etc/bench.log ] && CoreMark=$(egrep -o "[0-9]+" /etc/bench.log | awk 'NR==1')
2022-03-22 15:09:04 +00:00
if [ -n "$(sensors 2> /dev/null | grep Core)" ]
then
2022-05-27 11:21:37 +00:00
TEMP=$(echo "$(sensors 2> /dev/null | grep Core | awk '{Sum += $3};END {print Sum}') / $(sensors 2>/dev/null | grep Core | wc -l)" | bc 2> /dev/null)
2022-03-22 15:09:04 +00:00
fi
2022-05-27 11:21:37 +00:00
TEMP="$(temp_color ${TEMP})"
2022-05-05 05:52:21 +00:00
if [ -n "${TARGET_BOOTABLE}" ]
then
printf " 设备信息: %-7s ${Div} ${Green}%-12s${White}\n" ${TARGET_PROFILE} ${TARGET_BOOTABLE}
else
[ -n "${TARGET_PROFILE}" ] && printf " 设备信息: ${TARGET_PROFILE}\n"
fi
2021-09-10 14:43:29 +00:00
printf " 内核版本: $(uname -rs | cut -d ' ' -f2)\n"
printf " 可用内存: %-7s ${Div} %s of %s\n" $(free | grep Mem | awk '{a=$7*100/$2;b=$7/1024;c=$2/1024} {printf("%.1fM %.1f%% %.1fM",b,a,c)}')
2022-03-15 03:46:54 +00:00
printf " 可用存储: %-7s ${Div} %s of %s\n" $(df -T '/' | grep -v File | awk '{a=$5*100/$3;b=$5/1024;c=$3/1024} {printf("%.1fM %.1f%% %.1fM",b,a,c)}')
2022-05-27 11:21:37 +00:00
[ -n "${TEMP}" ] && printf " 设备温度: ${TEMP}\n"
2022-01-14 11:48:27 +00:00
[ -n "${CoreMark}" ] && printf " 性能得分: ${CoreMark}\n"
2021-09-10 14:43:29 +00:00
[ -f /proc/uptime ] && printf " 运行时间: $(awk '{a=$1/86400;b=($1%86400)/3600;c=($1%3600)/60;d=($1%60)} {printf("%d 天 %d 小时 %d 分钟 %d 秒\n",a,b,c,d)}' /proc/uptime)\n"
2022-01-20 12:38:17 +00:00
[ -n "${SSH_CONNECTION}" ] && printf " 登录用户: %-7s ${Div} %s\n" ${LOGNAME} $(echo ${SSH_CONNECTION} | awk '{print $1":"$2}')
2022-01-14 11:48:27 +00:00
printf "${White}\n"
}
2021-09-05 07:50:11 +00:00
getinf() {
2022-03-22 15:09:04 +00:00
local i=$(grep $1 $2 2> /dev/null | awk 'END {print}')
2022-01-14 11:48:27 +00:00
[ -z "${i}" ] && return 1
eval echo ${i} | sed "s/^[$1=]*//g" 2> /dev/null
2021-09-05 07:50:11 +00:00
}
2022-05-27 11:21:37 +00:00
temp_color() {
if [ -n "$1" ]
then
2022-07-24 04:58:43 +00:00
if [ $1 -gt 55 ]
2022-05-27 11:21:37 +00:00
then
echo -ne "${Red}WARN ${1}°C${White}"
else
echo -n "${1}°C"
fi
fi
}
White="\e[0m"
Yellow="\e[33m"
Red="\e[31m"
Blue="\e[34m"
Grey="\e[36m"
Green="\e[32m"
2021-08-05 07:27:21 +00:00
Div="${Grey}|${White}"
2021-06-18 13:52:28 +00:00
clear
2021-06-17 15:43:35 +00:00
2021-06-18 13:52:28 +00:00
[ -e /tmp/.failsafe ] && export FAILSAFE=1
2022-01-14 11:48:27 +00:00
[ -f /etc/banner ] && printf "$(cat /etc/banner)\n"
2021-06-17 15:43:35 +00:00
[ -n "$FAILSAFE" ] && cat /etc/banner.failsafe
Sysinfo
fgrep -sq '/ overlay ro,' /proc/mounts && {
2022-01-14 11:48:27 +00:00
printf "${Red}警告: 固件可用空间已满,请尝试清理文件或重新刷写固件!
相反地,卸载系统自带软件包对空间清理没有任何帮助; 因此,请尝试卸载用户安装的软件包${White}\n\n"
}
2021-06-18 13:52:28 +00:00
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
export HOME=$(grep -e "^${USER:-root}:" /etc/passwd | cut -d ":" -f 6)
export HOME=${HOME:-/root}
2022-05-27 11:21:37 +00:00
export CONFIG=/etc/config
if [ -n "${TARGET_PROFILE}" ]
then
2022-07-24 04:58:43 +00:00
export PS1='\u@\h[${TARGET_PROFILE}]:\w\$ '
2022-05-27 11:21:37 +00:00
else
2022-07-24 04:58:43 +00:00
export PS1='\u@\h:\w\$ '
2022-05-27 11:21:37 +00:00
fi
export ENV=/etc/shinit
case "$TERM" in
xterm*|rxvt*)
export PS1='\[\e]0;\u@\h: \w\a\]'$PS1
;;
esac
[ -n "$FAILSAFE" ] || {
2021-06-17 15:43:35 +00:00
for FILE in /etc/profile.d/*.sh; do
[ -e "$FILE" ] && . "$FILE"
done
unset FILE
}
2021-06-17 15:43:35 +00:00
if ( grep -qs '^root::' /etc/shadow && \
[ -z "$FAILSAFE" ] )
then
echo -e "${Red} ==================== 警告 ========================
当前设备没有为 root 用户设置密码!
请使用 "passwd" 指令来设置一个系统密码来提高安全性
同时防止未经授权的 SSH 使用 root 非法登录
--------------------------------------------------${White}
"
2021-06-17 15:43:35 +00:00
fi
2021-05-15 08:10:57 +00:00
2022-07-24 04:58:43 +00:00
alias reload='. /etc/profile'
2021-09-05 07:50:11 +00:00
alias coremarkd='/etc/coremark.sh'
2022-05-05 05:52:21 +00:00
alias shutdown='sync && poweroff'
2021-05-26 13:26:14 +00:00
alias ls='ls --color=auto'
alias l='ls -CF'
2021-05-26 13:26:14 +00:00
alias ll='ls -alF'
alias la='ls -A'
alias cls='clear'
alias dh='df -h'
2022-04-22 11:51:20 +00:00
alias syslog='cat $(uci get system.@system[0].log_file) 2> /dev/null'
2021-08-05 07:27:21 +00:00
alias ramfree='sync && echo 3 > /proc/sys/vm/drop_caches'
2022-05-05 05:52:21 +00:00
alias top='top -d 1'