Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
aa53b3ed7a
9
scripts/update-motd.d/10-header
Normal file
9
scripts/update-motd.d/10-header
Normal file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
clear
|
||||
DISTROID=$(lsb_release -s -i)
|
||||
DISTROCODE=$(lsb_release -s -c)
|
||||
KERNELID=$(uname -r)
|
||||
toilet -f standard -F metal $(hostname)
|
||||
echo -e "Welcome to \e[0;91mARMBIAN\x1B[0m ($DISTROID $DISTROCODE $KERNELID)"
|
||||
echo ""
|
||||
|
||||
168
scripts/update-motd.d/30-sysinfo
Normal file
168
scripts/update-motd.d/30-sysinfo
Normal file
@ -0,0 +1,168 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# 10-sysinfo - generate the system information
|
||||
# Copyright (c) 2015 Igor Pecovnik
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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.
|
||||
|
||||
storage=/dev/sda1
|
||||
|
||||
function displaytime {
|
||||
local T=$(cat /proc/uptime | awk '{print $1}' | sed 's/[.].*//')
|
||||
local D=$((T/60/60/24))
|
||||
local H=$((T/60/60%24))
|
||||
local M=$((T/60%60))
|
||||
local S=$((T%60))
|
||||
local time=$S
|
||||
time=$S" sec"
|
||||
(( $M > 0 )) && time=$M" min"
|
||||
(( $H > 0 )) && time=$H" hour"
|
||||
(( $H > 1 )) && time=$H" hours"
|
||||
(( $D > 0 )) && time=$D" day"
|
||||
(( $D > 1 )) && time=$D" days"
|
||||
#printf "Up time: \x1B[92m\t\t%s\t\x1B[0m" "$time"
|
||||
printf "%-13s%s" "Up time:"
|
||||
printf "\x1B[92m%-10s\x1B[0m\t\t" " $time"
|
||||
}
|
||||
|
||||
function display()
|
||||
# $1=name $2=value $3=red_limit $4=minimal_show_limit $5=unit $6=after
|
||||
{
|
||||
if [[ -n "$2" && "$2" > "0" && (( "${2%.*}" -ge "$4" )) ]]; then
|
||||
printf "%-14s%s" "$1:"
|
||||
if (( $(echo "$2 > $3" | bc -l) )); 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
|
||||
}
|
||||
|
||||
|
||||
if [[ "$UID" == 0 ]]; then
|
||||
|
||||
|
||||
|
||||
# Battery info for Allwinner
|
||||
HARDWARE=$(cat /proc/cpuinfo | grep Hardware | awk '{print $3}')
|
||||
# for root users which have acces to hw and allwinner and old kernel
|
||||
if [[ "$UID" == 0 && ($HARDWARE = "sun7i" || $HARDWARE = "Allwinner") ]]; then
|
||||
if [ "$(printf '0x%X' $(($(i2cget -y -f 0 0x34 0x82) & 0xC3)))" != "0xC3" ]; then
|
||||
i2cset -y -f 0 0x34 0x82 0xC3
|
||||
fi
|
||||
POWER_OP_MODE=$(i2cget -y -f 0 0x34 0x01) # read power OPERATING MODE register @01h
|
||||
BAT_EXIST=$(($(($POWER_OP_MODE&0x20))/32)) # divide by 32 is like shifting rigth 5 times
|
||||
CHARG_IND=$(($(($POWER_OP_MODE&0x40))/64)) # divide by 64 is like shifting rigth 6 times
|
||||
|
||||
if [ "$BAT_EXIST" == "1" ]; then
|
||||
#read battery voltage 79h, 78h 0 mV -> 000h, 1.1 mV/bit FFFh -> 4.5045 V
|
||||
BAT_VOLT_LSB=$(i2cget -y -f 0 0x34 0x79)
|
||||
BAT_VOLT_MSB=$(i2cget -y -f 0 0x34 0x78)
|
||||
|
||||
BAT_BIN=$(( $(($BAT_VOLT_MSB << 4)) | $(($(($BAT_VOLT_LSB & 0xF0)) >> 4)) ))
|
||||
BAT_VOLT=$(echo "($BAT_BIN*1.1)"|bc)
|
||||
|
||||
# store maximum battery voltage to compare to
|
||||
if [ -f "/etc/default/battery" ]; then
|
||||
source "/etc/default/battery"
|
||||
else
|
||||
echo "MAX=$BAT_VOLT" > /etc/default/battery
|
||||
echo "MIN=3484" >> /etc/default/battery
|
||||
source "/etc/default/battery"
|
||||
fi
|
||||
# integer is enough, cut down the decimals
|
||||
|
||||
BAT_VOLT=${BAT_VOLT%.*}
|
||||
MAX=${MAX%.*}
|
||||
# if we have new max value, alter defaults
|
||||
if [[ "$CHARG_IND" == "0" && "$BAT_VOLT" -gt "$MAX" ]]; then
|
||||
MAX=$BAT_VOLT
|
||||
sed -e 's/MAX=.*/MAX='$BAT_VOLT'/g' -i /etc/default/battery
|
||||
fi
|
||||
|
||||
# if we have new min value, alter defaults
|
||||
if [ "$BAT_VOLT" -lt "$MIN" ]; then
|
||||
MIN=$BAT_VOLT
|
||||
#sed -e 's/MIN=.*/MIN='$BAT_VOLT'/g' -i /etc/default/battery
|
||||
fi
|
||||
|
||||
# calculate percentage
|
||||
batt_percent=$(echo "($BAT_VOLT-$MIN)*100/($MAX-$MIN)"|bc)
|
||||
|
||||
|
||||
# dispay charging / percentage
|
||||
if [[ "$CHARG_IND" == "1" && "$batt_percent" == "100" ]]; then
|
||||
batt_status=" charged"
|
||||
elif [ "$CHARG_IND" == "1" ]; then
|
||||
batt_status=" charging"
|
||||
else
|
||||
batt_status=" discharging"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
load=$(cat /proc/loadavg | awk '{print $1}')
|
||||
memory_usage=$(free | awk '/Mem/ {printf("%.0f",(($2-($4+$6+$7))/$2) * 100)}')
|
||||
memory_total=$(free -m | awk '/Mem/ {print $(2)}')
|
||||
users=$(users | wc -w)
|
||||
swap_total=$(free -m | awk '/Swap/ { printf("%3.0f", $3/$2*100) }' | sed 's/ //g')
|
||||
swap_usage=${swap_usage//[!0-9]/} # to remove alfanumeric if swap not used
|
||||
swap_total=$(free -m | awk '/Swap/ {print $(2)}')
|
||||
ip_address=$(ifconfig eth0 | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p')
|
||||
|
||||
root_usage=$(df -h / | awk '/\// {print $(NF-1)}' | sed 's/%//g')
|
||||
root_total=$(df -h / | awk '/\// {print $(NF-4)}')
|
||||
storage_usage=$(df -h $storage | awk '/\// {print $(NF-1)}' | sed 's/%//g')
|
||||
storage_total=$(df -h $storage | awk '/\// {print $(NF-4)}')
|
||||
hdd_temp=$(hddtemp -u C -nq /dev/sda)
|
||||
|
||||
# read temperature from two different locations
|
||||
if [ -d "/sys/devices/virtual/thermal/thermal_zone0/" ]; then
|
||||
board_temp=$(cat /sys/devices/virtual/thermal/thermal_zone0/temp | awk '{printf("%d",$1/1000)}')
|
||||
fi
|
||||
if [[ -d "/sys/devices/virtual/thermal/thermal_zone1/" && $board_temp == "0" ]]; then
|
||||
board_temp=$(cat /sys/devices/virtual/thermal/thermal_zone1/temp | awk '{printf("%d",$1/1000)}')
|
||||
fi
|
||||
|
||||
# read ambient temperature from USB device
|
||||
if which temper >/dev/null; then
|
||||
TEMPER=$(temper -c)
|
||||
if echo $TEMPER | egrep -qv "Couldn't find the USB device"; then
|
||||
TEMPER=$(echo "scale=1;${TEMPER}/1" | bc)
|
||||
TEMPER="- Ambient: ${TEMPER}"
|
||||
else
|
||||
TEMPER=""
|
||||
fi
|
||||
fi
|
||||
|
||||
display "System load" "$load" "1" "0" "" ""
|
||||
displaytime
|
||||
display "Local users" "$users" "3" "2" ""
|
||||
echo "" # fixed newline
|
||||
display "Memory usage" "$memory_usage" "10" "0" " %" " of $memory_total""Mb"
|
||||
display "Swap usage" "$swap_usage" "10" "0" " %" " of $swap_total""Mb"
|
||||
echo "" # fixed newline
|
||||
a=0;b=0;c=0
|
||||
display "Board temp" "$board_temp" "10" "0" "°C" "" ; a=$?
|
||||
display "HDD temp" "$hdd_temp" "40" "0" "°C" "" ; b=$?
|
||||
display "Ambient temp" "$amb_temp" "40" "0" "°C" "" ; c=$?
|
||||
(( ($a+$b+$c) >0 )) && echo "" # new line only if some value is displayed
|
||||
a=0;b=0;c=0
|
||||
display "Battery" "$batt_percent" "100" "1" "%" "$batt_status" ; a=$?
|
||||
(( ($a+$b+$c) >0 )) && echo "" # new line only if some value is displayed
|
||||
|
||||
display "Usage of /" "$root_usage" "90" "1" "%" " of $root_total"
|
||||
display "storage/" "$storage_usage" "90" "1" "%" " of $storage_total"
|
||||
echo ""
|
||||
echo ""
|
||||
116
scripts/update-motd.d/40-updates
Normal file
116
scripts/update-motd.d/40-updates
Normal file
@ -0,0 +1,116 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# 20-updates - create the system updates section of the MOTD
|
||||
# Copyright (c) 2013 Nick Charlton
|
||||
#
|
||||
# Authors: Nick Charlton <hello@nickcharlton.net>
|
||||
# Based upon prior work by Dustin Kirkland and Michael Vogt.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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.
|
||||
|
||||
import sys
|
||||
import subprocess
|
||||
import apt_pkg
|
||||
|
||||
DISTRO = subprocess.Popen(["lsb_release", "-c", "-s"],
|
||||
stdout=subprocess.PIPE).communicate()[0].strip()
|
||||
|
||||
class OpNullProgress(object):
|
||||
'''apt progress handler which supresses any output.'''
|
||||
def update(self):
|
||||
pass
|
||||
def done(self):
|
||||
pass
|
||||
|
||||
def is_security_upgrade(pkg):
|
||||
'''
|
||||
Checks to see if a package comes from a DISTRO-security source.
|
||||
'''
|
||||
security_package_sources = [("Ubuntu", "%s-security" % DISTRO),
|
||||
("Debian", "%s-security" % DISTRO)]
|
||||
|
||||
for (file, index) in pkg.file_list:
|
||||
for origin, archive in security_package_sources:
|
||||
if (file.archive == archive and file.origin == origin):
|
||||
return True
|
||||
return False
|
||||
|
||||
# init apt and config
|
||||
apt_pkg.init()
|
||||
|
||||
# open the apt cache
|
||||
try:
|
||||
cache = apt_pkg.Cache(OpNullProgress())
|
||||
except SystemError, e:
|
||||
sys.stderr.write("Error: Opening the cache (%s)" % e)
|
||||
sys.exit(-1)
|
||||
|
||||
# setup a DepCache instance to interact with the repo
|
||||
depcache = apt_pkg.DepCache(cache)
|
||||
|
||||
# take into account apt policies
|
||||
depcache.read_pinfile()
|
||||
|
||||
# initialise it
|
||||
depcache.init()
|
||||
|
||||
# give up if packages are broken
|
||||
if depcache.broken_count > 0:
|
||||
sys.stderr.write("Error: Broken packages exist.")
|
||||
sys.exit(-1)
|
||||
|
||||
# mark possible packages
|
||||
try:
|
||||
# run distro-upgrade
|
||||
depcache.upgrade(True)
|
||||
# reset if packages get marked as deleted -> we don't want to break anything
|
||||
if depcache.del_count > 0:
|
||||
depcache.init()
|
||||
|
||||
# then a standard upgrade
|
||||
depcache.upgrade()
|
||||
except SystemError, e:
|
||||
sys.stderr.write("Error: Couldn't mark the upgrade (%s)" % e)
|
||||
sys.exit(-1)
|
||||
|
||||
# run around the packages
|
||||
upgrades = 0
|
||||
security_upgrades = 0
|
||||
for pkg in cache.packages:
|
||||
candidate = depcache.get_candidate_ver(pkg)
|
||||
current = pkg.current_ver
|
||||
|
||||
# skip packages not marked as upgraded/installed
|
||||
if not (depcache.marked_install(pkg) or depcache.marked_upgrade(pkg)):
|
||||
continue
|
||||
|
||||
# increment the upgrade counter
|
||||
upgrades += 1
|
||||
|
||||
# keep another count for security upgrades
|
||||
if is_security_upgrade(candidate):
|
||||
security_upgrades += 1
|
||||
|
||||
# double check for security upgrades masked by another package
|
||||
for version in pkg.version_list:
|
||||
if (current and apt_pkg.version_compare(version.ver_str, current.ver_str) <= 0):
|
||||
continue
|
||||
if is_security_upgrade(version):
|
||||
security_upgrades += 1
|
||||
break
|
||||
if upgrades > 0:
|
||||
print "[ \033[92m%d updates to install\033[0m: apt-get upgrade ]" % (upgrades)
|
||||
print ""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user