-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall
More file actions
executable file
·205 lines (171 loc) · 5.25 KB
/
install
File metadata and controls
executable file
·205 lines (171 loc) · 5.25 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
#!/usr/bin/env bash
set -euo pipefail
APP=godo
REPO="biisal/godo"
# 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
Godo 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 " godo ..----.._ _"
echo -e " .' .--. \"-.(O)_"
echo -e "'-.__.-'\"'=:| , _)_ \__ . c\'-.."
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/.godo/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 | tr '[:upper:]' '[:lower:]')
arch=$(uname -m)
[[ "$arch" == "x86_64" || "$arch" == "amd64" ]] && arch="amd64"
[[ "$arch" == "arm64" || "$arch" == "aarch64" ]] && arch="arm64"
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/godo.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}"
log "Downloading identity files..."
mkdir -p "$HOME/.godo/content/identity"
files=$(curl -s "https://api.github.com/repos/$REPO/contents/content/identity" | grep '"name":' | cut -d '"' -f 4 | grep '\.md$' || true)
if [ -n "$files" ]; then
for file in $files; do
log "Fetching $file..."
curl -s -L -o "$HOME/.godo/content/identity/$file" "https://raw.githubusercontent.com/$REPO/main/content/identity/$file" || true
done
fi
log "Downloading skills files..."
mkdir -p "$HOME/.godo/content/skills"
files=$(curl -s "https://api.github.com/repos/$REPO/contents/content/skills" | grep '"name":' | cut -d '"' -f 4 | grep '\.md$' || true)
if [ -n "$files" ]; then
for file in $files; do
log "Fetching $file..."
curl -s -L -o "$HOME/.godo/content/skills/$file" "https://raw.githubusercontent.com/$REPO/main/content/skills/$file" || true
done
fi
# 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# Godo\nexport PATH=\"$INSTALL_DIR:\$PATH\"" >>"$shell_config"
log "Permanent path added to $shell_config."
fi
fi
fi
# desktop entry
if [[ "$(uname -s)" == "Linux" ]]; then
log "Setting up desktop..."
DESKTOP_DIR="$HOME/.local/share/applications"
DESKTOP_FILE="$DESKTOP_DIR/godo.desktop"
mkdir -p "$DESKTOP_DIR"
TERMINAL=""
for term in kitty alacritty konsole xfce4-terminal xterm; do
if command -v "$term" >/dev/null 2>&1; then
TERMINAL="$term"
break
fi
done
if [[ -z "$TERMINAL" ]]; then
TERMINAL="xterm"
fi
cat >"$DESKTOP_FILE" <<EOF
[Desktop Entry]
Name=Godo
Comment=Run Godo CLI
Exec=$TERMINAL -e $HOME/.godo/bin/godo
Icon=utilities-terminal
Terminal=false
Type=Application
Categories=Development;Utility;
EOF
fi
# Final Success Output
echo -e "\n------------------------------------------------"
show_logo
echo -e "${GREEN}Godo $specific_version successfully installed!${NC}"
echo -e "Close the terminal and reopen it to run ${GREEN}godo${NC} command"
echo -e "Documentation: https://github.com/$REPO"
echo -e "------------------------------------------------\n"