-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstaller.sh
More file actions
212 lines (186 loc) · 7.5 KB
/
Copy pathinstaller.sh
File metadata and controls
212 lines (186 loc) · 7.5 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/env bash
# installer.sh - Installer and Uninstaller for neovector on Linux / macOS
# Auto detects OS and architecture, downloads the release binary, sets up PATH, and supports self-uninstallation.
set -euo pipefail
# ── Configuration ────────────────────────────────────────────────────────────
PROJECT_NAME="neovector"
PUBLISHER_NAME="rkriad585"
GITHUB_REPO="rkriad585/neovector"
# Paths
CONFIG_DIR="${HOME}/.config/neostore/${PROJECT_NAME}"
BIN_DIR="${CONFIG_DIR}/bin"
BINARY_PATH="${BIN_DIR}/${PROJECT_NAME}"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
NC='\033[0m'
clean_profile() {
local profile="$1"
if [[ -f "$profile" ]]; then
grep -v "neostore/${PROJECT_NAME}/bin" "$profile" > "${profile}.tmp" || true
mv "${profile}.tmp" "$profile"
fi
}
add_to_profile() {
local profile="$1"
if [[ -f "$profile" ]]; then
if ! grep -q "neostore/${PROJECT_NAME}/bin" "$profile"; then
echo "" >> "$profile"
echo "# neovector PATH configuration" >> "$profile"
echo "export PATH=\"\$HOME/.config/neostore/${PROJECT_NAME}/bin:\$PATH\"" >> "$profile"
fi
fi
}
# ── Check for Uninstallation Flag ───────────────────────────────────────────
IS_UNINSTALL=false
for arg in "$@"; do
if [[ "$arg" == "--selfuninstall" || "$arg" == "-selfuninstall" || "$arg" == "--uninstall" || "$arg" == "-u" ]]; then
IS_UNINSTALL=true
fi
done
if [ "$IS_UNINSTALL" = true ]; then
echo ""
echo -e "${YELLOW}╔══════════════════════════════════════════════════╗${NC}"
echo -e "${YELLOW}║ neovector Uninstaller ║${NC}"
echo -e "${YELLOW}╚══════════════════════════════════════════════════╝${NC}"
echo ""
if [[ -f "$BINARY_PATH" ]]; then
printf " Removing binary: %s ... " "$BINARY_PATH"
rm -f "$BINARY_PATH"
echo -e "${GREEN}OK${NC}"
fi
if [[ -d "$CONFIG_DIR" ]]; then
printf " Removing config directory: %s ... " "$CONFIG_DIR"
rm -rf "$CONFIG_DIR"
echo -e "${GREEN}OK${NC}"
fi
echo -e " Cleaning shell profile PATH configurations ... "
PROFILES=(
"${HOME}/.bashrc"
"${HOME}/.zshrc"
"${HOME}/.profile"
"${HOME}/.bash_profile"
)
for p in "${PROFILES[@]}"; do
if [[ -f "$p" ]]; then
printf " Updating %s ... " "$(basename "$p")"
clean_profile "$p"
echo -e "${GREEN}OK${NC}"
fi
done
echo ""
echo -e "${GREEN} neovector has been successfully uninstalled from your system.${NC}"
echo -e "${CYAN} Please restart your shell or run: hash -r${NC}"
echo ""
exit 0
fi
# ── Installation / Update Flow ───────────────────────────────────────────────
echo ""
echo -e "${CYAN}╔══════════════════════════════════════════════════╗${NC}"
echo -e "${CYAN}║ neovector Installer ║${NC}"
echo -e "${CYAN}╚══════════════════════════════════════════════════╝${NC}"
echo ""
# 1. Resolve Version from GitHub
printf " Checking latest version from GitHub ... "
VERSION_URL="https://raw.githubusercontent.com/${GITHUB_REPO}/main/.version"
if command -v curl >/dev/null 2>&1; then
VERSION=$(curl -fsSL "$VERSION_URL" | tr -d '[:space:]')
elif command -v wget >/dev/null 2>&1; then
VERSION=$(wget -qO- "$VERSION_URL" | tr -d '[:space:]')
else
echo -e "${RED}FAILED${NC}"
echo "Error: curl or wget is required to run this installer." >&2
exit 1
fi
echo -e "${GREEN}${VERSION}${NC}"
# 2. Detect System OS and Architecture
printf " Detecting platform ... "
OS_NAME=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$OS_NAME" in
linux*) OS="linux" ;;
darwin*) OS="darwin" ;;
*)
echo -e "${RED}FAILED${NC}"
echo "Error: Unsupported operating system: ${OS_NAME}" >&2
exit 1
;;
esac
ARCH_NAME=$(uname -m)
case "$ARCH_NAME" in
x86_64) ARCH="amd64" ;;
amd64) ARCH="amd64" ;;
arm64) ARCH="arm64" ;;
aarch64) ARCH="arm64" ;;
*)
echo -e "${RED}FAILED${NC}"
echo "Error: Unsupported CPU architecture: ${ARCH_NAME}" >&2
exit 1
;;
esac
echo -e "${GREEN}${OS}-${ARCH}${NC}"
# 3. Download the Release Binary
DOWNLOAD_URL="https://github.com/${GITHUB_REPO}/releases/download/${VERSION}/${PROJECT_NAME}-${OS}-${ARCH}"
echo -e " Downloading binary from ${DOWNLOAD_URL} ...\n"
mkdir -p "$BIN_DIR"
if command -v curl >/dev/null 2>&1; then
curl -L --progress-bar -o "$BINARY_PATH" "$DOWNLOAD_URL"
elif command -v wget >/dev/null 2>&1; then
wget --show-progress -O "$BINARY_PATH" "$DOWNLOAD_URL"
else
echo -e " ${RED}Failed to download binary. No curl or wget found.${NC}" >&2
exit 1
fi
if [[ ! -f "$BINARY_PATH" ]]; then
echo -e " ${RED}Downloaded file not found. Download failed.${NC}" >&2
exit 1
fi
chmod +x "$BINARY_PATH"
SIZE=$(du -h "$BINARY_PATH" | cut -f1)
echo -e " ${GREEN}Successfully downloaded ${PROJECT_NAME} (${SIZE})${NC}"
# 4. Configure PATH Environment Variable
printf " Configuring shell profile PATH configurations ... "
UPDATED_PROFILES=()
ACTIVE_SHELL=$(basename "$SHELL")
if [ "$ACTIVE_SHELL" = "bash" ]; then
touch "${HOME}/.bashrc"
add_to_profile "${HOME}/.bashrc"
UPDATED_PROFILES+=(".bashrc")
elif [ "$ACTIVE_SHELL" = "zsh" ]; then
touch "${HOME}/.zshrc"
add_to_profile "${HOME}/.zshrc"
UPDATED_PROFILES+=(".zshrc")
else
PROFILES=(
"${HOME}/.bashrc"
"${HOME}/.zshrc"
"${HOME}/.profile"
"${HOME}/.bash_profile"
)
for p in "${PROFILES[@]}"; do
if [[ -f "$p" ]]; then
add_to_profile "$p"
UPDATED_PROFILES+=("$(basename "$p")")
fi
done
fi
if [ ${#UPDATED_PROFILES[@]} -eq 0 ]; then
touch "${HOME}/.profile"
add_to_profile "${HOME}/.profile"
UPDATED_PROFILES+=(".profile")
fi
echo -e "${GREEN}OK${NC} (Updated: ${UPDATED_PROFILES[*]})"
# ── Success Banner ────────────────────────────────────────────────────────────
echo ""
echo -e "${GREEN}╔══════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ neovector successfully installed! ║${NC}"
echo -e "${GREEN}╚══════════════════════════════════════════════════╝${NC}"
echo ""
echo " Installation Path: ${BINARY_PATH}"
echo " Version : ${VERSION}"
echo ""
echo -e "${YELLOW} Please RESTART your terminal window or run:${NC}"
echo -e "${CYAN} source ~/${UPDATED_PROFILES[0]}${NC}"
echo -e "${YELLOW} to start using neovector immediately!${NC}"
echo ""