56 lines
1.2 KiB
Bash
Executable file
56 lines
1.2 KiB
Bash
Executable file
#!/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() {
|
|
ssh -i "$SSH_KEY" -t "$SSH_HOST" "$@"
|
|
}
|
|
|
|
copy_and_run() {
|
|
file=$1
|
|
scp -i "$SSH_KEY" "$file" "$SSH_HOST":"$SSH_DEST_DIR"
|
|
ssh_run_cmd "${SSH_DEST_DIR:-.}/sojourn"
|
|
}
|
|
|
|
{
|
|
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;;
|
|
"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"
|
|
;;
|
|
"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
|
|
}
|