2024-08-29 13:54:20 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
if [ -f "./.env" ]; then
|
|
|
|
set -a
|
|
|
|
source .env
|
|
|
|
set +a
|
|
|
|
else
|
|
|
|
echo "No .env file found."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$#" -gt 0 ]; then
|
|
|
|
cmd=$1
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
cmd="help"
|
|
|
|
fi
|
|
|
|
|
|
|
|
ssh_run_cmd() {
|
2024-09-01 09:13:12 -05:00
|
|
|
ssh -i "$SSH_KEY" -t "$SSH_HOST" "$@"
|
2024-08-29 13:54:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
copy_and_run() {
|
|
|
|
file=$1
|
|
|
|
scp -i "$SSH_KEY" "$file" "$SSH_HOST":"$SSH_DEST_DIR"
|
2024-09-01 09:13:12 -05:00
|
|
|
ssh_run_cmd "${SSH_DEST_DIR:-.}/sojourn"
|
2024-08-29 13:54:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
set -euo pipefail
|
|
|
|
case "$cmd" in
|
|
|
|
"clean") cargo clean;;
|
|
|
|
"build") cargo build --target arm-unknown-linux-gnueabihf;;
|
|
|
|
"release") cargo build --release --target arm-unknown-linux-gnueabihf;;
|
2024-09-01 09:13:12 -05:00
|
|
|
"debug") ./cmd build && copy_and_run ./target/arm-unknown-linux-gnueabihf/debug/sojourn;;
|
|
|
|
"run") ./cmd release && copy_and_run ./target/arm-unknown-linux-gnueabihf/release/sojourn;;
|
|
|
|
"remote-clean")
|
|
|
|
ssh_run_cmd killall sojourn
|
|
|
|
ssh_run_cmd rm -f "${SSH_DEST_DIR:-.}/sojourn"
|
|
|
|
;;
|
2024-08-29 13:54:20 -05:00
|
|
|
"help")
|
|
|
|
echo "Usage: ./cmd [task]"
|
|
|
|
echo "Tasks: clean, build, release, debug, run, remote-clean, help"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unrecognized task '$cmd'."
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
} || {
|
|
|
|
code=$?
|
|
|
|
echo "An error occurred while executing the command ($code)."
|
|
|
|
exit $code
|
|
|
|
}
|