-
Notifications
You must be signed in to change notification settings - Fork 1
/
tiger.sh
executable file
·1296 lines (1098 loc) · 42.3 KB
/
tiger.sh
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
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# tiger.sh: package manager for PowerPC Macs running OS X Tiger (10.4).
# Try 'tiger.sh --help'.
# See https://github.com/cellularmitosis/leopard.sh
set -e
pkgmgr=tiger.sh
if test "${BASH_VERSION:0:2}" = "2." && test -e /opt/tigersh-deps-0.1/bin/bash ; then
# recurse but with bash 3.2:
PATH="/opt/tigersh-deps-0.1/bin:$PATH" $0 "$@"
exit $?
fi
if test "$1" = "--verbose" ; then
shift 1
export TIGERSH_VERBOSE=1
fi
if test -n "$TIGERSH_VERBOSE" ; then
set -x
fi
# Note: for offline use or to run you own local fork, put this in your ~/.bashrc:
# export TIGERSH_MIRROR=file:///Users/foo/leopard.sh
# If you care more about speed than glowies, drop HTTPS for a speed-up:
# export TIGERSH_MIRROR=http://leopard.sh
TIGERSH_MIRROR=${TIGERSH_MIRROR:-https://leopard.sh}
export TIGERSH_MIRROR
# no alarms and no surprises, please.
ORIG_PATH="$PATH"
export PATH="/opt/tigersh-deps-0.1/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
# colors:
export COLOR_RED="\e[31;1m"
export COLOR_GREEN="\e[32;1m"
export COLOR_YELLOW="\e[33;1m"
export COLOR_MAGENTA="\e[35;1m"
export COLOR_CYAN="\e[36;1m"
export COLOR_NONE="\e[0m"
# process the command line args:
needs_setup_check=1
if test "$1" = "--help" ; then
op=help
elif test "$1" = "--list" ; then
op=list
elif test "$1" = "--describe" -o "$1" = "--descriptions"; then
op=describe
elif test "$1" = "--tags" ; then
op=tags
elif test "$1" = "--tag" ; then
op=tag
elif test "$1" = "--setup" ; then
op=setup
elif test "$1" = "--self-update" ; then
op=self-update
elif test "$1" = "--install" ; then
op=install
elif test "$1" = "--link" ; then
op=link
elif test "$1" = "--unlink" ; then
op=unlink
elif test "$1" = "-j" ; then
op=makeflags
unset needs_setup_check
elif test "$1" = "-m32" -o "$1" = "-mcpu" -o "$1" = "-O" ; then
op=gccflags
elif test "$1" = "--cpu" -o "$1" = "--os.cpu" -o "$1" = "--bits" ; then
op=platform-info
elif test "$1" = "--arch-check" ; then
op=arch-check
elif test "$1" = "--linker-check" ; then
op=linker-check
elif test "$1" = "--url-exists" ; then
op=url-exists
elif test "$1" = "--install-binpkg" ; then
op=install-binpkg
elif test "$1" = "--unpack-dist" ; then
op=unpack-dist
elif test "$1" = "--unpack-tarball-check-md5" ; then
op=unpack-tarball-check-md5
elif test "$1" = "--spotlight" ; then
op=spotlight
elif test "$1" = "--dashboard" ; then
op=dashboard
elif test -n "$1" ; then
op=install
else
op=list
fi
if test "$1" = "--help" \
-o "$1" = "-j" \
-o "$1" = "-m32" \
-o "$1" = "-mcpu" \
-o "$1" = "-O" \
-o "$1" = "--cpu" \
-o "$1" = "--os.cpu" \
-o "$1" = "--bits" \
-o "$1" = "--spotlight" \
-o "$1" = "--dashboard" \
; then
unset needs_setup_check
fi
if test "$op" = "list" \
-o "$op" = "install" \
-o "$op" = "gccflags" \
-o "$op" = "platform-info" \
-o "$op" = "arch-check" \
; then
needs_cpu_info=1
fi
if test -n "$TIGERSH_RECURSED" ; then
unset needs_setup_check
fi
orig_pwd=$PWD
if ! test -e ~/.tigersh/checks ; then
mkdir -p ~/.tigersh/checks
fi
# get the CPU type:
if test -n "$needs_cpu_info" ; then
cpu_id=$(sysctl hw.cpusubtype | awk '{print $NF}')
if test "$cpu_id" = "9" ; then
cpu_name=g3
cpu_num=750
elif test "$cpu_id" = "10" ; then
cpu_name=g4
cpu_num=7400
elif test "$cpu_id" = "11" ; then
cpu_name=g4e
cpu_num=7450
elif test "$cpu_id" = "100" ; then
cpu_name=g5
cpu_num=970
else
echo -e "${COLOR_RED}Error${COLOR_NONE}: unsupported CPU type." >&2
exit 1
fi
fi
# setup:
if test "$op" = "setup" || test -n "$needs_setup_check" ; then
if ! test -e ~/.tigersh/checks/os-is-tiger ; then
osversion=$(sw_vers -productVersion)
if ! test "${osversion:0:4}" = "10.4" ; then
echo "Sorry, this script was written for OS X Tiger :(" >&2
exit 1
else
touch ~/.tigersh/checks/os-is-tiger
fi
fi
needs_new_terminal="false"
if ! test -e ~/.tigersh/checks/usr-local-bin-in-path ; then
if ! echo $ORIG_PATH | tr ':' '\n' | egrep '^/usr/local/bin/?$' >/dev/null ; then
echo "Adding /usr/local/bin to your \$PATH." >&2
if ! test -e ~/.bashrc -o -e ~/.bash_profile -o -e ~/.profile ; then
# This is a brand-new user with no rc files.
touch ~/.profile
fi
for f in ~/.bashrc ~/.bash_profile ~/.profile ; do
if test -e $f ; then
echo >> $f
echo "# Added by tiger.sh:" >> $f
echo "export PATH=\"/usr/local/bin:/usr/local/sbin:\$PATH\"" >> $f
fi
done
needs_new_terminal="true"
else
touch ~/.tigersh/checks/usr-local-bin-in-path
fi
fi
if ! test -e ~/.tigersh/checks/user-in-admin-group ; then
if ! dseditgroup -o checkmember -m $USER admin >/dev/null ; then
echo "Adding your user to the admin group." >&2
# thanks to https://blog.travismclarke.com/post/osx-cli-group-management/
set -x
sudo dseditgroup -o edit -a $USER -t user admin
{ set +x; } 2>/dev/null
sleep 1
if ! dseditgroup -o checkmember -m $USER admin >/dev/null ; then
needs_new_terminal="true"
fi
else
touch ~/.tigersh/checks/user-in-admin-group
fi
fi
if ! test -e ~/.tigersh/checks/user-in-wheel-group ; then
if ! dseditgroup -o checkmember -m $USER wheel >/dev/null ; then
echo "Adding your user to the wheel group." >&2
# thanks to https://blog.travismclarke.com/post/osx-cli-group-management/
set -x
sudo dseditgroup -o edit -a $USER -t user wheel
{ set +x; } 2>/dev/null
sleep 1
if ! dseditgroup -o checkmember -m $USER wheel >/dev/null ; then
needs_new_terminal="true"
fi
else
touch ~/.tigersh/checks/user-in-wheel-group
fi
fi
if test "$needs_new_terminal" = "true" ; then
echo "This change won't take effect until you open a new Terminal window." >&2
echo "Please open a new Terminal window and run $0 again." >&2
exit 1
fi
# thanks to https://stackoverflow.com/a/61367055
for pair in \
"opt /opt" \
"usr-local /usr/local" \
"usr-local-bin /usr/local/bin" \
"usr-local-sbin /usr/local/sbin" \
"usr-local-share /usr/local/share" \
"usr-local-share-man /usr/local/share/man" \
"usr-local-share-man1 /usr/local/share/man/man1" \
"usr-local-share-man3 /usr/local/share/man/man3" \
; do
arr=($pair)
stamp="can-write-in-${arr[0]}"
d="${arr[1]}"
if test -e ~/.tigersh/checks/$stamp ; then
continue
fi
if ! test -e $d ; then
echo "Creating $d." >&2
set -x
sudo mkdir $d
sudo chgrp admin $d
sudo chmod g+w $d
{ set +x; } 2>/dev/null
else
if ! test "$(stat -f '%Sg' $d)" = "admin" ; then
echo "Changing group of $d to admin." >&2
set -x
sudo chgrp admin $d
{ set +x; } 2>/dev/null
fi
if ! test "$(expr $(stat -f '%Sp' $d) : '.....\(.\)')" = "w" ; then
echo "Making $d group-writeable." >&2
set -x
sudo chmod g+w $d
{ set +x; } 2>/dev/null
fi
fi
if ! mktemp $d/tiger.sh.write-check.XXX >/dev/null ; then
echo -e "${COLOR_RED}Error${COLOR_NONE}: can't write to $d." >&2
exit 1
else
touch ~/.tigersh/checks/$stamp
rm -f $d/tiger.sh.write-check.*
fi
done
if ! test -e ~/Downloads ; then
mkdir -p ~/Downloads
fi
if test "$0" != "/usr/local/bin/tiger.sh" ; then
echo "Moving tiger.sh into /usr/local/bin." >&2
set -x
sudo mv "$0" /usr/local/bin/
{ set +x; } 2>/dev/null
fi
deps_pkgspec=tigersh-deps-0.1
if test ! -e /opt/$deps_pkgspec \
|| test -e /opt/$deps_pkgspec/INCOMPLETE_INSTALLATION ; then
echo -e "${COLOR_CYAN}Installing${COLOR_NONE} tiger.sh dependencies (pv, curl w/SSL, otool w/ppc64 support)." >&2
rm -rf /opt/$deps_pkgspec
mkdir -p /opt/$deps_pkgspec
touch /opt/$deps_pkgspec/INCOMPLETE_INSTALLATION
cd /tmp
binpkg=$deps_pkgspec.tiger.g3.tar.gz
fifo=/tmp/$binpkg.fifo
rm -f $fifo /tmp/$binpkg.localmd5_ /tmp/$binpkg.localmd5
( mkfifo $fifo \
&& cat $fifo | nice md5 > /tmp/$binpkg.localmd5_ \
&& mv /tmp/$binpkg.localmd5_ /tmp/$binpkg.localmd5
) &
while ! test -e $fifo ; do sleep 0.1 ; done
if test -e /tmp/$binpkg ; then
# If the user provided the file locally, use that.
url=file:///tmp/$binpkg
insecure_url=$url
else
url=$TIGERSH_MIRROR/binpkgs/$binpkg
# At this point we are still using /usr/bin/curl, so drop back to http.
insecure_url=$(echo "$url" | sed 's|^https:|http:|')
if test -n "$TIGERSH_MIRROR_NO_HTTP" ; then
echo "Error: unable to fetch $url" >&2
echo "/usr/bin/curl is unable to use HTTPS, but TIGERSH_MIRROR_NO_HTTP has been set." >&2
echo "Please place a copy of $binpkg into /tmp and try again." >&2
exit 1
fi
fi
cd /opt
nice curl --fail --silent --show-error $insecure_url \
| tee $fifo \
| nice gunzip \
| nice tar x
while ! test -e /tmp/$binpkg.localmd5 ; do sleep 0.1 ; done
rm $fifo
# Note: this qr code was generated via 'qrencode -t ANSI https://leopard.sh/md5'
echo
cat >&2 << EOF
[47m [0m
[47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [40m [47m [0m
[47m [0m
[47m [0m
EOF
echo >&2
echo "OS X Tiger's support for SSL is too old to use, which means this script" >&2
echo "can't verify the integrity of the dependencies which it just downloaded." >&2
echo >&2
echo "Please visit https://leopard.sh/md5 in a modern browser (or by scanning the" >&2
echo "above QR code on your smartphone) and verify the following MD5 sums:" >&2
echo >&2
echo "The MD5 sum of tiger.sh is:" >&2
echo >&2
echo " $(md5 -q /usr/local/bin/tiger.sh)" >&2
echo >&2
echo "The MD5 sum of $binpkg is:" >&2
echo >&2
echo " $(cat /tmp/$binpkg.localmd5)" >&2
echo >&2
read -p "Do the MD5 sums match? [Y/n]: " answer
while true ; do
if test "$answer" = "y" -o "$answer" = "Y" -o "$answer" = "" ; then
rm -f /tmp/$binpkg.localmd5
break
elif test "$answer" = "n" -o "$answer" = "N" ; then
echo >&2
echo "If the MD5 sums don't match, that means something is wrong." >&2
echo >&2
echo "Please google 'macrumors powerpc' and start a forum thread." >&2
echo "The user 'cellularmitosis' will assist you." >&2
echo >&2
echo "Alternatively, if you are a github user, feel free to create an" >&2
echo "issue at https://github.com/cellularmitosis/leopard.sh" >&2
exit 1
else
read -p "Please type 'y', 'n' or hit ENTER (same as 'y') " answer
fi
done
rm /opt/$deps_pkgspec/INCOMPLETE_INSTALLATION
fi
opt_config_cache=/opt/tiger.sh/share/tiger.sh/config.cache
if ! test -e $opt_config_cache ; then
mkdir -p $opt_config_cache
fi
if test "$(sysctl hw.cpusubtype | awk '{print $NF}')" = "100" ; then
bits=64
else
bits=32
fi
if test ! -e $opt_config_cache/tiger.cache || test ! -e $opt_config_cache/tiger.$bits.cache ; then
cd $opt_config_cache
if ! test -e $opt_config_cache/tiger.cache ; then
echo "Fetching configure cache (tiger.cache)." >&2
url=$TIGERSH_MIRROR/tigersh/config.cache/tiger.cache
curl --fail --silent --show-error --location --remote-name $url
fi
if ! test -e $opt_config_cache/tiger.$bits.cache ; then
echo "Fetching configure cache (tiger.$bits.cache)." >&2
url=$TIGERSH_MIRROR/tigersh/config.cache/tiger.$bits.cache
curl --fail --silent --show-error --location --remote-name $url
fi
fi
if test "${BASH_VERSION:0:2}" = "2." ; then
# recurse but with bash 3.2:
PATH="/opt/tigersh-deps-0.1/bin:$PATH" /usr/local/bin/tiger.sh "$@"
exit $?
fi
fi
# at this point we should be running bash 3.2.
set -o pipefail
# list:
if test "$op" = "list" ; then
echo "Available packages:" >&2
cd /tmp
url=$TIGERSH_MIRROR/tigersh/packages.txt
if test -n "$TIGERSH_MIRROR_NO_HTTP" ; then
insecure_url=$url
else
insecure_url=$(echo "$url" | sed 's|^https:|http:|')
fi
curl --fail --silent --show-error --location --remote-name $insecure_url
if test "$cpu_name" = "g5" ; then
url=$TIGERSH_MIRROR/tigersh/packages.ppc64.txt
if test -n "$TIGERSH_MIRROR_NO_HTTP" ; then
insecure_url=$url
else
insecure_url=$(echo "$url" | sed 's|^https:|http:|')
fi
curl --fail --silent --show-error --location --remote-name $insecure_url
cat packages.txt packages.ppc64.txt | sort
else
cat packages.txt
fi
rm -f packages.txt packages.ppc64.txt
exit 0
fi
# describe:
if test "$op" = "describe" ; then
shift 1
if test -n "$1" ; then
pkgspec="$1"
shift 1
echo "Description of '$pkgspec':" >&2
else
echo "Available package descriptions:" >&2
fi
cd /tmp
url=$TIGERSH_MIRROR/tigersh/descriptions.txt
if test -n "$TIGERSH_MIRROR_NO_HTTP" ; then
insecure_url=$url
else
insecure_url=$(echo "$url" | sed 's|^https:|http:|')
fi
curl --fail --silent --show-error --location --remote-name $insecure_url
if test "$cpu_name" = "g5" ; then
url=$TIGERSH_MIRROR/tigersh/descriptions.ppc64.txt
if test -n "$TIGERSH_MIRROR_NO_HTTP" ; then
insecure_url=$url
else
insecure_url=$(echo "$url" | sed 's|^https:|http:|')
fi
curl --fail --silent --show-error --location --remote-name $insecure_url
if test -n "$pkgspec" ; then
cat descriptions.txt descriptions.ppc64.txt | sort | grep "^$pkgspec: "
else
cat descriptions.txt descriptions.ppc64.txt | sort
fi
else
if test -n "$pkgspec" ; then
cat descriptions.txt | sort | grep "^$pkgspec: "
else
cat descriptions.txt | sort
fi
fi
rm -f descriptions.txt descriptions.ppc64.txt
exit 0
fi
# tags:
if test "$op" = "tags" ; then
echo "Available tags:" >&2
cd /tmp
url=$TIGERSH_MIRROR/tigersh/tags/tags.txt
if test -n "$TIGERSH_MIRROR_NO_HTTP" ; then
insecure_url=$url
else
insecure_url=$(echo "$url" | sed 's|^https:|http:|')
fi
curl --fail --silent --show-error --location --remote-name $insecure_url
cat tags.txt
rm -f tags.txt
exit 0
fi
# tag:
if test "$op" = "tag" ; then
shift 1
if test -z "$1" ; then
TIGERSH_RECURSED=1 tiger.sh --tags
exit 0
fi
tag="$1"
echo "Packages tagged as '$tag':" >&2
cd /tmp
url=$TIGERSH_MIRROR/tigersh/tags/$tag.txt
if test -n "$TIGERSH_MIRROR_NO_HTTP" ; then
insecure_url=$url
else
insecure_url=$(echo "$url" | sed 's|^https:|http:|')
fi
curl --fail --silent --show-error --location --remote-name $insecure_url
if test "$cpu_name" = "g5" ; then
cat $tag.txt
else
cat $tag.txt | grep -v '\.ppc64$'
fi
rm -f $tag.txt
exit 0
fi
# install:
if test "$op" = "install" ; then
if test "$1" = "--install" ; then
shift 1
fi
pkgspec="$1"
shift 1
script=install-$pkgspec.sh
if test "$1" = "wip" ; then
wip=1
fi
# Note: we check for symlinks because e.g. the /opt/gcc-... symlink created
# by gcc-libs should be replaced by the real gcc if explicitly requested.
if test -e "/opt/$pkgspec" -a ! -L "/opt/$pkgspec" \
&& test ! -e "/opt/$pkgspec/INCOMPLETE_INSTALLATION" ; then
echo -e "${COLOR_YELLOW}${pkgspec}${COLOR_NONE} is already installed at /opt/$pkgspec" >&2
exit 0
fi
# Thanks to https://trac.macports.org/ticket/16286
export MACOSX_DEPLOYMENT_TARGET=10.4
echo -e "${COLOR_CYAN}Installing${COLOR_NONE} ${COLOR_YELLOW}$pkgspec${COLOR_NONE}." >&2
echo -n -e "\033]0;tiger.sh $pkgspec (tiger.$cpu_name)\007"
echo -e "${COLOR_CYAN}Fetching${COLOR_NONE} $script." >&2
url=$TIGERSH_MIRROR/tigersh/scripts/$script
if test -n "$wip" ; then
url=$TIGERSH_MIRROR/tigersh/scripts/wip/$script
fi
cd /tmp
curl --fail --silent --show-error --location --remote-name $url &
curl_script_pid=$!
rm -rf /opt/$pkgspec
wait $curl_script_pid
mkdir -p /opt/$pkgspec
touch /opt/$pkgspec/INCOMPLETE_INSTALLATION
chmod +x $script
if test -n "$TIGERSH_VERBOSE" ; then
TIGERSH_RECURSED=1 nice bash -x ./$script 2>&1 | tee /tmp/$script.log
else
TIGERSH_RECURSED=1 nice ./$script 2>&1 | tee /tmp/$script.log
fi
TIGERSH_RECURSED=1 tiger.sh --link $pkgspec
if ! test -e /opt/$pkgspec/share/tiger.sh/$pkgspec/$script.log.gz ; then
mkdir -p /opt/$pkgspec/share/tiger.sh/$pkgspec
nice gzip -9 /tmp/$script
mv /tmp/$script.gz /opt/$pkgspec/share/tiger.sh/$pkgspec/
nice gzip -9 /tmp/$script.log
mv /tmp/$script.log.gz /opt/$pkgspec/share/tiger.sh/$pkgspec/
fi
rm -f /opt/$pkgspec/INCOMPLETE_INSTALLATION
if test -e /opt/$pkgspec/SUPERFLUOUS_DIRECTORY ; then
rm -rf /opt/$pkgspec
fi
exit 0
fi
# url exists:
if test "$op" = "url-exists" ; then
shift 1
if test -z "$1" ; then
echo -e "${COLOR_RED}Error${COLOR_NONE}: check which url?" >&2
echo "e.g. tiger.sh --url-exists http://example.com" >&2
exit 1
fi
url="$1"
curl --fail --silent --show-error --head "$url" >/dev/null 2>&1
exit 0
fi
# install a binpkg into /opt:
if test "$op" = "install-binpkg" ; then
shift 1
if test -z "$1" ; then
echo -e "${COLOR_RED}Error${COLOR_NONE}: install which binpkg?" >&2
echo "e.g. tiger.sh --install-binpkg gzip-1.11" >&2
echo "e.g. tiger.sh --install-binpkg gzip-1.11 tiger.g3" >&2
exit 1
fi
pkgspec="$1"
shift 1
if test -n "$1" ; then
os_cpu="$1"
shift 1
else
os_cpu=$(TIGERSH_RECURSED=1 tiger.sh --os.cpu)
fi
binpkg=$pkgspec.$os_cpu.tar.gz
url=$TIGERSH_MIRROR/binpkgs/$binpkg
if test -n "$TIGERSH_MIRROR_NO_HTTP" ; then
insecure_url=$url
else
insecure_url=$(echo "$url" | sed 's|^https:|http:|')
fi
if ! TIGERSH_RECURSED=1 tiger.sh --url-exists "$insecure_url" ; then
echo "Pre-compiled binary package unavailable for $pkgspec on $os_cpu." >&2
exit 1
fi
if test "$TIGERSH_FORCE_BUILD_PKGSPEC" = "$pkgspec" ; then
echo "Ignoring $binpkg due to '\$TIGERSH_FORCE_BUILD_PKGSPEC'" >&2
exit 1
fi
if test -n "$TIGERSH_FORCE_BUILD_ALL" ; then
echo "Ignoring $binpkg due to '\$TIGERSH_FORCE_BUILD_ALL'" >&2
exit 1
fi
echo -e "${COLOR_CYAN}Unpacking${COLOR_NONE} $binpkg into /opt." >&2
TIGERSH_RECURSED=1 tiger.sh --unpack-tarball-check-md5 $url /opt
exit 0
fi
# unpack a distfile into /tmp:
if test "$op" = "unpack-dist" ; then
shift 1
if test -z "$1" ; then
echo -e "${COLOR_RED}Error${COLOR_NONE}: unpack distfile for which pkgspec?" >&2
echo "e.g. tiger.sh --unpack-dist gzip-1.11" >&2
exit 1
fi
pkgspec="$(echo $1 | sed 's/\.ppc64//')"
shift 1
tarball=$pkgspec.tar.gz
url=$TIGERSH_MIRROR/dist/$tarball
echo -e "${COLOR_CYAN}Unpacking${COLOR_NONE} $tarball into /tmp." >&2
rm -rf /tmp/$pkgspec
TIGERSH_RECURSED=1 tiger.sh --unpack-tarball-check-md5 $url /tmp
if test -e /tmp/$pkgspec/configure ; then
cat /opt/tiger.sh/share/tiger.sh/config.cache/tiger.cache \
/opt/tiger.sh/share/tiger.sh/config.cache/tiger.$(tiger.sh --bits).cache \
> /tmp/$pkgspec/config.cache
fi
exit 0
fi
# unpack a tarball and verify its MD5 sum:
if test "$op" = "unpack-tarball-check-md5" ; then
shift 1
if test -z "$1" ; then
echo -e "${COLOR_RED}Error${COLOR_NONE}: unpack which tarball url?" >&2
echo "e.g. tiger.sh --unpack-tarball-check-md5 http://leopard.sh/dist/gzip-1.11.tar.gz /tmp" >&2
echo "e.g. tiger.sh --unpack-tarball-check-md5 http://leopard.sh/binpkgs/gzip-1.11.tiger.g3.tar.gz /opt" >&2
exit 1
fi
url="$1"
if test -n "$TIGERSH_MIRROR_NO_HTTP" ; then
insecure_url=$url
else
insecure_url=$(echo "$url" | sed 's|^https:|http:|')
fi
shift 1
if test -z "$1" ; then
echo -e "${COLOR_RED}Error${COLOR_NONE}: unpack tarball where?" >&2
echo "e.g. tiger.sh --unpack-tarball-check-md5 http://leopard.sh/dist/gzip-1.11.tar.gz /tmp" >&2
echo "e.g. tiger.sh --unpack-tarball-check-md5 http://leopard.sh/binpkgs/gzip-1.11.tiger.g3.tar.gz /opt" >&2
exit 1
fi
dest="$1"
shift 1
if test "$1" = "sudo" ; then
sudo="sudo"
shift 1
fi
if test -n "$1" ; then
md5arg="$1"
shift 1
fi
cd /tmp
tmp=$(mktemp -u /tmp/tiger.sh.tarball.XXXX)
if test -n "$md5arg" ; then
echo "$md5arg" > $tmp.md5
else
curl --fail --silent --show-error --location $url.md5 > $tmp.md5 &
curl_md5_pid=$!
fi
fifo=$tmp.fifo
( mkfifo $fifo \
&& cat $fifo | nice md5 > $tmp.localmd5_ \
&& mv $tmp.localmd5_ $tmp.localmd5
) &
while ! test -e $fifo ; do sleep 0.1 ; done
if test -n "$TIGERSH_MIRROR_NO_HEAD" ; then
# Some servers don't support HTTP HEAD
size=0
else
size=$(curl --fail --silent --show-error --location --head $insecure_url \
| grep -i '^content-length:' \
| tail -n1 \
| awk '{print $NF}' \
| sed "s/$(printf '\r')//"
)
fi
if test -n "$sudo" ; then
# prompt the user for their password before we start the curl pipeline.
sudo true
fi
cd $dest
nice curl --fail --silent --show-error --location $insecure_url \
| pv --force --size $size \
| tee $fifo \
| nice gunzip \
| nice $sudo tar x
while ! test -e $tmp.localmd5 ; do sleep 0.1 ; done
wait $curl_md5_pid
if ! test "$(cat $tmp.localmd5)" = "$(cat $tmp.md5)" ; then
badmd5=1
fi
rm -f $fifo $tmp.localmd5 $tmp.md5
if test -n "$badmd5" ; then
echo -e "${COLOR_RED}Error${COLOR_NONE}: MD5 sum mismatch for $url."
exit 1
else
exit 0
fi
fi
# link:
if test "$op" = "link" ; then
shift 1
if test -z "$1" ; then
echo -e "${COLOR_RED}Error${COLOR_NONE}: link which package?" >&2
echo "e.g. tiger.sh --link foo-1.0" >&2
exit 1
fi
pkgspec="$1"
if find /opt/$pkgspec/bin -mindepth 1 2>/dev/null | grep -q . ; then
if test -z "$did_print_header" ; then
echo -e "${COLOR_CYAN}Linking${COLOR_NONE} $pkgspec into /usr/local." >&2
did_print_header=1
fi
ln -vsf /opt/$pkgspec/bin/* /usr/local/bin | sed 's/^/ /'
fi
if find /opt/$pkgspec/sbin -mindepth 1 2>/dev/null | grep -q . ; then
if test -z "$did_print_header" ; then
echo -e "${COLOR_CYAN}Linking${COLOR_NONE} $pkgspec into /usr/local." >&2
did_print_header=1
fi
ln -vsf /opt/$pkgspec/sbin/* /usr/local/sbin | sed 's/^/ /'
fi
for optpkgman in /opt/$pkgspec/man /opt/$pkgspec/share/man ; do
if find $optpkgman -mindepth 1 2>/dev/null | grep -q . ; then
cd $optpkgman
for d in * ; do
if find $optpkgman/$d -mindepth 1 2>/dev/null | grep -q . ; then
if test -z "$did_print_header" ; then
echo -e "${COLOR_CYAN}Linking${COLOR_NONE} $pkgspec into /usr/local." >&2
did_print_header=1
fi
if ! test -e /usr/local/share/man/$d ; then
mkdir -p /usr/local/share/man/$d
chmod g+w /usr/local/share/man/$d
fi
ln -vsf $optpkgman/$d/* /usr/local/share/man/$d | sed 's/^/ /'
fi
done
cd - >/dev/null
fi
done
if find /opt/$pkgspec/lib/pkgconfig -mindepth 1 2>/dev/null | grep -q . ; then
if test -z "$did_print_header" ; then
echo -e "${COLOR_CYAN}Linking${COLOR_NONE} $pkgspec into /usr/local." >&2
did_print_header=1
fi
mkdir -p /usr/local/lib/pkgconfig
ln -vsf /opt/$pkgspec/lib/pkgconfig/* /usr/local/lib/pkgconfig | sed 's/^/ /'
fi
exit 0
fi
# unlink:
if test "$op" = "unlink" ; then
shift 1
if test -z "$1" ; then
echo -e "${COLOR_RED}Error${COLOR_NONE}: unlink which package?" >&2
echo "e.g. tiger.sh --unlink foo-1.0" >&2
exit 1
fi
pkgspec="$1"
if ! test -e /opt/$pkgspec ; then
echo -e "${COLOR_YELLOW}Warning${COLOR_NONE}: /opt/$pkgspec doesn't exist, can't unlink." >&2
exit 0
fi
echo -e "${COLOR_CYAN}Unlinking${COLOR_NONE} $pkgspec from /usr/local." >&2
# deletes any symlinks in /usr/local/* which point to /opt/foo-1.0/*.
# what a pain in the ass!
cd "/opt/$pkgspec"
find . -mindepth 1 \( -type f -or -type l \) -exec \
bash -e -c \
"subpath=\$(echo {} | sed 's|^\\./||')
if test -L \"/usr/local/\$subpath\" \
&& test \"\$(readlink \"/usr/local/\$subpath\")\" = \"/opt/$pkgspec/\$subpath\" ; \
then \
rm -v \"/usr/local/\$subpath\" | sed 's/^/ rm /'
fi" \
\;
exit 0
fi
# self-update:
if test "$op" = "self-update" ; then
echo "Fetching the latest tiger.sh (into /usr/local/bin)." >&2
cd /tmp
url=$TIGERSH_MIRROR/tigersh/tiger.sh
curl --fail --silent --show-error --location --remote-name $url
chmod +x tiger.sh
mv tiger.sh /usr/local/bin/
exit 0
fi
# display the help message:
if test "$op" = "help" ; then
echo "$pkgmgr: a packge manager for PowerPC Macs running OS X 10.4 \"Tiger\"."
echo " * To list the available packages, just run '$pkgmgr'."
echo " * To install a package, run e.g. '$pkgmgr foo-1.0'".
echo " * To uninstall a package, '$pkgmgr --unlink foo-1.0 && rm -r /opt/foo-1.0'".
echo
echo "Command-line commands:"
echo " --help: display this message."
echo " --describe: describe all available packages (or --descriptions)."
echo " --describe foo-1.0: describe 'foo-1.0'."
echo " --tag: list the available tags (or --tags)."
echo " --tag foo: list the packages tagged as 'foo'."
echo " --link foo-1.0: symlink bin, man, share/man from /opt/foo-1.0 into /usr/local."
echo " --unlink foo-1.0: remove the /usr/local symlinks for foo-1.0."
echo " --self-update: install the latest version of this script."
echo
echo "Unnecessary command-line commands:"
echo " --list: list the available packages (redundant, just run '$pkgmgr')."
echo " --install foo-1.0: install 'foo-1.0' (redundant, just run '$pkgmgr foo-1.0')."
echo " --setup: perform initial setup (this is done automatically as needed)."
echo
echo "Performance tweaks:"
echo " --spotlight (on|off): turn Spotlight on or off."
echo " --dashboard (on|off): turn Dashboard on or off."
echo
echo "Command-line options:"
echo " --verbose: print every command being run (note: must be the first arg)."
echo
echo "Obscure command-line commands (used internally by $pkgmgr):"
echo " --cpu: print the CPU type (g3, g4, g4e, or g5)."
echo " --os.cpu: print OS and CPU type (e.g. tiger.g4e)."
echo " --bits: print the bit-width of the CPU (32 or 64)."
echo " -j: (for make) print the -j flag based on number of CPU's (e.g. '-j1')."
echo " -m32: (for gcc) print '-m32', but only if a G5 chip is detected."
echo " -mcpu: (for gcc) print the CPU flag (e.g. '-mcpu=970')."
echo " -O: (for gcc) print the optimization flag (e.g. '-O2')."
echo " --arch-check foo-1.0: print the architecture of foo-1.0's binaries."
echo " --linker-check foo-1.0: print the linked libraries for foo-1.0."
echo " --url-exists http://...: fail if the url is a 404."
echo " --install-binpkg foo-1.0: download and unpack a binary tarball into /opt."
echo " --unpack-dist foo-1.0: download and unpack a source tarball into /tmp."
echo " --unpack-tarball-check-md5 http://... /dest/dir:"
echo " download, unpack and verify a tarball into /dest/dir."
echo
echo "Influential environmental variables:"
echo " TIGERSH_MIRROR: the root URL to fetch all files from."