commit 570a8e3

shtrophic  ·  2025-04-01 09:33:54 +0000 UTC
parent 84e72a5
convert snac-admin to bash
1 files changed,  +25, -17
+25, -17
 1@@ -1,43 +1,51 @@
 2-#!/usr/bin/env fish
 3+#!/usr/bin/env bash
 4 ##
 5 ## SNAC-ADMIN
 6 ##  a simple script that is supposed to improve
 7 ##  a snac admin's life, especially when snac
 8 ##  is being run as a systemd.unit with
 9 ##  DynamicUser=yes enabled.
10-##  Please make sure to adjust SNAC_BASEDIR
11+##  Please make sure to adjust SNAC_DIR
12 ##  down below according to your setup.
13 ##
14 ## USAGE
15 ##  snac-admin state
16 ##  snac-admin adduser rikkert
17+##  snac-admin block example.org
18+##  snac-admin verify_links lisa
19+##  ...
20 ##
21 ## Author: @chris@social.shtrophic.net
22 ## 
23 ## Released into the public domain 
24 ##
25 
26-set -l SNAC_PID 	$(pidof snac)
27-set -l SNAC_BASEDIR	/var/lib/snac
28+set -e
29 
30-if test -z $SNAC_PID
31-	echo "no such process" 1>&2
32+SNAC_PID=$(pidof snac)
33+SNAC_DIR=/var/lib/snac
34+
35+SNAC_VERB=$1
36+shift
37+
38+if [ -z $SNAC_PID ]; then
39+	echo "no such process" >&2
40 	exit 1
41-end
42+fi
43 
44-if test $(id -u) -ne 0
45-	echo "not root" 1>&2
46+if [ $(id -u) -ne 0 ]; then
47+	echo "not root" >&2
48 	exit 1
49-end
50+fi
51 
52-if ! test -d $SNAC_BASEDIR
53-	echo "$SNAC_BASEDIR does not exist" 1>&2
54+if [ ! -d $SNAC_DIR ]; then
55+	echo "$SNAC_DIR is not a directory" >&2
56 	exit 1
57-end
58+fi
59 
60-if test -z $argv[1]
61-	echo "no arguments" 1>&2
62+if [ -z $SNAC_VERB ]; then
63+	echo "no arguments" >&2
64 	exit 1
65-end
66+fi
67 
68-nsenter -ae -S follow -G follow -t $SNAC_PID -- snac $argv[1] $SNAC_BASEDIR $argv[2..]
69+nsenter -ae -S follow -G follow -t $SNAC_PID -- snac $SNAC_VERB $SNAC_DIR $@