-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·383 lines (335 loc) · 10.6 KB
/
install.sh
File metadata and controls
executable file
·383 lines (335 loc) · 10.6 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#!/bin/bash
# Git CLI with Emojis - Installation Script
# This script compiles and installs git-cli to /usr/bin/
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
BINARY_NAME="git-cli"
INSTALL_DIR="/usr/bin"
CONFIG_DIR="$HOME/.config/git-cli"
REPO_URL="https://github.com/yourusername/git-cli.git"
# Functions
print_header() {
echo -e "${BLUE}"
echo "╔══════════════════════════════════════════════════╗"
echo "║ ║"
echo "║ Git CLI with Emojis v0.2.0 ║"
echo "║ Installation Script ║"
echo "║ ║"
echo "╚══════════════════════════════════════════════════╝"
echo -e "${NC}"
}
print_step() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
check_prerequisites() {
print_step "Checking prerequisites..."
# Check if running as root for system-wide installation
if [[ $EUID -ne 0 ]] && [[ "$INSTALL_DIR" == "/usr/bin" ]]; then
print_error "This script requires sudo privileges to install to /usr/bin"
echo "Please run: sudo $0"
exit 1
fi
# Check if Rust is installed
if ! command -v rustc &> /dev/null; then
print_error "Rust is not installed. Please install Rust first:"
echo "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"
exit 1
fi
# Check if Cargo is installed
if ! command -v cargo &> /dev/null; then
print_error "Cargo is not installed. Please install Rust toolchain."
exit 1
fi
# Check if Git is installed
if ! command -v git &> /dev/null; then
print_error "Git is not installed. Please install Git first."
exit 1
fi
# Check Rust version
rust_version=$(rustc --version | awk '{print $2}')
print_success "Rust version: $rust_version"
# Check Git version
git_version=$(git --version | awk '{print $3}')
print_success "Git version: $git_version"
}
install_from_source() {
print_step "Installing from source..."
# Create temporary directory
TEMP_DIR=$(mktemp -d)
cd "$TEMP_DIR"
# Clone repository
if [[ -d "/var/www/html/robert/git-cli" ]]; then
print_step "Using local repository..."
cp -r "/var/www/html/robert/git-cli" .
cd git-cli
else
print_step "Cloning repository..."
git clone "$REPO_URL" git-cli
cd git-cli
fi
# Build in release mode
print_step "Building git-cli in release mode..."
cargo build --release --quiet
if [[ ! -f "target/release/$BINARY_NAME" ]]; then
print_error "Build failed - binary not found"
exit 1
fi
# Install binary
print_step "Installing binary to $INSTALL_DIR..."
cp "target/release/$BINARY_NAME" "$INSTALL_DIR/"
chmod +x "$INSTALL_DIR/$BINARY_NAME"
# Cleanup
cd /
rm -rf "$TEMP_DIR"
print_success "Binary installed successfully!"
}
install_from_cargo() {
print_step "Installing from cargo..."
# Try to install from crates.io (if published)
if cargo install git-cli-emoji --quiet 2>/dev/null; then
print_success "Installed from crates.io!"
return 0
else
print_warning "Package not found on crates.io, falling back to source installation"
return 1
fi
}
setup_configuration() {
print_step "Setting up configuration..."
# Create config directory
mkdir -p "$CONFIG_DIR"
# Create default config if it doesn't exist
if [[ ! -f "$CONFIG_DIR/config.toml" ]]; then
cat > "$CONFIG_DIR/config.toml" << 'EOF'
[general]
default_emoji = "✨"
auto_push = false
confirm_before_push = true
debug = false
[commit]
enforce_conventional = true
max_title_length = 50
max_body_length = 72
auto_capitalize_title = true
[hooks]
run_pre_commit = true
auto_fix_lint = true
retry_on_failure = true
EOF
print_success "Created default configuration at $CONFIG_DIR/config.toml"
else
print_warning "Configuration already exists at $CONFIG_DIR/config.toml"
fi
# Set proper permissions
chmod 755 "$CONFIG_DIR"
chmod 644 "$CONFIG_DIR/config.toml"
}
setup_emojis() {
print_step "Setting up emoji configuration..."
# Create custom emojis file if it doesn't exist
if [[ ! -f "$HOME/emojis.json" ]]; then
cat > "$HOME/emojis.json" << 'EOF'
{
"emojis": [
{
"emoji": "✨",
"entity": "✨",
"code": ":sparkles:",
"description": "Introduce new features",
"name": "sparkles"
},
{
"emoji": "🐛",
"entity": "🐛",
"code": ":bug:",
"description": "Fix a bug",
"name": "bug"
},
{
"emoji": "🔧",
"entity": "🔧",
"code": ":wrench:",
"description": "Add or update configuration files",
"name": "wrench"
},
{
"emoji": "📝",
"entity": "📝",
"code": ":memo:",
"description": "Add or update documentation",
"name": "memo"
},
{
"emoji": "🎨",
"entity": "🎨",
"code": ":art:",
"description": "Improve structure / format of the code",
"name": "art"
},
{
"emoji": "⚡️",
"entity": "⚡",
"code": ":zap:",
"description": "Improve performance",
"name": "zap"
},
{
"emoji": "💄",
"entity": "&#ff99cc;",
"code": ":lipstick:",
"description": "Add or update the UI and style files",
"name": "lipstick"
},
{
"emoji": "✅",
"entity": "✅",
"code": ":white_check_mark:",
"description": "Add, update, or pass tests",
"name": "white-check-mark"
},
{
"emoji": "🔒️",
"entity": "🔒",
"code": ":lock:",
"description": "Fix security issues",
"name": "lock"
},
{
"emoji": "♻️",
"entity": "♾",
"code": ":recycle:",
"description": "Refactor code",
"name": "recycle"
},
{
"emoji": "🚀",
"entity": "F680;",
"code": ":rocket:",
"description": "Deploy stuff",
"name": "rocket"
},
{
"emoji": "🐳",
"entity": "f433;",
"code": ":whale:",
"description": "Work about Docker",
"name": "whale"
}
]
}
EOF
print_success "Created emoji configuration at $HOME/emojis.json"
else
print_warning "Emoji configuration already exists at $HOME/emojis.json"
fi
}
create_alias() {
print_step "Setting up shell alias..."
# Add alias to common shell config files
for shell_config in "$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.profile"; do
if [[ -f "$shell_config" ]]; then
if ! grep -q "alias gcli=" "$shell_config"; then
echo "" >> "$shell_config"
echo "# Git CLI with Emojis alias" >> "$shell_config"
echo "alias gcli='git-cli'" >> "$shell_config"
print_success "Added alias 'gcli' to $shell_config"
fi
fi
done
}
verify_installation() {
print_step "Verifying installation..."
# Check if binary exists and is executable
if [[ -x "$INSTALL_DIR/$BINARY_NAME" ]]; then
print_success "Binary found at $INSTALL_DIR/$BINARY_NAME"
else
print_error "Binary not found or not executable"
exit 1
fi
# Test the binary
if "$INSTALL_DIR/$BINARY_NAME" --version &>/dev/null; then
version=$("$INSTALL_DIR/$BINARY_NAME" --version)
print_success "Installation verified: $version"
else
print_error "Binary test failed"
exit 1
fi
}
show_usage() {
echo ""
echo -e "${GREEN}╔══════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ Installation Complete! ║${NC}"
echo -e "${GREEN}╚══════════════════════════════════════════════════╝${NC}"
echo ""
echo -e "${BLUE}Usage:${NC}"
echo " git-cli # Interactive mode"
echo " git-cli --help # Show help"
echo " git-cli --debug # Debug mode"
echo " gcli # Short alias"
echo ""
echo -e "${BLUE}Configuration:${NC}"
echo " Config file: $CONFIG_DIR/config.toml"
echo " Emoji file: $HOME/emojis.json"
echo ""
echo -e "${BLUE}Examples:${NC}"
echo " git-cli --emoji '✨' --title 'Add new feature'"
echo " git-cli --no-interactive --emoji '🐛' --title 'Fix bug'"
echo ""
echo -e "${YELLOW}Tip:${NC} Restart your shell or run 'source ~/.bashrc' to use the 'gcli' alias"
}
main() {
print_header
# Check for help flag
if [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]]; then
echo "Git CLI with Emojis - Installation Script"
echo ""
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --local-only Skip cargo installation attempt"
echo " --help, -h Show this help message"
echo ""
echo "This script will:"
echo " 1. Check prerequisites (Rust, Cargo, Git)"
echo " 2. Try to install from cargo (if available)"
echo " 3. Fall back to source compilation"
echo " 4. Install binary to /usr/bin/"
echo " 5. Set up configuration files"
echo " 6. Create shell aliases"
exit 0
fi
check_prerequisites
# Try cargo installation first (unless --local-only is specified)
if [[ "$1" != "--local-only" ]]; then
if ! install_from_cargo; then
install_from_source
fi
else
install_from_source
fi
setup_configuration
setup_emojis
create_alias
verify_installation
show_usage
print_success "Git CLI with Emojis has been successfully installed! 🎉"
}
# Handle interruption
trap 'print_error "Installation interrupted"; exit 1' INT TERM
# Run main function
main "$@"