-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathinstaller
More file actions
executable file
·580 lines (493 loc) · 19 KB
/
Copy pathinstaller
File metadata and controls
executable file
·580 lines (493 loc) · 19 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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
#!/bin/bash
# KhiproKeyboard Installer Script
# This script installs KhiproKeyboard for IBus and Fcitx5
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
# Function to print colored output
print_status() {
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"
}
# Function to detect distribution
detect_distro() {
if [ -f /etc/os-release ]; then
. /etc/os-release
echo "$ID"
elif command -v lsb_release &> /dev/null; then
lsb_release -is | tr '[:upper:]' '[:lower:]'
else
echo "unknown"
fi
}
# Function to check if command exists
command_exists() {
command -v "$1" &> /dev/null
}
# Function to check if package is installed (for Debian/Ubuntu)
check_package_debian() {
dpkg -l "$1" 2>/dev/null | grep -q '^ii'
}
# Function to check if package is installed (for Fedora/RHEL)
check_package_fedora() {
rpm -q "$1" &> /dev/null
}
# Function to check if package is installed (for Arch)
check_package_arch() {
pacman -Q "$1" &> /dev/null
}
# Welcome message
echo "=========================================="
echo " KhiproKeyboard Installer"
echo "=========================================="
echo ""
# Determine installation paths based on privileges
if [ "$EUID" -eq 0 ]; then
INSTALL_DIR="/usr/share/m17n"
ICON_DIR="/usr/share/m17n/icons"
PRIV_SUFFIX=""
print_status "Running as root. Installing system-wide to $INSTALL_DIR"
else
INSTALL_DIR="$HOME/.m17n.d"
ICON_DIR="$HOME/.m17n.d/icons"
PRIV_SUFFIX="-local"
print_status "Running as user. Installing to $INSTALL_DIR"
# Create user directories if they don't exist
if [ ! -d "$INSTALL_DIR" ]; then
print_status "Creating directory: $INSTALL_DIR"
mkdir -p "$INSTALL_DIR"
fi
fi
# Check if Git is installed
print_status "Checking for Git..."
if ! command_exists git; then
print_error "Git is not installed but required to download KhiproKeyboard."
distro=$(detect_distro)
case $distro in
ubuntu|debian)
print_status "To install Git on Ubuntu/Debian:"
echo " sudo apt update && sudo apt install git"
;;
fedora|rhel|centos)
print_status "To install Git on Fedora/RHEL/CentOS:"
echo " sudo dnf install git"
;;
arch|manjaro)
print_status "To install Git on Arch/Manjaro:"
echo " sudo pacman -S git"
;;
*)
print_status "Please install Git using your distribution's package manager."
;;
esac
exit 1
else
print_success "Git is installed"
fi
# Main Menu: Install or Uninstall
echo ""
echo "What would you like to do?"
echo "1. Install KhiproKeyboard (Default)"
echo "2. Uninstall KhiproKeyboard"
read -p "Enter choice [1/2]: " main_choice
main_choice=${main_choice:-1}
if [ "$main_choice" = "2" ]; then
print_status "Uninstallation Mode Selected"
# List installed versions
if [ ! -d "$INSTALL_DIR" ]; then
print_error "Installation directory does not exist: $INSTALL_DIR"
exit 1
fi
# Find installed mim files
installed_files=($(find "$INSTALL_DIR" -maxdepth 1 -name "bn-khipro*.mim" | sort))
if [ ${#installed_files[@]} -eq 0 ]; then
print_warning "No KhiproKeyboard installations found in $INSTALL_DIR"
exit 0
fi
echo ""
print_status "Found the following installations:"
for i in "${!installed_files[@]}"; do
filename=$(basename "${installed_files[$i]}")
echo "$((i+1)). $filename"
done
echo "A. Uninstall ALL versions"
echo ""
print_warning "Default choice is 'None' (Cancel uninstallation)"
read -p "Select number to uninstall (or 'A' for all): " uninstall_choice
uninstall_choice=${uninstall_choice}
if [ -z "$uninstall_choice" ]; then
print_status "Cancelled. Exiting."
exit 0
fi
if [[ "$uninstall_choice" =~ ^[Aa]$ ]]; then
read -p "Are you sure you want to uninstall ALL versions? (y/N): " confirm_all
if [[ "$confirm_all" =~ ^[Yy]$ ]]; then
print_status "Removing all KhiproKeyboard files..."
rm -f "$INSTALL_DIR"/bn-khipro*.mim
rm -f "$ICON_DIR"/bn-khipro*.png
# Also clean up from INSTALL_DIR if different/same
rm -f "$INSTALL_DIR"/bn-khipro*.png 2>/dev/null || true
print_success "All versions uninstalled successfully!"
else
print_status "Cancelled."
fi
exit 0
elif [[ "$uninstall_choice" =~ ^[0-9]+$ ]]; then
index=$((uninstall_choice - 1))
if [ $index -ge 0 ] && [ $index -lt ${#installed_files[@]} ]; then
file_to_remove="${installed_files[$index]}"
base_name=$(basename "$file_to_remove" .mim)
print_status "Uninstalling $base_name..."
rm -f "$file_to_remove"
rm -f "$ICON_DIR/$base_name.png"
rm -f "$INSTALL_DIR/$base_name.png" 2>/dev/null || true
print_success "Uninstallation of $base_name complete!"
# Restart reminder
echo ""
print_warning "COMPUTER LOG OUT KORE LOG-IN KORUN"
else
print_error "Invalid selection. Exiting."
exit 1
fi
exit 0
else
print_status "Invalid input or Cancelled. Exiting."
exit 0
fi
fi
# Check for input method frameworks and their m17n support
print_status "Checking input method frameworks and m17n support..."
ibus_installed=false
ibus_m17n_installed=false
fcitx_installed=false
fcitx_m17n_installed=false
# Check IBus status
if command_exists ibus; then
ibus_installed=true
if check_package_debian "ibus-m17n" 2>/dev/null || \
check_package_fedora "ibus-m17n" 2>/dev/null || \
check_package_arch "ibus-m17n" 2>/dev/null; then
ibus_m17n_installed=true
fi
fi
# Check Fcitx5 status
if command_exists fcitx5; then
fcitx_installed=true
if check_package_debian "fcitx5-m17n" 2>/dev/null || \
check_package_fedora "fcitx5-m17n" 2>/dev/null || \
check_package_arch "fcitx5-m17n" 2>/dev/null; then
fcitx_m17n_installed=true
fi
fi
# Determine readiness
ibus_ready=false
if [ "$ibus_installed" = true ] && [ "$ibus_m17n_installed" = true ]; then
ibus_ready=true
fi
fcitx_ready=false
if [ "$fcitx_installed" = true ] && [ "$fcitx_m17n_installed" = true ]; then
fcitx_ready=true
fi
# Logic Flow
if [ "$ibus_ready" = true ] && [ "$fcitx_ready" = true ]; then
print_success "Both IBus and Fcitx5 are fully installed and supported."
print_status "Suggestion: We recommend using IBus for KhiproKeyboard."
elif [ "$ibus_ready" = true ]; then
print_success "IBus (with m17n support) is ready."
elif [ "$fcitx_ready" = true ]; then
print_success "Fcitx5 (with m17n support) is ready."
else
# Neither is fully ready. Diagnose why.
print_error "No fully compatible input method framework found!"
missing_packages=()
show_install_help=false
if [ "$ibus_installed" = false ] && [ "$fcitx_installed" = false ]; then
print_warning "You need to install either IBus or Fcitx5 framework."
show_install_help=true
else
# At least one framework is installed but missing m17n
if [ "$ibus_installed" = true ] && [ "$ibus_m17n_installed" = false ]; then
missing_packages+=("ibus-m17n")
fi
if [ "$fcitx_installed" = true ] && [ "$fcitx_m17n_installed" = false ]; then
missing_packages+=("fcitx5-m17n")
fi
fi
if [ ${#missing_packages[@]} -gt 0 ]; then
print_warning "The following packages are missing for your installed frameworks:"
for pkg in "${missing_packages[@]}"; do
echo " - $pkg"
done
show_install_help=true
fi
if [ "$show_install_help" = true ]; then
distro=$(detect_distro)
echo ""
case $distro in
ubuntu|debian)
print_status "Install commands for Ubuntu/Debian:"
[ "$ibus_installed" = false ] && echo " sudo apt install ibus ibus-m17n"
[ "$fcitx_installed" = false ] && echo " sudo apt install fcitx5 fcitx5-m17n"
if [ ${#missing_packages[@]} -gt 0 ]; then
echo " sudo apt install ${missing_packages[*]}"
fi
;;
fedora|rhel|centos)
print_status "Install commands for Fedora/RHEL/CentOS:"
[ "$ibus_installed" = false ] && echo " sudo dnf install ibus ibus-m17n"
[ "$fcitx_installed" = false ] && echo " sudo dnf install fcitx5 fcitx5-m17n"
if [ ${#missing_packages[@]} -gt 0 ]; then
echo " sudo dnf install ${missing_packages[*]}"
fi
;;
arch|manjaro)
print_status "Install commands for Arch/Manjaro:"
[ "$ibus_installed" = false ] && echo " sudo pacman -S ibus ibus-m17n"
[ "$fcitx_installed" = false ] && echo " sudo pacman -S fcitx5 fcitx5-m17n"
if [ ${#missing_packages[@]} -gt 0 ]; then
echo " sudo pacman -S ${missing_packages[*]}"
fi
;;
*)
print_status "Please install IBus or Fcitx5 along with their m17n packages."
;;
esac
fi
echo ""
read -p "Do you want to continue with installation anyway? (y/N): " continue_choice
continue_choice=${continue_choice:-N}
if [[ ! $continue_choice =~ ^[Yy]$ ]]; then
print_status "Installation cancelled. Please resolve the dependencies."
exit 1
fi
print_warning "Continuing installation..."
fi
# Branch selection
print_status "Checking available versions..."
read -p "Install stable release from the main branch? (Y/n): " branch_choice
branch_choice=${branch_choice:-Y}
if [[ $branch_choice =~ ^[Nn]$ ]]; then
# Fetch available release tags for preview
print_status "Fetching recent release tags..."
# Using awk to handle formatting more reliably across platforms
recent_tags=$(git ls-remote --tags --refs https://github.com/rank-coder/khipro-m17n.git 2>/dev/null | cut -d/ -f3 | sort -V -r | head -n 3 | awk -v ORS=', ' '{print $0}' | sed 's/, $/ etc./')
if [ -z "$recent_tags" ]; then
recent_tags="e.g. v34.0.0-beta, v33.1.0, etc."
fi
print_status "Fetching available branches from GitHub..."
# Get list of branches from remote repository
branches=$(git ls-remote --heads https://github.com/rank-coder/khipro-m17n.git 2>/dev/null | \
awk '{print $2}' | \
sed 's#refs/heads/##' | \
sort)
if [ -z "$branches" ]; then
print_warning "Could not fetch branch list. Please check your internet connection."
print_status "You can view branches at: https://github.com/rank-coder/khipro-m17n/branches"
exit 1
fi
echo ""
print_success "Available installation options:"
echo " 1. Install by Release Number (Version Number) ($recent_tags) [DEFAULT]"
# Store branches in an array for number selection
branches_array=()
counter=2
while IFS= read -r branch; do
echo " $counter. Install from branch: $branch"
branches_array+=("$branch")
((counter++))
done <<< "$branches"
echo ""
read -p "Enter number [Default: 1]: " input_ver
input_ver=${input_ver:-1}
if [ "$input_ver" -eq 1 ]; then
# Show tags with pagination
print_status "Fetching available release tags..."
all_tags=$(git ls-remote --tags --refs https://github.com/rank-coder/khipro-m17n.git 2>/dev/null | cut -d/ -f3 | sort -V -r)
if [ -z "$all_tags" ]; then
print_error "No release tags found."
exit 1
fi
mapfile -t tags_array <<< "$all_tags"
total_tags=${#tags_array[@]}
current_page=0
items_per_page=5
while true; do
start_index=$((current_page * items_per_page))
if [ $start_index -ge $total_tags ]; then
print_warning "No more release tags found."
# If we run out of tags, what to do? Exit or loop?
# Let's just exit for safety or allow re-selection?
# The user looped here previously. Let's just break and exit logic if forced.
# However, cleaner UI is to just say no more tags.
break
fi
echo ""
print_success "Release Tags (Page $((current_page + 1))):"
current_items=()
for ((i=0; i<items_per_page; i++)); do
idx=$((start_index + i))
if [ $idx -lt $total_tags ]; then
tag="${tags_array[$idx]}"
echo " $((i+1)). $tag"
current_items+=("$tag")
fi
done
option_next=$((items_per_page + 1))
user_options="1-${#current_items[@]}"
if [ $((start_index + items_per_page)) -lt $total_tags ]; then
echo " $option_next. Show next 5 releases"
user_options="$user_options, $option_next"
fi
echo ""
# Default choice is 1 (newest on page)
read -p "Select release ($user_options) [Default: 1]: " tag_choice
tag_choice=${tag_choice:-1}
# Check for "Next Page" option
if [[ "$tag_choice" -eq "$option_next" ]]; then
if [ $((start_index + items_per_page)) -lt $total_tags ]; then
current_page=$((current_page + 1))
continue
else
print_warning "No more release tags found."
continue
fi
elif [[ "$tag_choice" =~ ^[1-5]$ ]]; then
# Map 1-5 to array index
selected_idx=$((tag_choice - 1))
if [ $selected_idx -lt ${#current_items[@]} ]; then
branch_name="${current_items[$selected_idx]}"
print_success "Selected release: $branch_name"
break
else
print_error "Invalid selection. Please try again."
continue
fi
else
print_error "Invalid input. Please enter a valid number."
continue
fi
done
# If we broke out of the loop without selecting (e.g. no more tags), ensure we handle it?
# If branch_name is not set (empty), defaulting to main or erroring is wise.
if [ -z "$branch_name" ]; then
print_warning "No release selected. Defaulting to 'main'."
branch_name="main"
fi
elif [[ "$input_ver" =~ ^[0-9]+$ ]]; then
# User selected a branch number (offset by 2)
index=$((input_ver - 2))
if [ $index -ge 0 ] && [ $index -lt ${#branches_array[@]} ]; then
branch_name="${branches_array[$index]}"
print_success "Selected branch: $branch_name"
else
print_error "Invalid number. Please select a valid option."
exit 1
fi
else
# Fallback if they typed a name directly
branch_name="$input_ver"
if echo "$branches" | grep -q "^${branch_name}$"; then
print_success "Branch '$branch_name' found!"
else
print_warning "Branch '$branch_name' not found in the list. Defaulting to 'main' if failure occurs."
fi
fi
else
# User chose Yes (or default) for stable release
branch_name="main"
print_status "Using stable release (main branch)"
fi
# Determine final suffixes
if [ "$branch_name" = "main" ]; then
BRANCH_SUFFIX=""
else
# Replace dots with hyphens for the suffix to avoid issues in filenames/internal names
clean_branch_name=$(echo "$branch_name" | tr '.' '-')
BRANCH_SUFFIX="-${clean_branch_name}"
fi
FILE_SUFFIX="${BRANCH_SUFFIX}${PRIV_SUFFIX}"
# Installation process begins
print_status "Starting KhiproKeyboard installation..."
# Remove existing files
print_status "Cleaning up previous installations..."
rm -f "$INSTALL_DIR"/bn-khipro${FILE_SUFFIX}*.mim 2>/dev/null || true
rm -f "$INSTALL_DIR"/bn-khipro${FILE_SUFFIX}*.png 2>/dev/null || true
rm -rf /tmp/khipro-m17n 2>/dev/null || true
# Clone repository
print_status "Downloading KhiproKeyboard from GitHub..."
if [ "$branch_name" = "main" ]; then
git clone https://github.com/rank-coder/khipro-m17n.git /tmp/khipro-m17n
else
git clone --branch "$branch_name" https://github.com/rank-coder/khipro-m17n.git /tmp/khipro-m17n
fi
# Check if clone was successful
if [ ! -d /tmp/khipro-m17n ]; then
print_error "Failed to clone repository. Please check your internet connection and branch name."
exit 1
fi
print_success "Repository cloned successfully!"
# Copy files
print_status "Installing keyboard files..."
cd /tmp/khipro-m17n
# Check if the required files exist
if [ ! -f bn-khipro.mim ]; then
print_error "Required file bn-khipro.mim not found in the repository!"
exit 1
fi
TARGET_MIM="$INSTALL_DIR/bn-khipro${FILE_SUFFIX}.mim"
cp bn-khipro.mim "$TARGET_MIM"
# If installing locally or from a branch, modify the internal name and title
if [ -n "$FILE_SUFFIX" ]; then
print_status "Modifying internal name for installation (Suffix: $FILE_SUFFIX)..."
sed -i "s/(input-method bn khipro)/(input-method bn khipro${FILE_SUFFIX})/" "$TARGET_MIM"
fi
# Copy icon if it exists
if [ -f bn-khipro.png ]; then
print_status "Installing icon..."
mkdir -p "$ICON_DIR/"
cp bn-khipro.png "$ICON_DIR/bn-khipro${FILE_SUFFIX}.png"
print_success "Icon installed!"
else
print_warning "Icon file not found, skipping icon installation."
fi
print_success "Keyboard files installed successfully!"
# Clean up
rm -rf /tmp/khipro-m17n
# Final instructions
echo ""
print_success "KhiproKeyboard installation completed!"
echo ""
print_status "Next steps:"
echo "1. Log out and log back in to restart your input method framework"
echo "2. Add KhiproKeyboard to your input method:"
if [ "$ibus_installed" = true ]; then
echo " - For IBus: Open IBus Preferences → Add input method: Bengali → Khipro"
fi
if [ "$fcitx_installed" = true ]; then
echo " - For Fcitx5: Open Fcitx5 Configuration → Add Khipro keyboard"
fi
# Show missing packages reminder if any
if [ ${#missing_packages[@]} -gt 0 ]; then
echo ""
print_warning "REMEMBER: You need to install these packages for KhiproKeyboard to work:"
for pkg in "${missing_packages[@]}"; do
echo " - $pkg"
done
fi
echo ""
print_status "If you encounter any issues, please visit:"
echo " Our telegram group :: https://t.me/KhiproChat"
echo ""
print_warning "COMPUTER LOG OUT KORE LOG-IN KORUN"