-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_cli.sh
More file actions
138 lines (107 loc) · 3.81 KB
/
Copy pathinstall_cli.sh
File metadata and controls
138 lines (107 loc) · 3.81 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
#!/usr/bin/env bash
# License: MIT
# Neterial Cross-Platform CLI installer script
# Supports:
# - Linux (primarily Ubuntu, including WSL)
# - macOS via Homebrew
set -euo pipefail
# Print error message and exit
die() {
echo "Error: $*" >&2
exit 1
}
# Detect OS
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
# macOS (Darwin) specific installation
if [ "$OS" = "darwin" ]; then
echo "→ Detected macOS system"
# Check if Homebrew is installed
if ! command -v brew >/dev/null 2>&1; then
echo "⚠️ Homebrew is required on macOS. Please install it from https://brew.sh" >&2
exit 1
fi
echo "→ Installing neterial via Homebrew..."
brew tap neterial-cloud/tap || die "Failed to tap neterial-cloud/tap"
brew install neterial-cli || die "Failed to install neterial-cli"
# Verify installation
if command -v neterial >/dev/null 2>&1; then
echo "✅ neterial installed successfully via Homebrew"
neterial --version
echo
echo "🚀 You can now use the 'neterial' command"
else
die "Installation appeared to succeed but 'neterial' command not found"
fi
exit 0
fi
# Linux installation
if [ "$OS" != "linux" ]; then
die "Unsupported operating system: $OS. This installer supports Linux and macOS only."
fi
# Linux-specific installation below
echo "→ Detected Linux system"
### 1. Installation prefix (override with PREFIX=/some/where)
PREFIX=${PREFIX:-$HOME/.local}
BINDIR="$PREFIX/bin"
### 2. Compute & create all needed directories
COMPDIR="${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion/completions"
mkdir -p "$HOME/bin" "$BINDIR" "$COMPDIR"
### 3. Make new bin dir available for future non-login shells
# Auto-append to ~/.bashrc if not already present
if [ -w "$HOME/.bashrc" ] && ! grep -Fq 'export PATH="$HOME/.local/bin:$PATH"' "$HOME/.bashrc"; then
printf '\n# add neterial installer bin dir\nexport PATH="$HOME/.local/bin:$PATH"\n' >> "$HOME/.bashrc"
fi
### 4. Detect ARCH, error on unsupported
ARCH=$(uname -m)
case "$ARCH" in
x86_64|amd64) ARCH=amd64 ;;
aarch64|arm64) ARCH=arm64 ;;
*)
die "Unsupported architecture '$ARCH'"
;;
esac
### 5. Ensure required tools exist
for cmd in curl tar; do
if ! command -v "$cmd" >/dev/null 2>&1; then
die "'$cmd' is required but not found. Please install it and re-run."
fi
done
### 6. Download & extract with failure checks
VERSION=${VERSION:-"v0.5.0"} # override as needed
REPO="github.com/neterial-cloud/cli"
TARBALL="neterial-${VERSION}-${OS}-${ARCH}.tar.gz"
URL="https://${REPO}/releases/download/${VERSION}/${TARBALL}"
echo "→ Downloading neterial ${VERSION} for ${OS}/${ARCH} from:"
echo " $URL"
if ! curl --fail --silent --show-error --location "$URL" | tar xz -C "$BINDIR"; then
die "Download or extraction failed"
fi
chmod +x "$BINDIR/neterial"
### 7. Generate & install Bash completion
echo "→ Generating Bash completion script..."
if ! "$BINDIR/neterial" completion bash > "$COMPDIR/neterial"; then
echo "⚠️ Warning: failed to generate completion; skipping." >&2
else
echo "→ Installed Bash completion to $COMPDIR/neterial"
fi
### 8. Check for bash-completion package
if [ ! -f "/etc/bash_completion" ] && [ ! -d "/usr/share/bash-completion" ]; then
echo
echo "⚠️ You don't appear to have the 'bash-completion' package installed."
echo " To enable completions on new shells, run: sudo apt install bash-completion"
fi
### 9. Final message
cat <<EOF
✅ neterial ${VERSION} installed to:
$BINDIR/neterial
📜 Bash completion script:
$COMPDIR/neterial
🚀 Usage:
• To use right now, run:
source ~/.bashrc
(or restart your shell)
🔧 Overrides (Linux only):
• PREFIX=/your/path bash install_linux_cli.sh
• VERSION=vX.Y.Z bash install_linux_cli.sh
Enjoy! 🎉
EOF