1
0

more cleaning

This commit is contained in:
dtb
2022-09-17 23:19:09 -04:00
parent 8e455a7e3f
commit 1aed01279b
15 changed files with 72 additions and 290 deletions

125
data/data Executable file
View File

@@ -0,0 +1,125 @@
#!/bin/sh
set -e
# on Linux only:
# these files (separated by newlines) will have the current CPU temperature
# multiplied by $CPU_TEMP_SCALE. this script divides the file contents by scale
# and displays that temperature (assumed to be in Celsius units)
CPU_TEMP_FILES="/sys/devices/platform/coretemp.0/hwmon/hwmon4/temp2_input
/sys/devices/platform/coretemp.0/hwmon/hwmon4/temp3_input"
CPU_TEMP_SCALE=1000
# format for the date (by default in this script, ISO 8601)
DATE="date +%Y-%m-%dT%T"
DELIMITER=" || "
# how fast to refresh the display (in seconds, will be substituted with 1 if
# not an integer)
INTERVAL=1
# this URL will have in plain text the public IP address from which it was
# accessed
#PUBLIC_IP_FETCH_URL="http://ifconfig.io/"
#PUBLIC_IP_FETCH_URL="https://ifconfig.io"
#PUBLIC_IP_FETCH_URL="http://icanhazip.com"
PUBLIC_IP_FETCH_URL="https://icanhazip.com"
PUBLIC_IP6_FETCH_URL="$PUBLIC_IP_FETCH_URL"
get_cpu_temp() {
if [ "$(uname)" = "Linux" ]; then
RETVAL=""
# iterate over files, adjust, print out "%dC "
for file in $CPU_TEMP_FILES;
do RETVAL="$RETVAL$(fdivide $(cat $file) $CPU_TEMP_SCALE)C "
done
# in-line python (bet you've never seen that before) that
# strips off trailing whitespace. could be done with sed but
# this was more fun
printf "%b" "$RETVAL" \
| python -c "from sys import stdin; print(stdin.read().rstrip() + '\n')"
return
elif [ "$(uname)" = "NetBSD" ]; then
printf "%bC" "$(envstat -s coretemp0:'cpu0 temperature' \
| sed 1,2d \
| cut -d ':' -f 2 \
| awk '{print $1}' \
| cut -d '.' -f 1)"
return
else
printf "get_cpu_temp: unsupported OS"
fi
}
get_current_desktop() {
case "$WM" in
(bspwm) printf "[%b] " "$(bspc query -D -d focused --names)" ;;
esac
}
get_memory_usage() {
if [ "$(uname)" = "Linux" ]; then
printf "%b" \
"$(free | head -n 2 | tail -n 1 \
| awk '{print $3 " used / " $2 " total"}')"
return
fi
}
get_public_ip() {
PUBLIC_IP4="$(curl -4 "$PUBLIC_IP_FETCH_URL" --no-progress-meter 2>/dev/null \
|| printf "-1")"
PUBLIC_IP6="$(curl -6 "$PUBLIC_IP6_FETCH_URL" --no-progress-meter 2>/dev/null \
|| printf "-1")"
if [ "$PUBLIC_IP4" = "-1" ] && [ "$PUBLIC_IP6" = "-1" ]; then
printf "[error fetching address]"
elif [ "$PUBLIC_IP4" = "-1" ]; then
printf "%b" "$PUBLIC_IP6"
elif [ "$PUBLIC_IP6" = "-1" ]; then
printf "%b" "$PUBLIC_IP4"
else
printf "%b / %b" "$PUBLIC_IP4" "$PUBLIC_IP6"
fi
return
}
PUBLIC_IP="$(get_public_ip)"
printbar() {
printf "%b" "$(get_current_desktop)"
printf "%b" $($DATE)
printf "%b" "$DELIMITER"
printf "%b" "BAT: $(battery)"
printf "%b" "$DELIMITER"
printf "%b" "CPU: $(get_cpu_temp)"
printf "%b" "$DELIMITER"
printf "%b" "PuIP: $PUBLIC_IP"
#printf "%b" "$DELIMITER"
#printf "%b" "MEM: $(get_memory_usage)"
printf "\n"
return
}
# check to make sure customizeable vars are in proper format
[ -n "$INTERVAL" ] && str isdigit "$INTERVAL" \
|| INTERVAL=1
[ -n "$CPU_TEMP_SCALE" ] && str isdigit "$CPU_TEMP_SCALE" \
&& [ "$CPU_TEMP_SCALE" -gt 0 ] \
|| CPU_TEMP_SCALE=1
[ -n "$CPU_TEMP_FILES" ] \
|| alias get_cpu_temp="printf '[no temperature files specified]\n'"
# main loop
while true; do
printbar
sleep "$INTERVAL"
if streq $(date +'%S') 00; then
# every minute
PUBLIC_IP="$(get_public_ip)"
fi
done