-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·155 lines (130 loc) · 5.33 KB
/
install.sh
File metadata and controls
executable file
·155 lines (130 loc) · 5.33 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
#!/usr/bin/env bash
# install.sh — installs the containerised toolchain proxies
# Usage: curl -fsSL <url>/install.sh | bash
# Can be re-run to update the proxy scripts in-place.
set -euo pipefail
# --- Configuration ---
REPO_BASE_URL="${REPO_BASE_URL:-https://raw.githubusercontent.com/TykTechnologies/devproxy/refs/heads/main}"
INSTALL_DIR="$HOME/.local/bin/devproxy"
# --- Detect shell profile ---
detect_profile() {
case "${SHELL:-}" in
*/zsh) echo "$HOME/.zshrc" ;;
*/bash) echo "$HOME/.bashrc" ;;
*) echo "$HOME/.profile" ;;
esac
}
PROFILE="$(detect_profile)"
MARKER_START="# >>> devproxy >>>"
MARKER_END="# <<< devproxy <<<"
# --- Remove existing proxies so they don't shadow the real binaries during detection ---
rm -f "$INSTALL_DIR/go" "$INSTALL_DIR/npm" "$INSTALL_DIR/npx" "$INSTALL_DIR/devproxy"
# --- Find the real binaries ---
GO_BINARY="$(command -v go 2>/dev/null || true)"
if [ -z "$GO_BINARY" ]; then
echo "install: 'go' not found on PATH - install Go first" >&2
exit 1
fi
NPM_BINARY="$(command -v npm 2>/dev/null || true)"
if [ -z "$NPM_BINARY" ]; then
echo "install: 'npm' not found on PATH - install Node.js first" >&2
exit 1
fi
NPX_BINARY="$(command -v npx 2>/dev/null || true)"
if [ -z "$NPX_BINARY" ]; then
echo "install: 'npx' not found on PATH - install Node.js first" >&2
exit 1
fi
echo "Using go binary: $GO_BINARY"
echo "Using npm binary: $NPM_BINARY"
echo "Using npx binary: $NPX_BINARY"
# --- Create synthetic GOROOT for IDE integration (e.g. GoLand) ---
REAL_GOROOT="$("$GO_BINARY" env GOROOT)"
SYNTHETIC_GOROOT="$HOME/.local/share/devproxy/goroot"
mkdir -p "$SYNTHETIC_GOROOT/bin"
ln -sf "$INSTALL_DIR/go" "$SYNTHETIC_GOROOT/bin/go"
for dir in src pkg api; do
[ -d "$REAL_GOROOT/$dir" ] && ln -sfn "$REAL_GOROOT/$dir" "$SYNTHETIC_GOROOT/$dir"
done
echo "Created synthetic GOROOT at $SYNTHETIC_GOROOT"
# --- Write ~/.devproxy config file (only on first install) ---
DEVPROXY_CONFIG="$HOME/.devproxy"
if [ -f "$DEVPROXY_CONFIG" ]; then
# Update only binary paths — preserve all other user config
sed -i '' "s|^GO_BINARY=.*|GO_BINARY=\"${GO_BINARY}\"|" "$DEVPROXY_CONFIG"
sed -i '' "s|^NPM_BINARY=.*|NPM_BINARY=\"${NPM_BINARY}\"|" "$DEVPROXY_CONFIG"
sed -i '' "s|^NPX_BINARY=.*|NPX_BINARY=\"${NPX_BINARY}\"|" "$DEVPROXY_CONFIG"
echo "Updated binary paths in $DEVPROXY_CONFIG"
else
cat > "$DEVPROXY_CONFIG" <<EOF
# devproxy configuration - managed by install.sh
# Edit this file to change tool versions or override runtime settings.
# DEVPROXY_UNSECURE=1 # uncomment to always use the native tool binaries
CONTAINER_RUNTIME=
GO_BINARY="${GO_BINARY}"
NPM_BINARY="${NPM_BINARY}"
NPX_BINARY="${NPX_BINARY}"
GODEV_IMAGE=golang:1.25
GODEV_SYNTHETIC_GOROOT="${SYNTHETIC_GOROOT}"
# GODEV_EXTRA_VOLUMES= # uncomment to provide a list of directories to be mounted (colon-separated)
# GODEV_PORTS= # comma-separated ports to publish (e.g. 8080:8080,9090:9090)
# GODEV_NETRC=1 # uncomment to mount ~/.netrc into the container (private modules)
NODEDEV_IMAGE=node:24
# NODEDEV_OS= # target OS for npm binary downloads: empty=linux, host/auto=detect host OS
# NODEDEV_ARCH= # target CPU for npm binary downloads: empty=container arch, host/auto=detect host CPU
# NODEDEV_PORTS= # comma-separated ports to publish (e.g. 3000:3000,8080:8080)
# NODEDEV_NPMRC=1 # uncomment to mount ~/.npmrc into the container (private registries)
EOF
echo "Wrote config to $DEVPROXY_CONFIG"
fi
# --- Download proxy scripts ---
mkdir -p "$INSTALL_DIR"
echo "Downloading go proxy..."
curl -fsSL "$REPO_BASE_URL/go-proxy.sh" -o "$INSTALL_DIR/go"
chmod +x "$INSTALL_DIR/go"
echo "Downloading npm/npx proxy..."
curl -fsSL "$REPO_BASE_URL/npm-npx-proxy.sh" -o "$INSTALL_DIR/npm"
chmod +x "$INSTALL_DIR/npm"
ln -sf "$INSTALL_DIR/npm" "$INSTALL_DIR/npx"
echo "Downloading devproxy manager..."
curl -fsSL "$REPO_BASE_URL/devproxy.sh" -o "$INSTALL_DIR/devproxy"
chmod +x "$INSTALL_DIR/devproxy"
# --- Download Dockerfiles ---
DOCKERFILES_DIR="$HOME/.local/share/devproxy/Dockerfiles"
mkdir -p "$DOCKERFILES_DIR"
echo "Downloading Dockerfiles..."
for dockerfile in devproxy-golang.Dockerfile; do
curl -fsSL "$REPO_BASE_URL/Dockerfiles/$dockerfile" -o "$DOCKERFILES_DIR/$dockerfile"
echo " → $DOCKERFILES_DIR/$dockerfile"
done
# --- Write shell profile block (idempotent via markers) ---
BLOCK="${MARKER_START}
export PATH=\"${INSTALL_DIR}:\$PATH\"
[ -f \"\$HOME/.devproxy\" ] && source \"\$HOME/.devproxy\"
${MARKER_END}"
if grep -qF "$MARKER_START" "$PROFILE" 2>/dev/null; then
# Replace the existing block in-place
# Write block to a temp file — awk -v doesn't support newlines in variable values
BLOCK_FILE="$(mktemp)"
printf '%s\n' "$BLOCK" > "$BLOCK_FILE"
awk -v start="$MARKER_START" -v end="$MARKER_END" -v blockfile="$BLOCK_FILE" '
$0 == start { while ((getline line < blockfile) > 0) print line; skip=1; next }
$0 == end { skip=0; next }
!skip { print }
' "$PROFILE" > "$PROFILE.tmp" && mv "$PROFILE.tmp" "$PROFILE"
rm -f "$BLOCK_FILE"
echo "Updated existing devproxy config in $PROFILE"
else
printf '\n%s\n' "$BLOCK" >> "$PROFILE"
echo "Added devproxy config to $PROFILE"
fi
echo ""
echo "Done. To activate:"
echo " source $PROFILE"
echo ""
echo "Then verify:"
echo " go version"
echo " npm --version"
echo ""
echo "GoLand integration:"
echo " Settings → Go → GOROOT → Add local → $SYNTHETIC_GOROOT"