You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

145 lines
3.4 KiB

#!/usr/bin/env sh
# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh"
trap "update" USR1
pgrep -f sxmo_statusbar.sh | grep -v $$ | xargs -r kill -9
update() {
# In-call.. show length of call
CALLINFO=" "
if pgrep -f sxmo_modemcall.sh; then
NOWS="$(date +"%s")"
CALLSTARTS="$(date +"%s" -d "$(
grep -aE 'call_start|call_pickup' "$XDG_DATA_HOME"/sxmo/modem/modemlog.tsv |
tail -n1 |
cut -f1
)")"
CALLSECONDS="$(echo "$NOWS" - "$CALLSTARTS" | bc)"
CALLINFO="${CALLSECONDS}s"
fi
# symbol if wireguard/vpn is connected
VPN=""
VPNDEVICE="$(nmcli con show | grep vpn | awk '{ print $4 }')"
WGDEVICE="$(nmcli con show | grep wireguard | awk '{ print $4 }')"
if [ -n "$VPNDEVICE" ] && [ "$VPNDEVICE" != "--" ]; then
VPN=""
elif [ -n "$WGDEVICE" ] && [ "$WGDEVICE" != "--" ]; then
VPN=""
fi
# W symbol if wireless is connect
WIRELESS=""
WLANSTATE="$(tr -d "\n" < /sys/class/net/wlan0/operstate)"
if [ "$WLANSTATE" = "up" ]; then
WIRELESS=""
fi
# M symbol if modem monitoring is on & modem present
MODEMMON=""
if [ -f "$MODEMSTATEFILE" ]; then
MODEMSTATE="$(cat "$MODEMSTATEFILE")"
if [ locked = "$MODEMSTATE" ]; then
MODEMMON=""
elif [ registered = "$MODEMSTATE" ]; then
MODEMMON=""
elif [ connected = "$MODEMSTATE" ]; then
MODEMMON=""
else
MODEMMON=""
fi
fi
# Battery pct
BATTERY_DEVICE="${BATTERY_DEVICE:-"/sys/class/power_supply/*-battery"}"
PCT="$(cat "$BATTERY_DEVICE"/capacity)"
BATSTATUS="$(
cut -c1 "$BATTERY_DEVICE"/status
)"
if [ "$BATSTATUS" = "C" ]; then
if [ "$PCT" -lt 20 ]; then
BATSTATUS=""
elif [ "$PCT" -lt 30 ]; then
BATSTATUS=""
elif [ "$PCT" -lt 40 ]; then
BATSTATUS=""
elif [ "$PCT" -lt 60 ]; then
BATSTATUS=""
elif [ "$PCT" -lt 80 ]; then
BATSTATUS=""
elif [ "$PCT" -lt 90 ]; then
BATSTATUS=""
else
BATSTATUS=""
fi
else
if [ "$PCT" -lt 10 ]; then
BATSTATUS=""
elif [ "$PCT" -lt 20 ]; then
BATSTATUS=""
elif [ "$PCT" -lt 30 ]; then
BATSTATUS=""
elif [ "$PCT" -lt 40 ]; then
BATSTATUS=""
elif [ "$PCT" -lt 50 ]; then
BATSTATUS=""
elif [ "$PCT" -lt 60 ]; then
BATSTATUS=""
elif [ "$PCT" -lt 70 ]; then
BATSTATUS=""
elif [ "$PCT" -lt 80 ]; then
BATSTATUS=""
elif [ "$PCT" -lt 90 ]; then
BATSTATUS=""
else
BATSTATUS=""
fi
fi
# Volume
AUDIODEV="$(sxmo_audiocurrentdevice.sh)"
AUDIOSYMBOL=$(echo "$AUDIODEV" | cut -c1)
if [ "$AUDIOSYMBOL" = "L" ] || [ "$AUDIOSYMBOL" = "N" ]; then
AUDIOSYMBOL="" #speakers or none, use no special symbol
elif [ "$AUDIOSYMBOL" = "H" ]; then
AUDIOSYMBOL=" "
elif [ "$AUDIOSYMBOL" = "E" ]; then
AUDIOSYMBOL=" " #earpiece
fi
VOL=0
[ "$AUDIODEV" = "None" ] || VOL="$(
amixer sget "$AUDIODEV" |
grep -oE '([0-9]+)%' |
tr -d ' %' |
awk '{ s += $1; c++ } END { print s/c }' |
xargs printf %.0f
)"
if [ "$AUDIODEV" != "None" ]; then
if [ "$VOL" -eq 0 ]; then
VOLUMESYMBOL="ﱝ"
elif [ "$VOL" -lt 25 ]; then
VOLUMESYMBOL="奄"
elif [ "$VOL" -gt 75 ]; then
VOLUMESYMBOL="墳"
else
VOLUMESYMBOL="奔"
fi
fi
# Time
TIME="$(date +%R)"
BAR="$(echo "${CALLINFO} ${MODEMMON} ${WIRELESS} ${VPN} ${AUDIOSYMBOL}${VOLUMESYMBOL} ${BATSTATUS} ${TIME}" | sed 's| \+| |g')"
xsetroot -name "$BAR"
}
# E.g. on first boot justs to make sure the bar comes in quickly
update && sleep 1 && update && sleep 1
while :
do
update
sleep 30 & wait
done