forked from lodi-g/phpvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
phpvm
executable file
·853 lines (679 loc) · 21.4 KB
/
phpvm
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
#!/usr/bin/env bash
# a php version manager
phpvm_path="$HOME/.phpvm"
old_rels_cache_path_php="$phpvm_path/tmp/old_releases_php.html"
rels_cache_path_php="$phpvm_path/tmp/releases_php.html"
rels_cache_path_composer="$phpvm_path/tmp/releases_composer.html"
downloads_path="$phpvm_path/tmp"
php_installs_path="$phpvm_path/php-installs"
composer_installs_path="$phpvm_path/composer-installs"
phpopts_path="$phpvm_path/phpopts"
libs_path="$phpvm_path/libs"
usage() {
echo "Usage: phpvm <command>"
echo ""
echo "Commands:"
echo -e " help show this"
echo -e " ls [tool] list installed php/composer versions"
echo -e " ls-remote <tool> list remote php/composer versions"
echo -e " install <tool> [version] [conf args...] installs a remote php/composer version"
echo -e " bin <tool> [version] get bin path for an install"
echo -e " remove <tool> <version> removes a php/composer version"
echo -e " path <tool> [version] prints a PATH text including the PHP version"
echo -e " install-lib <codename> <package ...> installs an Ubuntu package from an older version"
echo ""
echo "Examples:"
echo -e " phpvm install php 8.0"
echo -e " phpvm install composer"
echo -e " \$(phpvm bin php 8.0)/php --version"
echo -e " \$(phpvm bin composer)/composer --version"
}
dir_setup() {
mkdir -p "$phpvm_path" "$downloads_path" "$php_installs_path" "$composer_installs_path" "$libs_path"
if [[ ! -f "$phpopts_path" ]]; then
echo "--with-openssl --with-curl --with-zlib --enable-mbstring --with-pear" > "$phpopts_path"
fi
}
require_linux() {
if [[ "$(uname -s)" != "Linux" ]]; then
echo "This command only works on Linux"
exit 1
fi
}
ls_remote_php__get_releases() {
wget -qO- 'http://php.net/releases/' > "$old_rels_cache_path_php"
wget -qO- 'http://php.net/downloads.php' > "$rels_cache_path_php"
return 0
}
ls_remote_composer__get_releases() {
wget -qO- 'https://getcomposer.org/download/' > "$rels_cache_path_composer"
return 0
}
ls_remote_php__versions() {
extract_versions "$old_rels_cache_path_php"
extract_versions "$rels_cache_path_php"
return 0
}
ls_remote_composer__versions() {
extract_versions "$rels_cache_path_composer"
return 0
}
ls_local() {
if [[ "$1" != "composer" ]]; then
echo "PHP:"
local dir
for dir in $php_installs_path/*; do
if [[ "$(basename "$dir")" != "*" ]]; then
if [ -f "$dir/bin/php" ]; then
echo "$(basename "$dir")"
else
echo "$(basename "$dir") (broken)"
fi
fi
done
fi
if [[ "$1" != "composer" ]]; then
echo "Composer:"
for dir in $composer_installs_path/*; do
if [[ "$(basename "$dir")" != "*" ]]; then
if [ -f "$dir/composer" ]; then
echo "$(basename "$dir")"
else
echo "$(basename "$dir") (broken)"
fi
fi
done
fi
}
extract_versions() {
local file="$1"
cat "$file" | grep -v '<script' | grep -o -e '[0-9]\+\.[0-9]\+\.[0-9]\+' | sort -V | uniq
return 0
}
latest_matching_version() {
local version_regex="$1"
sort -V | uniq | grep -E "$version_regex" | tail -n 1
return 0
}
ls_remote_php() {
local cache_time=$((60*15))
# local cache_time=0 # for debug
if [ -f "$old_rels_cache_path_php" ]
then
local last_mod_time=$(stat "$old_rels_cache_path_php" -c %Y)
local cur_time=$(date +"%s")
local time_diff=$(($cur_time - $last_mod_time))
if [ "$time_diff" -gt "$cache_time" ]
then
ls_remote_php__get_releases
fi
else
ls_remote_php__get_releases
fi
local old_versions="$(extract_versions "$old_rels_cache_path_php")"
local new_versions="$(extract_versions "$rels_cache_path_php")"
echo "Old versions:"
echo "$old_versions"
echo ""
echo "Stable versions:"
echo "$new_versions"
}
ls_remote_composer() {
local cache_time=$((60*15))
# local cache_time=0 # for debug
if [ -f "$rels_cache_path_composer" ]
then
local last_mod_time=$(stat "$rels_cache_path_composer" -c %Y)
local cur_time=$(date +"%s")
local time_diff=$(($cur_time - $last_mod_time))
if [ "$time_diff" -gt "$cache_time" ]
then
ls_remote_composer__get_releases
fi
else
ls_remote_composer__get_releases
fi
local versions="$(extract_versions "$rels_cache_path_composer")"
echo "Stable versions:"
echo "$versions"
}
version_to_regex() {
local version="$1"
if echo "$version" | grep -q -E '^([0-9]+|\*)$'; then
version="$version.*.*"
elif echo "$version" | grep -q -E '^([0-9]+|\*)\.([0-9]+|\*)$'; then
version="$version.*"
elif echo "$version" | grep -q -E '^([0-9]+|\*)\.([0-9]+|\*)\.([0-9]+|\*)$'; then
: # Do nothing
else
echo "Not a valid version number: $version"
return 1
fi
echo "$version" | sed -E -e 's/\./[.]/g' -e 's/\*/[0-9]+/g'
return 0
}
test_full_version() {
local version="$1"
if echo "$version" | grep -q -e '[0-9]\+\.[0-9]\+\.[0-9]\+'
then
return 0
fi
return 1
}
get_php_version_dir() {
local version="$1"
echo "$php_installs_path/$version"
return 0
}
get_composer_version_dir() {
local version="$1"
echo "$composer_installs_path/$version"
return 0
}
get_php_tar_url() {
local version="$1"
echo "http://php.net/get/php-$version.tar.bz2/from/this/mirror"
}
install_php() {
local requested_version="${1:-"*"}"
shift
local pkg_config_path
local ld_lib_path
if [[ "$1" == "--libs-from" ]]; then
if [[ -z "$2" ]]; then
echo "Expected a second argument after --libs-from"
return 1
fi
require_linux
local ubuntu_version="$2"
local gnu_tuple="$(gcc -dumpmachine)"
pkg_config_path="$libs_path/$ubuntu_version/usr/lib/$gnu_tuple/pkgconfig"
ld_lib_path="$libs_path/$ubuntu_version/usr/lib/$gnu_tuple"
export PKG_CONFIG_PATH="$pkg_config_path:$PKG_CONFIG_PATH"
export LD_LIBRARY_PATH="$ld_lib_path:$LD_LIBRARY_PATH"
echo "Using PKG_CONFIG_PATH=$PKG_CONFIG_PATH"
echo "Using LD_LIBRARY_PATH=$LD_LIBRARY_PATH (will be saved to PHP installation)"
shift 2
fi
local configure_string=("$@")
# init cache files
ls_remote_php > /dev/null
local version_regex
if ! version_regex=$(version_to_regex "$requested_version"); then
echo "$version_regex"
return 1
fi
# search for version
local version=$(ls_remote_php__versions | latest_matching_version "$version_regex")
if [[ -z "$version" ]]; then
echo "$requested_version not in available versions, try again"
return 1
fi
echo "$version in available versions (matched from $requested_version)"
if bin_path_php "$version" >/dev/null; then
echo "Already installed"
return 0
fi
echo "Starting install"
local install_dir="$(get_php_version_dir "$version")"
echo "Install dir: $install_dir"
local install_src_dir="$(get_php_version_dir "$version")/src"
local tar_url="$(get_php_tar_url "$version")"
local tar_file="php-${version}.tar.bz2"
local tar_path="$downloads_path/$tar_file"
if [ ! -f "$tar_path" ]
then
echo "Getting: $tar_url saving to $tar_file"
wget -O "$tar_path" "$tar_url"
fi
if [ ! -f "$tar_path" ]
then
echo "Cannot find $tar_path, check download"
return 1
fi
mkdir -p "$install_src_dir"
local extracted_dir="$install_src_dir/php-$version"
if [ -d "$extracted_dir" ]
then
echo "Extracted dir exists: $extracted_dir"
else
tar -xvf "$tar_path" -C "$install_src_dir" || return 1
rm "$install_src_dir"
fi
cd "$extracted_dir"
# link bins
local install_bin_dir="$install_dir/bin"
local install_conf_dir="$install_dir/etc"
./configure "--prefix=$install_dir" "--with-config-file-path=$install_conf_dir" "--with-config-file-scan-dir=$install_conf_dir/php.ini.d" $(cat "$phpopts_path") "$configure_string" || return
make "-j$(nproc)" || return
make install || return
echo "$ld_lib_path" > "$install_dir/LD_LIBRARY_PATH"
# make configs
echo "# Add config overrides here" > "$install_conf_dir/php.ini"
mkdir -p "$install_conf_dir/php.ini.d"
echo "php --version"
if ! "$install_bin_dir/php" --version; then
echo "PHP installation failed, binaries not linked"
return 1
fi
# Tell pear where our php.ini is
"$install_bin_dir/pear" config-set php_ini "$install_conf_dir/php.ini" system
echo "Installation complete"
return 0
}
install_composer() {
local requested_version="${1:-"*"}"
# init cache files
ls_remote_composer >/dev/null
local version_regex
if ! version_regex=$(version_to_regex "$requested_version"); then
echo "$version_regex"
return 1
fi
# search for version
local version=$(ls_remote_composer__versions | latest_matching_version "$version_regex")
if [[ -z "$version" ]]; then
echo "$requested_version not in available versions, try again"
return 1
fi
echo "$version in available versions (matched from $requested_version)"
local install_dir="$(get_composer_version_dir "$version")"
mkdir -p "$install_dir"
local installed_path="$install_dir/composer.phar"
if [ ! -f "$installed_path" ]
then
echo "Downloading"
wget -O "$installed_path" "https://getcomposer.org/download/$version/composer.phar"
else
echo "Already downloaded"
fi
echo "#!/usr/bin/env bash
php $install_dir/composer.phar \"\$@\"
" > "$install_dir/composer"
chmod +x "$install_dir/composer"
chmod -w "$install_dir/composer.phar" # prevent `composer self-update` from working
echo "Installation complete"
return 0
}
bin_path_php() {
local requested_version="${1:-"*"}"
local version_regex
if ! version_regex=$(version_to_regex "$requested_version"); then
echo "$version_regex"
return 1
fi
local version=$(ls "$php_installs_path" | latest_matching_version "$version_regex")
local version_dir="$(get_php_version_dir "$version")"
local bin_dir="$version_dir/bin"
local bin_file="$bin_dir/php"
if [ ! -f "$bin_file" ]
then
echo "No PHP binary found"
return 1
fi
echo "$bin_dir"
return 0
}
ld_lib_path_php() {
local requested_version="${1:-"*"}"
local version_regex
if ! version_regex=$(version_to_regex "$requested_version"); then
echo "$version_regex"
return 1
fi
local version=$(ls "$php_installs_path" | latest_matching_version "$version_regex")
local version_dir="$(get_php_version_dir "$version")"
local path_file="$version_dir/LD_LIBRARY_PATH"
if [ ! -f "$path_file" ]; then
return 1
fi
cat "$path_file"
return 0
}
bin_path_composer() {
local requested_version="${1:-"*"}"
local version_regex
if ! version_regex=$(version_to_regex "$requested_version"); then
echo "$version_regex"
return 1
fi
local version=$(ls "$composer_installs_path" | latest_matching_version "$version_regex")
local version_dir="$(get_composer_version_dir "$version")"
local bin_dir="$version_dir"
local bin_file="$bin_dir/composer"
if [ ! -f "$bin_file" ]
then
echo "No Composer executable found"
return 1
fi
echo "$bin_dir"
return 0
}
remove_php() {
local version="$1"
if ! test_full_version "$version"; then
echo "Invalid PHP version $version"
return 1
fi
local version_dir="$(get_php_version_dir "$version")"
if [ -d "$version_dir" ]
then
rm -rf "$version_dir"
echo "Removed PHP $version at $version_dir"
else
echo "PHP $version not installed"
fi
}
remove_composer() {
local version="$1"
if ! test_full_version "$version"; then
echo "Invalid Composer version $version"
return 1
fi
local version_dir="$(get_composer_version_dir "$version")"
if [ -d "$version_dir" ]
then
rm -rf "$version_dir"
echo "Removed Composer $version at $version_dir"
else
echo "Composer $version not installed"
fi
}
path_php() {
local version="$1"
local bin_path
if ! bin_path=$(bin_path_php "$version"); then
echo "$bin_path"
return 1
fi
echo "$bin_path:$(echo "$PATH" | sed -E "s%$php_installs_path/[^:]+:?%%g")"
return 0
}
ld_path_php() {
local version="$1"
local ld_lib_path
if ! ld_lib_path=$(ld_lib_path_php "$version"); then
echo "$ld_lib_path"
return 1
fi
echo "$ld_lib_path:$(echo "$LD_LIBRARY_PATH" | sed -E "s%$libs_path/[^:]+:?%%g")"
return 0
}
path_composer() {
local version="$1"
local bin_path
if ! bin_path=$(bin_path_composer "$version"); then
echo "$bin_path"
return 1
fi
echo "$bin_path:$(echo "$PATH" | sed -E "s%$composer_installs_path/[^:]+:?%%g")"
return 0
}
get_deb_server() {
case "$(uname -m)" in
x86_64)
echo "http://archive.ubuntu.com/ubuntu"
;;
i386|i686)
echo "http://archive.ubuntu.com/ubuntu"
;;
arm64|aarch64)
echo "http://ports.ubuntu.com/ubuntu-ports"
;;
armv7l)
echo "http://ports.ubuntu.com/ubuntu-ports"
;;
esac
}
get_ubuntu_arch() {
case "$(uname -m)" in
x86_64)
echo "amd64"
;;
i386|i686)
echo "i386"
;;
arm64|aarch64)
echo "arm64"
;;
armv7l)
echo "armhf"
;;
esac
}
refresh_ubuntu_indexes() {
local ubuntu_version="$1"
local ubuntu_arch="$2"
local deb_server="$3"
local cache_time=$((60*60*24))
# local cache_time=0 # for debug
local ubuntu_dists=("$ubuntu_version" "$ubuntu_version-security" "$ubuntu_version-updates")
local ubuntu_channels=("main" "restricted" "universe" "multiverse")
local dist
local channel
local idx=0
local download_dir="$downloads_path/$ubuntu_version"
mkdir -p "$download_dir"
for dist in "${ubuntu_dists[@]}"; do
for channel in "${ubuntu_channels[@]}"; do
idx=$((idx+1))
local download_file="$download_dir/$(printf %03d $idx)-$dist.$channel.packages"
if [[ -f "$download_file" ]]; then
local last_mod_time=$(stat "$download_file" -c %Y)
local cur_time=$(date +"%s")
local time_diff=$(($cur_time - $last_mod_time))
if [[ "$time_diff" -lt "$cache_time" ]]; then
continue
fi
fi
echo "Downloading package index for Ubuntu $dist $channel $ubuntu_arch"
wget -q -O "$download_file.gz" "$deb_server/dists/$dist/$channel/binary-$ubuntu_arch/Packages.gz" || return
gunzip -f "$download_file.gz" || return
touch "$download_file" # Set updated time
done
done
return 0
}
get_deb_url_path() {
local ubuntu_version="$1"
local lib="$2"
local deb
local file
for file in $(find "$downloads_path/$ubuntu_version" -maxdepth 1 -type f | sort); do
deb=$(awk -F': ' '$1 == "Package" && $2 == "'"$lib"'" {f=0; while(getline > 0 && $0 != "") { if ($1 == "Filename") print $2 }}' "$file")
if [[ ! -z "$deb" ]]; then
echo "$deb"
return 0
fi
done
return 1
}
get_deb_dependencies() {
local ubuntu_version="$1"
local lib="$2"
local deps
local deb
local file
for file in $(find "$downloads_path/$ubuntu_version" -maxdepth 1 -type f | sort); do
deb=$(awk -F': ' '$1 == "Package" && $2 == "'"$lib"'" {f=0; while(getline > 0 && $0 != "") { if ($1 == "Filename") print $2 }}' "$file")
deps=$(awk -F': ' '$1 == "Package" && $2 == "'"$lib"'" {f=0; while(getline > 0 && $0 != "") { if ($1 == "Depends") print $2 }}' "$file" | sed 's/, /\n/g' | cut -d' ' -f1)
if [[ ! -z "$deb" ]]; then
echo "$deps"
return 0
fi
done
return 1
}
install_lib() {
local ubuntu_version="$1"
local deb_server="$2"
local lib="$3"
local download_dir="$downloads_path/$ubuntu_version/$lib"
mkdir -p "$download_dir"
local deb_path="$download_dir/package.deb"
local deb_url_path
if ! deb_url_path="$(get_deb_url_path "$ubuntu_version" "$lib")"; then
echo "Package $lib not found in package indexes for Ubuntu $ubuntu_version"
return 1
fi
local extract_to_dir="$libs_path/$ubuntu_version"
mkdir -p "$extract_to_dir"
local install_manifest="$extract_to_dir/installed/$lib"
if [[ -f "$install_manifest" ]]; then
if [[ "$(head -n 1 $install_manifest)" == "$deb_url_path" ]]; then
echo "Package $lib already installed and up-to-date"
return 0
fi
echo "Removing old $lib version"
remove_lib "$ubuntu_version" "$lib"
fi
echo "Downloading $(basename "$deb_url_path")"
wget -q -O "$deb_path" "$deb_server/$deb_url_path" || return
ar -x "$deb_path" --output "$download_dir" || return
echo "Extracting"
local data_file=$(find "$download_dir" -maxdepth 1 -type f -name 'data.tar.*')
tar -C "$extract_to_dir" -xaf "$data_file" || return
local extracted_files
mapfile -t extracted_files < <(tar -taf "$data_file")
local extracted_file
for extracted_file in "${extracted_files[@]}"; do
echo "Extracted $extracted_file"
if [[ "$extracted_file" =~ ^'./usr/lib/'[^/]+'/pkgconfig/'[^/]+'.pc'$ ]]; then
# Fix pkg-config files
extracted_file="$extract_to_dir/${extracted_file:2}"
echo "Fixing pkg-config file $extracted_file"
sed -i -E -e "s%^([a-z_]+)=/usr%\1=$extract_to_dir/usr%g" "$extracted_file"
elif [[ "$extracted_file" =~ ^'./usr/lib/'[^/]+'/'[^/]+'.la'$ ]]; then
# Fix libtool files
extracted_file="$extract_to_dir/${extracted_file:2}"
echo "Fixing libtool file $extracted_file"
sed -i -E -e "s%^([a-z_]+)='/usr%\1='$extract_to_dir/usr%g" "$extracted_file"
fi
done
mkdir -p "$extract_to_dir/installed"
echo "$deb_url_path" > "$install_manifest"
tar -taf "$data_file" >> "$install_manifest"
rm -rf "$download_dir"
local deps
mapfile -t deps < <(get_deb_dependencies "$ubuntu_version" "$lib")
local dep
for dep in "${deps[@]}"; do
if [[ ! -z "$dep" ]]; then
echo "Package $lib has dependency $dep"
install_lib "$ubuntu_version" "$deb_server" "$dep" || return
fi
done
return 0
}
remove_lib() {
local ubuntu_version="$1"
local lib="$2"
local extract_to_dir="$libs_path/$ubuntu_version"
local install_manifest="$extract_to_dir/installed/$lib"
if [[ -f "$install_manifest" ]]; then
local files
mapfile -t files < <(tail "$install_manifest" -n +2 | awk '{ print(length, "'"$extract_to_dir/"'"substr($0, 3)) }' | sort -nr | cut -d" " -f2-)
local file
for file in "${files[@]}"; do
if [[ -d $file ]]; then
rmdir $file &>/dev/null # Attempt to remove it if it's empty
else
rm $file &>/dev/null # Remove the file
fi
done
rm "$install_manifest"
fi
return 0
}
install_libs() {
local ubuntu_version="$1"
shift
local libs=("$@")
if [[ -z "$1" ]]; then
usage
return 1
fi
local deb_server="$(get_deb_server)"
local ubuntu_arch="$(get_ubuntu_arch)"
refresh_ubuntu_indexes "$ubuntu_version" "$ubuntu_arch" "$deb_server" || return
local lib
for lib in "${libs[@]}"; do
install_lib "$ubuntu_version" "$deb_server" "$lib" || return
done
echo "Done"
return 0
}
remove_libs() {
local ubuntu_version="$1"
shift
local libs=("$@")
if [[ -z "$1" ]]; then
usage
return 1
fi
local lib
for lib in "${libs[@]}"; do
remove_lib "$ubuntu_version" "$lib"
done
echo "Done"
return 0
}
switch_tool() {
local func="$1"
local tool="$2"
shift 2
case "$tool" in
php)
"$func"_php "$@"
;;
composer)
"$func"_composer "$@"
;;
*)
usage
return 1
;;
esac
}
dir_setup
command="$1"
shift
case "$command" in
help)
usage
;;
bin)
switch_tool bin_path "$@"
;;
ls)
ls_local "$@"
;;
ls-remote)
switch_tool ls_remote "$@"
;;
remove)
switch_tool remove "$@"
;;
install)
switch_tool install "$@"
;;
install-lib)
require_linux
install_libs "$@"
;;
remove-lib)
require_linux
remove_libs "$@"
;;
path)
switch_tool path "$@"
;;
ld-path)
require_linux
ld_path_php "$@"
;;
*)
usage
exit 1
;;
esac