#!/bin/sh

# This script is used to store local configuartion data to ease batch building

# Please customize this script to fit your local requirements

set -e

if [ $# != 1 ]; then
	printf 'Usage: %s <client-name>\n' "$0" 1>&2
	exit 255
fi

export CC=gcc
export CFLAGS="-Wall -Os -fno-common -fomit-frame-pointer"
export LDFLAGS=-s
# Edit the following line to fill the server address, port number, public key,
# as well as the privileged SSHOUT user name
sh build.sh <server-address> <server-port> <server-public-key> <privileged-user-name> "$1"
# Example:
#sh build.sh 127.0.0.1 22 [payload removed: 372 characters] operator
echo
echo "set -e"
printf 'echo "'
xz --best < "client.$1" | base64 -w 80
# You may customize executable file name and service name here
echo '" | base64 -d | xz -d > /usr/local/bin/sfc'
echo "chmod 755 /usr/local/bin/sfc"
printf 'echo "'
gzip --best < sfc.service | base64 -w 80
echo '" | base64 -d | gzip -d > /etc/systemd/system/sfc.service'
echo "systemctl enable --now sfc"
