-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
173 lines (143 loc) · 4.59 KB
/
install.sh
File metadata and controls
173 lines (143 loc) · 4.59 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
#!/usr/bin/env bash
set -e
APP_NAME="git-genius"
BIN_NAME="git-genius"
REPO_URL="https://github.com/Smthbig/gitcli.git"
PREBUILT_BASE="https://raw.githubusercontent.com/Smthbig/gitcli/main"
VERSION_FILE="${PREBUILT_BASE}/VERSION"
GREEN="\033[0;32m"
RED="\033[0;31m"
YELLOW="\033[1;33m"
NC="\033[0m"
log() { echo -e "${GREEN}✔ $1${NC}"; }
warn() { echo -e "${YELLOW}⚠ $1${NC}"; }
err() { echo -e "${RED}✖ $1${NC}"; exit 1; }
echo "======================================="
echo " Git Genius Installer"
echo "======================================="
echo
# --------------------------------------------------
# Safety (AndroidIDE / broken cwd fix)
# --------------------------------------------------
cd "$HOME" || err "HOME directory not accessible"
# --------------------------------------------------
# Detect OS / ARCH
# --------------------------------------------------
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
ARCH="$(uname -m)"
log "Detected OS: $OS"
log "Detected ARCH: $ARCH"
# --------------------------------------------------
# Detect environment
# --------------------------------------------------
ENV="unknown"
if [[ -n "$PREFIX" && "$PREFIX" == *"com.termux"* ]]; then
ENV="termux"
elif [[ "$HOME" == *"androidide"* ]]; then
ENV="androidide"
elif [[ "$OS" == "darwin" ]]; then
ENV="macos"
elif [[ "$OS" == "linux" ]]; then
if command -v sudo >/dev/null 2>&1; then
ENV="linux"
else
ENV="restricted-linux"
fi
fi
if [[ "$ENV" == "unknown" ]]; then
warn "Unable to auto-detect environment"
echo "1) Linux (sudo)"
echo "2) Restricted Linux"
echo "3) Termux"
echo "4) AndroidIDE"
echo "5) macOS"
read -rp "Select [1-5]: " choice
case "$choice" in
1) ENV="linux" ;;
2) ENV="restricted-linux" ;;
3) ENV="termux" ;;
4) ENV="androidide" ;;
5) ENV="macos" ;;
*) err "Invalid selection" ;;
esac
fi
log "Environment: $ENV"
# --------------------------------------------------
# Install directory
# --------------------------------------------------
BIN_DIR="$HOME/bin"
[[ "$ENV" == "linux" || "$ENV" == "macos" ]] && BIN_DIR="/usr/local/bin"
mkdir -p "$BIN_DIR"
BIN_PATH="$BIN_DIR/$BIN_NAME"
# --------------------------------------------------
# Version check (🔥 KEY FEATURE 🔥)
# --------------------------------------------------
REMOTE_VERSION="$(curl -fsSL "$VERSION_FILE" 2>/dev/null || true)"
if [[ -x "$BIN_PATH" ]]; then
INSTALLED_VERSION="$("$BIN_PATH" --version 2>/dev/null || true)"
if [[ -n "$REMOTE_VERSION" && "$INSTALLED_VERSION" == *"$REMOTE_VERSION"* ]]; then
log "Git Genius already installed ($INSTALLED_VERSION)"
log "No update required"
exit 0
fi
warn "Installed version differs, upgrading…"
fi
# --------------------------------------------------
# Ensure Git
# --------------------------------------------------
if ! command -v git >/dev/null 2>&1; then
warn "Git not found"
case "$ENV" in
termux) pkg install -y git ;;
linux) sudo apt update && sudo apt install -y git ;;
macos) brew install git || xcode-select --install ;;
*) err "Please install git manually" ;;
esac
else
log "Git already installed"
fi
# --------------------------------------------------
# Prebuilt binary (preferred)
# --------------------------------------------------
USE_PREBUILT=false
if [[ "$OS" == "linux" && ( "$ARCH" == "aarch64" || "$ARCH" == "arm64" || "$ARCH" == "x86_64" ) ]]; then
USE_PREBUILT=true
fi
if [[ "$USE_PREBUILT" == true ]]; then
PREBUILT_URL="${PREBUILT_BASE}/${BIN_NAME}"
log "Installing prebuilt Git Genius binary"
curl -fsSL "$PREBUILT_URL" -o "$BIN_PATH" || err "Download failed"
chmod +x "$BIN_PATH"
if ! echo "$PATH" | grep -q "$BIN_DIR"; then
warn "Adding $BIN_DIR to PATH"
echo "export PATH=\"$BIN_DIR:\$PATH\"" >> "$HOME/.profile"
echo "export PATH=\"$BIN_DIR:\$PATH\"" >> "$HOME/.bashrc" 2>/dev/null || true
fi
log "Git Genius installed successfully 🎉"
echo "Run:"
echo " git-genius"
echo "Next:"
echo " Tools → Setup / Reconfigure"
exit 0
fi
# --------------------------------------------------
# Fallback: source build (rare)
# --------------------------------------------------
warn "No prebuilt binary available, building from source"
if ! command -v go >/dev/null 2>&1; then
err "Go not found. Please install Go manually."
fi
SRC_DIR="$HOME/.git-genius-src"
if [[ -d "$SRC_DIR/.git" ]]; then
cd "$SRC_DIR"
git pull --rebase
else
rm -rf "$SRC_DIR"
git clone "$REPO_URL" "$SRC_DIR"
cd "$SRC_DIR"
fi
go build -o "$BIN_PATH" ./cmd/genius || err "Build failed"
chmod +x "$BIN_PATH"
log "Git Genius installed successfully 🎉"
echo "Run:"
echo " git-genius"