diff options
Diffstat (limited to 'examples/snac-admin')
| -rw-r--r-- | examples/snac-admin | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/examples/snac-admin b/examples/snac-admin index 971618b..e51e28b 100644 --- a/examples/snac-admin +++ b/examples/snac-admin | |||
| @@ -1,43 +1,51 @@ | |||
| 1 | #!/usr/bin/env fish | 1 | #!/usr/bin/env bash |
| 2 | ## | 2 | ## |
| 3 | ## SNAC-ADMIN | 3 | ## SNAC-ADMIN |
| 4 | ## a simple script that is supposed to improve | 4 | ## a simple script that is supposed to improve |
| 5 | ## a snac admin's life, especially when snac | 5 | ## a snac admin's life, especially when snac |
| 6 | ## is being run as a systemd.unit with | 6 | ## is being run as a systemd.unit with |
| 7 | ## DynamicUser=yes enabled. | 7 | ## DynamicUser=yes enabled. |
| 8 | ## Please make sure to adjust SNAC_BASEDIR | 8 | ## Please make sure to adjust SNAC_DIR |
| 9 | ## down below according to your setup. | 9 | ## down below according to your setup. |
| 10 | ## | 10 | ## |
| 11 | ## USAGE | 11 | ## USAGE |
| 12 | ## snac-admin state | 12 | ## snac-admin state |
| 13 | ## snac-admin adduser rikkert | 13 | ## snac-admin adduser rikkert |
| 14 | ## snac-admin block example.org | ||
| 15 | ## snac-admin verify_links lisa | ||
| 16 | ## ... | ||
| 14 | ## | 17 | ## |
| 15 | ## Author: @chris@social.shtrophic.net | 18 | ## Author: @chris@social.shtrophic.net |
| 16 | ## | 19 | ## |
| 17 | ## Released into the public domain | 20 | ## Released into the public domain |
| 18 | ## | 21 | ## |
| 19 | 22 | ||
| 20 | set -l SNAC_PID $(pidof snac) | 23 | set -e |
| 21 | set -l SNAC_BASEDIR /var/lib/snac | ||
| 22 | 24 | ||
| 23 | if test -z $SNAC_PID | 25 | SNAC_PID=$(pidof snac) |
| 24 | echo "no such process" 1>&2 | 26 | SNAC_DIR=/var/lib/snac |
| 27 | |||
| 28 | SNAC_VERB=$1 | ||
| 29 | shift | ||
| 30 | |||
| 31 | if [ -z $SNAC_PID ]; then | ||
| 32 | echo "no such process" >&2 | ||
| 25 | exit 1 | 33 | exit 1 |
| 26 | end | 34 | fi |
| 27 | 35 | ||
| 28 | if test $(id -u) -ne 0 | 36 | if [ $(id -u) -ne 0 ]; then |
| 29 | echo "not root" 1>&2 | 37 | echo "not root" >&2 |
| 30 | exit 1 | 38 | exit 1 |
| 31 | end | 39 | fi |
| 32 | 40 | ||
| 33 | if ! test -d $SNAC_BASEDIR | 41 | if [ ! -d $SNAC_DIR ]; then |
| 34 | echo "$SNAC_BASEDIR does not exist" 1>&2 | 42 | echo "$SNAC_DIR is not a directory" >&2 |
| 35 | exit 1 | 43 | exit 1 |
| 36 | end | 44 | fi |
| 37 | 45 | ||
| 38 | if test -z $argv[1] | 46 | if [ -z $SNAC_VERB ]; then |
| 39 | echo "no arguments" 1>&2 | 47 | echo "no arguments" >&2 |
| 40 | exit 1 | 48 | exit 1 |
| 41 | end | 49 | fi |
| 42 | 50 | ||
| 43 | nsenter -ae -S follow -G follow -t $SNAC_PID -- snac $argv[1] $SNAC_BASEDIR $argv[2..] | 51 | nsenter -ae -S follow -G follow -t $SNAC_PID -- snac $SNAC_VERB $SNAC_DIR $@ |