Skip to main content

max / pom

2.1 KB · 72 lines History Blame Raw
1 #!/usr/bin/env bash
2 set -euo pipefail
3
4 ASTRA_HOST="max@100.106.221.39"
5 HETZNER_HOST="root@100.120.174.96"
6
7 SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
8 PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
9
10 deploy_target() {
11 local name="$1"
12 local host target sudo_prefix=""
13
14 case "$name" in
15 astra)
16 host="$ASTRA_HOST"
17 target="aarch64-unknown-linux-gnu"
18 sudo_prefix="sudo"
19 ;;
20 hetzner)
21 host="$HETZNER_HOST"
22 target="x86_64-unknown-linux-gnu"
23 ;;
24 *)
25 echo "Unknown target: $name (use astra, hetzner, or all)"
26 exit 1
27 ;;
28 esac
29
30 echo "=== Building pom for $name ($target) ==="
31 cargo zigbuild --release --target "$target" --manifest-path "$PROJECT_DIR/Cargo.toml"
32
33 local binary="$PROJECT_DIR/target/$target/release/pom"
34
35 local config_file="$SCRIPT_DIR/pom-${name}.toml"
36 if [ ! -f "$config_file" ]; then
37 echo "Config not found: $config_file"
38 exit 1
39 fi
40
41 echo "=== Deploying to $name ($host) ==="
42 ssh "$host" "$sudo_prefix mkdir -p /etc/pom"
43 scp "$binary" "$host:/tmp/pom"
44 scp "$config_file" "$host:/tmp/pom.toml"
45 scp "$SCRIPT_DIR/pom.service" "$host:/tmp/pom.service"
46
47 ssh "$host" "$sudo_prefix mv /tmp/pom /usr/local/bin/pom && $sudo_prefix chmod +x /usr/local/bin/pom && $sudo_prefix mv /tmp/pom.toml /etc/pom/pom.toml && $sudo_prefix mv /tmp/pom.service /etc/systemd/system/pom.service"
48
49 # Create env file with Postmark token if it doesn't exist
50 ssh "$host" "if [ ! -f /etc/pom/env ]; then echo 'POM_POSTMARK_TOKEN=SET_ME' | $sudo_prefix tee /etc/pom/env > /dev/null && $sudo_prefix chmod 600 /etc/pom/env; fi"
51
52 ssh "$host" "$sudo_prefix systemctl daemon-reload && $sudo_prefix systemctl enable pom && $sudo_prefix systemctl restart pom"
53
54 echo "=== $name: deployed ==="
55 ssh "$host" "$sudo_prefix systemctl status pom --no-pager"
56 }
57
58 if [ $# -eq 0 ]; then
59 echo "Usage: $0 <astra|hetzner|all>"
60 exit 1
61 fi
62
63 case "$1" in
64 all)
65 deploy_target astra
66 deploy_target hetzner
67 ;;
68 *)
69 deploy_target "$1"
70 ;;
71 esac
72