commit 233b085a8fa0b1eef043b2e61398eb6becd96707
parent e4da83dbb7d3fbea2421d5a327780653f8d1b40c
Author: Jan Pobrislo <ccx@te2000.cz>
Date: Thu, 22 May 2025 21:10:30 +0000
rfkill capability
Diffstat:
2 files changed, 103 insertions(+), 7 deletions(-)
diff --git a/sbin/login.capability.app-terminal b/sbin/login.capability.app-terminal
@@ -1,10 +1,11 @@
#!/bin/zsh
setopt no_unset extended_glob warn_create_global
+typeset -g scriptname=${0:t}
die_n() {
exitcode=$1
shift
- printf >&2 '%s\n' "$@"
+ printf >&2 '%s\n' "$scriptname: fatal: $@"
exit $exitcode
}
@@ -16,6 +17,10 @@ die111() {
die_n 111 "$@"
}
+die_usage() {
+ die100 "$@" "usage: login.capability.app-terminal app_name"
+}
+
launch-urxvt() {
local container cmd exec_sock urxvt_sock
container=$1
@@ -86,13 +91,8 @@ check_command() {
quoted_cmd="${(j: :)quoted}"
}
-ensure-container-started() {
- [[ $1 == */* ]] && die "Invalid container name: ${(qqq)1}"
- s6-svc -wU -T 4000 -o /run/service/container.$1 || die111 "failed to start container ${(qqq)1}"
-}
-
main() {
- [[ $# == 1 ]] || die100 "usage: ${0:t} app"
+ [[ $# == 1 ]] || die_usage "Incorrect number of arguments"
check_command $1
ensure-container-started $container
launch-urxvt $container $quoted_cmd
diff --git a/sbin/login.capability.rfkill b/sbin/login.capability.rfkill
@@ -0,0 +1,96 @@
+#!/bin/zsh
+setopt no_unset warn_create_global extended_glob
+
+# # rfkill -h
+#
+# Usage:
+# rfkill [options] command [identifier ...]
+#
+# Tool for enabling and disabling wireless devices.
+#
+# Options:
+# -J, --json use JSON output format
+# -n, --noheadings don't print headings
+# -o, --output <list> define which output columns to use
+# --output-all output all columns
+# -r, --raw use the raw output format
+#
+# -h, --help display this help
+# -V, --version display version
+#
+# Available output columns:
+# DEVICE kernel device name
+# ID device identifier value
+# TYPE device type name that can be used as identifier
+# TYPE-DESC device type description
+# SOFT status of software block
+# HARD status of hardware block
+#
+# Commands:
+# help
+# event
+# list [identifier]
+# block identifier
+# unblock identifier
+# toggle identifier
+#
+# For more details see rfkill(8).
+
+typeset -g scriptname=${0:t}
+die_n() {
+ exitcode=$1
+ shift
+ printf >&2 '%s\n' "$scriptname: fatal: $@"
+ exit $exitcode
+}
+
+die100() {
+ die_n 100 "$@"
+}
+
+die111() {
+ die_n 111 "$@"
+}
+
+die_usage() {
+ die100 "$@" "usage: login.capability.rfkill (block|unblock|toggle) identifier"
+}
+
+check_arguments() {
+ [[ $# == 2 ]] || die_usage "Incorrect number of arguments"
+ case $1 in
+ (block|unblock|toggle) return;;
+ esac
+ die_usage "invalid command: ${(qqq)1}"
+ case $2 in
+ ([0-9]) return;;
+ esac
+ die100 "identifier not allowed: ${(qqq)2}"
+}
+
+ensure-container-started() {
+ [[ $1 == */* ]] && die "Invalid container name: ${(qqq)1}"
+ s6-svc -wU -T 4000 -o /run/service/container.$1 || die111 "failed to start container ${(qqq)1}"
+}
+
+container_exec() {
+ local container exec_sock
+ container=$1
+ shift
+
+ exec_sock=/run/containers/$container/run/exec/exec
+ [[ -S $exec_sock ]] ||
+ die111 "Socket for exec not present: ${(qqq)exec_sock}"
+
+ exec s6-sudo $exec_sock
+}
+
+main() {
+ check_arguments "$@"
+ ensure-container-started networking.networking
+ container_exec networking.networking rfkill "$@"
+}
+typeset -f -t main
+
+main "$@"
+# vim: ft=zsh noet ts=4 sts=4 sw=4