-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall
More file actions
executable file
·139 lines (114 loc) · 3.98 KB
/
Copy pathinstall
File metadata and controls
executable file
·139 lines (114 loc) · 3.98 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
#!/usr/bin/env bash
set -euo pipefail
APP=rowsql
REPO="biisal/rowsql"
# Colors
MUTED='\033[0;2m'
RED='\033[0;31m'
ORANGE='\033[38;5;214m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
NC='\033[0m'
# --- 1. Helper Functions ---
log() {
echo -e "${MUTED}[$(date +'%H:%M:%S')]${NC} $1"
}
usage() {
cat <<EOF
RowSQL Installer
Usage: install.sh [options]
Options:
-h, --help Display this help message
-v, --version <version> Install a specific version
-b, --binary <path> Install from a local binary
EOF
}
show_logo() {
echo -e "${CYAN}"
echo -e " ____ ____ ___ _ "
echo -e " | _ \ _____ __/ ___| / _ \| | "
echo -e " | |_) / _ \ \ /\ / /\___ \| | | | | "
echo -e " | _ < (_) \ V V / ___) | |_| | |___ "
echo -e " |_| \_\___/ \_/\_/ |____/ \__\_\_____|"
echo -e "${NC}"
}
# --- 2. Main Script Logic ---
requested_version=""
binary_path=""
no_modify_path=false
# Argument Parsing
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help) usage; exit 0 ;;
-v|--version) requested_version="${2:-}"; shift 2 ;;
-b|--binary) binary_path="${2:-}"; shift 2 ;;
--no-modify-path) no_modify_path=true; shift ;;
*) shift ;;
esac
done
INSTALL_DIR=$HOME/.rowsql/bin
mkdir -p "$INSTALL_DIR"
log "System: ${GREEN}$(uname -s)/$(uname -m)${NC}"
# Version and Asset Resolution
if [ -n "$binary_path" ]; then
log "Mode: ${ORANGE}Local Binary Installation${NC}"
specific_version="local-dev"
else
log "Mode: ${GREEN}Remote Download${NC}"
# OS/Arch Detection
os=$(uname -s); arch=$(uname -m)
[[ "$os" == "Darwin" ]] && os="Darwin" || os="Linux"
[[ "$arch" == "arm64" || "$arch" == "aarch64" ]] && arch="arm64" || arch="x86_64"
filename="${APP}_${os}_${arch}.tar.gz"
log "Resolving latest version from GitHub..."
# Fetches first release found (handles pre-releases/snapshots)
release_data=$(curl -s "https://api.github.com/repos/$REPO/releases" | grep -m 1 '"tag_name":' || true)
if [ -z "$release_data" ]; then
echo -e "${RED}Error: No releases found at https://github.com/$REPO/releases${NC}"
exit 1
fi
specific_version=$(echo "$release_data" | sed -E 's/.*"([^"]+)".*/\1/')
url="https://github.com/$REPO/releases/download/$specific_version/$filename"
log "Selected Version: ${CYAN}$specific_version${NC}"
fi
# Installation Execution
if [ -n "$binary_path" ]; then
cp "$binary_path" "$INSTALL_DIR/$APP"
else
log "Downloading: ${MUTED}$url${NC}"
tmp_dir=$(mktemp -d)
if ! curl -# -L -f -o "$tmp_dir/$filename" "$url"; then
echo -e "${RED}Error: Download failed. The file may not exist for your architecture.${NC}"
rm -rf "$tmp_dir"
exit 1
fi
log "Extracting assets..."
tar -xzf "$tmp_dir/$filename" -C "$tmp_dir"
mv "$tmp_dir/$APP" "$INSTALL_DIR/" 2>/dev/null || mv "$tmp_dir/rowsql.exe" "$INSTALL_DIR/" 2>/dev/null
rm -rf "$tmp_dir"
fi
chmod +x "${INSTALL_DIR}/$APP"
log "Binary installed to: ${MUTED}$INSTALL_DIR/$APP${NC}"
# Shell Path Configuration
if [ "$no_modify_path" = "false" ]; then
log "Configuring shell path..."
shell_config=""
case $(basename "$SHELL") in
zsh) shell_config="$HOME/.zshrc" ;;
bash) shell_config="$HOME/.bashrc" ;;
fish) shell_config="$HOME/.config/fish/config.fish" ;;
esac
if [ -n "$shell_config" ] && [ -f "$shell_config" ]; then
if ! grep -q "$INSTALL_DIR" "$shell_config"; then
echo -e "\n# RowSQL\nexport PATH=\"$INSTALL_DIR:\$PATH\"" >> "$shell_config"
log "Permanent path added to $shell_config."
fi
fi
fi
# Final Success Output
echo -e "\n------------------------------------------------"
show_logo
echo -e "${GREEN}RowSQL $specific_version successfully installed!${NC}"
echo -e "Close the terminal and reopen it to run ${GREEN}rowsql${NC} command"
echo -e "Documentation: https://github.com/$REPO"
echo -e "------------------------------------------------\n"