-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathptb
More file actions
673 lines (566 loc) · 21.4 KB
/
ptb
File metadata and controls
673 lines (566 loc) · 21.4 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
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
#!/bin/bash
# ptb - Paymenter ToolBox CLI
# Feel free to use this and modify according to QKOL v3.0
set -e
SCRIPT_NAME="ptb"
VERSION="1.2"
DEFAULT_THEME_DIR="/var/www/paymenter/themes"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Print colored output
print_info() {
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"
}
# Show usage information
show_usage() {
cat << EOF
${SCRIPT_NAME} v${VERSION} - Paymenter ToolBox CLI
Usage:
${SCRIPT_NAME} export -t <theme_path/theme_name> Export theme to .paytheme file
${SCRIPT_NAME} import -t <theme_file> Import .paytheme file to themes directory
${SCRIPT_NAME} update -t <theme_name> <update_file> Update theme directory with .paytheme update file
${SCRIPT_NAME} rename -t <theme_file> -n <new_name> Rename theme in .paytheme file
${SCRIPT_NAME} list -t <theme_file> List contents of .paytheme file
${SCRIPT_NAME} extract -t <theme_file> <output_dir> Extract .paytheme file to target directory
${SCRIPT_NAME} validate -t <theme_file> Validate .paytheme file structure
${SCRIPT_NAME} diff -t <theme1> <theme2> Compare two themes for differences
${SCRIPT_NAME} info -t <theme_name> Show detailed info about a theme directory or .paytheme file
${SCRIPT_NAME} --help Show this help message
${SCRIPT_NAME} --version Show version information
Default theme directory: ${DEFAULT_THEME_DIR}
EOF
}
# Export theme to .paytheme file for easy use
export_theme() {
local theme_path="$1"
if [[ -z "$theme_path" ]]; then
print_error "Theme path or name is required for export"
echo "Usage: $SCRIPT_NAME export -t <theme_path_or_name>"
exit 1
fi
if [[ ! -d "$theme_path" ]]; then
local assumed_path="${DEFAULT_THEME_DIR}/${theme_path}"
if [[ -d "$assumed_path" ]]; then
print_info "Theme '$theme_path' found in default theme directory"
theme_path="$assumed_path"
else
print_error "Theme directory does not exist: $theme_path or $assumed_path"
exit 1
fi
fi
local theme_name
theme_name=$(basename "$theme_path")
local output_file="${theme_name}.paytheme"
print_info "Exporting theme '$theme_name' from: $theme_path"
if tar -czf "$output_file" -C "$(dirname "$theme_path")" "$theme_name"; then
print_success "Theme exported successfully to: $output_file"
print_info "Archive size: $(du -h "$output_file" | cut -f1)"
else
print_error "Failed to export theme"
exit 1
fi
}
# Extract the .paytheme file and import it to /var/www/paymenter or other target directory
import_theme() {
local theme_file="$1"
local target_dir="${2:-$DEFAULT_THEME_DIR}"
if [[ -z "$theme_file" ]]; then
print_error "Theme file is required for import"
echo "Usage: $SCRIPT_NAME import -t <theme_file> [target_directory]"
exit 1
fi
if [[ ! -f "$theme_file" ]]; then
print_error "Theme file does not exist: $theme_file"
exit 1
fi
if [[ "$theme_file" != *.paytheme ]]; then
print_warning "File doesn't have .paytheme extension, proceeding anyway..."
fi
if [[ ! -d "$target_dir" ]]; then
print_info "Creating target directory: $target_dir"
mkdir -p "$target_dir" || {
print_error "Failed to create target directory"
exit 1
}
fi
print_info "Importing theme from: $theme_file"
print_info "Target directory: $target_dir"
if tar -xzf "$theme_file" -C "$target_dir"; then
local extracted_theme=$(tar -tzf "$theme_file" | head -1 | cut -f1 -d'/')
print_success "Theme imported successfully to: $target_dir/$extracted_theme"
if [[ -d "$target_dir/$extracted_theme" ]]; then
chmod -R 755 "$target_dir/$extracted_theme"
sudo npm run build $extracted_theme
print_info "Permissions set to 755"
fi
else
print_error "Failed to import theme"
exit 1
fi
}
# Rename theme and debug shit
rename_theme() {
local theme_file="$1"
local new_name="$2"
if [[ -z "$theme_file" ]]; then
print_error "Theme file is required for rename"
echo "Usage: $SCRIPT_NAME rename -t <theme_file> -n <new_name>"
exit 1
fi
if [[ -z "$new_name" ]]; then
print_error "New name is required for rename"
echo "Usage: $SCRIPT_NAME rename -t <theme_file> -n <new_name>"
exit 1
fi
if [[ ! -f "$theme_file" ]]; then
print_error "Theme file does not exist: $theme_file"
exit 1
fi
if [[ ! "$new_name" =~ ^[a-zA-Z0-9_-]+$ ]]; then
print_error "Invalid theme name. Use only letters, numbers, underscores, and hyphens."
exit 1
fi
local original_name
original_name=$(tar -tzf "$theme_file" | head -1 | cut -f1 -d'/')
if [[ -z "$original_name" ]]; then
print_error "Could not determine original theme name from archive"
exit 1
fi
if [[ "$original_name" == "$new_name" ]]; then
print_warning "New name is the same as current name. No changes made."
exit 0
fi
print_info "Renaming theme from '$original_name' to '$new_name'"
local temp_dir
temp_dir=$(mktemp -d)
local backup_file="${theme_file}.backup.$(date +%s)"
print_info "Using temporary directory: $temp_dir"
if ! cp "$theme_file" "$backup_file"; then
print_error "Failed to create backup file"
rm -rf "$temp_dir"
exit 1
fi
print_info "Backup created: $backup_file"
print_info "Extracting theme archive..."
if ! tar -xzf "$theme_file" -C "$temp_dir" 2>/dev/null; then
print_error "Failed to extract theme archive"
rm -rf "$temp_dir"
exit 1
fi
if [[ ! -d "$temp_dir/$original_name" ]]; then
print_error "Original theme directory not found after extraction: $temp_dir/$original_name"
ls -la "$temp_dir/"
rm -rf "$temp_dir"
exit 1
fi
print_info "Theme extracted successfully"
if ! mv "$temp_dir/$original_name" "$temp_dir/$new_name"; then
print_error "Failed to rename theme directory"
rm -rf "$temp_dir"
exit 1
fi
if [[ ! -d "$temp_dir/$new_name" ]]; then
print_error "Renamed theme directory not found: $temp_dir/$new_name"
rm -rf "$temp_dir"
exit 1
fi
print_info "Directory renamed successfully"
if ! update_theme_references "$temp_dir/$new_name" "$original_name" "$new_name"; then
print_warning "Reference update failed or skipped — continuing anyway"
fi
local new_theme_file="${new_name}.paytheme"
local current_dir
current_dir=$(pwd)
print_info "Creating renamed theme archive..."
if ! tar -czf "$current_dir/$new_theme_file" -C "$temp_dir" "$new_name"; then
print_error "Failed to create renamed theme archive"
rm -rf "$temp_dir"
exit 1
fi
if [[ -f "$current_dir/$new_theme_file" ]]; then
print_success "Theme renamed successfully!"
print_success "New file: $current_dir/$new_theme_file"
print_info "Original file preserved as: $backup_file"
print_info "Archive size: $(du -h "$current_dir/$new_theme_file" | cut -f1)"
if tar -tzf "$current_dir/$new_theme_file" >/dev/null 2>&1; then
print_info "Archive integrity verified"
else
print_warning "Archive may be corrupted, but file was created"
fi
else
print_error "Failed to create renamed theme archive"
rm -rf "$temp_dir"
exit 1
fi
rm -rf "$temp_dir"
print_info "Temporary files cleaned up"
}
# Replace the directory name of in vite.config.js with this messy shit
update_theme_references() {
local theme_dir="$1"
local old_name="$2"
local new_name="$3"
print_info "Updating theme references in vite.config.js from '$old_name' to '$new_name'"
local config_file="vite.config.js"
local file_path="$theme_dir/$config_file"
if [[ -f "$file_path" ]]; then
print_info "Processing: $config_file"
cp "$file_path" "$file_path.bak"
local content
content=$(cat "$file_path")
local new_content="$content"
new_content=$(echo "$new_content" | sed "s/buildDirectory:[[:space:]]*['\"]${old_name}\/['\"]/buildDirectory: '${new_name}\/'/g")
new_content=$(echo "$new_content" | sed "s/buildDirectory:[[:space:]]*['\"]${old_name}['\"]/buildDirectory: '${new_name}'/g")
if [[ "$content" != "$new_content" ]]; then
echo "$new_content" > "$file_path"
print_success " Updated references in $config_file"
rm -f "$file_path.bak"
else
print_info " No changes needed in $config_file"
mv "$file_path.bak" "$file_path"
fi
else
print_info "No vite.config.js file found in $theme_dir"
fi
}
# List theme contents so you can verify or something....
list_theme_contents() {
local theme_file="$1"
if [[ ! -f "$theme_file" ]]; then
print_error "Theme file does not exist: $theme_file"
exit 1
fi
print_info "Contents of $theme_file:"
tar -tzf "$theme_file" | head -20
local total_files=$(tar -tzf "$theme_file" | wc -l)
if [[ $total_files -gt 20 ]]; then
print_info "... and $((total_files - 20)) more files"
fi
print_info "Total files: $total_files"
print_info "Archive size: $(du -h "$theme_file" | cut -f1)"
}
# Update an existing theme with contents of an update .paytheme file
update_theme() {
local existing_theme="$1"
local update_file="$2"
local target_dir="${DEFAULT_THEME_DIR}/${existing_theme}"
if [[ -z "$existing_theme" || -z "$update_file" ]]; then
print_error "Usage: $SCRIPT_NAME update -t <existing_theme> <update_file>.paytheme"
exit 1
fi
if [[ ! -f "$update_file" ]]; then
print_error "Update file does not exist: $update_file"
exit 1
fi
if [[ ! -d "$target_dir" ]]; then
print_error "Existing theme not found: $target_dir"
exit 1
fi
print_info "Updating theme '$existing_theme' using: $update_file"
local temp_dir
temp_dir=$(mktemp -d)
print_info "Extracting update package..."
if ! tar -xzf "$update_file" -C "$temp_dir"; then
print_error "Failed to extract update archive"
rm -rf "$temp_dir"
exit 1
fi
local extracted_dir
extracted_dir=$(find "$temp_dir" -mindepth 1 -maxdepth 1 -type d | head -1)
if [[ ! -d "$extracted_dir" ]]; then
print_error "No directory found inside update package"
rm -rf "$temp_dir"
exit 1
fi
print_info "Copying updated files to $target_dir..."
cp -a "$extracted_dir/." "$target_dir/" || {
print_error "Failed to copy updated files"
rm -rf "$temp_dir"
exit 1
}
print_success "Theme '$existing_theme' successfully updated!"
chmod -R 755 "$target_dir"
sudo npm run build "$existing_theme"
rm -rf "$temp_dir"
print_info "Temporary files cleaned up"
}
validate_theme() {
local theme_file="$1"
if [[ -z "$theme_file" ]]; then
print_error "Theme file is required"
exit 1
fi
if [[ ! -f "$theme_file" ]]; then
print_error "File not found: $theme_file"
exit 1
fi
local temp_dir
temp_dir=$(mktemp -d)
tar -xzf "$theme_file" -C "$temp_dir" || {
print_error "Failed to extract archive"
rm -rf "$temp_dir"
exit 1
}
local extracted_dir
extracted_dir=$(find "$temp_dir" -mindepth 1 -maxdepth 1 -type d)
local required_files=("css/app.css" "css/easymde.css" "js/app.js" "theme.php" "views/auth/2fa.blade.php" "views/auth/login.blade.php" "views/auth/logout.blade.php" "views/auth/password/request.blade.php" "views/auth/password/reset.blade.php" "views/auth/register.blade.php" "views/auth/verify-email.blade.php" "views/cart.blade.php" "views/client/account/credits.blade.php" "views/client/account/index.blade.php" "views/client/account/security.blade.php" "views/components/admin-footer.blade.php" "views/components/button/danger.blade.php" "views/components/button/primary.blade.php" "views/components/button/save.blade.php" "views/components/button/secondary.blade.php" "views/components/captcha/hcaptcha.blade.php" "views/components/captcha/index.blade.php" "views/components/captcha/recaptcha-v2.blade.php" "views/components/captcha/recaptcha-v3.blade.php" "views/components/captcha/turnstile.blade.php" "views/components/cart.blade.php" "views/components/center.blade.php" "views/components/currency-switch.blade.php" "views/components/dropdown.blade.php" "views/components/easymde-editor.blade.php" "views/components/form/checkbox.blade.php" "views/components/form/configoption.blade.php" "views/components/form/input.blade.php" "views/components/form/properties.blade.php" "views/components/form/radio.blade.php" "views/components/form/select.blade.php" "views/components/form/setting.blade.php" "views/components/form/textarea.blade.php" "views/components/language-switch.blade.php" "views/components/loading.blade.php" "views/components/logo.blade.php" "views/components/modal.blade.php" "views/components/navigation/breadcrumb.blade.php" "views/components/navigation/footer.blade.php" "views/components/navigation/index.blade.php" "views/components/navigation/link.blade.php" "views/components/navigation/sidebar.blade.php" "views/components/navigation/sidebar-links.blade.php" "views/components/notification.blade.php" "views/components/pagination.blade.php" "views/components/select.blade.php" "views/components/theme-toggle.blade.php" "views/dashboard.blade.php" "views/home.blade.php" "views/invoices/index.blade.php" "views/invoices/show.blade.php" "views/invoices/widget.blade.php" "views/layouts/app.blade.php" "views/layouts/colors.blade.php" "views/products/checkout.blade.php" "views/products/index.blade.php" "views/products/show.blade.php" "views/services/cancel.blade.php" "views/services/index.blade.php" "views/services/show.blade.php" "views/services/upgrade.blade.php" "views/services/widget.blade.php" "views/tickets/create.blade.php" "views/tickets/index.blade.php" "views/tickets/show.blade.php" "views/tickets/widget.blade.php" "views/vendor/passport/authorize.blade.php" "vite.config.js" )
local missing=0
for file in "${required_files[@]}"; do
if [[ ! -f "$extracted_dir/$file" ]]; then
print_warning "Missing: $file"
missing=1
fi
done
if [[ $missing -eq 0 ]]; then
print_success "All required files are present"
else
print_warning "Some required files are missing"
fi
rm -rf "$temp_dir"
}
info_theme() {
local theme_file="$1"
if [[ ! -f "$theme_file" ]]; then
print_error "File not found: $theme_file"
exit 1
fi
local name=$(tar -tzf "$theme_file" | head -1 | cut -d/ -f1)
local size=$(du -h "$theme_file" | cut -f1)
local count=$(tar -tzf "$theme_file" | wc -l)
print_info "Theme name: $name"
print_info "Total files: $count"
print_info "Size: $size"
}
extract_theme() {
local theme_file="$1"
local output_dir="$2"
if [[ -z "$theme_file" || -z "$output_dir" ]]; then
print_error "Usage: $SCRIPT_NAME extract -t <theme_file> -o <output_dir>"
exit 1
fi
mkdir -p "$output_dir"
tar -xzf "$theme_file" -C "$output_dir" && print_success "Extracted to $output_dir"
}
diff_themes() {
local theme1="$1"
local theme2="$2"
if [[ -z "$theme1" || -z "$theme2" ]]; then
print_error "Usage: $SCRIPT_NAME diff <theme1> <theme2>"
exit 1
fi
local path1="${DEFAULT_THEME_DIR}/${theme1}"
local path2="${DEFAULT_THEME_DIR}/${theme2}"
if [[ ! -d "$path1" ]]; then
print_error "Theme not found: $path1"
exit 1
fi
if [[ ! -d "$path2" ]]; then
print_error "Theme not found: $path2"
exit 1
fi
print_info "Comparing '$theme1' with '$theme2'..."
diff -qr "$path1" "$path2" || {
print_warning "Some differences were found."
exit 1
}
print_success "No differences found!"
}
# Main script logic
main() {
case "${1:-}" in
export)
shift
while [[ $# -gt 0 ]]; do
case $1 in
-t)
export_theme "$2"
shift 2
;;
*)
print_error "Unknown option: $1"
show_usage
exit 1
;;
esac
done
;;
import)
shift
while [[ $# -gt 0 ]]; do
case $1 in
-t)
import_theme "$2"
shift 2
;;
*)
print_error "Unknown option: $1"
show_usage
exit 1
;;
esac
done
;;
rename)
shift
local theme_file=""
local new_name=""
while [[ $# -gt 0 ]]; do
case $1 in
-t)
theme_file="$2"
shift 2
;;
-n)
new_name="$2"
shift 2
;;
*)
print_error "Unknown option: $1"
show_usage
exit 1
;;
esac
done
rename_theme "$theme_file" "$new_name"
;;
diff)
shift
local theme1=""
local theme2=""
while [[ $# -gt 0 ]]; do
case $1 in
-t)
theme1="$2"
theme2="$3"
shift 3
;;
*)
print_error "Unknown option: $1"
show_usage
exit 1
;;
esac
done
diff_themes "$theme1" "$theme2"
;;
list)
shift
while [[ $# -gt 0 ]]; do
case $1 in
-t)
list_theme_contents "$2"
shift 2
;;
*)
print_error "Unknown option: $1"
show_usage
exit 1
;;
esac
done
;;
update)
shift
local existing_theme=""
local update_file=""
while [[ $# -gt 0 ]]; do
case $1 in
-t)
existing_theme="$2"
shift 2
;;
*)
update_file="$1"
shift
;;
esac
done
update_theme "$existing_theme" "$update_file"
;;
validate)
shift
while [[ $# -gt 0 ]]; do
case $1 in
-t)
validate_theme "$2"
shift 2
;;
*) shift ;;
esac
done
;;
extract)
shift
local theme_file=""
local output_dir=""
while [[ $# -gt 0 ]]; do
case $1 in
-t)
theme_file="$2"
shift 2
;;
-o)
output_dir="$2"
shift 2
;;
*) shift ;;
esac
done
extract_theme "$theme_file" "$output_dir"
;;
info)
shift
while [[ $# -gt 0 ]]; do
case $1 in
-t)
info_theme "$2"
shift 2
;;
*) shift ;;
esac
done
;;
--help|-h)
show_usage
;;
--version|-v)
echo "$SCRIPT_NAME version $VERSION"
;;
"")
print_error "No command specified"
show_usage
exit 1
;;
*)
print_error "Unknown command: $1"
show_usage
exit 1
;;
esac
}
#make sure the dependecies are installed
check_dependencies() {
local deps=("tar" "gzip" "sed")
for dep in "${deps[@]}"; do
if ! command -v "$dep" &> /dev/null; then
print_error "Required dependency '$dep' is not installed"
exit 1
fi
done
}
#function call
check_dependencies
main "$@"