From bfd8f46ac48d6b73f907f1d052a6e093fe45a4fe Mon Sep 17 00:00:00 2001 From: mar77i Date: Tue, 30 Jun 2026 12:03:32 +0200 Subject: [PATCH 1/1] initial commit --- reinstall_from_today.py | 35 ++++++++++++++++++ select_wifi.py | 78 +++++++++++++++++++++++++++++++++++++++++ set_brightness.sh | 41 ++++++++++++++++++++++ static_ip.sh | 8 +++++ 4 files changed, 162 insertions(+) create mode 100755 reinstall_from_today.py create mode 100755 select_wifi.py create mode 100755 set_brightness.sh create mode 100755 static_ip.sh diff --git a/reinstall_from_today.py b/reinstall_from_today.py new file mode 100755 index 0000000..ec6e18a --- /dev/null +++ b/reinstall_from_today.py @@ -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 index 0000000..d0c3a53 --- /dev/null +++ b/select_wifi.py @@ -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 index 0000000..0e22fd2 --- /dev/null +++ b/set_brightness.sh @@ -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 index 0000000..a6b3661 --- /dev/null +++ b/static_ip.sh @@ -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 -- 2.54.0