-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·124 lines (104 loc) · 3.48 KB
/
install.sh
File metadata and controls
executable file
·124 lines (104 loc) · 3.48 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
#!/bin/sh
# unifly installer
# Usage: curl -fsSL https://raw.githubusercontent.com/hyperb1iss/unifly/main/install.sh | sh
set -e
REPO="hyperb1iss/unifly"
BINARY="unifly"
# Colors (if terminal supports them)
if [ -t 1 ]; then
PURPLE='\033[38;2;225;53;255m'
CYAN='\033[38;2;128;255;234m'
GREEN='\033[38;2;80;250;123m'
RED='\033[38;2;255;99;99m'
YELLOW='\033[38;2;241;250;140m'
RESET='\033[0m'
else
PURPLE='' CYAN='' GREEN='' RED='' YELLOW='' RESET=''
fi
info() { printf "${CYAN}::${RESET} %s\n" "$1"; }
ok() { printf "${GREEN}::${RESET} %s\n" "$1"; }
warn() { printf "${YELLOW}::${RESET} %s\n" "$1"; }
error() { printf "${RED}::${RESET} %s\n" "$1" >&2; exit 1; }
# Detect platform
detect_platform() {
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$OS" in
linux) PLATFORM="linux" ;;
darwin) PLATFORM="macos" ;;
*) error "Unsupported OS: $OS (use cargo install unifly instead)" ;;
esac
case "$ARCH" in
x86_64|amd64) ARCH_SUFFIX="amd64" ;;
aarch64|arm64) ARCH_SUFFIX="arm64" ;;
*) error "Unsupported architecture: $ARCH" ;;
esac
# macOS only ships arm64 builds
if [ "$PLATFORM" = "macos" ] && [ "$ARCH_SUFFIX" = "amd64" ]; then
error "macOS x86_64 builds are not available. Use Homebrew (brew install hyperb1iss/tap/unifly) or build from source."
fi
ASSET="${BINARY}-${PLATFORM}-${ARCH_SUFFIX}"
}
# Get latest version
get_latest_version() {
VERSION=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \
| grep '"tag_name"' | head -1 | sed 's/.*"tag_name": *"//;s/".*//')
if [ -z "$VERSION" ]; then
error "Failed to fetch latest version from GitHub"
fi
}
# Choose install directory
choose_install_dir() {
if [ -n "$INSTALL_DIR" ]; then
# User specified
return
elif [ -w /usr/local/bin ]; then
INSTALL_DIR="/usr/local/bin"
elif [ -d "$HOME/.local/bin" ]; then
INSTALL_DIR="$HOME/.local/bin"
else
mkdir -p "$HOME/.local/bin"
INSTALL_DIR="$HOME/.local/bin"
fi
}
# Download and install
install() {
URL="https://github.com/${REPO}/releases/download/${VERSION}/${ASSET}"
TMPDIR=$(mktemp -d)
TMPFILE="${TMPDIR}/${BINARY}"
info "Downloading ${ASSET} ${VERSION}..."
if ! curl -fsSL -o "$TMPFILE" "$URL"; then
rm -rf "$TMPDIR"
error "Download failed. Check https://github.com/${REPO}/releases for available assets."
fi
chmod +x "$TMPFILE"
info "Installing to ${INSTALL_DIR}/${BINARY}..."
if [ -w "$INSTALL_DIR" ]; then
mv "$TMPFILE" "${INSTALL_DIR}/${BINARY}"
else
sudo mv "$TMPFILE" "${INSTALL_DIR}/${BINARY}"
fi
rm -rf "$TMPDIR"
}
# Verify installation
verify() {
if command -v "$BINARY" >/dev/null 2>&1; then
INSTALLED_VERSION=$("$BINARY" --version 2>/dev/null | head -1)
ok "Installed ${INSTALLED_VERSION}"
else
warn "Installed to ${INSTALL_DIR}/${BINARY} but it's not in your PATH"
warn "Add this to your shell profile:"
printf " export PATH=\"%s:\$PATH\"\n" "$INSTALL_DIR"
fi
}
# Main
printf "\n${PURPLE} unifly installer${RESET}\n\n"
detect_platform
get_latest_version
choose_install_dir
install
verify
printf "\n${CYAN} Get started:${RESET}\n"
printf " unifly config init # Set up your controller\n"
printf " unifly devices list # List network devices\n"
printf " unifly tui # Launch the dashboard\n\n"