151

(206 odpowiedzi, napisanych Oprogramowanie / Software)

@build000 a co i z kąd miałoby się pokazywać apropo dhcp?

152

(206 odpowiedzi, napisanych Oprogramowanie / Software)

@build dhcp dla lan w konfiguracji masz wyłączone stąd sysinfo.sh wyswietla n/a.
Błędy w logu są więc się wyświetlają.
Kolejna wersja skryptu :

#!/bin/sh
#
# sysinfo.sh dla OpenWRT AA Cezary Jackiewicz 2013
# 
#    1.00    CJ    Pierwsza wersja kodu
#    1.01    RD    Drobna przebudowa
#    1.02    RD    Korekta b³êdu wyœw. zajetoœci Flash-a, dodanie kolorów
#    1.03    RD    Dodanie nazwy routera, zmiana formatowania
#    1.04    RD    Kosmetyka, sugestie @mikhnal. Zmiana przetwarzania info. o wan.
#    1.05    RD    Zmiana algorytmu pobierania danych dla wan i lan
#    1.06    RD    Parametryzacja kolorów i pojawiania siê podkreœleñ
#    1.07    RD    Modyfikacja zwi¹zana z poprawnym wyœwietlaniem interfejsu dla prot.3g
#    1.08    RD    Modyfikacja wyœwietlania DNS-ów dla wan, dodanie uptime dla interfejsów
#    1.09    RD    Dodanie statusu "Down" dla wy³¹czonego wifi, zmiana wyœwietlania dla WLAN(sta)
#    1.10    RD    Korekta wyœwietlania dla WLAN(sta)
#    1.11    RD    Korekta wyœwietlania stanu pamiêci, sugestie @dopsz 
#    1.12    RD    Zmiana kolejnoœci wyœwietlania wartoœci stanu pamiêci + kosmetyka 
#    1.13    RD    Dodanie info o dhcp w LAN, zmiana sposobu wyœwietlania informacji o LAN
#    1.14    RD    Dodanie informacji o ostatnich 5 b³êdach
#    1.15    RD    Zmiana stderr
#    1.16    RD    Dodanie wyœwietlania informacji o swap
#    1.17    RD    Zmiana wyliczania informacji o flash
#    1.18    RD    Zmiana wyœwietlania informacji o flash
#    1.19    RD    Zmiana wyœwietlania informacji o sprzêcie
#
# Destination /sbin/sysinfo.sh
#
. /usr/share/libubox/jshn.sh

local Width=60
local StartRuler="1"
local EndRuler="1"
local LastErrors="1"
local NormalColor=""
local MachineColor=""
local ValueColor=""
local AddrColor=""
local RXTXColor=""
local ErrorColor=""
local ExtraName=""
local ExtraValue=""

initialize() { # <Script Parameters>
    local ColorMode="c"
    while [ -n "$1" ]; do
        case "$1" in
        -h|--help)    echo -e    "Usage: $0 [-h|--help] [[-m|--mono]|[-bw|-black-white]|[-c2|--color-2]] [-sr|--no-start-ruler] [-er|--no-end-ruler]"\
                            "[-w N|--width N] [-en Name|--extra-name Name] [-ev Value|--extra-value Value] [-le|--no-last-err]"\
                            "\n\t-h\t\tThis help,"\
                            "\n\t-m\t\tDisplay mono version,"\
                            "\n\t-bw\t\tDisplay black-white version,"\
                            "\n\t-c2\t\tDisplay alternative color version 2,"\
                            "\n\t-sr\t\tWithout start horizontal ruler,"\
                            "\n\t-er\t\tWithout end horizontal ruler,"\
                            "\n\t-w N\t\tSet width of text area to N characters (minimum 60)"\
                            "\n\t-en Name\tPrint extra name"\
                            "\n\t-ev Value\tPrint extra value"\
                            "\n\t-le\t\tDon't display last errors"
                    exit 1;;
        -m|--mono) ColorMode="m";;
        -bw|--black-white) ColorMode="bw";;
        -c2|--color-2) ColorMode="c2";;
        -sr|--no-start-ruler) StartRuler="0";;
        -er|--no-end-ruler) EndRuler="0";;
        -w|--width) shift; Width=$1;;
        -en|--extra-name)    while [ -n "$2" ] && [ "${2:0:1}" != "-" ]; do
                                shift
                                [ "$ExtraName" != "" ] && ExtraName="$ExtraName "
                                ExtraName="$ExtraName$1"
                            done;;
        -ev|--extra-value)    while [ -n "$2" ] && [ "${2:0:1}" != "-" ]; do
                                shift
                                [ "$ExtraValue" != "" ] && ExtraValue="$ExtraValue "
                                ExtraValue="$ExtraValue$1"
                            done;;
        -le|--no-last-err)    LastErrors="0";;
        *) echo "Invalid option: $1. Use -h for help";;
        esac
        shift;
    done
    case "$ColorMode" in
        c)    NormalColor="\e[0m"
            MachineColor="\e[0;33m"
            ValueColor="\e[1;36m"
            AddrColor="\e[1;31m"
            RXTXColor="\e[2;32m"
            ErrorColor="\e[0;31m";;
        c2)    NormalColor="\e[0m"
            MachineColor="\e[0;31m"
            ValueColor="\e[0;33m"
            AddrColor="\e[0;35m"
            RXTXColor="\e[0;36m"
            ErrorColor="\e[0;31m";;
        m)    NormalColor="\e[0m"
            MachineColor="\e[7m"
            ValueColor="\e[1m"
            AddrColor="\e[4m"
            RXTXColor="\e[1m"
            ErrorColor="\e[4";;
        *)    ;;
    esac
    ([ "$Width" == "" ] || [ "$Width" -lt 60 ]) && Width=60
}

human_readable() { # <Number of bytes>
    if [ $1 -gt 0 ]; then
        printf "$(awk -v n=$1 'BEGIN{for(i=split("B KB MB GB TB PB",suffix);s<1;i--)s=n/(2**(10*i));printf (int(s)==s)?"%.0f%s":"%.1f%s",s,suffix[i+2]}' 2>/dev/null)"
    else
        printf "0B"
    fi
}

device_rx_tx() { # <Device>
    local RXTX=$(awk -v Device=$1 '$1==Device ":"{printf "%.0f\t%.0f",$2,$10}' /proc/net/dev 2>/dev/null)
    [ "$RXTX" != "" ] && printf ", rx/tx: $RXTXColor$(human_readable $(echo "$RXTX" | cut -f 1))$NormalColor/$RXTXColor$(human_readable $(echo "$RXTX" | cut -f 2))$NormalColor"
}

uptime_str() { # <Time in Seconds>
    local Uptime=$1
    if [ $Uptime -gt 0 ]; then
        local Days=$(expr $Uptime / 60 / 60 / 24)
        local Hours=$(expr $Uptime / 60 / 60 % 24)
        local Minutes=$(expr $Uptime / 60 % 60)
        local Seconds=$(expr $Uptime % 60)
        if [ $Days -gt 0 ]; then
            Days=$(printf "%dd " $Days)
        else
            Days=""
        fi 2>/dev/null
        printf "$Days%02d:%02d:%02d" $Hours $Minutes $Seconds
    fi
}

print_line() { # <String to Print>, [[<String to Print>] ...]
    local Line="$@"
    printf " | %-${Width}s |\r | $Line\n" 2>/dev/null
}

print_horizontal_ruler() {
    printf "/%$(expr $Width + 4 )s\n" | tr ' /' '- ' 2>/dev/null
}

print_machine() {
    local Machine=""
    local HostName=$(uci -q get system.@system[0].hostname)
    if [ -e /tmp/sysinfo/model ]; then
        Machine=$(cat /tmp/sysinfo/model 2>/dev/null)
    elif [ -e /proc/cpuinfo ]; then
        Machine=$(awk 'BEGIN{FS="[ \t]+:[ \t]"} /machine/ {print $2}' /proc/cpuinfo 2>/dev/null)
    fi
    print_line     "Machine: $MachineColor${Machine:-n/a}$NormalColor,"\
                "Name: $MachineColor${HostName:-n/a}$NormalColor"
}

print_times() {
    local SysUptime=$(cut -d. -f1 /proc/uptime)
    local Uptime=$(uptime_str $SysUptime)
    local Now=$(date +'%Y-%m-%d %H:%M:%S')
    print_line     "System uptime: $ValueColor$Uptime$NormalColor,"\
                "Now: $ValueColor$Now$NormalColor"
}

print_loadavg() {
    local LoadAvg=$(awk '{printf"'$ValueColor'%s'$NormalColor', '$ValueColor'%s'$NormalColor', '$ValueColor'%s'$NormalColor'",$1,$2,$3}' /proc/loadavg 2>/dev/null)
    print_line "System load: $LoadAvg"
}

print_fs_summary() { # <Mount point> <Label>
    local DeviceInfo=$(df -k $1 2>/dev/null| awk 'BEGIN{Total=0;Free=0} NR>1 && $6=="'$1'"{Total=$2;Free=$4}END{Used=Total-Free;printf"%.0f\t%.0f\t%.1f\t%.0f",Total*1024,Used*1024,(Total>0)?((Used/Total)*100):0,Free*1024}' 2>/dev/null)
    local Total=$(echo "$DeviceInfo" | cut -f 1)
    local Used=$(echo "$DeviceInfo" | cut -f 2)
    local UsedPercent=$(echo "$DeviceInfo" | cut -f 3)
    local Free=$(echo "$DeviceInfo" | cut -f 4)
    [ "$Total" -gt 0 ] && print_line "$2:"\
                "total: $ValueColor$(human_readable $Total)$NormalColor,"\
                "used: $ValueColor$(human_readable $Used)$NormalColor, $ValueColor$UsedPercent$NormalColor%%,"\
                "free: $ValueColor$(human_readable $Free)$NormalColor"
}

print_disk() {
    local Overlay=$(awk '$3=="overlayfs"{print $2}' /proc/mounts 2>/dev/null)
    if [ "$Overlay" != "" ]; then
        print_fs_summary /overlay "Flash"        
    fi
    if [ "$Overlay" == "" ] || [ "$Overlay" != "/" ]; then
        print_fs_summary / "RootFS"
    fi
}

print_memory() {
    local Memory=$(awk 'BEGIN{Total=0;Free=0}$1~/^MemTotal:/{Total=$2}$1~/^MemFree:|^Buffers:|^Cached:/{Free+=$2}END{Used=Total-Free;printf"%.0f\t%.0f\t%.1f\t%.0f",Total*1024,Used*1024,(Total>0)?((Used/Total)*100):0,Free*1024}' /proc/meminfo 2>/dev/null)
    local Total=$(echo "$Memory" | cut -f 1)
    local Used=$(echo "$Memory" | cut -f 2)
    local UsedPercent=$(echo "$Memory" | cut -f 3)
    local Free=$(echo "$Memory" | cut -f 4)
    print_line "Memory:"\
                "total: $ValueColor$(human_readable $Total)$NormalColor,"\
                "used: $ValueColor$(human_readable $Used)$NormalColor, $ValueColor$UsedPercent$NormalColor%%,"\
                "free: $ValueColor$(human_readable $Free)$NormalColor"
}

print_swap() {
    local Swap=$(awk 'BEGIN{Total=0;Free=0}$1~/^SwapTotal:/{Total=$2}$1~/^SwapFree:/{Free=$2}END{Used=Total-Free;printf"%.0f\t%.0f\t%.1f\t%.0f",Total*1024,Used*1024,(Total>0)?((Used/Total)*100):0,Free*1024}' /proc/meminfo 2>/dev/null)
    local Total=$(echo "$Swap" | cut -f 1)
    local Used=$(echo "$Swap" | cut -f 2)
    local UsedPercent=$(echo "$Swap" | cut -f 3)
    local Free=$(echo "$Swap" | cut -f 4)
    [ "$Total" -gt 0 ] && print_line "Swap:"\
                "total: $ValueColor$(human_readable $Total)$NormalColor,"\
                "used: $ValueColor$(human_readable $Used)$NormalColor, $ValueColor$UsedPercent$NormalColor%%,"\
                "free: $ValueColor$(human_readable $Free)$NormalColor"
}

print_wan() {
    local Zone
    local Device
    for Zone in $(uci -q show firewall | grep .masq= | cut -f2 -d.); do
        if [ "$(uci -q get firewall.$Zone.masq)" == "1" ]; then
            for Device in $(uci -q get firewall.$Zone.network); do
                local Status="$(ubus call network.interface.$Device status 2>/dev/null)"
                if [ "$Status" != "" ]; then
                    local State=""
                    local Iface=""
                    local Uptime=""
                    local IP4=""
                    local IP6=""
                    local Subnet4=""
                    local Subnet6=""
                    local Gateway4=""
                    local Gateway6=""
                    local DNS=""
                    local Protocol=""
                    json_load "${Status:-{}}"
                    json_get_var State up
                    json_get_var Uptime uptime
                    json_get_var Iface l3_device
                    json_get_var Protocol proto
                    if json_get_type Status ipv4_address && [ "$Status" = array ]; then
                        json_select ipv4_address
                        json_get_type Status 1
                        if [ "$Status" = object ]; then
                            json_select 1
                            json_get_var IP4 address
                            json_get_var Subnet4 mask
                            [ "$IP4" != "" ] && [ "$Subnet4" != "" ] && IP4="$IP4/$Subnet4"
                        fi
                    fi
                    json_select
                    if json_get_type Status ipv6_address && [ "$Status" = array ]; then
                        json_select ipv6_address
                        json_get_type Status 1
                        if [ "$Status" = object ]; then
                            json_select 1
                            json_get_var IP6 address
                            json_get_var Subnet6 mask
                            [ "$IP6" != "" ] && [ "$Subnet6" != "" ] && IP6="$IP6/$Subnet6"
                        fi
                    fi
                    json_select
                    if json_get_type Status route && [ "$Status" = array ]; then
                        json_select route
                        local Index="1"
                        while json_get_type Status $Index && [ "$Status" = object ]; do
                            json_select "$((Index++))"
                            json_get_var Status target
                            case "$Status" in
                                0.0.0.0)
                                    json_get_var Gateway4 nexthop;;
                                ::)
                                    json_get_var Gateway6 nexthop;;
                            esac
                            json_select ".."
                        done    
                    fi
                    json_select
                    if json_get_type Status dns_server && [ "$Status" = array ]; then
                        json_select dns_server
                        local Index="1"
                        while json_get_type Status $Index && [ "$Status" = string ]; do
                            json_get_var Status "$((Index++))"
                            DNS="${DNS:+$DNS }$Status"
                        done
                    fi
                    if [ "$State" == "1" ]; then
                        [ "$IP4" != "" ] && print_line     "WAN: $AddrColor$IP4$NormalColor($Iface),"\
                                                        "gateway: $AddrColor${Gateway4:-n/a}$NormalColor"
                        [ "$IP6" != "" ] && print_line    "WAN: $AddrColor$IP6$NormalColor($Iface),"\
                                                        "gateway: $AddrColor${Gateway6:-n/a}$NormalColor"
                        print_line    "proto: $ValueColor${Protocol:-n/a}$NormalColor,"\
                                    "uptime: $ValueColor$(uptime_str $Uptime)$NormalColor$(device_rx_tx $Iface)"
                        [ "$DNS" != "" ] && print_line "dns: $AddrColor$DNS$NormalColor"
                    fi
                fi
            done
        fi 
    done
}

print_lan() {
    local Zone
    local Device
    for Zone in $(uci -q show firewall | grep []]=zone | cut -f2 -d. | cut -f1 -d=); do
        if [ "$(uci -q get firewall.$Zone.masq)" != "1" ]; then
            for Device in $(uci -q get firewall.$Zone.network); do
                local Status="$(ubus call network.interface.$Device status 2>/dev/null)"
                if [ "$Status" != "" ]; then
                    local State=""
                    local Iface=""
                    local IP4=""
                    local IP6=""
                    local Subnet4=""
                    local Subnet6=""
                    json_load "${Status:-{}}"
                    json_get_var State up
                    json_get_var Iface device
                    if json_get_type Status ipv4_address && [ "$Status" = array ]; then
                        json_select ipv4_address
                        json_get_type Status 1
                        if [ "$Status" = object ]; then
                            json_select 1
                            json_get_var IP4 address
                            json_get_var Subnet4 mask
                            [ "$IP4" != "" ] && [ "$Subnet4" != "" ] && IP4="$IP4/$Subnet4"
                        fi
                    fi
                    json_select
                    if json_get_type Status ipv6_address && [ "$Status" = array ]; then
                        json_select ipv6_address
                        json_get_type Status 1
                        if [ "$Status" = object ]; then
                            json_select 1
                            json_get_var IP6 address
                            json_get_var Subnet6 mask
                            [ "$IP6" != "" ] && [ "$Subnet6" != "" ] && IP6="$IP6/$Subnet6"
                        fi
                    fi
                    local DHCPConfig=$(uci -q show dhcp | grep .interface=$Device | cut -d. -f2)
                    if [ "$DHCPConfig" != "" ] && [ "$(uci -q get dhcp.$DHCPConfig.ignore)" != "1" ]; then
                        local DHCPStart=$(uci -q get dhcp.$DHCPConfig.start)
                        local DHCPLimit=$(uci -q get dhcp.$DHCPConfig.limit)
                        [ "$DHCPStart" != "" ] && [ "$DHCPLimit" != "" ] && DHCP="$(echo $IP4 | cut -d. -f1-3).$DHCPStart-$(expr $DHCPStart + $DHCPLimit - 1)"
                    fi
                    [ "$IP4" != "" ] && print_line "LAN: $AddrColor$IP4$NormalColor($Iface), dhcp: $AddrColor${DHCP:-n/a}$NormalColor"
                    [ "$IP6" != "" ] && print_line "LAN: $AddrColor$IP6$NormalColor($Iface)"
                fi
            done
        fi 
    done
}

print_wlan() {
    local Iface
    for Iface in $(uci -q show wireless | grep device=radio | cut -f2 -d.); do
        local Device=$(uci -q get wireless.$Iface.device)
        local SSID=$(uci -q get wireless.$Iface.ssid)
        local IfaceDisabled=$(uci -q get wireless.$Iface.disabled)
        local DeviceDisabled=$(uci -q get wireless.$Device.disabled)
        if [ -n "$SSID" ] && [ "$IfaceDisabled" != "1" ] && [ "$DeviceDisabled" != "1" ]; then
            local Mode=$(uci -q -P /var/state get wireless.$Iface.mode)
            local Channel=$(uci -q get wireless.$Device.channel)
            local RadioIface=$(uci -q -P /var/state get wireless.$Iface.ifname)
            local Connection="Down"
            if [ -n "$RadioIface" ]; then
                if [ "$Mode" == "ap" ]; then
                    Connection="$(iw dev $RadioIface station dump | grep Station | wc -l 2>/dev/null)"
                else
                    Connection="$(iw dev $RadioIface link | awk 'BEGIN{FS=": ";Signal="";Bitrate=""} $1~/signal/ {Signal=$2} $1~/tx bitrate/ {Bitrate=$2}END{print Signal" "Bitrate}' 2>/dev/null)"
                fi
            fi
            if [ "$Mode" == "ap" ]; then
                print_line    "WLAN: $ValueColor$SSID$NormalColor($Mode),"\
                            "ch: $ValueColor${Channel:-n/a}$NormalColor,"\
                            "conn: $ValueColor$Connection$NormalColor$(device_rx_tx $RadioIface)"
            else
                print_line    "WLAN: $ValueColor$SSID$NormalColor($Mode),"\
                            "ch: $ValueColor${Channel:-n/a}$NormalColor"
                print_line    "conn: $ValueColor$Connection$NormalColor$(device_rx_tx $RadioIface)"
            fi
        fi
    done
}

print_vpn() {
    local VPN
    for VPN in $(uci -q show openvpn | grep .ca= | cut -f2 -d.); do
        local Device=$(uci -q get openvpn.$VPN.dev)
        local Enabled=$(uci -q get openvpn.$VPN.enabled)
        if [ "$Enabled" == "1" ] || [ "$Enabled" == "" ]; then
            local Mode=$(uci -q get openvpn.$VPN.mode)
            local Connection="n/a"
            if [ "$Mode" == "server" ]; then
                Mode="$ValueColor$VPN$NormalColor(svr):$(uci -q get openvpn.$VPN.port)"
                Status=$(uci -q get openvpn.$VPN.status)
                Connection=$(awk 'BEGIN{FS=",";c=0;l=0}{if($1=="Common Name")l=1;else if($1=="ROUTING TABLE")exit;else if (l==1) c=c+1}END{print c}' $Status 2>/dev/null)
            else
                Mode="$ValueColor$VPN$NormalColor(cli)"
                Connection="Down"
                ifconfig $Device &>/dev/null && Connection="Up"
            fi
            print_line    "VPN: $Mode,"\
                        "conn: $ValueColor$Connection$NormalColor$(device_rx_tx $Device)"
        fi
    done
}

print_extra() {
    ([ "$ExtraName" != "" ] || [ "$ExtraValue" != "" ]) && print_line "$ExtraName $ValueColor$ExtraValue$NormalColor"
}

print_error() {
    logread | awk '/\w{3}+\.(err|warn|alert|emerg|crit)/{err[++i]=$0}END{j=i-4;j=j>=1?j:1;while(j<=i)print" '$ErrorColor'"err[j++]"'$NormalColor'"}' 2>/dev/null
}

initialize $@
[ "$StartRuler" == "1" ] && print_horizontal_ruler
print_machine
print_times
print_loadavg
print_disk
print_memory
print_swap
print_wan
print_lan
print_wlan
print_vpn
print_extra
[ "$EndRuler" == "1" ] && print_horizontal_ruler
[ "$LastErrors" == "1" ] && print_error
exit 0

153

(206 odpowiedzi, napisanych Oprogramowanie / Software)

Cezary napisał/a:

Nie ma /tmp/sysinfo/model smile Dla tej platformy jest to

MACH=$(awk -F: '/Hardware/ {print $2}' /proc/cpuinfo)

. Dla ramipsów - machine z /proc/cpuinfo.

A to ci.;-)  Uczę się cały czas pilnie i głupi umre:-D
Będzie kolejna wersja.

154

(206 odpowiedzi, napisanych Oprogramowanie / Software)

Pokaż sekcje lan z pliku /etc/config/dhcp i zawartość pliku /tmp/sysinfo/model.

155

(206 odpowiedzi, napisanych Oprogramowanie / Software)

Jeżeli chodzi o skrypt to ostatnia wersja nie powinna wyświetlać:

sh: 0: unknown operand

156

(206 odpowiedzi, napisanych Oprogramowanie / Software)

Nadal jest tak

sh: 0: unknown operand
sh: 0: unknown operand
sh: 0: unknown operand

?

157

(206 odpowiedzi, napisanych Oprogramowanie / Software)

No, to proszę nowa wersja skryptu:

#!/bin/sh
#
# sysinfo.sh dla OpenWRT AA Cezary Jackiewicz 2013
# 
#    1.00    CJ    Pierwsza wersja kodu
#    1.01    RD    Drobna przebudowa
#    1.02    RD    Korekta błędu wyśw. zajetości Flash-a, dodanie kolorów
#    1.03    RD    Dodanie nazwy routera, zmiana formatowania
#    1.04    RD    Kosmetyka, sugestie @mikhnal. Zmiana przetwarzania info. o wan.
#    1.05    RD    Zmiana algorytmu pobierania danych dla wan i lan
#    1.06    RD    Parametryzacja kolorów i pojawiania się podkreśleń
#    1.07    RD    Modyfikacja związana z poprawnym wyświetlaniem interfejsu dla prot.3g
#    1.08    RD    Modyfikacja wyświetlania DNS-ów dla wan, dodanie uptime dla interfejsów
#    1.09    RD    Dodanie statusu "Down" dla wyłączonego wifi, zmiana wyświetlania dla WLAN(sta)
#    1.10    RD    Korekta wyświetlania dla WLAN(sta)
#    1.11    RD    Korekta wyświetlania stanu pamięci, sugestie @dopsz 
#    1.12    RD    Zmiana kolejności wyświetlania wartości stanu pamięci + kosmetyka 
#    1.13    RD    Dodanie info o dhcp w LAN, zmiana sposobu wyświetlania informacji o LAN
#    1.14    RD    Dodanie informacji o ostatnich 5 błędach
#    1.15    RD    Zmiana stderr
#    1.16    RD    Dodanie wyświetlania informacji o swap
#    1.17    RD    Zmiana wyliczania informacji o flash
#    1.18    RD    Zmiana wyświetlania informacji o flash
#
# Destination /sbin/sysinfo.sh
#
. /usr/share/libubox/jshn.sh

local Width=60
local StartRuler="1"
local EndRuler="1"
local LastErrors="1"
local NormalColor=""
local MachineColor=""
local ValueColor=""
local AddrColor=""
local RXTXColor=""
local ErrorColor=""
local ExtraName=""
local ExtraValue=""

initialize() { # <Script Parameters>
    local ColorMode="c"
    while [ -n "$1" ]; do
        case "$1" in
        -h|--help)    echo -e    "Usage: $0 [-h|--help] [[-m|--mono]|[-bw|-black-white]|[-c2|--color-2]] [-sr|--no-start-ruler] [-er|--no-end-ruler]"\
                            "[-w N|--width N] [-en Name|--extra-name Name] [-ev Value|--extra-value Value] [-le|--no-last-err]"\
                            "\n\t-h\t\tThis help,"\
                            "\n\t-m\t\tDisplay mono version,"\
                            "\n\t-bw\t\tDisplay black-white version,"\
                            "\n\t-c2\t\tDisplay alternative color version 2,"\
                            "\n\t-sr\t\tWithout start horizontal ruler,"\
                            "\n\t-er\t\tWithout end horizontal ruler,"\
                            "\n\t-w N\t\tSet width of text area to N characters (minimum 60)"\
                            "\n\t-en Name\tPrint extra name"\
                            "\n\t-ev Value\tPrint extra value"\
                            "\n\t-le\t\tDon't display last errors"
                    exit 1;;
        -m|--mono) ColorMode="m";;
        -bw|--black-white) ColorMode="bw";;
        -c2|--color-2) ColorMode="c2";;
        -sr|--no-start-ruler) StartRuler="0";;
        -er|--no-end-ruler) EndRuler="0";;
        -w|--width) shift; Width=$1;;
        -en|--extra-name)    while [ -n "$2" ] && [ "${2:0:1}" != "-" ]; do
                                shift
                                [ "$ExtraName" != "" ] && ExtraName="$ExtraName "
                                ExtraName="$ExtraName$1"
                            done;;
        -ev|--extra-value)    while [ -n "$2" ] && [ "${2:0:1}" != "-" ]; do
                                shift
                                [ "$ExtraValue" != "" ] && ExtraValue="$ExtraValue "
                                ExtraValue="$ExtraValue$1"
                            done;;
        -le|--no-last-err)    LastErrors="0";;
        *) echo "Invalid option: $1. Use -h for help";;
        esac
        shift;
    done
    case "$ColorMode" in
        c)    NormalColor="\e[0m"
            MachineColor="\e[0;33m"
            ValueColor="\e[1;36m"
            AddrColor="\e[1;31m"
            RXTXColor="\e[2;32m"
            ErrorColor="\e[0;31m";;
        c2)    NormalColor="\e[0m"
            MachineColor="\e[0;31m"
            ValueColor="\e[0;33m"
            AddrColor="\e[0;35m"
            RXTXColor="\e[0;36m"
            ErrorColor="\e[0;31m";;
        m)    NormalColor="\e[0m"
            MachineColor="\e[7m"
            ValueColor="\e[1m"
            AddrColor="\e[4m"
            RXTXColor="\e[1m"
            ErrorColor="\e[4";;
        *)    ;;
    esac
    ([ "$Width" == "" ] || [ "$Width" -lt 60 ]) && Width=60
}

human_readable() { # <Number of bytes>
    if [ $1 -gt 0 ]; then
        printf "$(awk -v n=$1 'BEGIN{for(i=split("B KB MB GB TB PB",suffix);s<1;i--)s=n/(2**(10*i));printf (int(s)==s)?"%.0f%s":"%.1f%s",s,suffix[i+2]}' 2>/dev/null)"
    else
        printf "0B"
    fi
}

device_rx_tx() { # <Device>
    local RXTX=$(awk -v Device=$1 '$1==Device ":"{printf "%.0f\t%.0f",$2,$10}' /proc/net/dev 2>/dev/null)
    [ "$RXTX" != "" ] && printf ", rx/tx: $RXTXColor$(human_readable $(echo "$RXTX" | cut -f 1))$NormalColor/$RXTXColor$(human_readable $(echo "$RXTX" | cut -f 2))$NormalColor"
}

uptime_str() { # <Time in Seconds>
    local Uptime=$1
    if [ $Uptime -gt 0 ]; then
        local Days=$(expr $Uptime / 60 / 60 / 24)
        local Hours=$(expr $Uptime / 60 / 60 % 24)
        local Minutes=$(expr $Uptime / 60 % 60)
        local Seconds=$(expr $Uptime % 60)
        if [ $Days -gt 0 ]; then
            Days=$(printf "%dd " $Days)
        else
            Days=""
        fi
        printf "$Days%02d:%02d:%02d" $Hours $Minutes $Seconds
    fi
}

print_line() { # <String to Print>, [[<String to Print>] ...]
    local Line="$@"
    printf " | %-${Width}s |\r | $Line\n" 2>/dev/null
}

print_horizontal_ruler() {
    printf "/%$(expr $Width + 4 )s\n" | tr ' /' '- ' 2>/dev/null
}

print_machine() {
    local Machine=""
    local HostName=$(uci -q get system.@system[0].hostname)
    [ -e /tmp/sysinfo/model ] && Machine=$(cat /tmp/sysinfo/model 2>/dev/null)
    print_line     "Machine: $MachineColor${Machine:-n/a}$NormalColor,"\
                "Name: $MachineColor${HostName:-n/a}$NormalColor"
}

print_times() {
    local SysUptime=$(cut -d. -f1 /proc/uptime)
    local Uptime=$(uptime_str $SysUptime)
    local Now=$(date +'%Y-%m-%d %H:%M:%S')
    print_line     "System uptime: $ValueColor$Uptime$NormalColor,"\
                "Now: $ValueColor$Now$NormalColor"
}

print_loadavg() {
    local LoadAvg=$(awk '{printf"'$ValueColor'%s'$NormalColor', '$ValueColor'%s'$NormalColor', '$ValueColor'%s'$NormalColor'",$1,$2,$3}' /proc/loadavg 2>/dev/null)
    print_line "System load: $LoadAvg"
}

print_flash() {
    local Flash=$(df -k /overlay 2>/dev/null| awk 'BEGIN{Total=0;Free=0}/\/overlay/{Total=$2;Free=$4}END{Used=Total-Free;printf"%.0f\t%.0f\t%.1f\t%.0f",Total*1024,Used*1024,(Total>0)?((Used/Total)*100):0,Free*1024}' 2>/dev/null)
    local Total=$(echo "$Flash" | cut -f 1)
    local Used=$(echo "$Flash" | cut -f 2)
    local UsedPercent=$(echo "$Flash" | cut -f 3)
    local Free=$(echo "$Flash" | cut -f 4)
    [ "$Total" -gt 0 ] && print_line     "Flash:"\
                "total: $ValueColor$(human_readable $Total)$NormalColor,"\
                "used: $ValueColor$(human_readable $Used)$NormalColor, $ValueColor$UsedPercent$NormalColor%%,"\
                "free: $ValueColor$(human_readable $Free)$NormalColor"
}

print_memory() {
    local Memory=$(awk 'BEGIN{Total=0;Free=0}$1~/^MemTotal:/{Total=$2}$1~/^MemFree:|^Buffers:|^Cached:/{Free+=$2}END{Used=Total-Free;printf"%.0f\t%.0f\t%.1f\t%.0f",Total*1024,Used*1024,(Total>0)?((Used/Total)*100):0,Free*1024}' /proc/meminfo 2>/dev/null)
    local Total=$(echo "$Memory" | cut -f 1)
    local Used=$(echo "$Memory" | cut -f 2)
    local UsedPercent=$(echo "$Memory" | cut -f 3)
    local Free=$(echo "$Memory" | cut -f 4)
    print_line "Memory:"\
                "total: $ValueColor$(human_readable $Total)$NormalColor,"\
                "used: $ValueColor$(human_readable $Used)$NormalColor, $ValueColor$UsedPercent$NormalColor%%,"\
                "free: $ValueColor$(human_readable $Free)$NormalColor"
}

print_swap() {
    local Swap=$(awk 'BEGIN{Total=0;Free=0}$1~/^SwapTotal:/{Total=$2}$1~/^SwapFree:/{Free=$2}END{Used=Total-Free;printf"%.0f\t%.0f\t%.1f\t%.0f",Total*1024,Used*1024,(Total>0)?((Used/Total)*100):0,Free*1024}' /proc/meminfo 2>/dev/null)
    local Total=$(echo "$Swap" | cut -f 1)
    local Used=$(echo "$Swap" | cut -f 2)
    local UsedPercent=$(echo "$Swap" | cut -f 3)
    local Free=$(echo "$Swap" | cut -f 4)
    [ "$Total" -gt 0 ] && print_line "Swap:"\
                "total: $ValueColor$(human_readable $Total)$NormalColor,"\
                "used: $ValueColor$(human_readable $Used)$NormalColor, $ValueColor$UsedPercent$NormalColor%%,"\
                "free: $ValueColor$(human_readable $Free)$NormalColor"
}

print_wan() {
    local Zone
    local Device
    for Zone in $(uci -q show firewall | grep .masq= | cut -f2 -d.); do
        if [ "$(uci -q get firewall.$Zone.masq)" == "1" ]; then
            for Device in $(uci -q get firewall.$Zone.network); do
                local Status="$(ubus call network.interface.$Device status 2>/dev/null)"
                if [ "$Status" != "" ]; then
                    local State=""
                    local Iface=""
                    local Uptime=""
                    local IP4=""
                    local IP6=""
                    local Subnet4=""
                    local Subnet6=""
                    local Gateway4=""
                    local Gateway6=""
                    local DNS=""
                    local Protocol=""
                    json_load "${Status:-{}}"
                    json_get_var State up
                    json_get_var Uptime uptime
                    json_get_var Iface l3_device
                    json_get_var Protocol proto
                    if json_get_type Status ipv4_address && [ "$Status" = array ]; then
                        json_select ipv4_address
                        json_get_type Status 1
                        if [ "$Status" = object ]; then
                            json_select 1
                            json_get_var IP4 address
                            json_get_var Subnet4 mask
                            [ "$IP4" != "" ] && [ "$Subnet4" != "" ] && IP4="$IP4/$Subnet4"
                        fi
                    fi
                    json_select
                    if json_get_type Status ipv6_address && [ "$Status" = array ]; then
                        json_select ipv6_address
                        json_get_type Status 1
                        if [ "$Status" = object ]; then
                            json_select 1
                            json_get_var IP6 address
                            json_get_var Subnet6 mask
                            [ "$IP6" != "" ] && [ "$Subnet6" != "" ] && IP6="$IP6/$Subnet6"
                        fi
                    fi
                    json_select
                    if json_get_type Status route && [ "$Status" = array ]; then
                        json_select route
                        local Index="1"
                        while json_get_type Status $Index && [ "$Status" = object ]; do
                            json_select "$((Index++))"
                            json_get_var Status target
                            case "$Status" in
                                0.0.0.0)
                                    json_get_var Gateway4 nexthop;;
                                ::)
                                    json_get_var Gateway6 nexthop;;
                            esac
                            json_select ".."
                        done    
                    fi
                    json_select
                    if json_get_type Status dns_server && [ "$Status" = array ]; then
                        json_select dns_server
                        local Index="1"
                        while json_get_type Status $Index && [ "$Status" = string ]; do
                            json_get_var Status "$((Index++))"
                            DNS="${DNS:+$DNS }$Status"
                        done
                    fi
                    if [ "$State" == "1" ]; then
                        [ "$IP4" != "" ] && print_line     "WAN: $AddrColor$IP4$NormalColor($Iface),"\
                                                        "gateway: $AddrColor${Gateway4:-n/a}$NormalColor"
                        [ "$IP6" != "" ] && print_line    "WAN: $AddrColor$IP6$NormalColor($Iface),"\
                                                        "gateway: $AddrColor${Gateway6:-n/a}$NormalColor"
                        print_line    "proto: $ValueColor${Protocol:-n/a}$NormalColor,"\
                                    "uptime: $ValueColor$(uptime_str $Uptime)$NormalColor$(device_rx_tx $Iface)"
                        [ "$DNS" != "" ] && print_line "dns: $AddrColor$DNS$NormalColor"
                    fi
                fi
            done
        fi 
    done
}

print_lan() {
    local Zone
    local Device
    for Zone in $(uci -q show firewall | grep []]=zone | cut -f2 -d. | cut -f1 -d=); do
        if [ "$(uci -q get firewall.$Zone.masq)" != "1" ]; then
            for Device in $(uci -q get firewall.$Zone.network); do
                local Status="$(ubus call network.interface.$Device status 2>/dev/null)"
                if [ "$Status" != "" ]; then
                    local State=""
                    local Iface=""
                    local IP4=""
                    local IP6=""
                    local Subnet4=""
                    local Subnet6=""
                    json_load "${Status:-{}}"
                    json_get_var State up
                    json_get_var Iface device
                    if json_get_type Status ipv4_address && [ "$Status" = array ]; then
                        json_select ipv4_address
                        json_get_type Status 1
                        if [ "$Status" = object ]; then
                            json_select 1
                            json_get_var IP4 address
                            json_get_var Subnet4 mask
                            [ "$IP4" != "" ] && [ "$Subnet4" != "" ] && IP4="$IP4/$Subnet4"
                        fi
                    fi
                    json_select
                    if json_get_type Status ipv6_address && [ "$Status" = array ]; then
                        json_select ipv6_address
                        json_get_type Status 1
                        if [ "$Status" = object ]; then
                            json_select 1
                            json_get_var IP6 address
                            json_get_var Subnet6 mask
                            [ "$IP6" != "" ] && [ "$Subnet6" != "" ] && IP6="$IP6/$Subnet6"
                        fi
                    fi
                    local DHCPConfig=$(uci -q show dhcp | grep .interface=$Device | cut -d. -f2)
                    if [ "$DHCPConfig" != "" ] && [ "$(uci -q get dhcp.$DHCPConfig.ignore)" != "1" ]; then
                        local DHCPStart=$(uci -q get dhcp.$DHCPConfig.start)
                        local DHCPLimit=$(uci -q get dhcp.$DHCPConfig.limit)
                        [ "$DHCPStart" != "" ] && [ "$DHCPLimit" != "" ] && DHCP="$(echo $IP4 | cut -d. -f1-3).$DHCPStart-$(expr $DHCPStart + $DHCPLimit - 1)"
                    fi
                    [ "$IP4" != "" ] && print_line "LAN: $AddrColor$IP4$NormalColor($Iface), dhcp: $AddrColor${DHCP:-n/a}$NormalColor"
                    [ "$IP6" != "" ] && print_line "LAN: $AddrColor$IP6$NormalColor($Iface)"
                fi
            done
        fi 
    done
}

print_wlan() {
    local Iface
    for Iface in $(uci -q show wireless | grep device=radio | cut -f2 -d.); do
        local Device=$(uci -q get wireless.$Iface.device)
        local SSID=$(uci -q get wireless.$Iface.ssid)
        local IfaceDisabled=$(uci -q get wireless.$Iface.disabled)
        local DeviceDisabled=$(uci -q get wireless.$Device.disabled)
        if [ -n "$SSID" ] && [ "$IfaceDisabled" != "1" ] && [ "$DeviceDisabled" != "1" ]; then
            local Mode=$(uci -q -P /var/state get wireless.$Iface.mode)
            local Channel=$(uci -q get wireless.$Device.channel)
            local RadioIface=$(uci -q -P /var/state get wireless.$Iface.ifname)
            local Connection="Down"
            if [ -n "$RadioIface" ]; then
                if [ "$Mode" == "ap" ]; then
                    Connection="$(iw dev $RadioIface station dump | grep Station | wc -l 2>/dev/null)"
                else
                    Connection="$(iw dev $RadioIface link | awk 'BEGIN{FS=": ";Signal="";Bitrate=""} $1~/signal/ {Signal=$2} $1~/tx bitrate/ {Bitrate=$2}END{print Signal" "Bitrate}' 2>/dev/null)"
                fi
            fi
            if [ "$Mode" == "ap" ]; then
                print_line    "WLAN: $ValueColor$SSID$NormalColor($Mode),"\
                            "ch: $ValueColor${Channel:-n/a}$NormalColor,"\
                            "conn: $ValueColor$Connection$NormalColor$(device_rx_tx $RadioIface)"
            else
                print_line    "WLAN: $ValueColor$SSID$NormalColor($Mode),"\
                            "ch: $ValueColor${Channel:-n/a}$NormalColor"
                print_line    "conn: $ValueColor$Connection$NormalColor$(device_rx_tx $RadioIface)"
            fi
        fi
    done
}

print_vpn() {
    local VPN
    for VPN in $(uci -q show openvpn | grep .ca= | cut -f2 -d.); do
        local Device=$(uci -q get openvpn.$VPN.dev)
        local Enabled=$(uci -q get openvpn.$VPN.enabled)
        if [ "$Enabled" == "1" ] || [ "$Enabled" == "" ]; then
            local Mode=$(uci -q get openvpn.$VPN.mode)
            local Connection="n/a"
            if [ "$Mode" == "server" ]; then
                Mode="$ValueColor$VPN$NormalColor(svr):$(uci -q get openvpn.$VPN.port)"
                Status=$(uci -q get openvpn.$VPN.status)
                Connection=$(awk 'BEGIN{FS=",";c=0;l=0}{if($1=="Common Name")l=1;else if($1=="ROUTING TABLE")exit;else if (l==1) c=c+1}END{print c}' $Status 2>/dev/null)
            else
                Mode="$ValueColor$VPN$NormalColor(cli)"
                Connection="Down"
                ifconfig $Device &>/dev/null && Connection="Up"
            fi
            print_line    "VPN: $Mode,"\
                        "conn: $ValueColor$Connection$NormalColor$(device_rx_tx $Device)"
        fi
    done
}

print_extra() {
    ([ "$ExtraName" != "" ] || [ "$ExtraValue" != "" ]) && print_line "$ExtraName $ValueColor$ExtraValue$NormalColor"
}

print_error() {
    logread | awk '/\w{3}+\.(err|warn|alert|emerg|crit)/{err[++i]=$0}END{j=i-4;j=j>=1?j:1;while(j<=i)print" '$ErrorColor'"err[j++]"'$NormalColor'"}' 2>/dev/null
}

initialize $@
[ "$StartRuler" == "1" ] && print_horizontal_ruler
print_machine
print_times
print_loadavg
print_flash
print_memory
print_swap
print_wan
print_lan
print_wlan
print_vpn
print_extra
[ "$EndRuler" == "1" ] && print_horizontal_ruler
[ "$LastErrors" == "1" ] && print_error
exit 0
# Done.

158

(206 odpowiedzi, napisanych Oprogramowanie / Software)

Witaj,
wydaj proszę komendę df /overlay.

159

(37 odpowiedzi, napisanych Oprogramowanie / Software)

Miłego urlopu

160

(37 odpowiedzi, napisanych Oprogramowanie / Software)

Nimloth napisał/a:

OK przy kolejnym updacie AA

Witam,
jest kolejną wersją AA. Będę wdzięczny za test ostatniej wersji skryptu i opinie.

161

(206 odpowiedzi, napisanych Oprogramowanie / Software)

bhb co masz na myśli pisząc ze źle działa.
Wydaj proszę polecenie  free i pokaż.

162

(206 odpowiedzi, napisanych Oprogramowanie / Software)

Witam,
dodałem informacje o swap.

Aby informacja wyświetlała się automatycznie po zalogowaniu należy do pliku /etc/profile dodać na końcu linie (o ile jej już tam nie ma) :

[ -x /sbin/sysinfo.sh ] && /sbin/sysinfo.sh -sr

Skrypt /sbin/sysinfo.sh

#!/bin/sh
#
# sysinfo.sh dla OpenWRT AA Cezary Jackiewicz 2013
# 
#    1.00    CJ    Pierwsza wersja kodu
#    1.01    RD    Drobna przebudowa
#    1.02    RD    Korekta błędu wyśw. zajetości Flash-a, dodanie kolorów
#    1.03    RD    Dodanie nazwy routera, zmiana formatowania
#    1.04    RD    Kosmetyka, sugestie @mikhnal. Zmiana przetwarzania info. o wan.
#    1.05    RD    Zmiana algorytmu pobierania danych dla wan i lan
#    1.06    RD    Parametryzacja kolorów i pojawiania się podkreśleń
#    1.07    RD    Modyfikacja związana z poprawnym wyświetlaniem interfejsu dla prot.3g
#    1.08    RD    Modyfikacja wyświetlania DNS-ów dla wan, dodanie uptime dla interfejsów
#    1.09    RD    Dodanie statusu "Down" dla wyłączonego wifi, zmiana wyświetlania dla WLAN(sta)
#    1.10    RD    Korekta wyświetlania dla WLAN(sta)
#    1.11    RD    Korekta wyświetlania stanu pamięci, sugestie @dopsz 
#    1.12    RD    Zmiana kolejności wyświetlania wartości stanu pamięci + kosmetyka 
#    1.13    RD    Dodanie info o dhcp w LAN, zmiana sposobu wyświetlania informacji o LAN
#    1.14    RD    Dodanie informacji o ostatnich 5 błędach
#    1.15    RD    Zmiana stderr
#    1.16    RD    Dodanie wyświetlania informacji o swap
#
# Destination /sbin/sysinfo.sh
#
. /usr/share/libubox/jshn.sh

local Width=60
local StartRuler="1"
local EndRuler="1"
local LastErrors="1"
local NormalColor=""
local MachineColor=""
local ValueColor=""
local AddrColor=""
local RXTXColor=""
local ErrorColor=""
local ExtraName=""
local ExtraValue=""

initialize() { # <Script Parameters>
    local ColorMode="c"
    while [ -n "$1" ]; do
        case "$1" in
        -h|--help)    echo -e    "Usage: $0 [-h|--help] [[-m|--mono]|[-bw|-black-white]|[-c2|--color-2]] [-sr|--no-start-ruler] [-er|--no-end-ruler]"\
                            "[-w N|--width N] [-en Name|--extra-name Name] [-ev Value|--extra-value Value] [-le|--no-last-err]"\
                            "\n\t-h\t\tThis help,"\
                            "\n\t-m\t\tDisplay mono version,"\
                            "\n\t-bw\t\tDisplay black-white version,"\
                            "\n\t-c2\t\tDisplay alternative color version 2,"\
                            "\n\t-sr\t\tWithout start horizontal ruler,"\
                            "\n\t-er\t\tWithout end horizontal ruler,"\
                            "\n\t-w N\t\tSet width of text area to N characters (minimum 60)"\
                            "\n\t-en Name\tPrint extra name"\
                            "\n\t-ev Value\tPrint extra value"\
                            "\n\t-le\t\tDon't display last errors"
                    exit 1;;
        -m|--mono) ColorMode="m";;
        -bw|--black-white) ColorMode="bw";;
        -c2|--color-2) ColorMode="c2";;
        -sr|--no-start-ruler) StartRuler="0";;
        -er|--no-end-ruler) EndRuler="0";;
        -w|--width) shift; Width=$1;;
        -en|--extra-name)    while [ -n "$2" ] && [ "${2:0:1}" != "-" ]; do
                                shift
                                [ "$ExtraName" != "" ] && ExtraName="$ExtraName "
                                ExtraName="$ExtraName$1"
                            done;;
        -ev|--extra-value)    while [ -n "$2" ] && [ "${2:0:1}" != "-" ]; do
                                shift
                                [ "$ExtraValue" != "" ] && ExtraValue="$ExtraValue "
                                ExtraValue="$ExtraValue$1"
                            done;;
        -le|--no-last-err)    LastErrors="0";;
        *) echo "Invalid option: $1. Use -h for help";;
        esac
        shift;
    done
    case "$ColorMode" in
        c)    NormalColor="\e[0m"
            MachineColor="\e[0;33m"
            ValueColor="\e[1;36m"
            AddrColor="\e[1;31m"
            RXTXColor="\e[2;32m"
            ErrorColor="\e[0;31m";;
        c2)    NormalColor="\e[0m"
            MachineColor="\e[0;31m"
            ValueColor="\e[0;33m"
            AddrColor="\e[0;35m"
            RXTXColor="\e[0;36m"
            ErrorColor="\e[0;31m";;
        m)    NormalColor="\e[0m"
            MachineColor="\e[7m"
            ValueColor="\e[1m"
            AddrColor="\e[4m"
            RXTXColor="\e[1m"
            ErrorColor="\e[4";;
        *)    ;;
    esac
    ([ "$Width" == "" ] || [ "$Width" -lt 60 ]) && Width=60
}

human_readable() { # <Number of bytes>
    if [ $1 -gt 0 ]; then
        printf "$(awk -v n=$1 'BEGIN{for(i=split("B KB MB GB TB PB",suffix);s<1;i--)s=n/(2**(10*i));printf (int(s)==s)?"%.0f%s":"%.1f%s",s,suffix[i+2]}' 2>/dev/null)"
    else
        printf "0B"
    fi
}

device_rx_tx() { # <Device>
    local RXTX=$(awk -v Device=$1 '$1==Device ":"{printf "%.0f\t%.0f",$2,$10}' /proc/net/dev 2>/dev/null)
    [ "$RXTX" != "" ] && printf ", rx/tx: $RXTXColor$(human_readable $(echo "$RXTX" | cut -f 1))$NormalColor/$RXTXColor$(human_readable $(echo "$RXTX" | cut -f 2))$NormalColor"
}

uptime_str() { # <Time in Seconds>
    local Uptime=$1
    if [ $Uptime -gt 0 ]; then
        local Days=$(expr $Uptime / 60 / 60 / 24)
        local Hours=$(expr $Uptime / 60 / 60 % 24)
        local Minutes=$(expr $Uptime / 60 % 60)
        local Seconds=$(expr $Uptime % 60)
        if [ $Days -gt 0 ]; then
            Days=$(printf "%dd " $Days)
        else
            Days=""
        fi
        printf "$Days%02d:%02d:%02d" $Hours $Minutes $Seconds
    fi
}

print_line() { # <String to Print>, [[<String to Print>] ...]
    local Line="$@"
    printf " | %-${Width}s |\r | $Line\n" 2>/dev/null
}

print_horizontal_ruler() {
    printf "/%$(expr $Width + 4 )s\n" | tr ' /' '- ' 2>/dev/null
}

print_machine() {
    local Machine=""
    local HostName=$(uci -q get system.@system[0].hostname)
    [ -e /tmp/sysinfo/model ] && Machine=$(cat /tmp/sysinfo/model 2>/dev/null)
    print_line     "Machine: $MachineColor${Machine:-n/a}$NormalColor,"\
                "Name: $MachineColor${HostName:-n/a}$NormalColor"
}

print_times() {
    local SysUptime=$(cut -d. -f1 /proc/uptime)
    local Uptime=$(uptime_str $SysUptime)
    local Now=$(date +'%Y-%m-%d %H:%M:%S')
    print_line     "System uptime: $ValueColor$Uptime$NormalColor,"\
                "Now: $ValueColor$Now$NormalColor"
}

print_loadavg() {
    local LoadAvg=$(awk '{printf"'$ValueColor'%s'$NormalColor', '$ValueColor'%s'$NormalColor', '$ValueColor'%s'$NormalColor'",$1,$2,$3}' /proc/loadavg 2>/dev/null)
    print_line "System load: $LoadAvg"
}

print_flash() {
    local Flash=$(df -k /overlay | awk '/overlay/{printf "%.0f\t%.0f\t%.1f\t%.0f",$2*1024,$3*1024,($2>0)?$3/$2*100:0,$4*1024}' 2>/dev/null)
    local Total=$(echo "$Flash" | cut -f 1)
    local Used=$(echo "$Flash" | cut -f 2)
    local UsedPercent=$(echo "$Flash" | cut -f 3)
    local Free=$(echo "$Flash" | cut -f 4)
    print_line     "Flash:"\
                "total: $ValueColor$(human_readable $Total)$NormalColor,"\
                "used: $ValueColor$(human_readable $Used)$NormalColor, $ValueColor$UsedPercent$NormalColor%%,"\
                "free: $ValueColor$(human_readable $Free)$NormalColor"
}

print_memory() {
    local Memory=$(awk 'BEGIN{Total=0;Free=0}$1~/^MemTotal:/{Total=$2}$1~/^MemFree:|^Buffers:|^Cached:/{Free+=$2}END{Used=Total-Free;printf"%.0f\t%.0f\t%.1f\t%.0f",Total*1024,Used*1024,(Total>0)?((Used/Total)*100):0,Free*1024}' /proc/meminfo 2>/dev/null)
    local Total=$(echo "$Memory" | cut -f 1)
    local Used=$(echo "$Memory" | cut -f 2)
    local UsedPercent=$(echo "$Memory" | cut -f 3)
    local Free=$(echo "$Memory" | cut -f 4)
    print_line "Memory:"\
                "total: $ValueColor$(human_readable $Total)$NormalColor,"\
                "used: $ValueColor$(human_readable $Used)$NormalColor, $ValueColor$UsedPercent$NormalColor%%,"\
                "free: $ValueColor$(human_readable $Free)$NormalColor"
}

print_swap() {
    local Swap=$(awk 'BEGIN{Total=0;Free=0}$1~/^SwapTotal:/{Total=$2}$1~/^SwapFree:/{Free=$2}END{Used=Total-Free;printf"%.0f\t%.0f\t%.1f\t%.0f",Total*1024,Used*1024,(Total>0)?((Used/Total)*100):0,Free*1024}' /proc/meminfo 2>/dev/null)
    local Total=$(echo "$Swap" | cut -f 1)
    local Used=$(echo "$Swap" | cut -f 2)
    local UsedPercent=$(echo "$Swap" | cut -f 3)
    local Free=$(echo "$Swap" | cut -f 4)
    [ "$Total" -gt 0 ] && print_line "Swap:"\
                "total: $ValueColor$(human_readable $Total)$NormalColor,"\
                "used: $ValueColor$(human_readable $Used)$NormalColor, $ValueColor$UsedPercent$NormalColor%%,"\
                "free: $ValueColor$(human_readable $Free)$NormalColor"
}

print_wan() {
    local Zone
    local Device
    for Zone in $(uci -q show firewall | grep .masq= | cut -f2 -d.); do
        if [ "$(uci -q get firewall.$Zone.masq)" == "1" ]; then
            for Device in $(uci -q get firewall.$Zone.network); do
                local Status="$(ubus call network.interface.$Device status 2>/dev/null)"
                if [ "$Status" != "" ]; then
                    local State=""
                    local Iface=""
                    local Uptime=""
                    local IP4=""
                    local IP6=""
                    local Subnet4=""
                    local Subnet6=""
                    local Gateway4=""
                    local Gateway6=""
                    local DNS=""
                    local Protocol=""
                    json_load "${Status:-{}}"
                    json_get_var State up
                    json_get_var Uptime uptime
                    json_get_var Iface l3_device
                    json_get_var Protocol proto
                    if json_get_type Status ipv4_address && [ "$Status" = array ]; then
                        json_select ipv4_address
                        json_get_type Status 1
                        if [ "$Status" = object ]; then
                            json_select 1
                            json_get_var IP4 address
                            json_get_var Subnet4 mask
                            [ "$IP4" != "" ] && [ "$Subnet4" != "" ] && IP4="$IP4/$Subnet4"
                        fi
                    fi
                    json_select
                    if json_get_type Status ipv6_address && [ "$Status" = array ]; then
                        json_select ipv6_address
                        json_get_type Status 1
                        if [ "$Status" = object ]; then
                            json_select 1
                            json_get_var IP6 address
                            json_get_var Subnet6 mask
                            [ "$IP6" != "" ] && [ "$Subnet6" != "" ] && IP6="$IP6/$Subnet6"
                        fi
                    fi
                    json_select
                    if json_get_type Status route && [ "$Status" = array ]; then
                        json_select route
                        local Index="1"
                        while json_get_type Status $Index && [ "$Status" = object ]; do
                            json_select "$((Index++))"
                            json_get_var Status target
                            case "$Status" in
                                0.0.0.0)
                                    json_get_var Gateway4 nexthop;;
                                ::)
                                    json_get_var Gateway6 nexthop;;
                            esac
                            json_select ".."
                        done    
                    fi
                    json_select
                    if json_get_type Status dns_server && [ "$Status" = array ]; then
                        json_select dns_server
                        local Index="1"
                        while json_get_type Status $Index && [ "$Status" = string ]; do
                            json_get_var Status "$((Index++))"
                            DNS="${DNS:+$DNS }$Status"
                        done
                    fi
                    if [ "$State" == "1" ]; then
                        [ "$IP4" != "" ] && print_line     "WAN: $AddrColor$IP4$NormalColor($Iface),"\
                                                        "gateway: $AddrColor${Gateway4:-n/a}$NormalColor"
                        [ "$IP6" != "" ] && print_line    "WAN: $AddrColor$IP6$NormalColor($Iface),"\
                                                        "gateway: $AddrColor${Gateway6:-n/a}$NormalColor"
                        print_line    "proto: $ValueColor${Protocol:-n/a}$NormalColor,"\
                                    "uptime: $ValueColor$(uptime_str $Uptime)$NormalColor$(device_rx_tx $Iface)"
                        [ "$DNS" != "" ] && print_line "dns: $AddrColor$DNS$NormalColor"
                    fi
                fi
            done
        fi 
    done
}

print_lan() {
    local Zone
    local Device
    for Zone in $(uci -q show firewall | grep []]=zone | cut -f2 -d. | cut -f1 -d=); do
        if [ "$(uci -q get firewall.$Zone.masq)" != "1" ]; then
            for Device in $(uci -q get firewall.$Zone.network); do
                local Status="$(ubus call network.interface.$Device status 2>/dev/null)"
                if [ "$Status" != "" ]; then
                    local State=""
                    local Iface=""
                    local IP4=""
                    local IP6=""
                    local Subnet4=""
                    local Subnet6=""
                    json_load "${Status:-{}}"
                    json_get_var State up
                    json_get_var Iface device
                    if json_get_type Status ipv4_address && [ "$Status" = array ]; then
                        json_select ipv4_address
                        json_get_type Status 1
                        if [ "$Status" = object ]; then
                            json_select 1
                            json_get_var IP4 address
                            json_get_var Subnet4 mask
                            [ "$IP4" != "" ] && [ "$Subnet4" != "" ] && IP4="$IP4/$Subnet4"
                        fi
                    fi
                    json_select
                    if json_get_type Status ipv6_address && [ "$Status" = array ]; then
                        json_select ipv6_address
                        json_get_type Status 1
                        if [ "$Status" = object ]; then
                            json_select 1
                            json_get_var IP6 address
                            json_get_var Subnet6 mask
                            [ "$IP6" != "" ] && [ "$Subnet6" != "" ] && IP6="$IP6/$Subnet6"
                        fi
                    fi
                    local DHCPConfig=$(uci -q show dhcp | grep .interface=$Device | cut -d. -f2)
                    if [ "$DHCPConfig" != "" ] && [ "$(uci -q get dhcp.$DHCPConfig.ignore)" != "1" ]; then
                        local DHCPStart=$(uci -q get dhcp.$DHCPConfig.start)
                        local DHCPLimit=$(uci -q get dhcp.$DHCPConfig.limit)
                        [ "$DHCPStart" != "" ] && [ "$DHCPLimit" != "" ] && DHCP="$(echo $IP4 | cut -d. -f1-3).$DHCPStart-$(expr $DHCPStart + $DHCPLimit - 1)"
                    fi
                    [ "$IP4" != "" ] && print_line "LAN: $AddrColor$IP4$NormalColor($Iface), dhcp: $AddrColor${DHCP:-n/a}$NormalColor"
                    [ "$IP6" != "" ] && print_line "LAN: $AddrColor$IP6$NormalColor($Iface)"
                fi
            done
        fi 
    done
}

print_wlan() {
    local Iface
    for Iface in $(uci -q show wireless | grep device=radio | cut -f2 -d.); do
        local Device=$(uci -q get wireless.$Iface.device)
        local SSID=$(uci -q get wireless.$Iface.ssid)
        local IfaceDisabled=$(uci -q get wireless.$Iface.disabled)
        local DeviceDisabled=$(uci -q get wireless.$Device.disabled)
        if [ -n "$SSID" ] && [ "$IfaceDisabled" != "1" ] && [ "$DeviceDisabled" != "1" ]; then
            local Mode=$(uci -q -P /var/state get wireless.$Iface.mode)
            local Channel=$(uci -q get wireless.$Device.channel)
            local RadioIface=$(uci -q -P /var/state get wireless.$Iface.ifname)
            local Connection="Down"
            if [ -n "$RadioIface" ]; then
                if [ "$Mode" == "ap" ]; then
                    Connection="$(iw dev $RadioIface station dump | grep Station | wc -l 2>/dev/null)"
                else
                    Connection="$(iw dev $RadioIface link | awk 'BEGIN{FS=": ";Signal="";Bitrate=""} $1~/signal/ {Signal=$2} $1~/tx bitrate/ {Bitrate=$2}END{print Signal" "Bitrate}' 2>/dev/null)"
                fi
            fi
            if [ "$Mode" == "ap" ]; then
                print_line    "WLAN: $ValueColor$SSID$NormalColor($Mode),"\
                            "ch: $ValueColor${Channel:-n/a}$NormalColor,"\
                            "conn: $ValueColor$Connection$NormalColor$(device_rx_tx $RadioIface)"
            else
                print_line    "WLAN: $ValueColor$SSID$NormalColor($Mode),"\
                            "ch: $ValueColor${Channel:-n/a}$NormalColor"
                print_line    "conn: $ValueColor$Connection$NormalColor$(device_rx_tx $RadioIface)"
            fi
        fi
    done
}

print_vpn() {
    local VPN
    for VPN in $(uci -q show openvpn | grep .ca= | cut -f2 -d.); do
        local Device=$(uci -q get openvpn.$VPN.dev)
        local Enabled=$(uci -q get openvpn.$VPN.enabled)
        if [ "$Enabled" == "1" ] || [ "$Enabled" == "" ]; then
            local Mode=$(uci -q get openvpn.$VPN.mode)
            local Connection="n/a"
            if [ "$Mode" == "server" ]; then
                Mode="$ValueColor$VPN$NormalColor(svr):$(uci -q get openvpn.$VPN.port)"
                Status=$(uci -q get openvpn.$VPN.status)
                Connection=$(awk 'BEGIN{FS=",";c=0;l=0}{if($1=="Common Name")l=1;else if($1=="ROUTING TABLE")exit;else if (l==1) c=c+1}END{print c}' $Status 2>/dev/null)
            else
                Mode="$ValueColor$VPN$NormalColor(cli)"
                Connection="Down"
                ifconfig $Device &>/dev/null && Connection="Up"
            fi
            print_line    "VPN: $Mode,"\
                        "conn: $ValueColor$Connection$NormalColor$(device_rx_tx $Device)"
        fi
    done
}

print_extra() {
    ([ "$ExtraName" != "" ] || [ "$ExtraValue" != "" ]) && print_line "$ExtraName $ValueColor$ExtraValue$NormalColor"
}

print_error() {
    logread | awk '/\w{3}+\.(err|warn|alert|emerg|crit)/{err[++i]=$0}END{j=i-4;j=j>=1?j:1;while(j<=i)print" '$ErrorColor'"err[j++]"'$NormalColor'"}' 2>/dev/null
}

initialize $@
[ "$StartRuler" == "1" ] && print_horizontal_ruler
print_machine
print_times
print_loadavg
print_flash
print_memory
print_swap
print_wan
print_lan
print_wlan
print_vpn
print_extra
[ "$EndRuler" == "1" ] && print_horizontal_ruler
[ "$LastErrors" == "1" ] && print_error
exit 0
# Done.

163

(37 odpowiedzi, napisanych Oprogramowanie / Software)

Witam,
zrobiłem kolejne modyfikacje,  tym razem pod kątem extroota.

Nowa wersja skryptu

164

(37 odpowiedzi, napisanych Oprogramowanie / Software)

Nimloth czy sprawdzisz nową wersję, zrobiłem zmiany?
Cezary dziękuję za pomysł z "odgadywaniem" nazwy skryptu dla pakietu.

Nowa wersja skryptu

165

(37 odpowiedzi, napisanych Oprogramowanie / Software)

Nimloth napisał/a:

Nie zainstalowal:
minidlna, 6in4

Nie wystartowal:
samba36-server

1. Czy pobrał libexif libjpeg libsqlite3 libffmpeg libid3tag libflac libvorbis libuuid to pakiety do minidlna?
2. Czy pobrał kmod-ipv6 kmod-iptunnel4 kmod-sit do 6in4?
3. Pakiet samba36-server obsługuje się poprzez /etc/init.d/samba [komenda], a ja zakładam że od nazwy pakietu pakietu pochodzi nazwa skryptu, czyli /etc/init.d/samba36-server. Coś trzeba będzie z tym zrobić.

166

(37 odpowiedzi, napisanych Oprogramowanie / Software)

To co robi install idzie na konsole a to co robią post-install i extroot-bypaser idzie go loga. Jak sobie przekierujesz loga do pliku to pozostaną w nim informacje.  W przeciwnym razie reboot lub wyłączenie czyści loga.
Jakich paczek nie zainstalował a jakich nie uruchomił?

167

(37 odpowiedzi, napisanych Oprogramowanie / Software)

Racja,  mialo byc-e. Zmienię w kolejnej wersji.
Wyjątek o którym piszesz jest wbrew procesowi aktualizacji opartej na numerze wersji. Do przemyślenia...

168

(37 odpowiedzi, napisanych Oprogramowanie / Software)

Witam,
przełącznik -e wyłącza ściąganie zainstalowanych paczek, pobierane są tylko z konfiguracji i zależne.
Pomoc to install.sh -h

Jest opcja aby pare paczek zainstalowal z hdd ?

Co masz na myśli?

169

(37 odpowiedzi, napisanych Oprogramowanie / Software)

Witam,
zrobiłem kilka poprawek, skrypt teraz poprawnie modyfikuje /etc/rc.local.

170

(206 odpowiedzi, napisanych Oprogramowanie / Software)

Witam,
zmieniłem sposób wyświetlania informacji o LAN, mam przypadki kilku LAN-ów i brakowało mi takiej informacji. Dodałem także informację o DHCP oraz infromację o ostatnich pięcu błędach z logu, jeżeli wystąpiły.
Dla tych, którzy chcieliby wyświetlać coś jeszcze dodałem extra linię.

#!/bin/sh
#
# sysinfo.sh dla OpenWRT AA Cezary Jackiewicz 2013
# 
#    1.00    CJ    Pierwsza wersja kodu
#    1.01    RD    Drobna przebudowa
#    1.02    RD    Korekta błędu wyśw. zajetości Flash-a, dodanie kolorów
#    1.03    RD    Dodanie nazwy routera, zmiana formatowania
#    1.04    RD    Kosmetyka, sugestie @mikhnal. Zmiana przetwarzania info. o wan.
#    1.05    RD    Zmiana algorytmu pobierania danych dla wan i lan
#    1.06    RD    Parametryzacja kolorów i pojawiania się podkreśleń
#    1.07    RD    Modyfikacja związana z poprawnym wyświetlaniem interfejsu dla prot.3g
#    1.08    RD    Modyfikacja wyświetlania DNS-ów dla wan, dodanie uptime dla interfejsów
#    1.09    RD    Dodanie statusu "Down" dla wyłączonego wifi, zmiana wyświetlania dla WLAN(sta)
#    1.10    RD    Korekta wyświetlania dla WLAN(sta)
#    1.11    RD    Korekta wyświetlania stanu pamięci, sugestie @dopsz 
#    1.12    RD    Zmiana kolejności wyświetlania wartości stanu pamięci + kosmetyka 
#    1.13    RD    Dodanie info o dhcp w LAN, zmiana sposobu wyświetlania informacji o LAN
#    1.14    RD    Dodanie informacji o ostatnich 5 błędach
#
# Destination /sbin/sysinfo.sh
#
. /usr/share/libubox/jshn.sh

local Width=60
local StartRuler="1"
local EndRuler="1"
local Rouler
local LastErrors="1"
local NormalColor=""
local MachineColor=""
local ValueColor=""
local AddrColor=""
local RXTXColor=""
local ErrorColor=""
local ExtraName=""
local ExtraValue=""

initialize() { # <Script Parameters>
    local ColorMode="c"
    while [ -n "$1" ]; do
        case "$1" in
        -h|--help)    echo -e    "Usage: $0 [-h|--help] [[-m|--mono]|[-bw|-black-white]|[-c2|--color-2]] [-sr|--no-start-ruler] [-er|--no-end-ruler]"\
                            "[-w N|--width N] [-en Name|--extra-name Name] [-ev Value|--extra-value Value] [-le|--no-last-err]"\
                            "\n\t-h\t\tThis help,"\
                            "\n\t-m\t\tDisplay mono version,"\
                            "\n\t-bw\t\tDisplay black-white version,"\
                            "\n\t-c2\t\tDisplay alternative color version 2,"\
                            "\n\t-sr\t\tWithout start horizontal ruler,"\
                            "\n\t-er\t\tWithout end horizontal ruler,"\
                            "\n\t-w N\t\tSet width of text area to N characters (minimum 60)"\
                            "\n\t-en Name\tPrint extra name"\
                            "\n\t-ev Value\tPrint extra value"\
                            "\n\t-le\t\tDon't display last errors"
                    exit 1;;
        -m|--mono) ColorMode="m";;
        -bw|--black-white) ColorMode="bw";;
        -c2|--color-2) ColorMode="c2";;
        -sr|--no-start-ruler) StartRuler="0";;
        -er|--no-end-ruler) EndRuler="0";;
        -w|--width) shift; Width=$1;;
        -en|--extra-name)    while [ -n "$2" ] && [ "${2:0:1}" != "-" ]; do
                                shift
                                [ "$ExtraName" != "" ] && ExtraName="$ExtraName "
                                ExtraName="$ExtraName$1"
                            done;;
        -ev|--extra-value)    while [ -n "$2" ] && [ "${2:0:1}" != "-" ]; do
                                shift
                                [ "$ExtraValue" != "" ] && ExtraValue="$ExtraValue "
                                ExtraValue="$ExtraValue$1"
                            done;;
        -le|--no-last-err)    LastErrors="0";;
        *) echo "Invalid option: $1. Use -h for help";;
        esac
        shift;
    done
    case "$ColorMode" in
        c)    NormalColor="\e[0m"
            MachineColor="\e[0;33m"
            ValueColor="\e[1;36m"
            AddrColor="\e[1;31m"
            RXTXColor="\e[2;32m"
            ErrorColor="\e[0;31m";;
        c2)    NormalColor="\e[0m"
            MachineColor="\e[0;31m"
            ValueColor="\e[0;33m"
            AddrColor="\e[0;35m"
            RXTXColor="\e[0;36m"
            ErrorColor="\e[0;31m";;
        m)    NormalColor="\e[0m"
            MachineColor="\e[7m"
            ValueColor="\e[1m"
            AddrColor="\e[4m"
            RXTXColor="\e[1m"
            ErrorColor="\e[4";;
        *)    ;;
    esac
    ([ "$Width" == "" ] || [ "$Width" -lt 60 ]) && Width=60
    local i
    for i in $(seq $(expr $Width + 4 )); do 
        Rouler="$Rouler-";
    done
}

human_readable() { # <Number of bytes>
    if [ $1 -gt 0 ]; then
        printf "$(awk -v n=$1 'BEGIN{for(i=split("B KB MB GB TB PB",suffix);s<1;i--)s=n/(2**(10*i));printf (int(s)==s)?"%.0f%s":"%.1f%s",s,suffix[i+2]}')"
    else
        printf "0B"
    fi
}

device_rx_tx() { # <Device>
    local RXTX=$(awk -v Device=$1 '$1==Device ":"{printf "%.0f\t%.0f",$2,$10}' /proc/net/dev)
    [ "$RXTX" != "" ] && printf ", rx/tx: $RXTXColor$(human_readable $(echo "$RXTX" | cut -f 1))$NormalColor/$RXTXColor$(human_readable $(echo "$RXTX" | cut -f 2))$NormalColor"
}

uptime_str() { # <Time in Seconds>
    local Uptime=$1
    if [ $Uptime -gt 0 ]; then
        local Days=$(expr $Uptime / 60 / 60 / 24)
        local Hours=$(expr $Uptime / 60 / 60 % 24)
        local Minutes=$(expr $Uptime / 60 % 60)
        local Seconds=$(expr $Uptime % 60)
        if [ $Days -gt 0 ]; then
            Days=$(printf "%dd " $Days)
        else
            Days=""
        fi
        printf "$Days%02d:%02d:%02d" $Hours $Minutes $Seconds
    fi
}

print_line() { # <String to Print>, [[<String to Print>] ...]
    local Line="$@"
    printf " | %-${Width}s |\r | $Line\n"
}

print_horizontal_ruler() {
    printf " $Rouler\n"
}

print_machine() {
    local Machine=""
    local HostName=$(uci -q get system.@system[0].hostname)
    [ -e /tmp/sysinfo/model ] && Machine=$(cat /tmp/sysinfo/model)
    print_line     "Machine: $MachineColor${Machine:-n/a}$NormalColor,"\
                "Name: $MachineColor${HostName:-n/a}$NormalColor"
}

print_times() {
    local SysUptime=$(cut -d. -f1 /proc/uptime)
    local Uptime=$(uptime_str $SysUptime)
    local Now=$(date +'%Y-%m-%d %H:%M:%S')
    print_line     "System uptime: $ValueColor$Uptime$NormalColor,"\
                "Now: $ValueColor$Now$NormalColor"
}

print_loadavg() {
    local LoadAvg=$(awk '{printf"'$ValueColor'%s'$NormalColor', '$ValueColor'%s'$NormalColor', '$ValueColor'%s'$NormalColor'",$1,$2,$3}' /proc/loadavg)
    print_line "System load: $LoadAvg"
}

print_flash() {
    local Flash=$(df -k /overlay | awk '/overlay/{printf "%.0f\t%.0f\t%.1f\t%.0f",$2*1024,$3*1024,($2>0)?$3/$2*100:0,$4*1024}')
    local Total=$(echo "$Flash" | cut -f 1)
    local Used=$(echo "$Flash" | cut -f 2)
    local UsedPercent=$(echo "$Flash" | cut -f 3)
    local Free=$(echo "$Flash" | cut -f 4)
    print_line     "Flash:"\
                "total: $ValueColor$(human_readable $Total)$NormalColor,"\
                "used: $ValueColor$(human_readable $Used)$NormalColor, $ValueColor$UsedPercent$NormalColor%%,"\
                "free: $ValueColor$(human_readable $Free)$NormalColor"
}

print_memory() {
    local Memory=$(awk 'BEGIN{Total=0;Free=0}$1~/^MemTotal:/{Total=$2}$1~/^MemFree:|^Buffers:|^Cached:/{Free+=$2}END{Used=Total-Free;printf"%.0f\t%.0f\t%.1f\t%.0f",Total*1024,Used*1024,(Total>0)?((Used/Total)*100):0,Free*1024}' /proc/meminfo)
    local Total=$(echo "$Memory" | cut -f 1)
    local Used=$(echo "$Memory" | cut -f 2)
    local UsedPercent=$(echo "$Memory" | cut -f 3)
    local Free=$(echo "$Memory" | cut -f 4)
    print_line "Memory:"\
                "total: $ValueColor$(human_readable $Total)$NormalColor,"\
                "used: $ValueColor$(human_readable $Used)$NormalColor, $ValueColor$UsedPercent$NormalColor%%,"\
                "free: $ValueColor$(human_readable $Free)$NormalColor"
}

print_wan() {
    local Zone
    local Device
    for Zone in $(uci -q show firewall | grep .masq= | cut -f2 -d.); do
        if [ "$(uci -q get firewall.$Zone.masq)" == "1" ]; then
            for Device in $(uci -q get firewall.$Zone.network); do
                local Status="$(ubus call network.interface.$Device status 2>/dev/null)"
                if [ "$Status" != "" ]; then
                    local State=""
                    local Iface=""
                    local Uptime=""
                    local IP4=""
                    local IP6=""
                    local Subnet4=""
                    local Subnet6=""
                    local Gateway4=""
                    local Gateway6=""
                    local DNS=""
                    local Protocol=""
                    json_load "${Status:-{}}"
                    json_get_var State up
                    json_get_var Uptime uptime
                    json_get_var Iface l3_device
                    json_get_var Protocol proto
                    if json_get_type Status ipv4_address && [ "$Status" = array ]; then
                        json_select ipv4_address
                        json_get_type Status 1
                        if [ "$Status" = object ]; then
                            json_select 1
                            json_get_var IP4 address
                            json_get_var Subnet4 mask
                            [ "$IP4" != "" ] && [ "$Subnet4" != "" ] && IP4="$IP4/$Subnet4"
                        fi
                    fi
                    json_select
                    if json_get_type Status ipv6_address && [ "$Status" = array ]; then
                        json_select ipv6_address
                        json_get_type Status 1
                        if [ "$Status" = object ]; then
                            json_select 1
                            json_get_var IP6 address
                            json_get_var Subnet6 mask
                            [ "$IP6" != "" ] && [ "$Subnet6" != "" ] && IP6="$IP6/$Subnet6"
                        fi
                    fi
                    json_select
                    if json_get_type Status route && [ "$Status" = array ]; then
                        json_select route
                        local Index="1"
                        while json_get_type Status $Index && [ "$Status" = object ]; do
                            json_select "$((Index++))"
                            json_get_var Status target
                            case "$Status" in
                                0.0.0.0)
                                    json_get_var Gateway4 nexthop;;
                                ::)
                                    json_get_var Gateway6 nexthop;;
                            esac
                            json_select ".."
                        done    
                    fi
                    json_select
                    if json_get_type Status dns_server && [ "$Status" = array ]; then
                        json_select dns_server
                        local Index="1"
                        while json_get_type Status $Index && [ "$Status" = string ]; do
                            json_get_var Status "$((Index++))"
                            DNS="${DNS:+$DNS }$Status"
                        done
                    fi
                    if [ "$State" == "1" ]; then
                        [ "$IP4" != "" ] && print_line     "WAN: $AddrColor$IP4$NormalColor($Iface),"\
                                                        "gateway: $AddrColor${Gateway4:-n/a}$NormalColor"
                        [ "$IP6" != "" ] && print_line    "WAN: $AddrColor$IP6$NormalColor($Iface),"\
                                                        "gateway: $AddrColor${Gateway6:-n/a}$NormalColor"
                        print_line    "proto: $ValueColor${Protocol:-n/a}$NormalColor,"\
                                    "uptime: $ValueColor$(uptime_str $Uptime)$NormalColor$(device_rx_tx $Iface)"
                        [ "$DNS" != "" ] && print_line "dns: $AddrColor$DNS$NormalColor"
                    fi
                fi
            done
        fi 
    done
}

print_lan() {
    local Zone
    local Device
    for Zone in $(uci -q show firewall | grep []]=zone | cut -f2 -d. | cut -f1 -d=); do
        if [ "$(uci -q get firewall.$Zone.masq)" != "1" ]; then
            for Device in $(uci -q get firewall.$Zone.network); do
                local Status="$(ubus call network.interface.$Device status 2>/dev/null)"
                if [ "$Status" != "" ]; then
                    local State=""
                    local Iface=""
                    local IP4=""
                    local IP6=""
                    local Subnet4=""
                    local Subnet6=""
                    json_load "${Status:-{}}"
                    json_get_var State up
                    json_get_var Iface device
                    if json_get_type Status ipv4_address && [ "$Status" = array ]; then
                        json_select ipv4_address
                        json_get_type Status 1
                        if [ "$Status" = object ]; then
                            json_select 1
                            json_get_var IP4 address
                            json_get_var Subnet4 mask
                            [ "$IP4" != "" ] && [ "$Subnet4" != "" ] && IP4="$IP4/$Subnet4"
                        fi
                    fi
                    json_select
                    if json_get_type Status ipv6_address && [ "$Status" = array ]; then
                        json_select ipv6_address
                        json_get_type Status 1
                        if [ "$Status" = object ]; then
                            json_select 1
                            json_get_var IP6 address
                            json_get_var Subnet6 mask
                            [ "$IP6" != "" ] && [ "$Subnet6" != "" ] && IP6="$IP6/$Subnet6"
                        fi
                    fi
                    local DHCPConfig=$(uci -q show dhcp | grep .interface=$Device | cut -d. -f2)
                    if [ "$DHCPConfig" != "" ] && [ "$(uci -q get dhcp.$DHCPConfig.ignore)" != "1" ]; then
                        local DHCPStart=$(uci -q get dhcp.$DHCPConfig.start)
                        local DHCPLimit=$(uci -q get dhcp.$DHCPConfig.limit)
                        [ "$DHCPStart" != "" ] && [ "$DHCPLimit" != "" ] && DHCP="$(echo $IP4 | cut -d. -f1-3).$DHCPStart-$(expr $DHCPStart + $DHCPLimit - 1)"
                    fi
                    [ "$IP4" != "" ] && print_line "LAN: $AddrColor$IP4$NormalColor($Iface), dhcp: $AddrColor${DHCP:-n/a}$NormalColor"
                    [ "$IP6" != "" ] && print_line "LAN: $AddrColor$IP6$NormalColor($Iface)"
                fi
            done
        fi 
    done
}

print_wlan() {
    local Iface
    for Iface in $(uci -q show wireless | grep device=radio | cut -f2 -d.); do
        local Device=$(uci -q get wireless.$Iface.device)
        local SSID=$(uci -q get wireless.$Iface.ssid)
        local IfaceDisabled=$(uci -q get wireless.$Iface.disabled)
        local DeviceDisabled=$(uci -q get wireless.$Device.disabled)
        if [ -n "$SSID" ] && [ "$IfaceDisabled" != "1" ] && [ "$DeviceDisabled" != "1" ]; then
            local Mode=$(uci -q -P /var/state get wireless.$Iface.mode)
            local Channel=$(uci -q get wireless.$Device.channel)
            local RadioIface=$(uci -q -P /var/state get wireless.$Iface.ifname)
            local Connection="Down"
            if [ -n "$RadioIface" ]; then
                if [ "$Mode" == "ap" ]; then
                    Connection="$(iw dev $RadioIface station dump | grep Station | wc -l)"
                else
                    Connection="$(iw dev $RadioIface link | awk 'BEGIN{FS=": ";Signal="";Bitrate=""} $1~/signal/ {Signal=$2} $1~/tx bitrate/ {Bitrate=$2}END{print Signal" "Bitrate}')"
                fi
            fi
            if [ "$Mode" == "ap" ]; then
                print_line    "WLAN: $ValueColor$SSID$NormalColor($Mode),"\
                            "ch: $ValueColor${Channel:-n/a}$NormalColor,"\
                            "conn: $ValueColor$Connection$NormalColor$(device_rx_tx $RadioIface)"
            else
                print_line    "WLAN: $ValueColor$SSID$NormalColor($Mode),"\
                            "ch: $ValueColor${Channel:-n/a}$NormalColor"
                print_line    "conn: $ValueColor$Connection$NormalColor$(device_rx_tx $RadioIface)"
            fi
        fi
    done
}

print_vpn() {
    local VPN
    for VPN in $(uci -q show openvpn | grep .ca= | cut -f2 -d.); do
        local Device=$(uci -q get openvpn.$VPN.dev)
        local Enabled=$(uci -q get openvpn.$VPN.enabled)
        if [ "$Enabled" == "1" ] || [ "$Enabled" == "" ]; then
            local Mode=$(uci -q get openvpn.$VPN.mode)
            local Connection="n/a"
            if [ "$Mode" == "server" ]; then
                Mode="$ValueColor$VPN$NormalColor(svr):$(uci -q get openvpn.$VPN.port)"
                Status=$(uci -q get openvpn.$VPN.status)
                Connection=$(awk 'BEGIN{FS=",";c=0;l=0}{if($1=="Common Name")l=1;else if($1=="ROUTING TABLE")exit;else if (l==1) c=c+1}END{print c}' $Status)
            else
                Mode="$ValueColor$VPN$NormalColor(cli)"
                Connection="Down"
                ifconfig $Device &>/dev/null && Connection="Up"
            fi
            print_line    "VPN: $Mode,"\
                        "conn: $ValueColor$Connection$NormalColor$(device_rx_tx $Device)"
        fi
    done
}

print_extra() {
    ([ "$ExtraName" != "" ] || [ "$ExtraValue" != "" ]) && print_line "$ExtraName $ValueColor$ExtraValue$NormalColor"
}

print_error() {
    logread | awk '/\w{3}+\.(err|warn|alert|emerg|crit)/{err[++i]=$0}END{j=i-4;j=j>=1?j:1;while(j<=i)print" '$ErrorColor'"err[j++]"'$NormalColor'"}'
}

initialize $@
[ "$StartRuler" == "1" ] && print_horizontal_ruler
print_machine
print_times
print_loadavg
print_flash
print_memory
print_wan
print_lan
print_wlan
print_vpn
print_extra
[ "$EndRuler" == "1" ] && print_horizontal_ruler
[ "$LastErrors" == "1" ] && print_error
exit 0
# Done.

171

(206 odpowiedzi, napisanych Oprogramowanie / Software)

To jest:

#!/bin/sh
#
# sysinfo.sh dla OpenWRT AA Cezary Jackiewicz 2013
# 
#    1.00    CJ    Pierwsza wersja kodu
#    1.01    RD    Drobna przebudowa
#    1.02    RD    Korekta błędu wyśw. zajetości Flash-a, dodanie kolorów
#    1.03    RD    Dodanie nazwy routera, zmiana formatowania
#    1.04    RD    Kosmetyka, sugestie @mikhnal. Zmiana przetwarzania info. o wan.
#    1.05    RD    Zmiana algorytmu pobierania danych dla wan i lan
#    1.06    RD    Parametryzacja kolorów i pojawiania się podkreśleń
#    1.07    RD    Modyfikacja związana z poprawnym wyświetlaniem interfejsu dla prot.3g
#    1.08    RD    Modyfikacja wyświetlania DNS-ów dla wan, dodanie uptime dla interfejsów
#    1.09    RD    Dodanie statusu "Down" dla wyłączonego wifi, zmiana wyświetlania dla WLAN(sta)
#    1.10    RD    Korekta wyświetlania dla WLAN(sta)
#    1.11    RD    Korekta wyświetlania stanu pamięci, sugestie @dopsz 
#    1.12    RD    Zmiana kolejności wyświetlania wartości stanu pamięci + kosmetyka 
#
# Destination /sbin/sysinfo.sh
#
. /usr/share/libubox/jshn.sh

local Width=60
local StartRuler="1"
local EndRuler="1"
local Rouler
local NormalColor
local MachineColor
local ValueColor
local AddrColor
local RXTXColor

initialize() { # <Script Parameters>
    local ColorMode="1"
    for Parameter in $@; do
        case  $Parameter  in
        -m) ColorMode="0";;
        -sr) StartRuler="0";;
        -er) EndRuler="0";;
        -w1) Width=80;;
        -w2) Width=100;;
        -w3) Width=120;;
        -h|*)    
            echo "Usage: $0 - [parameter]"
            echo "    -h    : This help."
            echo "    -m    : Display mono version."
            echo "    -sr    : Without start horizontal ruler."    
            echo "    -er    : Without end horizontal ruler."    
            exit 1;;
        esac
    done
    if [ "$ColorMode" == "1" ]; then
        NormalColor="\e[0m"
        MachineColor="\e[0;33m"
        ValueColor="\e[1;36m"
        AddrColor="\e[1;31m"
        RXTXColor="\e[2;32m"
    else
        NormalColor="\e[0m"
        MachineColor="\e[7m"
        ValueColor="\e[1m"
        AddrColor="\e[4m"
        RXTXColor="\e[1m"
    fi
    local i
    for i in $(seq $(expr $Width + 4 )); do 
        Rouler="$Rouler-";
    done
}

human_readable() { # <Number of bytes>
    if [ $1 -gt 0 ]; then
        printf "$(awk -v n=$1 'BEGIN{for(i=split("B KB MB GB TB PB",suffix);s<1;i--)s=n/(2**(10*i));printf (int(s)==s)?"%.0f%s":"%.1f%s",s,suffix[i+2]}')"
    else
        printf "0B"
    fi
}

device_rx_tx() { # <Device>
    local RXTX=$(awk -v Device=$1 '$1==Device ":"{printf "%.0f\t%.0f",$2,$10}' /proc/net/dev)
    [ "$RXTX" != "" ] && printf ", rx/tx: $RXTXColor$(human_readable $(echo "$RXTX" | cut -f 1))$NormalColor/$RXTXColor$(human_readable $(echo "$RXTX" | cut -f 2))$NormalColor"
}

uptime_str() { # <Time in Seconds>
    local Uptime=$1
    if [ $Uptime -gt 0 ]; then
        local Days=$(expr $Uptime / 60 / 60 / 24)
        local Hours=$(expr $Uptime / 60 / 60 % 24)
        local Minutes=$(expr $Uptime / 60 % 60)
        local Seconds=$(expr $Uptime % 60)
        if [ $Days -gt 0 ]; then
            Days=$(printf "%dd " $Days)
        else
            Days=""
        fi
        printf "$Days%02d:%02d:%02d" $Hours $Minutes $Seconds
    fi
}

print_line() { # <String to Print>, [[<String to Print>] ...]
    local Line="$@"
    printf " | %-${Width}s |\r | $Line\n"
}

print_horizontal_ruler() {
    printf " $Rouler\n"
}

print_machine() {
    local Machine=""
    local HostName=$(uci -q get system.@system[0].hostname)
    [ -e /tmp/sysinfo/model ] && Machine=$(cat /tmp/sysinfo/model)
    print_line     "Machine: $MachineColor${Machine:-n/a}$NormalColor,"\
                "Name: $MachineColor${HostName:-n/a}$NormalColor"
}

print_times() {
    local SysUptime=$(cut -d. -f1 /proc/uptime)
    local Uptime=$(uptime_str $SysUptime)
    local Now=$(date +'%Y-%m-%d %H:%M:%S')
    print_line     "System uptime: $ValueColor$Uptime$NormalColor,"\
                "Now: $ValueColor$Now$NormalColor"
}

print_loadavg() {
    local LoadAvg=$(awk '{printf"'$ValueColor'%s'$NormalColor', '$ValueColor'%s'$NormalColor', '$ValueColor'%s'$NormalColor'",$1,$2,$3}' /proc/loadavg)
    print_line "System load: $LoadAvg"
}

print_flash() {
    local Flash=$(df -k /overlay | awk '/overlay/{printf "%.0f\t%.0f\t%.1f\t%.0f",$2*1024,$3*1024,($2>0)?$3/$2*100:0,$4*1024}')
    local Total=$(echo "$Flash" | cut -f 1)
    local Used=$(echo "$Flash" | cut -f 2)
    local UsedPercent=$(echo "$Flash" | cut -f 3)
    local Free=$(echo "$Flash" | cut -f 4)
    print_line     "Flash:"\
                "total: $ValueColor$(human_readable $Total)$NormalColor,"\
                "used: $ValueColor$(human_readable $Used)$NormalColor, $ValueColor$UsedPercent$NormalColor%%,"\
                "free: $ValueColor$(human_readable $Free)$NormalColor"
}

print_memory() {
    local Memory=$(awk 'BEGIN{Total=0;Free=0}$1~/^MemTotal:/{Total=$2}$1~/^MemFree:|^Buffers:|^Cached:/{Free+=$2}END{Used=Total-Free;printf"%.0f\t%.0f\t%.1f\t%.0f",Total*1024,Used*1024,(Total>0)?((Used/Total)*100):0,Free*1024}' /proc/meminfo)
    local Total=$(echo "$Memory" | cut -f 1)
    local Used=$(echo "$Memory" | cut -f 2)
    local UsedPercent=$(echo "$Memory" | cut -f 3)
    local Free=$(echo "$Memory" | cut -f 4)
    print_line "Memory:"\
                "total: $ValueColor$(human_readable $Total)$NormalColor,"\
                "used: $ValueColor$(human_readable $Used)$NormalColor, $ValueColor$UsedPercent$NormalColor%%,"\
                "free: $ValueColor$(human_readable $Free)$NormalColor"
}

print_wan() {
    local Zone
    local Device
    for Zone in $(uci -q show firewall | grep .masq= | cut -f2 -d.); do
        for Device in $(uci -q get firewall.$Zone.network); do
            local Status="$(ubus call network.interface.$Device status 2>/dev/null)"
            if [ "$Status" != "" ]; then
                local State=""
                local Iface=""
                local Uptime=""
                local IP4=""
                local IP6=""
                local Subnet4=""
                local Subnet6=""
                local Gateway4=""
                local Gateway6=""
                local DNS=""
                local Protocol=""
                json_load "${Status:-{}}"
                json_get_var State up
                json_get_var Uptime uptime
                json_get_var Iface l3_device
                json_get_var Protocol proto
                if json_get_type Status ipv4_address && [ "$Status" = array ]; then
                    json_select ipv4_address
                    json_get_type Status 1
                    if [ "$Status" = object ]; then
                        json_select 1
                        json_get_var IP4 address
                        json_get_var Subnet4 mask
                        [ "$IP4" != "" ] && [ "$Subnet4" != "" ] && IP4="$IP4/$Subnet4"
                    fi
                fi
                json_select
                if json_get_type Status ipv6_address && [ "$Status" = array ]; then
                    json_select ipv6_address
                    json_get_type Status 1
                    if [ "$Status" = object ]; then
                        json_select 1
                        json_get_var IP6 address
                        json_get_var Subnet6 mask
                        [ "$IP6" != "" ] && [ "$Subnet6" != "" ] && IP6="$IP6/$Subnet6"
                    fi
                fi
                json_select
                if json_get_type Status route && [ "$Status" = array ]; then
                    json_select route
                    local Index="1"
                    while json_get_type Status $Index && [ "$Status" = object ]; do
                        json_select "$((Index++))"
                        json_get_var Status target
                        case "$Status" in
                            0.0.0.0)
                                json_get_var Gateway4 nexthop;;
                            ::)
                                json_get_var Gateway6 nexthop;;
                        esac
                        json_select ".."
                    done    
                fi
                json_select
                if json_get_type Status dns_server && [ "$Status" = array ]; then
                    json_select dns_server
                    local Index="1"
                    while json_get_type Status $Index && [ "$Status" = string ]; do
                        json_get_var Status "$((Index++))"
                        DNS="${DNS:+$DNS }$Status"
                    done
                fi
                if [ "$State" == "1" ]; then
                    [ "$IP4" != "" ] && print_line     "WAN: $AddrColor$IP4$NormalColor($Iface),"\
                                                    "gateway: $AddrColor${Gateway4:-n/a}$NormalColor"
                    [ "$IP6" != "" ] && print_line    "WAN: $AddrColor$IP6$NormalColor($Iface),"\
                                                    "gateway: $AddrColor${Gateway6:-n/a}$NormalColor"
                    print_line    "proto: $ValueColor${Protocol:-n/a}$NormalColor,"\
                                "uptime: $ValueColor$(uptime_str $Uptime)$NormalColor$(device_rx_tx $Iface)"
                    [ "$DNS" != "" ] && print_line "dns: $AddrColor$DNS$NormalColor"
                fi
            fi
        done
    done
}

print_lan() {
    local Device="lan"
    local State
    local Iface
    local IP4
    local IP6
    local Subnet4
    local Subnet6
    local Status="$(ubus call network.interface.$Device status 2>/dev/null)"
    if [ "$Status" != "" ]; then
        json_load "${Status:-{}}"
        json_get_var State up
        json_get_var Iface device
        if json_get_type Status ipv4_address && [ "$Status" = array ]; then
            json_select ipv4_address
            json_get_type Status 1
            if [ "$Status" = object ]; then
                json_select 1
                json_get_var IP4 address
                json_get_var Subnet4 mask
                [ "$IP4" != "" ] && [ "$Subnet4" != "" ] && IP4="$IP4/$Subnet4"
            fi
        fi
        json_select
        if json_get_type Status ipv6_address && [ "$Status" = array ]; then
            json_select ipv6_address
            json_get_type Status 1
            if [ "$Status" = object ]; then
                json_select 1
                json_get_var IP6 address
                json_get_var Subnet6 mask
                [ "$IP6" != "" ] && [ "$Subnet6" != "" ] && IP6="$IP6/$Subnet6"
            fi
        fi
        [ "$IP4" != "" ] && print_line "LAN: $AddrColor$IP4$NormalColor"
        [ "$IP6" != "" ] && print_line "LAN: $AddrColor$IP6$NormalColor"
    fi
}

print_wlan() {
    local Iface
    for Iface in $(uci -q show wireless | grep device=radio | cut -f2 -d.); do
        local Device=$(uci -q get wireless.$Iface.device)
        local SSID=$(uci -q get wireless.$Iface.ssid)
        local IfaceDisabled=$(uci -q get wireless.$Iface.disabled)
        local DeviceDisabled=$(uci -q get wireless.$Device.disabled)
        if [ -n "$SSID" ] && [ "$IfaceDisabled" != "1" ] && [ "$DeviceDisabled" != "1" ]; then
            local Mode=$(uci -q -P /var/state get wireless.$Iface.mode)
            local Channel=$(uci -q get wireless.$Device.channel)
            local RadioIface=$(uci -q -P /var/state get wireless.$Iface.ifname)
            local Connection="Down"
            if [ -n "$RadioIface" ]; then
                if [ "$Mode" == "ap" ]; then
                    Connection="$(iw dev $RadioIface station dump | grep Station | wc -l)"
                else
                    Connection="$(iw dev $RadioIface link | awk 'BEGIN{FS=": ";Signal="";Bitrate=""} $1~/signal/ {Signal=$2} $1~/tx bitrate/ {Bitrate=$2}END{print Signal" "Bitrate}')"
                fi
            fi
            if [ "$Mode" == "ap" ]; then
                print_line    "WLAN: $ValueColor$SSID$NormalColor($Mode),"\
                            "ch: $ValueColor${Channel:-n/a}$NormalColor,"\
                            "conn: $ValueColor$Connection$NormalColor$(device_rx_tx $RadioIface)"
            else
                print_line    "WLAN: $ValueColor$SSID$NormalColor($Mode),"\
                            "ch: $ValueColor${Channel:-n/a}$NormalColor"
                print_line    "conn: $ValueColor$Connection$NormalColor$(device_rx_tx $RadioIface)"
            fi
        fi
    done
}

print_vpn() {
    local VPN
    for VPN in $(uci -q show openvpn | grep .ca= | cut -f2 -d.); do
        local Device=$(uci -q get openvpn.$VPN.dev)
        local Enabled=$(uci -q get openvpn.$VPN.enabled)
        if [ "$Enabled" == "1" ] || [ "$Enabled" == "" ]; then
            local Mode=$(uci -q get openvpn.$VPN.mode)
            local Connection="n/a"
            if [ "$Mode" == "server" ]; then
                Mode="$ValueColor$VPN$NormalColor(svr):$(uci -q get openvpn.$VPN.port)"
                Status=$(uci -q get openvpn.$VPN.status)
                Connection=$(awk 'BEGIN{FS=",";c=0;l=0}{if($1=="Common Name")l=1;else if($1=="ROUTING TABLE")exit;else if (l==1) c=c+1}END{print c}' $Status)
            else
                Mode="$ValueColor$VPN$NormalColor(cli)"
                Connection="Down"
                ifconfig $Device &>/dev/null && Connection="Up"
            fi
            print_line    "VPN: $Mode,"\
                        "conn: $ValueColor$Connection$NormalColor$(device_rx_tx $Device)"
        fi
    done
}

initialize $@
[ "$StartRuler" == "1" ] && print_horizontal_ruler
print_machine
print_times
print_loadavg
print_flash
print_memory
print_wan
print_lan
print_wlan
print_vpn
[ "$EndRuler" == "1" ] && print_horizontal_ruler
exit 0
# Done.

172

(206 odpowiedzi, napisanych Oprogramowanie / Software)

To prawda,  ale jak nikt nic nie chce wiecej;-)
Czas na fontanny i wodotryski...
A tak naprawdę to przyzwyczajenia do kolumn w df robią swoje.

173

(206 odpowiedzi, napisanych Oprogramowanie / Software)

Co myślicie o tym żeby stan Flash i Memory zrobić w kolejności podobnej jak w df?
Teraz w sysinfo.sh jest tak:

 ----------------------------------------------------------------
 | Machine: TP-Link TL-WDR4900 v1, Name: Router-Domowy          |
 | Uptime: 01:51:12, Now: 2013-06-12 20:51:33                   |
 | Load: 0.01, 0.07, 0.11                                       |
 | Flash: free: 2.1MB, total: 4.7MB, used: 56.2%                |
 | Memory: free: 103.4MB, total: 123.7MB, used: 16.4%           |
 | WAN: 123.123.123.123/22(eth0.2), gateway: 123.123.123.123    |
 | proto: dhcp, uptime: 01:50:25, rx/tx: 2.1MB/1.4MB            |
 | dns: 8.8.8.8 8.8.4.4 8.8.6.6 8.8.2.2                         |
 | LAN: 192.168.1.1/24                                          |
 | WLAN: Domowa1(ap), ch: 9, conn: 0, rx/tx: 0B/396.3KB         |
 | WLAN: Domowa2(ap), ch: 44, conn: 0, rx/tx: 0B/396.3KB        |
 | VPN: Domowy(svr):1234, conn: 1, rx/tx: 403.8KB/383.1KB       |
 | VPN: Domowy2(svr):345, conn: 1, rx/tx: 241.3KB/278.8KB       |
 ----------------------------------------------------------------

a df
pokazuje w takiej kolejności:

df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                    4.7M      2.6M      2.1M  56% /
/dev/root                 2.3M      2.3M         0 100% /rom
tmpfs                    61.8M    604.0K     61.3M   1% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev
/dev/mtdblock3            4.7M      2.6M      2.1M  56% /overlay
overlayfs:/overlay        4.7M      2.6M      2.1M  56% /

gdyby było tak

 ----------------------------------------------------------------
 . . .
 | Flash: total: 4.7MB, used: 56.2%, free: 2.1MB                |
 | Memory: total: 123.7MB, used: 16.4%, free: 103.4MB           |
 . . .
 ----------------------------------------------------------------

co Wy na to?

174

(37 odpowiedzi, napisanych Oprogramowanie / Software)

Witam,
nie wiem czy Tobie pomogę, ale miałem podobny problem z częstymi aktualizacjami. Tyle że oprócz aktualizacji firmware i pakietów chciałem to wszystko robić zdalnie na routerach które są daleko ode mnie.
Zależało mi na przeprowadzeniu tego procesu automatycznie i bezboleśnie, bez potrzeby „podejścia” do routera.

Zrobiłem skrypt który wykonuje jedną z trzech operacji:

  • download – pobranie pakietów i firmware-u od katalogu

  • install – instalacja pakietów z ich wyłączeniem i włączeniem + kopia zapasowa przed i przywrócenie konfiguracji po

  • sysupgrade – w skrócie aktualizacjia firmwar-u i instalacja pakietów + kopia zapasowa przed i przywrócenie konfiguracji po

  • backup – kopia konfiguracji

Mały help: install.sh –h

Usage:
    /sbin/install.sh [install|download|sysupgrade] [-h|--help] [-o|--online] [-b|--backup-off] [-i|--exclude-installed]

Commands:
    download    download all packages and system image do install directory.
    install        backup configuration,
                stop and disable packages,
                install packages,
                restore configuration,
                enable and start packages.
    sysupgrade    backup configuration,
                download all packages and system image do install directory (in off-line mode),
                prepare post upgrade package installer,
                system upgrade,
                ... reboot system ...,
                if extroot exist, clean check sum and reboot system,
                install packages,
                restore configuration,
                cleanup installation,
                ... reboot system ...
    backup    backup configuration,

Options:
    -h            This help,
    -b            Disable configuration backup and restore during installation or system upgrade process.
                By default, backup and restore configuration are enabled.
                Path to backup have to on external device otherwise during system upgrade can be lost.
    -o            Online packages installation by post-installer.
                Internet connection is needed after system restart and before packages installation.
    -i            Exclude installed packages. Only packages from configuration can be processed.

Current configuration:
    Local install directory : '/install'
    Configuration backup direcory : '/backup'
    Image source URL : 'http://ecco.selfip.net/<CODENAME> … pgrade.bin'
    Packages: 'nfs-utils kmod-fs-nfs libusb kmod-usb-serial-option kmod-usb-net-cdc-ether '

Przykładowa konfiguracja systemu w /etc/config/system

config sysupgrade
    option localinstall '/install'
    option backupconfig '/backup'
    option imagesource 'http://ecco.selfip.net/<CODENAME>/<TARGET>/openwrt-<TARGET>-<SUBTARGET>-<HARDWARE>-squashfs-sysupgrade.bin'
    list opkg libusb
    list opkg kmod-usb-serial-option
    list opkg kmod-usb-net-cdc-ether

Definiujesz sobie w pliku /etc/config/system jak wyżej parametry oraz pakiety, które mają się zainstalować, a skrypt robi resztę.

Zmienne użyte w imagesource to:

  • <CODENAME> nazwa gałęzi kodu (ex. "attitude_adjustment")

  • <TARGET> platforma (ex. "ar71xx")

  • <SUBTARGET> sub-wersja platformy (ex. "generic")

  • <HARDWARE> sprzętu z wersją (ex. "tl-wdr4300-v1")

Ten skrypt + zapisy w pliku /etc/sysupgrade.conf to lekarstwo na przeniesienie konfiguracji podczas aktualizacji systemu.

Założyłem w moim przypadku, że mam dwa katalogi automatycznie podmontowane z pendrive-a /backup i /install. Umożliwiają one przechowanie kopii zapasowych konfiguracji a drugi plików instalacyjnych bez ich utraty podczas procesu aktualizacji.
Oczywiście skrypt może obejść się bez nich, podczas aktualizacji systemu, ale wtedy rezygnuje się z kopii konfiguracji i dodatkowo musi być gwarancja, że po restarcie routera a przed instalacją pakietów będzie dostępny Internet, z którego proces instalacyjny pobierze potrzebne pakiety (jeżeli Internet to połączenie 3G a do niego potrzebna jest instalacja jakiegoś pakiet, to odpada).

To skrypt, który powinien trafić do pliku /sbin/install.sh

#!/bin/sh
# Install or download packages and/or sysupgrade.
# Script version 1.34 Rafal Drzymala 2013-2014
#
# Changelog
#
#    1.00    RD    First stable code
#    1.04    RD    Change code sequence
#    1.05    RD    Code tune up
#    1.06    RD    Code tune up
#    1.07    RD    ExtRoot code improvements
#    1.08    RD    Add image check sum control
#    1.09    RD    Add command line switch on/off-line package post-install
#                Add command line switch to disable configuration backup 
#    1.10    RD    Preparation scripts code improvements
#    1.11    RD    Preparation scripts code improvements (2)
#    1.12    RD    Preparation scripts code improvements (3)
#    1.13    RD    Preparation scripts code improvements (4)
#    1.14    RD    Extroot scripts code improvements
#    1.15    RD    Help improvements
#    1.16    RD    Help improvements (2), Preparation scripts code improvements (5)
#    1.17    RD    Extroot scripts code improvements (2)
#    1.18    RD    Include installed packages options
#    1.19    RD    Extroot scripts code improvements (3)
#    1.20    RD    Add status led toggle
#    1.21    RD    Correct rc.local manipulation code
#    1.22    RD    Add packages disabling to sysupgrade process
#                Preparation scripts code improvements (5)
#    1.23    RD    Extroot scripts code improvements
#    1.24    RD    Added recurrence of checking of package dependences
#                Changed packages initialization script name convention
#    1.25    RD    Preparation scripts code improvements (6)
#    1.26    RD    Preparation scripts code improvements (7)
#    1.27    RD    Code tune up
#    1.28    RD    Code tune up
#    1.29    RD    Dependency check code improvements
#    1.30    RD    Added post install file removing
#                Added external script
#    1.31    RD    Added backup command
#    1.32    RD    Removed I/O control after post install file removing
#    1.33    RD    Added variables to image source path
#    1.34    RD    Added image file and packages files sums calculation
#
# Destination /sbin/install.sh
#
. /etc/openwrt_release

local CMD=""
local OFFLINE_POST_INSTALL="1"
local INCLUDE_INSTALLED="1"
local HOST_NAME=""
local BACKUP_ENABLE="1"
local BACKUP_PATH=""
local BACKUP_FILE=""
local INSTALL_PATH="/tmp"
local PACKAGES=""
local IMAGE_SOURCE=""
local IMAGE_FILENAME="sysupgrade.bin"
local POST_INSTALL_SCRIPT="post-installer"
local POST_INSTALLER="/bin/$POST_INSTALL_SCRIPT.sh"
local POST_INSTALLER_LOG="/usr/$POST_INSTALL_SCRIPT.log"
local INSTALLER_KEEP_FILE="/lib/upgrade/keep.d/$POST_INSTALL_SCRIPT"
local RC_LOCAL="/etc/rc.local"
local POST_INSTALL_REMOVE="/etc/config/*-opkg"
local RUN_SCRIPT=""

check_exit_code() {
    local CODE=$?
    if [ $CODE != 0 ]; then 
        echo "Abort, error ($CODE) detected!"
        exit $CODE
    fi
}

get_mount_device() { # <Path to check>
    local CHECK_PATH=$1
    [ -L $CHECK_PATH ] && CHECK_PATH=$($BIN_LS -l $CHECK_PATH | $BIN_AWK -F " -> " '{print $2}')
    $BIN_AWK -v path="$CHECK_PATH" 'BEGIN{FS=" ";device=""}path~"^"$2{if($2>point){device=$1;point=$2}}END{print device}' /proc/mounts
    check_exit_code
}

which_binary() { # <Name of Binary> [<Name of Binary> [...]]
    while [ -n "$1" ]; do
        local WHICH=$(which $1)
        if [ "$WHICH" == "" ]; then
            echo "Binary $1 not found in system!"
            exit 1
        else
            eval "export -- \"BIN_$(echo $1 | tr '[a-z]' '[A-Z]')=$WHICH\""
        fi
        shift
    done
}

add_to_keep_file() { # <Content to save> <Root path>
    local CONTENT="$1"
    local ROOT_PATH="$2"
    $BIN_ECHO "$1">>$ROOT_PATH$INSTALLER_KEEP_FILE
    check_exit_code
}

run_script() { # <Event>
    if [ "$RUN_SCRIPT" != "" ] && [ -x $RUN_SCRIPT ]; then
        $BIN_ECHO "Run script $RUN_SCRIPT $1 ..."
        $RUN_SCRIPT $1
        check_exit_code
        $BIN_ECHO "Script $RUN_SCRIPT exited."
    fi
}

add_to_post_installer_log() { # <Content to save>
    $BIN_ECHO "$($BIN_DATE) $1">>$POST_INSTALLER_LOG
}

package_script_execute() { # <Package> <Script name> <Command>
    local PACKAGE="$1"
    local SCRIPT="$2"
    local CMD="$3"
    if [ -x $SCRIPT ]; then
        $BIN_ECHO "Executing $SCRIPT $CMD for package $PACKAGE"
        if [ "$CMD" == "enable" ] || [ "$CMD" == "stop" ]; then
            $SCRIPT $CMD
        else
            $SCRIPT $CMD
            check_exit_code
        fi
    fi
}

update_path_vars() { # <String to update>
    local PATH_VARS="$1"
    local TARGET=$(echo "$DISTRIB_TARGET" | cut -d "/" -f 1)
    local SUBTARGET=$(echo "$DISTRIB_TARGET" | cut -d "/" -f 2)
    local BOARD_NAME=$($BIN_CAT /tmp/sysinfo/model | $BIN_TR '[A-Z]' '[a-z]')
    local BOARD_VER=$($BIN_ECHO "$BOARD_NAME" | $BIN_CUT -d " " -f 3)
    BOARD_NAME=$($BIN_ECHO "$BOARD_NAME" | $BIN_CUT -d " " -f 2)
    [ -n "$BOARD_VER" ] && BOARD_NAME="$BOARD_NAME-$BOARD_VER"
    [ -n "$DISTRIB_CODENAME" ] && PATH_VARS=${PATH_VARS//\<CODENAME\>/$DISTRIB_CODENAME}
    [ -n "$TARGET" ] && PATH_VARS=${PATH_VARS//\<TARGET\>/$TARGET}
    [ -n "$SUBTARGET" ] && PATH_VARS=${PATH_VARS//\<SUBTARGET\>/$SUBTARGET}
    [ -n "$BOARD_NAME" ] && PATH_VARS=${PATH_VARS//\<HARDWARE\>/$BOARD_NAME}
    $BIN_ECHO "$PATH_VARS"
}

caution_alert() {
    local KEY
    $BIN_ECHO "Caution!"
    $BIN_ECHO "You can damage the system or hardware. You perform this operation at your own risk."
    read -t 60 -n 1 -p "Press Y to continue " KEY
    $BIN_ECHO ""
    [ "$KEY" != "Y" ] && exit 0
}

print_help() {
    $BIN_ECHO -e "Usage:"\
            "\n\t$0 [install|download|sysupgrade] [-h|--help] [-o|--online] [-b|--backup-off] [-i|--exclude-installed]"\
            "\n\nCommands:"\
            "\n\t\tdownload\tdownload all packages and system image do install directory,"\
            "\n\t\tinstall\t\tbackup configuration,"\
            "\n\t\t\t\tstop and disable packages,"\
            "\n\t\t\t\tinstall packages,"\
            "\n\t\t\t\trestore configuration,"\
            "\n\t\t\t\tenable and start packages."\
            "\n\t\tsysupgrade\tbackup configuration,"\
            "\n\t\t\t\tdownload all packages and system image do install directory (in off-line mode),"\
            "\n\t\t\t\tprepare post upgrade package installer,"\
            "\n\t\t\t\tsystem upgrade,"\
            "\n\t\t\t\t... reboot system ...,"\
            "\n\t\t\t\tif extroot exist, clean check sum and reboot system,"\
            "\n\t\t\t\tinstall packages,"\
            "\n\t\t\t\trestore configuration,"\
            "\n\t\t\t\tcleanup installation,"\
            "\n\t\t\t\t... reboot system ..."\
            "\n\t\tbackup\t\tbackup configuration"\
            "\n\nOptions:"\
            "\n\t\t-h\t\tThis help,"\
            "\n\t\t-b\t\tDisable configuration backup and restore during installation or system upgrade process."\
            "\n\t\t\t\tBy default, backup and restore configuration are enabled."\
            "\n\t\t\t\tPath to backup have to on external device otherwise during system upgrade can be lost."\
            "\n\t\t-o\t\tOnline packages installation by post-installer."\
            "\n\t\t\t\tInternet connection is needed after system restart and before packages installation."\
            "\n\t\t-i\t\tExclude installed packages. Only packages from configuration can be processed."\
            "\n\nCurrent configuration:"\
            "\n\tLocal install directory : '$($BIN_UCI -q get system.@sysupgrade[0].localinstall)'"\
            "\n\tConfiguration backup direcory : '$($BIN_UCI -q get system.@sysupgrade[0].backupconfig)'"\
            "\n\tImage source URL : '$($BIN_UCI -q get system.@sysupgrade[0].imagesource)'"\
            "\n\tRun external script : '$($BIN_UCI -q get system.@sysupgrade[0].runscript)'"\
            "\n\tPackages: '$($BIN_UCI -q get system.@sysupgrade[0].opkg)'"\
            "\n\nExamples configuration in /etc/config/system"\
            "\n\tconfig sysupgrade"\
            "\n\t\toption localinstall '/install'"\
            "\n\t\toption backupconfig '/backup'"\
            "\n\t\toption imagesource 'http://ecco.selfip.net/<CODENAME>/<TARGET>/openwrt-<TARGET>-<SUBTARGET>-<HARDWARE>-squashfs-sysupgrade.bin'"\
            "\n\t\tlist opkg libusb"\
            "\n\t\tlist opkg kmod-usb-serial-option"\
            "\n\t\tlist opkg kmod-usb-net-cdc-ether"\
            "\n"
    exit 0
}

initialize() { # <Script parametrs>
    which_binary echo basename dirname logger chmod uci date ls cat cut tr wc rm mv sync reboot awk grep wget opkg sysupgrade md5sum ping logread gzip
    while [ -n "$1" ]; do
        case "$1" in
            install|download|sysupgrade|backup) CMD="$1";; 
            -h|--help) print_help;;
            -b|--backup-off) BACKUP_ENABLE="";;
            -o|--online) OFFLINE_POST_INSTALL="";;
            -i|--exclude-installed) INCLUDE_INSTALLED="";;
            -*) $BIN_ECHO "Invalid option: $1";print_help;;
            *) $BIN_ECHO "Invalid command: $1";print_help;;
        esac
        shift
    done
    [ "$CMD" == "" ] && CMD=install
    [ "$CMD" == "backup" ] && BACKUP_ENABLE="1"
    HOST_NAME=$($BIN_UCI -q get system.@system[0].hostname)
    if [ "$HOST_NAME" == "" ]; then 
        $BIN_ECHO "Error while getting host name!"
        exit 1
    fi
    if [ "$CMD" == "download" ] || ([ "$CMD" == "sysupgrade" ] && [ "$OFFLINE_POST_INSTALL" != "" ]); then
        INSTALL_PATH=$($BIN_UCI -q get system.@sysupgrade[0].localinstall)
        if [ "$INSTALL_PATH" == "" ]; then
            $BIN_ECHO "Install path is empty!"
            exit 1
        fi    
        if [ ! -d "$INSTALL_PATH" ]; then
            $BIN_ECHO "Install path not exist!"
            exit 1
        fi    
    fi
    if [ "$BACKUP_ENABLE" != "" ]; then
        BACKUP_PATH=$($BIN_UCI -q get system.@sysupgrade[0].backupconfig)
        BACKUP_FILE="$BACKUP_PATH/backup-$HOST_NAME-$($BIN_DATE +%Y-%m-%d-%H-%M-%S).tar.gz"        
        if [ ! -d "$BACKUP_PATH" ]; then
            $BIN_ECHO "Backup path not exist!"
            exit 1
        fi
        local MOUNT_DEVICE=$(get_mount_device $BACKUP_PATH)
        if [ "$MOUNT_DEVICE" == "rootfs" ] || [ "$MOUNT_DEVICE" == "sysfs" ] || [ "$MOUNT_DEVICE" == "tmpfs" ]; then
            $BIN_ECHO "Backup path ($BACKUP_PATH) must be on external device. Now is mounted on $MOUNT_DEVICE."
            exit 1
        fi
    fi
    if [ "$CMD" == "download" ] || [ "$CMD" == "sysupgrade" ]; then
        IMAGE_SOURCE=$($BIN_UCI -q get system.@sysupgrade[0].imagesource)
        local IMAGE_PREFIX=$($BIN_UCI -q get system.@sysupgrade[0].imageprefix)
        local IMAGE_SUFFIX=$($BIN_UCI -q get system.@sysupgrade[0].imagesuffix)
        if [ -n "$IMAGE_PREFIX" ] || [ -n "$IMAGE_SUFFIX" ]; then
            IMAGE_SOURCE="$IMAGE_SOURCE/$IMAGE_PREFIX<HARDWARE>$IMAGE_SUFFIX"
        fi
    fi
    RUN_SCRIPT=$($BIN_UCI -q get system.@sysupgrade[0].runscript)
    PACKAGES=$($BIN_UCI -q get system.@sysupgrade[0].opkg)
    if [ "$CMD" == "sysupgrade" ] && [ "$OFFLINE_POST_INSTALL" != "" ]; then
        local MOUNT_DEVICE=$(get_mount_device $INSTALL_PATH)
        if [ "$MOUNT_DEVICE" == "rootfs" ] || [ "$MOUNT_DEVICE" == "sysfs" ] || [ "$MOUNT_DEVICE" == "tmpfs" ]; then
            $BIN_ECHO "Install path ($INSTALL_PATH) must be on external device. Now is mounted on $MOUNT_DEVICE."
            exit 1
        fi
    fi
    $BIN_ECHO "Operation $CMD on $HOST_NAME - $DISTRIB_ID $DISTRIB_RELEASE ($DISTRIB_REVISION)"
}

update_repository() {
    run_script before_opkg_update
    $BIN_ECHO "Updating packages repository ..."
    $BIN_OPKG update
    check_exit_code
    $BIN_ECHO "Packages repository updated."
}

check_installed() {
    if [ "$INCLUDE_INSTALLED" != "" ]; then
        $BIN_ECHO "Checking installed packages ..."
        local INSTALLED=$($BIN_AWK -v PKG="$PACKAGES " 'BEGIN{FS=": ";ORS=" "}/^Package\: /{Package=$2}/^Status\: / && /user installed/{if(index(PKG,Package" ")==0)print Package}' /usr/lib/opkg/status)
        check_exit_code
        INSTALLED=${INSTALLED%% }
        if [ "$INSTALLED" != "" ]; then
            $BIN_ECHO "Installed packages not in configuration: $INSTALLED."
            PACKAGES="$PACKAGES $INSTALLED"
        else
            $BIN_ECHO "All packages from configuration."
        fi
    fi
}

check_dependency() {
    if [ "$PACKAGES" != "" ]; then 
        $BIN_ECHO "Checking packages dependency ..."
        $BIN_ECHO "Main packages: $PACKAGES."
        local PACKAGES_COUNT=-1
        while [ "$($BIN_ECHO $PACKAGES | $BIN_WC -w)" != "$PACKAGES_COUNT" ]; do
            PACKAGES_COUNT=$($BIN_ECHO $PACKAGES | $BIN_WC -w)
            local DEPENDS
            local DEPENDS_COUNT=-1
            while [ "$($BIN_ECHO $DEPENDS | $BIN_WC -w)" != "$DEPENDS_COUNT" ]; do
                DEPENDS_COUNT=$($BIN_ECHO $DEPENDS | $BIN_WC -w)
                DEPENDS=$DEPENDS$($BIN_OPKG depends -A $DEPENDS $PACKAGES | $BIN_AWK -v PKG="$DEPENDS $PACKAGES " 'BEGIN{ORS=" "}{if($2=="" && !seen[$1]++ && index(PKG,$1" ")==0)print $1}')
                check_exit_code
            done
            DEPENDS=${DEPENDS%% }
            [ "$DEPENDS" != "" ] && PACKAGES="$DEPENDS $PACKAGES"
            PACKAGES=$($BIN_OPKG whatprovides -A $PACKAGES | $BIN_AWK -v PKG="$PACKAGES " 'function Select(){if(CNT<1)return;SEL=0;for(ITEM in LIST)if(index(PKG,LIST[ITEM]" ")!=0)SEL=ITEM;if(!seen[LIST[SEL]]++)print LIST[SEL];delete LIST;CNT=0}BEGIN{ORS=" "}{if($3!="")Select();else LIST[CNT++]=$1}END{Select()}')
            PACKAGES=${PACKAGES%% }
        done
        $BIN_ECHO "All packages: $PACKAGES."
    fi
}

config_backup() {
    if [ "$BACKUP_ENABLE" != "" ]; then
        if [ ! -d "$BACKUP_PATH" ]; then
            $BIN_ECHO "Backup path not exist."
            exit 1
        fi
        if [ "$BACKUP_FILE" == "" ]; then
            $BIN_ECHO "Backup file name is empty."
            exit 1
        fi
        $BIN_ECHO "Making configuration backup to $BACKUP_FILE ..."
        $BIN_SYSUPGRADE --create-backup $BACKUP_FILE
        check_exit_code
        $BIN_CHMOD 640 $BACKUP_FILE
        check_exit_code
        $BIN_ECHO "Configuration backuped."
    fi
}

config_restore() {
    if [ "$BACKUP_ENABLE" != "" ]; then
        if [ "$BACKUP_FILE" == "" ]; then
            $BIN_ECHO "Backup file name is empty."
            exit 1
        else
            $BIN_ECHO "Restoring configuration from backup $BACKUP_FILE ..."
            $BIN_SYSUPGRADE --restore-backup $BACKUP_FILE
            check_exit_code
            $BIN_ECHO "Configuration restored."
        fi
    fi
}

packages_disable() {
    if [ "$PACKAGES" != "" ]; then 
        $BIN_ECHO "Disabling packages ..."
        local SCRIPT
        for PACKAGE in $PACKAGES; do
            for SCRIPT in $($BIN_OPKG files $PACKAGE | $BIN_GREP /etc/init.d/); do
                package_script_execute $PACKAGE $SCRIPT disable
                package_script_execute $PACKAGE $SCRIPT stop
            done
        done
        $BIN_ECHO "Packages are disabled."
    fi
}

packages_enable() {
    if [ "$PACKAGES" != "" ]; then 
        $BIN_ECHO "Enabling packages ..."
        local SCRIPT
        for PACKAGE in $PACKAGES; do
            for SCRIPT in $($BIN_OPKG files $PACKAGE | $BIN_GREP /etc/init.d/); do
                package_script_execute $PACKAGE $SCRIPT enable
                package_script_execute $PACKAGE $SCRIPT start
            done
        done
        $BIN_ECHO "Packages are enabled."
    fi
}

packages_install() {
    if [ "$PACKAGES" != "" ]; then 
        run_script before_opkg_install
        $BIN_ECHO "Installing packages ..."
        $BIN_OPKG $CMD $PACKAGES
        check_exit_code
        $BIN_RM $POST_INSTALL_REMOVE
        $BIN_ECHO "Packages are installed."
        run_script after_opkg_install
    fi
}

packages_download() {
    if [ "$PACKAGES" != "" ]; then 
        local PACKAGES_FILE="Packages"
        local PACKAGES_LIST="$PACKAGES_FILE.gz"
        $BIN_ECHO "Downloading packages to $INSTALL_PATH ..."
        cd $INSTALL_PATH
        $BIN_RM -f *.ipk
        $BIN_OPKG download $PACKAGES
        check_exit_code
        $BIN_ECHO "Building packages information ..."
        [ -f $INSTALL_PATH/$PACKAGES_FILE ] && $BIN_RM -f $INSTALL_PATH/$PACKAGES_FILE
        [ -f $INSTALL_PATH/$PACKAGES_LIST ] && $BIN_RM -f $INSTALL_PATH/$PACKAGES_LIST
        for PACKAGE in $PACKAGES; do
            $BIN_ECHO "Getting information for package $PACKAGE."
            $BIN_OPKG info $PACKAGE >>$INSTALL_PATH/$PACKAGES_FILE
            check_exit_code
        done 
        $BIN_ECHO "Compressing packages information as $INSTALL_PATH/$PACKAGES_LIST ..."
        $BIN_AWK '{if($0!~/^Status\:|^Installed-Time\:/)print $0}' $INSTALL_PATH/$PACKAGES_FILE | $BIN_GZIP -c9 >$INSTALL_PATH/$PACKAGES_LIST
        check_exit_code
        $BIN_RM -f $INSTALL_PATH/$PACKAGES_FILE
        check_exit_code
        $BIN_ECHO "Packages are downloaded."
    fi
}

image_download() {
    if [ "$IMAGE_SOURCE" == "" ]; then 
        $BIN_ECHO "Image source information is empty."
        exit 1
    fi
    local IMAGE_REMOTE_NAME="$(update_path_vars $IMAGE_SOURCE)"
    local IMAGE_LOCAL_NAME="$INSTALL_PATH/$IMAGE_FILENAME"
    local SUMS_REMOTE_NAME="$($BIN_DIRNAME $IMAGE_REMOTE_NAME)/md5sums"
    local SUMS_LOCAL_NAME="$INSTALL_PATH/md5sums"
    [ -f $IMAGE_LOCAL_NAME ] && $BIN_RM -f $IMAGE_LOCAL_NAME
    $BIN_ECHO "Downloading system image as $IMAGE_LOCAL_NAME from $IMAGE_REMOTE_NAME ..."    
    $BIN_WGET -O $IMAGE_LOCAL_NAME $IMAGE_REMOTE_NAME
    check_exit_code
    [ -f $SUMS_LOCAL_NAME ] && $BIN_RM -f $SUMS_LOCAL_NAME
    $BIN_ECHO "Downloading images sums as $SUMS_LOCAL_NAME from $SUMS_REMOTE_NAME ..."    
    $BIN_WGET -O $SUMS_LOCAL_NAME $SUMS_REMOTE_NAME
    check_exit_code
    $BIN_ECHO "Checking system image control sum ..."    
    local SUM_ORG=$($BIN_GREP $($BIN_BASENAME $IMAGE_REMOTE_NAME) $SUMS_LOCAL_NAME | $BIN_CUT -d " " -f 1)
    check_exit_code
    local SUM_FILE=$($BIN_MD5SUM $IMAGE_LOCAL_NAME | $BIN_CUT -d " " -f 1)
    check_exit_code
    if [ "$SUM_ORG" == "" ]; then
        $BIN_ECHO "Can't get original control sum!"
        exit 1
    elif [ "$SUM_FILE" == "" ]; then
        $BIN_ECHO "Can't calculate system image control sum!"
        exit 1
    elif [ "$SUM_ORG" != "$SUM_FILE" ]; then
        $BIN_ECHO "Downloaded system image is damaged!"
        exit 1
    else
        $BIN_ECHO "System image is downloaded and checksum is correct."
    fi
    $BIN_ECHO "Calculate new checksum to file $SUMS_LOCAL_NAME ..."
    $BIN_MD5SUM $IMAGE_LOCAL_NAME $($BIN_DIRNAME $IMAGE_LOCAL_NAME)/*.ipk >$SUMS_LOCAL_NAME
    check_exit_code
    run_script after_image_downloaded
}

installer_prepare() {
    $BIN_ECHO "Preparing packages installer in $POST_INSTALLER ..."
    $BIN_ECHO -e "#!/bin/sh"\
            "\n# Script auto-generated by $0"\
            "\n. /etc/diag.sh"\
            "\nget_status_led"\
            "\nset_state preinit"\
            "\nif [ -d /tmp/overlay-disabled ]; then"\
            "\n\t$BIN_LOGGER -p user.notice -t $POST_INSTALL_SCRIPT \"Removing overlay-rootfs checksum and force reboot\""\
            "\n\t$BIN_RM -f /tmp/overlay-disabled/.extroot.md5sum"\
            "\n\t$BIN_RM -f /tmp/overlay-disabled/etc/extroot.md5sum"\
            "\nelif [ -d /tmp/whole_root-disabled ]; then"\
            "\n\t$BIN_LOGGER -p user.notice -t $POST_INSTALL_SCRIPT \"Removing whole-rootfs checksum and force reboot\""\
            "\n\t$BIN_RM -f /tmp/whole_root-disabled/.extroot.md5sum"\
            "\n\t$BIN_RM -f /tmp/whole_root-disabled/etc/extroot.md5sum"\
            "\nelse"\
            "\n\t$BIN_LOGGER -p user.notice -t $POST_INSTALL_SCRIPT \"Start instalation of packages\"">$POST_INSTALLER
    check_exit_code
    if [ "$OFFLINE_POST_INSTALL" != "" ]; then
        $BIN_ECHO -e "\t$BIN_CAT /etc/opkg.conf | $BIN_AWK 'BEGIN{print \"src/gz local file:/$INSTALL_PATH\"}!/^src/{print \$0}' >/etc/opkg.conf">>$POST_INSTALLER
        check_exit_code
    else
        $BIN_ECHO -e "\tuntil $BIN_PING -q -W 30 -c 1 8.8.8.8 &>/dev/null; do"\
                "\t\t$BIN_LOGGER -p user.notice -t $POST_INSTALL_SCRIPT \"Wait for internet connection\""\
                "\n\tdone">>$POST_INSTALLER
        check_exit_code
    fi
    if [ "$RUN_SCRIPT" != "" ] && [ -x $RUN_SCRIPT ]; then
        $BIN_ECHO -e "\t$RUN_SCRIPT before_opkg_update | $BIN_LOGGER -p user.notice -t $POST_INSTALL_SCRIPT">>$POST_INSTALLER
        check_exit_code
    fi
    $BIN_ECHO -e "\t$BIN_OPKG update | $BIN_LOGGER -p user.notice -t $POST_INSTALL_SCRIPT">>$POST_INSTALLER
    if [ "$RUN_SCRIPT" != "" ] && [ -x $RUN_SCRIPT ]; then
        $BIN_ECHO -e "\t$RUN_SCRIPT before_opkg_install | $BIN_LOGGER -p user.notice -t $POST_INSTALL_SCRIPT">>$POST_INSTALLER
        check_exit_code
    fi
    $BIN_ECHO -e "\tlocal PACKAGES=\"$PACKAGES\""\
            "\n\tlocal PACKAGE"\
            "\n\tlocal SCRIPT"\
            "\n\tfor PACKAGE in \$PACKAGES; do"\
            "\n\t\t$BIN_OPKG install \$PACKAGE | $BIN_LOGGER -p user.notice -t $POST_INSTALL_SCRIPT"\
            "\n\t\tfor SCRIPT in \$($BIN_OPKG files \$PACKAGE | $BIN_GREP /etc/init.d/); do"\
            "\n\t\t\tif [ -x \$SCRIPT ]; then"\
            "\n\t\t\t\t$BIN_LOGGER -p user.notice -t $POST_INSTALL_SCRIPT \"Executing \$SCRIPT enable for package \$PACKAGE\""\
            "\n\t\t\t\t\$SCRIPT enable | $BIN_LOGGER -p user.notice -t $POST_INSTALL_SCRIPT"\
            "\n\t\t\tfi"\
            "\n\t\tdone"\
            "\n\tdone">>$POST_INSTALLER
    check_exit_code
    if [ "$RUN_SCRIPT" != "" ] && [ -x $RUN_SCRIPT ]; then
        $BIN_ECHO -e "\t$RUN_SCRIPT after_opkg_install | $BIN_LOGGER -p user.notice -t $POST_INSTALL_SCRIPT">>$POST_INSTALLER
        check_exit_code
    fi
    if [ "$BACKUP_ENABLE" != "" ]; then
        $BIN_ECHO -e "\t$BIN_LOGGER -p user.notice -t $POST_INSTALL_SCRIPT \"Restoring configuration backup from $BACKUP_FILE\""\
                "\n\t$BIN_SYSUPGRADE --restore-backup $BACKUP_FILE">>$POST_INSTALLER
        check_exit_code
    fi
    $BIN_ECHO -e "\t$BIN_LOGGER -p user.notice -t $POST_INSTALL_SCRIPT \"Stop installation of packages, cleaning and force reboot\""\
            "\n\t$BIN_RM $POST_INSTALL_REMOVE"\
            "\n\t$BIN_RM -f $INSTALLER_KEEP_FILE"\
            "\n\t$BIN_AWK -v installer=\"$POST_INSTALLER\" '\$0!~installer' $RC_LOCAL>$RC_LOCAL.tmp"\
            "\n\t$BIN_MV -f $RC_LOCAL.tmp $RC_LOCAL"\
            "\n\t$BIN_RM -f $POST_INSTALLER"\
            "\nfi"\
            "\n$BIN_LOGREAD >>$POST_INSTALLER_LOG"\
            "\n$BIN_SYNC"\
            "\n$BIN_REBOOT -f"\
            "\n# Done.">>$POST_INSTALLER
    check_exit_code
    $BIN_CHMOD 777 $POST_INSTALLER
    check_exit_code
    add_to_keep_file $POST_INSTALLER
    [ "$RUN_SCRIPT" != "" ] && [ -x $RUN_SCRIPT ] && add_to_keep_file $RUN_SCRIPT
    $BIN_ECHO "Setting autorun packages installer on next boot in $RC_LOCAL ..."
    add_to_keep_file $RC_LOCAL
    $BIN_ECHO -e "[ -x $POST_INSTALLER ] && $POST_INSTALLER\n$($BIN_CAT $RC_LOCAL)">$RC_LOCAL
    check_exit_code
    add_to_post_installer_log "Packages installer prepared"
    $BIN_ECHO "Packages installer prepared."
}

sysupgrade_execute() {
    $BIN_ECHO "Upgrading system from image $INSTALL_PATH/$IMAGE_FILENAME ..."
    add_to_keep_file $0
    add_to_post_installer_log "Running system upgrade"
    cd $INSTALL_PATH
    $BIN_SYSUPGRADE $IMAGE_FILENAME
}

# Main routine
initialize $@
[ "$CMD" == "backup" ] && config_backup && exit
[ "$CMD" == "sysupgrade" ] && caution_alert
update_repository
check_installed
check_dependency
([ "$CMD" == "install" ] || [ "$CMD" == "sysupgrade" ]) && config_backup
[ "$CMD" == "install" ] && packages_disable && packages_install
([ "$CMD" == "download" ] || ([ "$CMD" == "sysupgrade" ] && [ "$OFFLINE_POST_INSTALL" != "" ])) && packages_download
[ "$CMD" == "install" ] && config_restore && packages_enable
([ "$CMD" == "download" ] || [ "$CMD" == "sysupgrade" ]) && image_download
[ "$CMD" == "sysupgrade" ] && installer_prepare && packages_disable && sysupgrade_execute
$BIN_ECHO "Done."
# Done.

Uwaga ! Nie testowałem tego z Gargoyle, tylko czyste AA lub AA i LuCI.
Uwaga ! Aktualizacja Extroot jest w fazie testów, nie odpowiadam za ewentualne szkody!

175

(206 odpowiedzi, napisanych Oprogramowanie / Software)

Dzięki, za info @dopsz. Kolejna wersja:

#!/bin/sh
#
# sysinfo.sh dla OpenWRT AA Cezary Jackiewicz 2013
# 
#    1.00    CJ    Pierwsza wersja kodu
#    1.01    RD    Drobna przebudowa
#    1.02    RD    Korekta błędu wyśw. zajetości Flash-a, dodanie kolorów
#    1.03    RD    Dodanie nazwy routera, zmiana formatowania
#    1.04    RD    Kosmetyka, sugestie @mikhnal. Zmiana przetwarzania info. o wan.
#    1.05    RD    Zmiana algorytmu pobierania danych dla wan i lan
#    1.06    RD    Parametryzacja kolorów i pojawiania się podkreśleń
#    1.07    RD    Modyfikacja związana z poprawnym wyświetlaniem interfejsu dla prot.3g
#    1.08    RD    Modyfikacja wyświetlania DNS-ów dla wan, dodanie uptime dla interfejsów
#    1.09    RD    Dodanie statusu "Down" dla wyłączonego wifi, zmiana wyświetlania dla WLAN(sta)
#    1.10    RD    Korekta wyświetlania dla WLAN(sta)
#    1.11    RD    Korekta wyświetlania stanu pamięci, sugestie @dopsz 
#
# Destination /sbin/sysinfo.sh
#
. /usr/share/libubox/jshn.sh

local Width=60
local StartRuler="1"
local EndRuler="1"
local Rouler
local NormalColor
local MachineColor
local ValueColor
local AddrColor
local RXTXColor

initialize() {
    local ColorMode="1"
    for Parameter in $@; do
        case  $Parameter  in
        -m) ColorMode="0";;
        -sr) StartRuler="0";;
        -er) EndRuler="0";;
        -w1) Width=80;;
        -w2) Width=100;;
        -w3) Width=120;;
        -h|*)    
            echo "Usage: $0 - [parameter]"
            echo "    -h    : This help."
            echo "    -m    : Display mono version."
            echo "    -sr    : Without start horizontal ruler."    
            echo "    -er    : Without end horizontal ruler."    
            exit 1;;
        esac
    done
    if [ "$ColorMode" == "1" ]; then
        NormalColor="\e[0m"
        MachineColor="\e[0;33m"
        ValueColor="\e[1;36m"
        AddrColor="\e[1;31m"
        RXTXColor="\e[2;32m"
    else
        NormalColor="\e[0m"
        MachineColor="\e[7m"
        ValueColor="\e[1m"
        AddrColor="\e[4m"
        RXTXColor="\e[1m"
    fi
    local i
    for i in $(seq $(expr $Width + 4 )); do 
        Rouler="$Rouler-";
    done
}

human_readable() {
    if [ $1 -gt 0 ]; then
        printf "$(awk -v n=$1 'BEGIN{for(i=split("B KB MB GB TB PB",suffix);s<1;i--)s=n/(2**(10*i));printf (int(s)==s)?"%.0f%s":"%.1f%s",s,suffix[i+2]}')"
    else
        printf "0B"
    fi
}

device_rx_tx() {
    local RXTX=$(awk -v Device=$1 '$1==Device ":"{printf "%.0f\t%.0f",$2,$10}' /proc/net/dev)
    [ "$RXTX" != "" ] && printf ", rx/tx: $RXTXColor$(human_readable $(echo "$RXTX" | cut -f 1))$NormalColor/$RXTXColor$(human_readable $(echo "$RXTX" | cut -f 2))$NormalColor"
}

uptime_str() {
    local Uptime=$1
    if [ $Uptime -gt 0 ]; then
        local Days=$(expr $Uptime / 60 / 60 / 24)
        local Hours=$(expr $Uptime / 60 / 60 % 24)
        local Minutes=$(expr $Uptime / 60 % 60)
        local Seconds=$(expr $Uptime % 60)
        if [ $Days -gt 0 ]; then
            Days=$(printf "%dd " $Days)
        else
            Days=""
        fi
        printf "$Days%02d:%02d:%02d" $Hours $Minutes $Seconds
    fi
}

print_line() {
    printf " | %-${Width}s |\r | $1\n"
}

print_horizontal_ruler() {
    printf " $Rouler\n"
}

print_machine() {
    local Machine=""
    local HostName=$(uci -q get system.@system[0].hostname)
    [ -e /tmp/sysinfo/model ] && Machine=$(cat /tmp/sysinfo/model)
    print_line "Machine: $MachineColor$Machine$NormalColor, Name: $MachineColor$HostName$NormalColor"
}

print_uptime() {
    local SysUptime=$(cut -d. -f1 /proc/uptime)
    local Uptime=$(uptime_str $SysUptime)
    local Now=$(date +'%Y-%m-%d %H:%M:%S')
    print_line "Uptime: $ValueColor$Uptime$NormalColor, Now: $ValueColor$Now$NormalColor"
}

print_loadavg() {
    local LoadAvg=$(awk '{printf"%s, %s, %s",$1,$2,$3}' /proc/loadavg)
    print_line "Load: $ValueColor$LoadAvg$NormalColor"
}

print_flash() {
    local Flash=$(df -k /overlay | awk '/overlay/{printf "%.0f\t%.0f\t%.1f",$4*1024,$2*1024,($2>0)?$3/$2*100:0}')
    local Free=$(echo "$Flash" | cut -f 1)
    local Total=$(echo "$Flash" | cut -f 2)
    local Used=$(echo "$Flash" | cut -f 3)
    print_line "Flash: free: $ValueColor$(human_readable $Free)$NormalColor, total: $ValueColor$(human_readable $Total)$NormalColor, used: $ValueColor$Used$NormalColor%%"
}

print_memory() {
    local Memory=$(awk 'BEGIN{Total=0;Free=0}$1~/^MemTotal:/{Total=$2}$1~/^MemFree:|^Buffers:|^Cached:/{Free+=$2}END{printf"%.0f\t%.0f\t%.1f",Free*1024,Total*1024,(Total>0)?(((Total-Free)/Total)*100):0}' /proc/meminfo)
    local Free=$(echo "$Memory" | cut -f 1)
    local Total=$(echo "$Memory" | cut -f 2)
    local Used=$(echo "$Memory" | cut -f 3)
    print_line "Memory: free: $ValueColor$(human_readable $Free)$NormalColor, total: $ValueColor$(human_readable $Total)$NormalColor, used: $ValueColor$Used$NormalColor%%"
}

print_wan() {
    local Zone
    local Device
    for Zone in $(uci -q show firewall | grep .masq= | cut -f2 -d.); do
        for Device in $(uci -q get firewall.$Zone.network); do
            local Status="$(ubus call network.interface.$Device status 2>/dev/null)"
            if [ "$Status" != "" ]; then
                local State=""
                local Iface=""
                local Uptime=""
                local IP4=""
                local IP6=""
                local Subnet4=""
                local Subnet6=""
                local Gateway4="n/a"
                local Gateway6="n/a"
                local DNS=""
                local Protocol=""
                json_load "${Status:-{}}"
                json_get_var State up
                json_get_var Uptime uptime
                json_get_var Iface l3_device
                json_get_var Protocol proto
                if json_get_type Status ipv4_address && [ "$Status" = array ]; then
                    json_select ipv4_address
                    json_get_type Status 1
                    if [ "$Status" = object ]; then
                        json_select 1
                        json_get_var IP4 address
                        json_get_var Subnet4 mask
                        [ "$IP4" != "" ] && [ "$Subnet4" != "" ] && IP4="$IP4/$Subnet4"
                    fi
                fi
                json_select
                if json_get_type Status ipv6_address && [ "$Status" = array ]; then
                    json_select ipv6_address
                    json_get_type Status 1
                    if [ "$Status" = object ]; then
                        json_select 1
                        json_get_var IP6 address
                        json_get_var Subnet6 mask
                        [ "$IP6" != "" ] && [ "$Subnet6" != "" ] && IP6="$IP6/$Subnet6"
                    fi
                fi
                json_select
                if json_get_type Status route && [ "$Status" = array ]; then
                    json_select route
                    local Index="1"
                    while json_get_type Status $Index && [ "$Status" = object ]; do
                        json_select "$((Index++))"
                        json_get_var Status target
                        case "$Status" in
                            0.0.0.0)
                                json_get_var Gateway4 nexthop;;
                            ::)
                                json_get_var Gateway6 nexthop;;
                        esac
                        json_select ".."
                    done    
                fi
                json_select
                if json_get_type Status dns_server && [ "$Status" = array ]; then
                    json_select dns_server
                    local Index="1"
                    while json_get_type Status $Index && [ "$Status" = string ]; do
                        json_get_var Status "$((Index++))"
                        DNS="${DNS:+$DNS }$Status"
                    done
                fi
                if [ "$State" == "1" ]; then
                    [ "$IP4" != "" ] && print_line "WAN: $AddrColor$IP4$NormalColor($Iface), gateway: $AddrColor$Gateway4$NormalColor"
                    [ "$IP6" != "" ] && print_line "WAN: $AddrColor$IP6$NormalColor($Iface), gateway: $AddrColor$Gateway6$NormalColor"
                    print_line "proto: $ValueColor$Protocol$NormalColor, uptime: $ValueColor$(uptime_str $Uptime)$NormalColor$(device_rx_tx $Iface)"
                    [ "$DNS" != "" ] && print_line "dns: $AddrColor$DNS$NormalColor"
                fi
            fi
        done
    done
}

print_lan() {
    local Device="lan"
    local State
    local Iface
    local IP4
    local IP6
    local Subnet4
    local Subnet6
    local Status="$(ubus call network.interface.$Device status 2>/dev/null)"
    if [ "$Status" != "" ]; then
        json_load "${Status:-{}}"
        json_get_var State up
        json_get_var Iface device
        if json_get_type Status ipv4_address && [ "$Status" = array ]; then
            json_select ipv4_address
            json_get_type Status 1
            if [ "$Status" = object ]; then
                json_select 1
                json_get_var IP4 address
                json_get_var Subnet4 mask
                [ "$IP4" != "" ] && [ "$Subnet4" != "" ] && IP4="$IP4/$Subnet4"
            fi
        fi
        json_select
        if json_get_type Status ipv6_address && [ "$Status" = array ]; then
            json_select ipv6_address
            json_get_type Status 1
            if [ "$Status" = object ]; then
                json_select 1
                json_get_var IP6 address
                json_get_var Subnet6 mask
                [ "$IP6" != "" ] && [ "$Subnet6" != "" ] && IP6="$IP6/$Subnet6"
            fi
        fi
        [ "$IP4" != "" ] && print_line "LAN: $AddrColor$IP4$NormalColor"
        [ "$IP6" != "" ] && print_line "LAN: $AddrColor$IP6$NormalColor"
    fi
}

print_wlan() {
    local Iface
    for Iface in $(uci -q show wireless | grep device=radio | cut -f2 -d.); do
        local Device=$(uci -q get wireless.$Iface.device)
        local SSID=$(uci -q get wireless.$Iface.ssid)
        local IfaceDisabled=$(uci -q get wireless.$Iface.disabled)
        local DeviceDisabled=$(uci -q get wireless.$Device.disabled)
        if [ -n "$SSID" ] && [ "$IfaceDisabled" != "1" ] && [ "$DeviceDisabled" != "1" ]; then
            local Mode=$(uci -q -P /var/state get wireless.$Iface.mode)
            local Channel=$(uci -q get wireless.$Device.channel)
            local RadioIface=$(uci -q -P /var/state get wireless.$Iface.ifname)
            local Connection="Down"
            if [ -n "$RadioIface" ]; then
                if [ "$Mode" == "ap" ]; then
                    Connection="$(iw dev $RadioIface station dump | grep Station | wc -l)"
                else
                    Connection="$(iw dev $RadioIface link | awk 'BEGIN{FS=": ";Signal="";Bitrate=""} $1~/signal/ {Signal=$2} $1~/tx bitrate/ {Bitrate=$2}END{print Signal" "Bitrate}')"
                fi
            fi
            if [ "$Mode" == "ap" ]; then
                print_line "WLAN: $ValueColor$SSID$NormalColor($Mode), ch: $ValueColor$Channel$NormalColor, conn: $ValueColor$Connection$NormalColor$(device_rx_tx $RadioIface)"
            else
                print_line "WLAN: $ValueColor$SSID$NormalColor($Mode), ch: $ValueColor$Channel$NormalColor"
                print_line "conn: $ValueColor$Connection$NormalColor$(device_rx_tx $RadioIface)"
            fi
        fi
    done
}

print_vpn() {
    local VPN
    for VPN in $(uci -q show openvpn | grep .ca= | cut -f2 -d.); do
        local Device=$(uci -q get openvpn.$VPN.dev)
        local Enabled=$(uci -q get openvpn.$VPN.enabled)
        if [ "$Enabled" == "1" ] || [ "$Enabled" == "" ]; then
            local Mode=$(uci -q get openvpn.$VPN.mode)
            local Connection="n/a"
            if [ "$Mode" == "server" ]; then
                Mode="$ValueColor$VPN$NormalColor(svr):$(uci -q get openvpn.$VPN.port)"
                Status=$(uci -q get openvpn.$VPN.status)
                Connection=$(awk 'BEGIN{FS=",";c=0;l=0}{if($1=="Common Name")l=1;else if($1=="ROUTING TABLE")exit;else if (l==1) c=c+1}END{print c}' $Status)
            else
                Mode="$ValueColor$VPN$NormalColor(cli)"
                Connection="Down"
                ifconfig $Device &>/dev/null && Connection="Up"
            fi
            print_line "VPN: $Mode, conn: $ValueColor$Connection$NormalColor$(device_rx_tx $Device)"
        fi
    done
}

initialize $@
[ "$StartRuler" == "1" ] && print_horizontal_ruler
print_machine
print_uptime
print_loadavg
print_flash
print_memory
print_wan
print_lan
print_wlan
print_vpn
[ "$EndRuler" == "1" ] && print_horizontal_ruler
exit 0
# Done.