summaryrefslogtreecommitdiff
path: root/configure
blob: 2a1a72a515933cbd3ff7b0a307a3aa47ab6ed874 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/sh

git checkout config.h

# CPU temp reporting is cancer
# find a correct file assuming CPU is the hottest element
Tmax="0"
for f in /sys/class/hwmon/hwmon*/temp*_input
do
	T="$(cat "$f")"
	if [ "$T" -gt "$Tmax" ]; then
		Tmax="$T"
		CPUtemp="$f"
	fi
done
sed -i "/cpu_perc/a\\\\t{ temp, \"%s° \", \"$CPUtemp\"}," config.h

# detect battery
for BAT_path in /sys/class/power_supply/BAT*
do
	BAT="$(basename "$BAT_path")"
	sed -i "/BATSTATE/a\\\\t{ battery_state, \"%s]\", \"$BAT\"}," config.h
	sed -i "/BATSTATE/a\\\\t{ battery_perc, \"[%s\", \"$BAT\"}," config.h
done

# detect ethernet interfaces
# WARNING: currently will fail with multiple interfaces due to as slstatus stores the # of bytes sent in a static variable
ETH="$(ip link | grep ': en' | cut -d':' -f2 | xargs)"
if [ -n "$ETH" ]; then
	sed -i "/NETSPEED/a\\\\t{ netspeed_tx, \"%7s]\", \"$ETH\"}," config.h
	sed -i "/NETSPEED/a\\\\t{ netspeed_rx, \"[%7s \", \"$ETH\"}," config.h
fi

# detect wireless interfaces
WLAN="$(ip link | grep ': wlp' | cut -d':' -f2 | xargs)"
if [ -n "$WLAN" ]; then
	sed -i "/NETSPEED/a\\\\t{ netspeed_tx, \"%7s]\", \"$WLAN\"}," config.h
	sed -i "/NETSPEED/a\\\\t{ netspeed_rx, \"%7s \", \"$WLAN\"}," config.h
	sed -i "/NETSPEED/a\\\\t{ wifi_perc, \"[%3s\", \"$WLAN\"}," config.h
fi

sed -i "s/#define CPUS.*/#define CPUS $(nproc)/" components/cpu.c