54 lines
1.1 KiB
Plaintext
54 lines
1.1 KiB
Plaintext
|
#!/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" "$SSH_HOST" "$@"
|
||
|
}
|
||
|
|
||
|
copy_and_run() {
|
||
|
file=$1
|
||
|
scp -i "$SSH_KEY" "$file" "$SSH_HOST":"$SSH_DEST_DIR"
|
||
|
ssh_run_cmd "${SSH_DEST_DIR:-.}/pipod"
|
||
|
}
|
||
|
|
||
|
{
|
||
|
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/pipod;;
|
||
|
"run") ./cmd release && copy_and_run ./target/arm-unknown-linux-gnueabihf/release/pipod;;
|
||
|
"remote-clean") ssh_run_cmd rm -f "${SSH_DEST_DIR:-.}/pipod";;
|
||
|
"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
|
||
|
}
|