summarylogtreecommitdiffstats
path: root/aur
blob: 2dbd382b97bcc030689329e5d9b900fbcb0488a5 (plain)
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
#!/bin/bash





# Colors


RED='\033[0;31m'


GREEN='\033[0;32m'


YELLOW='\033[0;33m'


BLUE='\033[0;34m'


NC='\033[0m'





# Config


AUR_DIR="$HOME/.aur_packages"


LOG_FILE="$AUR_DIR/aur.log"


MAX_RETRIES=2





# Initialize


init() {


    mkdir -p "$AUR_DIR" || die "Failed to create AUR directory"


    touch "$LOG_FILE" || die "Failed to create log file"


}





# Error handler


die() {


    echo -e "${RED}ERROR: $1${NC}" >&2


    echo "ERROR: $1" >> "$LOG_FILE"


    exit 1


}





# Logger


log() {


    local level="$1"


    local message="$2"


    local color


    


    case "$level" in


        "INFO") color="${BLUE}" ;;


        "WARN") color="${YELLOW}" ;;


        "SUCCESS") color="${GREEN}" ;;


        *) color="${NC}" ;;


    esac


    


    echo -e "${color}[$level]${NC} $message"


    echo "[$level] $message" >> "$LOG_FILE"


}





# Dependency check


check_deps() {


    local deps=("git" "makepkg" "sudo" "patch" "sed")


    for dep in "${deps[@]}"; do


        if ! command -v "$dep" >/dev/null 2>&1; then


            die "Missing dependency: $dep"


        fi


    done


}





# Build package with retries


build_pkg() {


    local pkg_dir="$1"


    local retries=0


    


    cd "$pkg_dir" || die "Can't enter package directory: $pkg_dir"


    


    while [ $retries -lt $MAX_RETRIES ]; do


        log "INFO" "Attempt $((retries+1)) to build $pkg_dir"


        


        # Clean previous attempts


        makepkg --cleanbuild --noconfirm >> "$LOG_FILE" 2>&1


        


        # Build with more verbosity


        if makepkg -si --noconfirm --needed --log >> "$LOG_FILE" 2>&1; then


            log "SUCCESS" "Built $pkg_dir successfully"


            return 0


        fi


        


        retries=$((retries+1))


        log "WARN" "Build attempt $retries failed"


        


        # Apply common fixes for known issues


        apply_build_fixes "$pkg_dir"


    done


    


    die "Failed to build $pkg_dir after $MAX_RETRIES attempts"


}





# Common build fixes


apply_build_fixes() {


    local pkg_dir="$1"


    


    # Fix for missing depends


    if grep -q "Could not resolve all dependencies" "$LOG_FILE"; then


        log "INFO" "Attempting to install missing dependencies"


        sudo pacman -Sy --noconfirm $(grep "cannot find" "$LOG_FILE" | awk '{print $4}') >> "$LOG_FILE" 2>&1


    fi


    


    # Fix for version conflicts


    if grep -q "version mismatch" "$LOG_FILE"; then


        log "INFO" "Adjusting pkgver in PKGBUILD"


        sed -i 's/^pkgver=.*/pkgver=new_version/' "$pkg_dir/PKGBUILD"


    fi


    


    # Fix for patch failures


    if grep -q "patch failed" "$LOG_FILE"; then


        log "INFO" "Applying manual patch fixes"


        patch --strip=1 --ignore-whitespace --fuzz=3 < *.patch >> "$LOG_FILE" 2>&1


    fi


}





# Install package


install_pkg() {


    local pkg="$1"


    local pkg_dir="$AUR_DIR/$pkg"


    


    log "INFO" "Installing $pkg from AUR"


    


    if [ -d "$pkg_dir" ]; then


        log "WARN" "Package directory exists - updating"


        cd "$pkg_dir" && git pull >> "$LOG_FILE" 2>&1 || die "Failed to update repo"


    else


        git clone "https://aur.archlinux.org/${pkg}.git" "$pkg_dir" >> "$LOG_FILE" 2>&1 || die "Failed to clone repo"


    fi


    


    build_pkg "$pkg_dir"


}





# Remove package


remove_pkg() {


    local pkg="$1"


    log "INFO" "Removing $pkg"


    


    if sudo pacman -R --noconfirm "$pkg" >> "$LOG_FILE" 2>&1; then


        log "SUCCESS" "Removed $pkg successfully"


    else


        die "Failed to remove $pkg"


    fi


}





# Update all packages


update_pkgs() {


    log "INFO" "Updating all AUR packages"


    


    for dir in "$AUR_DIR"/*; do


        if [ -d "$dir" ]; then


            local pkg=$(basename "$dir")


            log "INFO" "Processing $pkg"


            


            cd "$dir" || continue


            git pull >> "$LOG_FILE" 2>&1


            


            # Check if updates were pulled


            if [ $(git rev-list --count HEAD..origin/HEAD) -gt 0 ]; then


                build_pkg "$dir"


            else


                log "INFO" "$pkg is already up-to-date"


            fi


        fi


    done


}





# Show usage


usage() {


    echo -e "${YELLOW}Usage:${NC}"


    echo "  aur install <package> [package2...]  # Install packages"


    echo "  aur remove <package> [package2...]   # Remove packages"


    echo "  aur update                           # Update all packages"


    echo "  aur log                              # View installation log"


    exit 1


}





# Main function


main() {


    init


    check_deps


    


    case "$1" in


        install)


            shift


            [ $# -eq 0 ] && die "No packages specified"


            for pkg in "$@"; do


                install_pkg "$pkg"


            done


            ;;


        remove)


            shift


            [ $# -eq 0 ] && die "No packages specified"


            for pkg in "$@"; do


                remove_pkg "$pkg"


            done


            ;;


        update)


            update_pkgs


            ;;


        log)


            less -R "$LOG_FILE"


            ;;


        *)


            usage


            ;;


    esac


}





main "$@"