summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan-boikov <ik.boikov.public@protonmail.com>2024-02-27 23:59:23 +0100
committerivan-boikov <ik.boikov.public@protonmail.com>2024-02-28 00:01:04 +0100
commit6252b42a21927303d78b9587303904955ce486c5 (patch)
tree4cd6c599c04101a2cb6e1f9580a87a65bff71709
parentdb8d69656ae4ce7f146e0ac7baea60cf3958a894 (diff)
Configure script
-rw-r--r--components/cpu.c4
-rw-r--r--config.h24
-rwxr-xr-xconfigure25
3 files changed, 39 insertions, 14 deletions
diff --git a/components/cpu.c b/components/cpu.c
index a78f17a..bbebdfc 100644
--- a/components/cpu.c
+++ b/components/cpu.c
@@ -14,7 +14,11 @@
unsigned int cores = 0;
uintmax_t freq, freq_sum = 0;
+#ifdef N_CORES
+ for (cores = 0; cores < N_CORES;) {
+#else
while (1) {
+#endif
sprintf(cpu, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", cores);
if (pscanf(cpu, "%ju", &freq) != 1)
break;
diff --git a/config.h b/config.h
index c71a4a3..498350d 100644
--- a/config.h
+++ b/config.h
@@ -63,22 +63,18 @@ static const char unknown_str[] = "n/a";
* wifi_essid WiFi ESSID interface name (wlan0)
* wifi_perc WiFi signal in percent interface name (wlan0)
*/
-#define NET_INTERFACE "enp34s0"
static const struct arg args[] = {
/* function format argument */
- { mpd_track, "[%s", "/tmp/mpd.playing"},
- { cat, " %3s%%]", "/tmp/volume"},
- //{ battery_perc, "[%s", "BAT0"},
- //{ battery_state, "%s]", "BAT0"},
- { netspeed_rx, "[%7s ", NET_INTERFACE },
- { netspeed_tx, "%7s", NET_INTERFACE },
- { vpn_status, "%s", NULL},
- //{ wifi_perc, "%s", NET_INTERFACE},
- { cpu_perc, "][%3s%%  ", NULL },
+ { mpd_track, "[%s", "/tmp/mpd.playing" },
+ { cat, " %3s%%]", "/tmp/volume" },
+ // BATSTATE
+ // NETSPEED
+ { vpn_status, "%s", NULL },
+ { cpu_perc, "[%3s%%  ", NULL },
{ cpu_freq, "%s]", NULL },
- { ram_used, "[%s/", NULL},
- { ram_total, "%s ", NULL},
- { swap_used, "%s/", NULL},
- { swap_total, "%s] ", NULL},
+ { ram_used, "[%s/", NULL },
+ { ram_total, "%s ", NULL },
+ { swap_used, "%s/", NULL },
+ { swap_total, "%s] ", NULL },
{ datetime, "%s", "%F %T" },
};
diff --git a/configure b/configure
new file mode 100755
index 0000000..f133f15
--- /dev/null
+++ b/configure
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+git checkout config.h
+git checkout components/cpu.c
+
+sed -i "2i #define N_CORES $(nproc --all)" components/cpu.c
+
+for BAT in /sys/class/power_supply/BAT*
+do
+ sed -i "/BATSTATE/a { battery_state, \"%s]\", \"$BAT\"}," config.h
+ sed -i "/BATSTATE/a { battery_perc, \"[%s\", \"$BAT\"}," config.h
+done
+
+ETH="$(ip link | grep enp | cut -d':' -f2 | xargs)"
+if [ -n "$ETH" ]; then
+ sed -i "/NETSPEED/a{ netspeed_tx, \"%7s]\", \"$ETH\"}," config.h
+ sed -i "/NETSPEED/a{ netspeed_rx, \"[E%7s \", \"$ETH\"}," config.h
+fi
+
+WLAN="$(ip link | grep wlp | cut -d':' -f2 | xargs)"
+if [ -n "$WLAN" ]; then
+ sed -i "/NETSPEED/a{ netspeed_tx, \"%7s]\", \"$WLAN\"}," config.h
+ sed -i "/NETSPEED/a{ netspeed_rx, \"%7s \", \"$WLAN\"}," config.h
+ sed -i "/NETSPEED/a{ wifi_perc, \"[%3s\", \"$WLAN\"}," config.h
+fi