]> git.mar77i.info Git - superuser/commitdiff
initial commit
authormar77i <mar77i@protonmail.ch>
Tue, 30 Jun 2026 10:03:32 +0000 (12:03 +0200)
committermar77i <mar77i@protonmail.ch>
Tue, 30 Jun 2026 10:03:32 +0000 (12:03 +0200)
reinstall_from_today.py [new file with mode: 0755]
select_wifi.py [new file with mode: 0755]
set_brightness.sh [new file with mode: 0755]
static_ip.sh [new file with mode: 0755]

diff --git a/reinstall_from_today.py b/reinstall_from_today.py
new file mode 100755 (executable)
index 0000000..ec6e18a
--- /dev/null
@@ -0,0 +1,35 @@
+#!/usr/bin/env python3
+
+from argparse import ArgumentParser
+from datetime import date, datetime
+from subprocess import run
+
+PACMAN_LOG = "/var/log/pacman.log"
+
+
+def main():
+    ap = ArgumentParser()
+    ap.add_argument("--since", default=None)
+    args = ap.parse_args()
+    with open(PACMAN_LOG) as fh:
+        lines = [l.rstrip() for l in fh.readlines()]
+    if args.since is not None:
+        since_dt = date.fromisoformat(args.since)
+    else:
+        line = lines[-1]
+        assert line.startswith("[")
+        since_dt = datetime.fromisoformat(line[1:line.find("]")]).date()
+    lines = [l for l in lines if l.startswith(f"[{since_dt.isoformat()}T")]
+    pkgs = set()
+    for line in lines:
+        line = line[line.find(" ") + 1:]
+        if not line.startswith("[ALPM] "):
+            continue
+        line = line[7:].split(maxsplit=2)
+        if line[0] in ("installed", "upgraded", "reinstalled"):
+            pkgs.add(line[1])
+    run(["pacman", "-Syu", *pkgs])
+
+
+if __name__ == "__main__":
+    main()
diff --git a/select_wifi.py b/select_wifi.py
new file mode 100755 (executable)
index 0000000..d0c3a53
--- /dev/null
@@ -0,0 +1,78 @@
+#!/usr/bin/env python3
+
+import os
+import sys
+from subprocess import check_call
+
+WPA_CONFIG = "/etc/wpa_supplicant/wpa_supplicant.conf"
+
+
+class WpaConfig:
+    SSID_PREFIX = ("    #ssid=", "    ssid=")
+    PSK_PREFIX = ("    #psk=", "    psk=")
+    KEY_MGMT_PREFIX = ("    #key_mgmt=", "    key_mgmt=")
+
+    def __init__(self):
+        self.lines = []
+
+    class Line:
+        def __init__(self, s):
+            self.s = s
+
+    @staticmethod
+    def parse_str(s):
+        if s.endswith('"'):
+            if s.startswith('"'):
+                return s[1:-1]
+            elif s.startswith('P"'):
+                return s[2:-1].encode().decode("unicode_escape")
+
+    def print(self, fh=None):
+        if fh is None:
+            fh = sys.stdout
+        for line in self.lines:
+            print(line.s, file=fh)
+
+    def choose(self):
+        choices = []
+        for i, line in enumerate(self.lines):
+            if not any(line.s.startswith(pfx) for pfx in self.SSID_PREFIX):
+                continue
+            ssid = self.parse_str(line.s[line.s.find("=") + 1:])
+            chosen = " " if line.s[4] == "#" else "*"
+            print(f"{len(choices):3} {chosen}{ssid}")
+            choices.append((i, line))
+        index, line = choices[int(input("> "))]
+        if line.s.startswith(self.SSID_PREFIX[1]):
+            return
+        for line in self.lines:
+            if line.s.startswith("    ") and line.s[4] != "#":
+                line.s = f"    #{line.s[4:]}"
+        self.lines[index].s = f"    {self.lines[index].s[5:]}"
+        index += 1
+        if index < len(self.lines) and self.lines[index].s.startswith(
+            self.PSK_PREFIX[0]
+        ):
+            self.lines[index].s = f"    {self.lines[index].s[5:]}"
+            return
+        for line in self.lines:
+            if line.s.startswith(self.KEY_MGMT_PREFIX[0]):
+                assert line.s[5:] == "key_mgmt=NONE"
+                line.s = f"    {line.s[5:]}"
+                return
+
+
+def main():
+    assert os.access(WPA_CONFIG, os.W_OK)
+    wpa_config = WpaConfig()
+    with open(WPA_CONFIG) as fh:
+        for line in fh:
+            wpa_config.lines.append(WpaConfig.Line(line.rstrip()))
+    wpa_config.choose()
+    with open(WPA_CONFIG, "wt") as fh:
+        wpa_config.print(fh)
+    check_call(["rc-service", "wpa_supplicant", "restart"])
+
+
+if __name__ == "__main__":
+    main()
diff --git a/set_brightness.sh b/set_brightness.sh
new file mode 100755 (executable)
index 0000000..0e22fd2
--- /dev/null
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+
+if [[ $1 == --show-max || "${1}" == --show ]]; then
+    action="${1:2}"
+    shift
+elif (( ${1:-0} > 0 )); then
+    action=set
+    value=$1
+    shift
+fi
+
+if (( $# )); then
+    echo "Error: invalid argument: '${1}'" >&2
+    exit 1
+elif [[ -z "${action}" ]]; then
+    echo "Error: action required." >&2
+    exit 1
+fi
+
+card="/sys/devices/pci0000:00/0000:00:02.0/drm/card1"
+backlights=(
+    "card1-eDP-1/intel_backlight"
+    "card1-eDP-2/card1-eDP-2-backlight"
+)
+
+for backlight in "${backlights[@]}"; do
+    case "$action" in
+    show-max)
+        echo cat "${card}/${backlight}/max_brightness"
+        cat "${card}/${backlight}/max_brightness"
+        ;;
+    show)
+        echo cat "${card}/${backlight}/brightness"
+        cat "${card}/${backlight}/brightness"
+        ;;
+    set)
+        echo echo "${value}" \>"${card}/${backlight}/brightness"
+        echo "${value}" >"${card}/${backlight}/brightness"
+        ;;
+    esac
+done
diff --git a/static_ip.sh b/static_ip.sh
new file mode 100755 (executable)
index 0000000..a6b3661
--- /dev/null
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+
+set -e
+
+ip link show "${1}" >/dev/null
+ip link set "${1}" up
+ip addr add 192.168.0.254/24 dev "${1}"
+ip route add default via 192.168.0.1