-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·166 lines (144 loc) · 5.01 KB
/
install.sh
File metadata and controls
executable file
·166 lines (144 loc) · 5.01 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env bash
# dploy installer — downloads a prebuilt CLI bundle from GitHub Releases.
#
# If you have npm, the simplest install is:
# npm install -g @ryantanen/dploy
#
# This script is the no-npm path. It downloads the prebuilt tarball from
# GitHub Releases, extracts it, and drops a launcher on PATH. Same artifact
# CI publishes to npm — just delivered as a tarball instead.
#
# Quick install:
# curl -fsSL https://raw.githubusercontent.com/nathanaronson/hp-sp-26/main/install.sh | bash
#
# Pin a release / change install location / point at a backend:
# curl -fsSL https://.../install.sh | DPLOY_REF=v0.1.0 BIN_DIR=/usr/local/bin bash
#
# Environment variables:
# DPLOY_REPO GitHub repo (default: nathanaronson/hp-sp-26)
# DPLOY_REF Release tag to install (default: latest stable, falls back to nightly)
# Use "nightly" for the rolling main-branch build.
# DPLOY_HOME Where bundles are staged (default: $HOME/.dploy)
# BIN_DIR Where `dploy` is linked (default: $HOME/.local/bin)
# DPLOY_API_URL Backend URL the CLI calls (default: http://localhost:8000)
set -euo pipefail
DPLOY_REPO="${DPLOY_REPO:-nathanaronson/hp-sp-26}"
DPLOY_REF="${DPLOY_REF:-}"
DPLOY_HOME="${DPLOY_HOME:-$HOME/.dploy}"
BIN_DIR="${BIN_DIR:-$HOME/.local/bin}"
ARTIFACT="dploy.tgz"
LAUNCHER="$BIN_DIR/dploy"
# ---------- pretty output ----------
if [ -t 1 ]; then
BOLD=$(printf '\033[1m'); DIM=$(printf '\033[2m'); RESET=$(printf '\033[0m')
GREEN=$(printf '\033[32m'); YELLOW=$(printf '\033[33m'); RED=$(printf '\033[31m')
BLUE=$(printf '\033[34m')
else
BOLD=""; DIM=""; RESET=""; GREEN=""; YELLOW=""; RED=""; BLUE=""
fi
step() { printf '%s==>%s %s%s%s\n' "$BLUE" "$RESET" "$BOLD" "$1" "$RESET"; }
info() { printf ' %s%s%s\n' "$DIM" "$1" "$RESET"; }
warn() { printf '%s! %s%s\n' "$YELLOW" "$1" "$RESET"; }
ok() { printf '%s✓%s %s\n' "$GREEN" "$RESET" "$1"; }
die() { printf '%s✗ %s%s\n' "$RED" "$1" "$RESET" >&2; exit 1; }
# ---------- prerequisite checks ----------
step "Checking prerequisites"
for c in curl tar node; do
command -v "$c" >/dev/null 2>&1 || die "$c is required but not installed."
done
NODE_MAJOR="$(node -p 'process.versions.node.split(".")[0]' 2>/dev/null || echo 0)"
if [ "$NODE_MAJOR" -lt 20 ]; then
die "node >= 20 required (found $(node -v)). Upgrade via nvm or your package manager."
fi
ok "node $(node -v)"
# ---------- pick download URL ----------
release_url() {
local tag="$1"
printf 'https://github.com/%s/releases/download/%s/%s' \
"$DPLOY_REPO" "$tag" "$ARTIFACT"
}
if [ -n "$DPLOY_REF" ]; then
URL="$(release_url "$DPLOY_REF")"
CHANNEL="$DPLOY_REF"
else
URL="https://github.com/$DPLOY_REPO/releases/latest/download/$ARTIFACT"
CHANNEL="latest"
step "Resolving latest release"
if ! curl -fsSLI -o /dev/null "$URL" 2>/dev/null; then
info "no stable release yet — falling back to nightly"
URL="$(release_url "nightly")"
CHANNEL="nightly"
fi
fi
# ---------- download ----------
step "Downloading dploy ($CHANNEL)"
info "$URL"
TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT
if ! curl -fSL --progress-bar "$URL" -o "$TMP/$ARTIFACT"; then
die "download failed: $URL"
fi
SIZE_BYTES=$(wc -c < "$TMP/$ARTIFACT" | tr -d ' ')
[ "$SIZE_BYTES" -gt 1000 ] || die "downloaded archive is suspiciously small (${SIZE_BYTES}b)"
ok "downloaded ${SIZE_BYTES} bytes"
# ---------- extract ----------
step "Installing to $DPLOY_HOME"
INSTALL_DIR="$DPLOY_HOME/install"
rm -rf "$INSTALL_DIR"
mkdir -p "$INSTALL_DIR" "$BIN_DIR"
tar -xzf "$TMP/$ARTIFACT" -C "$INSTALL_DIR"
[ -f "$INSTALL_DIR/dist/cli.js" ] || die "archive is missing dist/cli.js (corrupt?)"
ok "extracted"
# Record what's installed so `dploy --version` and future updates can introspect.
cat > "$DPLOY_HOME/install.json" <<EOF
{
"channel": "$CHANNEL",
"source": "$URL",
"installed_at": "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
}
EOF
# ---------- launcher ----------
step "Linking $LAUNCHER"
cat > "$LAUNCHER" <<EOF
#!/usr/bin/env bash
# Auto-generated by dploy installer. Re-run installer to update.
DPLOY_HOME="\${DPLOY_HOME:-$DPLOY_HOME}"
exec node "\$DPLOY_HOME/install/dist/cli.js" "\$@"
EOF
chmod +x "$LAUNCHER"
ok "launcher installed"
# ---------- post-install ----------
echo
ok "${BOLD}dploy installed${RESET} → $LAUNCHER"
echo
case ":$PATH:" in
*":$BIN_DIR:"*) ;;
*)
warn "$BIN_DIR is not on your PATH."
case "${SHELL##*/}" in
zsh) RC="$HOME/.zshrc" ;;
bash) RC="$HOME/.bashrc" ;;
fish) RC="your fish config" ;;
*) RC="your shell rc file" ;;
esac
cat <<EOF
Add this to $RC and restart your shell:
export PATH="$BIN_DIR:\$PATH"
EOF
;;
esac
if [ -z "${DPLOY_API_URL:-}" ]; then
cat <<EOF
${DIM}By default, dploy talks to the hosted backend at
https://hackprinceton--dploy-backend-fastapi-app-dev.modal.run.
To point it at a self-hosted backend (or your local dev server), set:
export DPLOY_API_URL=http://localhost:8000
${RESET}
EOF
fi
cat <<EOF
Try it:
dploy --help
dploy login
dploy deploy https://github.com/org/repo
EOF