-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·51 lines (40 loc) · 1.26 KB
/
deploy.sh
File metadata and controls
executable file
·51 lines (40 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
set -e
# Deploy hu to junkpile (builds remotely)
# Usage: ./deploy.sh [-f|--force]
HOST="junkpile"
REPO_PATH="/tmp/hu-build"
CARGO_ENV="source ~/.cargo/env"
INSTALL_PATH="/usr/local/bin/hu"
FORCE=false
if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then
FORCE=true
fi
echo "=== Checking if deploy needed ==="
LOCAL_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/')
REMOTE_VERSION=$(ssh "$HOST" "hu --version 2>/dev/null | awk '{print \$2}'" || echo "not installed")
echo "Local: $LOCAL_VERSION"
echo "Remote: ${REMOTE_VERSION:-not installed}"
if [ "$FORCE" = false ] && [ "$LOCAL_VERSION" = "$REMOTE_VERSION" ]; then
echo ""
echo "=== Already up to date, skipping deploy ==="
echo "Use -f or --force to deploy anyway"
exit 0
fi
echo ""
echo "=== Syncing source to $HOST ==="
rsync -az --delete \
--exclude 'target' \
--exclude '.git' \
. "$HOST:$REPO_PATH/"
echo ""
echo "=== Building on $HOST ==="
ssh "$HOST" "$CARGO_ENV && cd $REPO_PATH && cargo build --release"
echo ""
echo "=== Installing to $INSTALL_PATH ==="
ssh "$HOST" "sudo cp $REPO_PATH/target/release/hu $INSTALL_PATH && sudo chmod +x $INSTALL_PATH"
echo ""
echo "=== Remote Version ==="
ssh "$HOST" "hu --version"
echo ""
echo "=== Deployment Complete ==="