sconnect/bin/sc
2024-06-06 02:17:54 +02:00

46 lines
1.3 KiB
Bash
Executable file

#!/bin/sh
SC_COMMAND="$0 $@"
SC_LIB=${SC_LIB:-/usr/lib/sc}
. $SC_LIB/setup-env
SC_HOSTS=""
while getopts "h:" opt; do
case $opt in
h)
SC_HOSTS="$SC_HOSTS $OPTARG"
;;
esac
done
shift $((OPTIND - 1))
([ $# -lt 1 ] || [ -z "$1" ]) && fatal_log "usage: $0 [...args] <command>"
command=$1
shift
for host in $SC_HOSTS; do
case $command in
install)
if [ "$host" = "local" ]; then
escalate_command a3 ./meta.a3 install
else
LOGI "attempting to install on $host..."
if ! ssh $host "command -v a3"; then
LOGI "no a3, installing..."
ssh -t $host "git clone https://git.saluco.nl/strix/aaa /tmp/a3 && cd /tmp/a3 && sudo A3_LIB=./lib bin/a3 ./meta.a3 install; rm -rf /tmp/a3"
fi
ssh $host "git clone https://git.saluco.nl/strix/sconnect /tmp/sconnect && cd /tmp/sconnect && sudo a3 /tmp/sconnect/main.a3 install; rm -rf /tmp/sconnect"
LOGI "installed"
fi
;;
*)
if [ "$host" = "local" ]; then
sc-client $command $@
else
ssh -t $host SC_SKIP_WELCOME_HEADER=1 sc-client check 2>/dev/null || fatal_log not installed
ssh -t $host sc-client $command $@
fi
;;
esac
done