-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·119 lines (100 loc) · 4.15 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·119 lines (100 loc) · 4.15 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
#!/usr/bin/env sh
# Install script for megalodon.
# Upload this file as a GitHub Release asset alongside the binaries so users can run:
# curl -fsSL https://github.com/ujjwall-R/megalodon/releases/latest/download/install.sh | sh
set -e
REPO="ujjwall-R/megalodon"
BINARY="meg"
INSTALL_DIR="/usr/local/bin"
# ── Colour helpers ─────────────────────────────────────────────────────────────
red() { printf '\033[31m%s\033[0m\n' "$*"; }
green() { printf '\033[32m%s\033[0m\n' "$*"; }
dim() { printf '\033[2m%s\033[0m\n' "$*"; }
bold() { printf '\033[1m%s\033[0m\n' "$*"; }
# ── Detect OS ──────────────────────────────────────────────────────────────────
detect_os() {
case "$(uname -s)" in
Darwin) echo "macos" ;;
Linux) echo "linux" ;;
*)
red "Unsupported OS: $(uname -s)"
exit 1
;;
esac
}
# ── Detect architecture ────────────────────────────────────────────────────────
detect_arch() {
case "$(uname -m)" in
arm64|aarch64) echo "arm64" ;;
x86_64|amd64) echo "x64" ;;
*)
red "Unsupported architecture: $(uname -m)"
exit 1
;;
esac
}
# ── Resolve latest release tag from GitHub ────────────────────────────────────
latest_version() {
curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \
| grep '"tag_name"' \
| sed 's/.*"tag_name": *"\(.*\)".*/\1/'
}
# ── Main ───────────────────────────────────────────────────────────────────────
main() {
bold ""
bold " meg installer"
dim " https://github.com/${REPO}"
bold ""
OS="$(detect_os)"
ARCH="$(detect_arch)"
VERSION="${VERSION:-$(latest_version)}"
if [ -z "$VERSION" ]; then
red "Could not resolve latest release. Set VERSION manually:"
red " VERSION=v1.0.0 sh install.sh"
exit 1
fi
ASSET="${BINARY}-${OS}-${ARCH}"
URL="https://github.com/${REPO}/releases/download/${VERSION}/${ASSET}"
dim " OS : ${OS}"
dim " Arch : ${ARCH}"
dim " Version : ${VERSION}"
dim " Binary : ${ASSET}"
printf "\n"
# ── Download ────────────────────────────────────────────────────────────────
TMP="$(mktemp)"
printf " Downloading... "
if ! curl -fsSL "$URL" -o "$TMP"; then
printf "\n"
red "Download failed. Check that release ${VERSION} exists:"
red " https://github.com/${REPO}/releases"
rm -f "$TMP"
exit 1
fi
printf "done\n"
chmod +x "$TMP"
# ── Install ─────────────────────────────────────────────────────────────────
TARGET="${INSTALL_DIR}/${BINARY}"
if [ ! -w "$INSTALL_DIR" ]; then
printf " Installing to %s (sudo required)... " "$INSTALL_DIR"
sudo mv "$TMP" "$TARGET"
else
printf " Installing to %s... " "$INSTALL_DIR"
mv "$TMP" "$TARGET"
fi
printf "done\n\n"
# ── Verify ──────────────────────────────────────────────────────────────────
if ! command -v "$BINARY" > /dev/null 2>&1; then
red "Installed but '${BINARY}' not found in PATH."
red "Add ${INSTALL_DIR} to your PATH and try again."
exit 1
fi
green " meg ${VERSION} installed successfully."
printf "\n"
dim " Run the interactive wizard:"
bold " meg deploy --interactive"
printf "\n"
dim " Or use directly in CI/scripts:"
bold " meg deploy"
printf "\n"
}
main "$@"