mrrl-logincaps

MRRL version of logincaps
git clone https://ccx.te2000.cz/git/mrrl-logincaps
Log | Files | Refs

login.capability.rfkill (2139B)


      1 #!/bin/zsh
      2 setopt no_unset warn_create_global extended_glob
      3 
      4 # # rfkill -h
      5 #
      6 # Usage:
      7 #  rfkill [options] command [identifier ...]
      8 #
      9 # Tool for enabling and disabling wireless devices.
     10 #
     11 # Options:
     12 #  -J, --json             use JSON output format
     13 #  -n, --noheadings       don't print headings
     14 #  -o, --output <list>    define which output columns to use
     15 #      --output-all       output all columns
     16 #  -r, --raw              use the raw output format
     17 #
     18 #  -h, --help             display this help
     19 #  -V, --version          display version
     20 #
     21 # Available output columns:
     22 #  DEVICE      kernel device name
     23 #  ID          device identifier value
     24 #  TYPE        device type name that can be used as identifier
     25 #  TYPE-DESC   device type description
     26 #  SOFT        status of software block
     27 #  HARD        status of hardware block
     28 #
     29 # Commands:
     30 #  help
     31 #  event
     32 #  list   [identifier]
     33 #  block   identifier
     34 #  unblock identifier
     35 #  toggle  identifier
     36 #
     37 # For more details see rfkill(8).
     38 
     39 typeset -g scriptname=${0:t}
     40 die_n() {
     41 	exitcode=$1
     42 	shift
     43 	printf >&2 '%s\n' "$scriptname: fatal: $@"
     44 	exit $exitcode
     45 }
     46 
     47 die100() {
     48 	die_n 100 "$@"
     49 }
     50 
     51 die111() {
     52 	die_n 111 "$@"
     53 }
     54 
     55 die_usage() {
     56 	die100 "$@" "usage: login.capability.rfkill (block|unblock|toggle) identifier"
     57 }
     58 
     59 check_arguments() {
     60 	[[ $# == 2 ]] || die_usage "Incorrect number of arguments"
     61 	case $1 in
     62 		(block|unblock|toggle) return;;
     63 	esac
     64 	die_usage "invalid command: ${(qqq)1}"
     65 	case $2 in
     66 		([0-9]) return;;
     67 	esac
     68 	die100 "identifier not allowed: ${(qqq)2}"
     69 }
     70 
     71 ensure-container-started() {
     72 	[[ $1 == */* ]] && die "Invalid container name: ${(qqq)1}"
     73 	s6-svc -wU -T 4000 -o /run/service/container.$1 || die111 "failed to start container ${(qqq)1}"
     74 }
     75 
     76 container_exec() {
     77 	local container exec_sock
     78 	container=$1
     79 	shift
     80 
     81 	exec_sock=/run/containers/$container/run/exec/exec
     82 	[[ -S $exec_sock ]] ||
     83 		die111 "Socket for exec not present: ${(qqq)exec_sock}"
     84 
     85 	exec s6-sudo $exec_sock "$@"
     86 }
     87 
     88 main() {
     89 	check_arguments "$@"
     90 	ensure-container-started networking.networking
     91 	container_exec networking.networking rfkill "$@"
     92 }
     93 typeset -f -t main
     94 
     95 main "$@"
     96 #  vim: ft=zsh noet ts=4 sts=4 sw=4