mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 09:01:54 +08:00
重构更新
This commit is contained in:
24
armbian/armbian-motd
Normal file
24
armbian/armbian-motd
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
if [ -e /etc/update-motd.d/10-armbian-header ]; then /etc/update-motd.d/10-armbian-header; fi
|
||||
if [ -e /etc/update-motd.d/30-armbian-sysinfo ]; then /etc/update-motd.d/30-armbian-sysinfo; fi
|
||||
if [ -e /etc/update-motd.d/41-armbian-config ]; then /etc/update-motd.d/41-armbian-config; fi
|
||||
|
||||
printf " 欢迎使用 One-KVM,基于开源程序 PiKVM 的 IP-KVM 应用
|
||||
____________________________________________________________________________
|
||||
|
||||
要阻止内核消息输出到终端,可以使用命令\"dmesg -n 1\"
|
||||
|
||||
要修改默认账户 admin 的密码可使用命令 \"kvmd-htpasswd set admin\"
|
||||
|
||||
项目链接:
|
||||
* https://pikvm.org
|
||||
* https://github.com/srepac/kvmd-armbian
|
||||
* https://github.com/mofeng-git/One-KVM
|
||||
|
||||
文档链接:
|
||||
* https://docs.pikvm.org
|
||||
* https://one-kvm.mofeng.run
|
||||
|
||||
"
|
||||
|
||||
if [ -e /etc/motd.custom ]; then cat /etc/motd.custom; fi
|
||||
206
armbian/opt/armbian-sysinfo
Normal file
206
armbian/opt/armbian-sysinfo
Normal file
@@ -0,0 +1,206 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (c) Authors: http://www.armbian.com/authors
|
||||
#
|
||||
# This file is licensed under the terms of the GNU General Public
|
||||
# License version 2. This program is licensed "as is" without any
|
||||
# warranty of any kind, whether express or implied.
|
||||
#
|
||||
|
||||
# DO NOT EDIT THIS FILE but add config options to /etc/default/armbian-motd
|
||||
# generate system information
|
||||
|
||||
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
|
||||
THIS_SCRIPT="sysinfo"
|
||||
MOTD_DISABLE=""
|
||||
STORAGE=/dev/sda1
|
||||
SHOW_IP_PATTERN="^bond.*|^[ewr].*|^br.*|^lt.*|^umts.*|^lan.*"
|
||||
|
||||
CPU_TEMP_LIMIT=60
|
||||
HDD_TEMP_LIMIT=60
|
||||
AMB_TEMP_LIMIT=40
|
||||
|
||||
[[ -f /etc/default/armbian-motd ]] && . /etc/default/armbian-motd
|
||||
|
||||
for f in $MOTD_DISABLE; do
|
||||
[[ $f == $THIS_SCRIPT ]] && exit 0
|
||||
done
|
||||
|
||||
# don't edit below here
|
||||
|
||||
function display() {
|
||||
# $1=name $2=value $3=red_limit $4=minimal_show_limit $5=unit $6=after $7=acs/desc{
|
||||
# battery red color is opposite, lower number
|
||||
if [[ "$1" == "Battery" ]]; then local great="<"; else local great=">"; fi
|
||||
if [[ -n "$2" && "$2" > "0" && (( "${2%.*}" -ge "$4" )) ]]; then
|
||||
printf "%-14s%s" "$1:"
|
||||
if awk "BEGIN{exit ! ($2 $great $3)}"; then echo -ne "\e[0;91m $2"; else echo -ne "\e[0;92m $2"; fi
|
||||
printf "%-1s%s\x1B[0m" "$5"
|
||||
printf "%-11s%s\t" "$6"
|
||||
return 1
|
||||
fi
|
||||
} # display
|
||||
|
||||
function getboardtemp() {
|
||||
if [ -f /etc/armbianmonitor/datasources/soctemp ]; then
|
||||
read raw_temp </etc/armbianmonitor/datasources/soctemp 2>/dev/null
|
||||
if [ ! -z $(echo "$raw_temp" | grep -o "^[1-9][0-9]*\.\?[0-9]*$") ] && (( $(echo "${raw_temp} < 200" |bc -l) )); then
|
||||
# Allwinner legacy kernels output degree C
|
||||
board_temp=${raw_temp}
|
||||
else
|
||||
board_temp=$(awk '{printf("%d",$1/1000)}' <<<${raw_temp})
|
||||
fi
|
||||
elif [ -f /etc/armbianmonitor/datasources/pmictemp ]; then
|
||||
# fallback to PMIC temperature
|
||||
board_temp=$(awk '{printf("%d",$1/1000)}' </etc/armbianmonitor/datasources/pmictemp)
|
||||
fi
|
||||
} # getboardtemp
|
||||
|
||||
function batteryinfo() {
|
||||
# Battery info for Allwinner
|
||||
mainline_dir="/sys/power/axp_pmu"
|
||||
legacy_dir="/sys/class/power_supply"
|
||||
if [[ -e "$mainline_dir" ]]; then
|
||||
read status_battery_connected < $mainline_dir/battery/connected 2>/dev/null
|
||||
if [[ "$status_battery_connected" == "1" ]]; then
|
||||
read status_battery_charging < $mainline_dir/charger/charging
|
||||
read status_ac_connect < $mainline_dir/ac/connected
|
||||
read battery_percent< $mainline_dir/battery/capacity
|
||||
# dispay charging / percentage
|
||||
if [[ "$status_ac_connect" == "1" && "$battery_percent" -lt "100" ]]; then
|
||||
status_battery_text=" charging"
|
||||
elif [[ "$status_ac_connect" == "1" && "$battery_percent" -eq "100" ]]; then
|
||||
status_battery_text=" charged"
|
||||
else
|
||||
status_battery_text=" discharging"
|
||||
fi
|
||||
fi
|
||||
elif [[ -e "$legacy_dir/axp813-ac" ]]; then
|
||||
read status_battery_connected < $legacy_dir/axp20x-battery/present
|
||||
if [[ "$status_battery_connected" == "1" ]]; then
|
||||
status_battery_text=" "$(awk '{print tolower($0)}' < $legacy_dir/axp20x-battery/status)
|
||||
read status_ac_connect < $legacy_dir/axp813-ac/present
|
||||
read battery_percent< $legacy_dir/axp20x-battery/capacity
|
||||
fi
|
||||
elif [[ -e "$legacy_dir/battery" ]]; then
|
||||
if [[ (("$(cat $legacy_dir/battery/voltage_now)" -gt "5" )) ]]; then
|
||||
status_battery_text=" "$(awk '{print tolower($0)}' < $legacy_dir/battery/status)
|
||||
read battery_percent <$legacy_dir/battery/capacity
|
||||
fi
|
||||
fi
|
||||
} # batteryinfo
|
||||
|
||||
function ambienttemp() {
|
||||
# define where w1 usually shows up
|
||||
W1_DIR="/sys/devices/w1_bus_master1/"
|
||||
if [ -f /etc/armbianmonitor/datasources/ambienttemp ]; then
|
||||
read raw_temp </etc/armbianmonitor/datasources/ambienttemp 2>/dev/null
|
||||
amb_temp=$(awk '{printf("%d",$1/1000)}' <<<${raw_temp})
|
||||
echo $amb_temp
|
||||
elif [[ -d $W1_DIR && $ONE_WIRE == yes ]]; then
|
||||
device=$(ls -1 $W1_DIR | grep -Eo '^[0-9]{1,4}' | head -1)
|
||||
if [[ -n $device ]]; then
|
||||
if [[ -d ${W1_DIR}${device}/hwmon/hwmon0 ]]; then hwmon=0; else hwmon=1; fi
|
||||
read raw_temp < ${W1_DIR}${device}/hwmon/hwmon${hwmon}/temp1_input 2>/dev/null
|
||||
amb_temp=$(awk '{printf("%d",$1/1000)}' <<<${raw_temp})
|
||||
echo $amb_temp
|
||||
fi
|
||||
else
|
||||
# read ambient temperature from USB device if available
|
||||
if [[ ! -f /usr/bin/temper ]]; then
|
||||
echo ""
|
||||
return
|
||||
fi
|
||||
amb_temp=$(temper -c 2>/dev/null)
|
||||
case ${amb_temp} in
|
||||
*"find the USB device"*)
|
||||
echo ""
|
||||
;;
|
||||
*)
|
||||
amb_temp=$(awk '{print $NF}' <<<$amb_temp | sed 's/C//g')
|
||||
echo -n "scale=1;${amb_temp}/1" | grep -oE "\-?[[:digit:]]+\.[[:digit:]]"
|
||||
esac
|
||||
fi
|
||||
} # ambienttemp
|
||||
|
||||
function get_ip_addresses() {
|
||||
local ips=()
|
||||
for f in /sys/class/net/*; do
|
||||
local intf=$(basename $f)
|
||||
# match only interface names starting with e (Ethernet), br (bridge), w (wireless), r (some Ralink drivers use ra<number> format)
|
||||
if [[ $intf =~ $SHOW_IP_PATTERN ]]; then
|
||||
local tmp=$(ip -4 addr show dev $intf | awk '/inet/ {print $2}' | cut -d'/' -f1)
|
||||
# add both name and IP - can be informative but becomes ugly with long persistent/predictable device names
|
||||
#[[ -n $tmp ]] && ips+=("$intf: $tmp")
|
||||
# add IP only
|
||||
[[ -n $tmp ]] && ips+=("$tmp")
|
||||
fi
|
||||
done
|
||||
echo "${ips[@]}"
|
||||
} # get_ip_addresses
|
||||
|
||||
function storage_info() {
|
||||
# storage info
|
||||
RootInfo=$(df -h /)
|
||||
root_usage=$(awk '/\// {print $(NF-1)}' <<<${RootInfo} | sed 's/%//g')
|
||||
root_total=$(awk '/\// {print $(NF-4)}' <<<${RootInfo})
|
||||
StorageInfo=$(df -h $STORAGE 2>/dev/null | grep $STORAGE)
|
||||
if [[ -n "${StorageInfo}" && ${RootInfo} != *$STORAGE* ]]; then
|
||||
storage_usage=$(awk '/\// {print $(NF-1)}' <<<${StorageInfo} | sed 's/%//g')
|
||||
storage_total=$(awk '/\// {print $(NF-4)}' <<<${StorageInfo})
|
||||
if [[ -n "$(command -v smartctl)" ]]; then
|
||||
DISK="${STORAGE::-1}"
|
||||
storage_temp+=$(sudo smartctl -A $DISK 2> /dev/null | grep -i temperature | awk '{print $(NF-2)}')
|
||||
fi
|
||||
fi
|
||||
} # storage_info
|
||||
|
||||
|
||||
|
||||
# query various systems and send some stuff to the background for overall faster execution.
|
||||
# Works only with ambienttemp and batteryinfo since A20 is slow enough :)
|
||||
amb_temp=$(ambienttemp &)
|
||||
ip_address=$(get_ip_addresses &)
|
||||
batteryinfo
|
||||
storage_info
|
||||
getboardtemp
|
||||
critical_load=80
|
||||
|
||||
# get uptime, logged in users and load in one take
|
||||
UPTIME=$(LC_ALL=C uptime)
|
||||
UPT1=${UPTIME#*'up '}
|
||||
UPT2=${UPT1%'user'*}
|
||||
users=${UPT2//*','}
|
||||
users=${users//' '}
|
||||
time=${UPT2%','*}
|
||||
time=${time//','}
|
||||
time=$(echo $time | xargs)
|
||||
load=${UPTIME#*'load average: '}
|
||||
load=${load//','}
|
||||
load=$(echo $load | cut -d" " -f1)
|
||||
[[ $load == 0.0* ]] && load=0.10
|
||||
cpucount=$(grep -c processor /proc/cpuinfo)
|
||||
|
||||
load=$(awk '{printf("%.0f",($1/$2) * 100)}' <<< "$load $cpucount")
|
||||
|
||||
# memory and swap
|
||||
mem_info=$(LC_ALL=C free -w 2>/dev/null | grep "^Mem" || LC_ALL=C free | grep "^Mem")
|
||||
memory_usage=$(awk '{printf("%.0f",(($2-($4+$6+$7))/$2) * 100)}' <<<${mem_info})
|
||||
mem_info=$(echo $mem_info | awk '{print $2}')
|
||||
memory_total=$(( mem_info / 1024 ))
|
||||
swap_info=$(LC_ALL=C free -m | grep "^Swap")
|
||||
swap_usage=$( (awk '/Swap/ { printf("%3.0f", $3/$2*100) }' <<<${swap_info} 2>/dev/null || echo 0) | tr -c -d '[:digit:]')
|
||||
swap_total=$(awk '{print $(2)}' <<<${swap_info})
|
||||
if [[ ${memory_total} -gt 1000 ]]; then
|
||||
memory_total=$(awk '{printf("%.2f",$1/1024)}' <<<${memory_total})"G"
|
||||
else
|
||||
memory_total+="M"
|
||||
fi
|
||||
|
||||
if [[ ${swap_total} -gt 500 ]]; then
|
||||
swap_total=$(awk '{printf("%.2f",$1/1024)}' <<<${swap_total})"G"
|
||||
else
|
||||
swap_total+="M"
|
||||
fi
|
||||
|
||||
70
armbian/opt/vcgencmd
Normal file
70
armbian/opt/vcgencmd
Normal file
@@ -0,0 +1,70 @@
|
||||
#!/bin/bash
|
||||
cd `dirname $0`
|
||||
source armbian-sysinfo
|
||||
|
||||
case $1 in
|
||||
get_throttled) echo "throttled=0x0";;
|
||||
# measure_temp) echo "temp=$board_temp'C";;
|
||||
get_config)
|
||||
case $2 in
|
||||
total_mem)
|
||||
NUM=$( free -m | grep Mem: | awk '{print $2}' )
|
||||
if [ -e /var/log/dmesg ]; then
|
||||
KB=$( sudo grep 'Memory:' /var/log/dmesg | awk '{print $5}' | cut -d'/' -f2 | sed 's/K//g' | head -1 )
|
||||
else
|
||||
KB=""
|
||||
fi
|
||||
|
||||
if [[ "$KB" == "" ]]; then
|
||||
GB=`echo "( $NUM + 256 ) / 256" | bc`
|
||||
MB=$( echo "${GB} * 256" | bc )
|
||||
else
|
||||
GB=$( echo "($KB + 2048) / 1024 / 256" | bc )
|
||||
MB=$( echo "${GB} * 256" | bc )
|
||||
fi
|
||||
echo "total_mem=$MB"
|
||||
;;
|
||||
*)
|
||||
echo "invalid option";;
|
||||
esac
|
||||
;;
|
||||
measure_clock)
|
||||
case ${2} in
|
||||
arm)
|
||||
# awk is probably overkill....
|
||||
value=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq | awk '{print $1 * 1000}'`
|
||||
echo 'frequency(45)='${value}
|
||||
exit
|
||||
;;
|
||||
core)
|
||||
value=0 # TODO / FIXME
|
||||
echo 'frequency(1)='${value}
|
||||
exit
|
||||
;;
|
||||
# TODO anything else thrown an error/debug
|
||||
esac
|
||||
exit
|
||||
;;
|
||||
measure_temp)
|
||||
# awk is probably overkill....
|
||||
value=`cat /sys/class/thermal/thermal_zone0/temp | awk '{print $1 / 1000}'`
|
||||
echo 'temp='${value}"'C"
|
||||
exit
|
||||
;;
|
||||
measure_volts)
|
||||
case ${2} in
|
||||
core)
|
||||
value=1 # TODO / FIXME
|
||||
echo 'volt='${value}'.0000V'
|
||||
exit
|
||||
;;
|
||||
# TODO anything else thrown an error/debug
|
||||
esac
|
||||
;;
|
||||
version)
|
||||
echo 'Nov 4 2018 16:31:07'
|
||||
echo 'Copyright (c) 2012 rock64'
|
||||
echo 'version rock64_TODO (clean) (release)'
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
6
armbian/udev/rules.d/99-kvmd.rules
Normal file
6
armbian/udev/rules.d/99-kvmd.rules
Normal file
@@ -0,0 +1,6 @@
|
||||
# https://unix.stackexchange.com/questions/66901/how-to-bind-usb-device-under-a-static-name
|
||||
# https://wiki.archlinux.org/index.php/Udev#Setting_static_device_names
|
||||
KERNEL=="video[1-9]*", SUBSYSTEM=="video4linux", PROGRAM="/usr/bin/kvmd-udev-hdmiusb-check rpi4 1-1.4:1.0", ATTR{index}=="0", GROUP="kvmd", SYMLINK+="kvmd-video"
|
||||
KERNEL=="hidg0", GROUP="kvmd", SYMLINK+="kvmd-hid-keyboard"
|
||||
KERNEL=="hidg1", GROUP="kvmd", SYMLINK+="kvmd-hid-mouse"
|
||||
KERNEL=="hidg2", GROUP="kvmd", SYMLINK+="kvmd-hid-mouse-alt"
|
||||
Reference in New Issue
Block a user