From 84e72a52286db8e0af2d4a671f4b042d3e69f0d2 Mon Sep 17 00:00:00 2001 From: shtrophic Date: Sun, 30 Mar 2025 22:13:54 +0200 Subject: add snac-admin --- examples/snac-admin | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 examples/snac-admin (limited to 'examples') diff --git a/examples/snac-admin b/examples/snac-admin new file mode 100644 index 0000000..971618b --- /dev/null +++ b/examples/snac-admin @@ -0,0 +1,43 @@ +#!/usr/bin/env fish +## +## SNAC-ADMIN +## a simple script that is supposed to improve +## a snac admin's life, especially when snac +## is being run as a systemd.unit with +## DynamicUser=yes enabled. +## Please make sure to adjust SNAC_BASEDIR +## down below according to your setup. +## +## USAGE +## snac-admin state +## snac-admin adduser rikkert +## +## Author: @chris@social.shtrophic.net +## +## Released into the public domain +## + +set -l SNAC_PID $(pidof snac) +set -l SNAC_BASEDIR /var/lib/snac + +if test -z $SNAC_PID + echo "no such process" 1>&2 + exit 1 +end + +if test $(id -u) -ne 0 + echo "not root" 1>&2 + exit 1 +end + +if ! test -d $SNAC_BASEDIR + echo "$SNAC_BASEDIR does not exist" 1>&2 + exit 1 +end + +if test -z $argv[1] + echo "no arguments" 1>&2 + exit 1 +end + +nsenter -ae -S follow -G follow -t $SNAC_PID -- snac $argv[1] $SNAC_BASEDIR $argv[2..] -- cgit v1.2.3 From 570a8e3d5ddad26ce2a348877e3d8d5f32f6f748 Mon Sep 17 00:00:00 2001 From: shtrophic Date: Tue, 1 Apr 2025 11:33:54 +0200 Subject: convert snac-admin to bash --- examples/snac-admin | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) (limited to 'examples') 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 @@ -#!/usr/bin/env fish +#!/usr/bin/env bash ## ## SNAC-ADMIN ## a simple script that is supposed to improve ## a snac admin's life, especially when snac ## is being run as a systemd.unit with ## DynamicUser=yes enabled. -## Please make sure to adjust SNAC_BASEDIR +## Please make sure to adjust SNAC_DIR ## down below according to your setup. ## ## USAGE ## snac-admin state ## snac-admin adduser rikkert +## snac-admin block example.org +## snac-admin verify_links lisa +## ... ## ## Author: @chris@social.shtrophic.net ## ## Released into the public domain ## -set -l SNAC_PID $(pidof snac) -set -l SNAC_BASEDIR /var/lib/snac +set -e -if test -z $SNAC_PID - echo "no such process" 1>&2 +SNAC_PID=$(pidof snac) +SNAC_DIR=/var/lib/snac + +SNAC_VERB=$1 +shift + +if [ -z $SNAC_PID ]; then + echo "no such process" >&2 exit 1 -end +fi -if test $(id -u) -ne 0 - echo "not root" 1>&2 +if [ $(id -u) -ne 0 ]; then + echo "not root" >&2 exit 1 -end +fi -if ! test -d $SNAC_BASEDIR - echo "$SNAC_BASEDIR does not exist" 1>&2 +if [ ! -d $SNAC_DIR ]; then + echo "$SNAC_DIR is not a directory" >&2 exit 1 -end +fi -if test -z $argv[1] - echo "no arguments" 1>&2 +if [ -z $SNAC_VERB ]; then + echo "no arguments" >&2 exit 1 -end +fi -nsenter -ae -S follow -G follow -t $SNAC_PID -- snac $argv[1] $SNAC_BASEDIR $argv[2..] +nsenter -ae -S follow -G follow -t $SNAC_PID -- snac $SNAC_VERB $SNAC_DIR $@ -- cgit v1.2.3