Skip to main content

max / makenotwork

2.3 KB · 74 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="" ssh_opts="" scp_opts=""
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 ssh_opts="-p 2200"
24 scp_opts="-P 2200"
25 ;;
26 *)
27 echo "Unknown target: $name (use astra, hetzner, or all)"
28 exit 1
29 ;;
30 esac
31
32 echo "=== Building pom for $name ($target) ==="
33 cargo zigbuild --release --target "$target" --manifest-path "$PROJECT_DIR/Cargo.toml"
34
35 local binary="$PROJECT_DIR/target/$target/release/pom"
36
37 local config_file="$SCRIPT_DIR/pom-${name}.toml"
38 if [ ! -f "$config_file" ]; then
39 echo "Config not found: $config_file"
40 exit 1
41 fi
42
43 echo "=== Deploying to $name ($host) ==="
44 ssh $ssh_opts "$host" "$sudo_prefix mkdir -p /etc/pom"
45 scp $scp_opts "$binary" "$host:/tmp/pom"
46 scp $scp_opts "$config_file" "$host:/tmp/pom.toml"
47 scp $scp_opts "$SCRIPT_DIR/pom.service" "$host:/tmp/pom.service"
48
49 ssh $ssh_opts "$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"
50
51 # Create env file with Postmark token if it doesn't exist
52 ssh $ssh_opts "$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"
53
54 ssh $ssh_opts "$host" "$sudo_prefix systemctl daemon-reload && $sudo_prefix systemctl enable pom && $sudo_prefix systemctl restart pom"
55
56 echo "=== $name: deployed ==="
57 ssh $ssh_opts "$host" "$sudo_prefix systemctl status pom --no-pager"
58 }
59
60 if [ $# -eq 0 ]; then
61 echo "Usage: $0 <astra|hetzner|all>"
62 exit 1
63 fi
64
65 case "$1" in
66 all)
67 deploy_target astra
68 deploy_target hetzner
69 ;;
70 *)
71 deploy_target "$1"
72 ;;
73 esac
74