/
functions
1110 lines (939 loc) · 27.9 KB
/
functions
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
#!/bin/sh
typeset -g src_path data_path package_user package_version package_base_url \
package_file package_directory archive_format package_md5 force_flag \
static_flag shared_flag package_user configure_flags
__sm.package.cli()
{
trace_filter package || set -o xtrace
typeset _token index
typeset -a _ignored_args _package_args
_package_args=( $@ )
for (( index=1 ; index <= ${#_package_args} ; index++ ))
do
_token="${_package_args[$index]}"
case "${_token}" in
(src)
src_path="${_package_args[$((++index))]}"
[[ -n "${src_path}" ]] ||
__sm.log.error "a path must follow keyword 'src'"
;;
(data)
data_path="${_package_args[$((++index))]}"
[[ -n "${data_path}" ]] ||
__sm.log.error "a path must follow keyword 'data'"
;;
(user)
package_user="${_package_args[$((++index))]}"
[[ -n "${package_user}" ]] ||
__sm.log.error "a user name must follow keyword 'user'"
;;
(version)
package_version="${_package_args[$((++index))]}"
[[ -n "${package_version}" ]] ||
__sm.log.error "a version number string must follow keyword 'version'"
;;
(base_url)
package_base_url="${_package_args[$((++index))]}"
[[ -n "${package_base_url}" ]] ||
__sm.log.error "a base path url must follow keyword 'base_url'"
;;
(file)
package_file="${_package_args[$((++index))]}"
[[ -n "${package_file}" ]] ||
__sm.log.error "a path must follow keyword 'file'"
;;
(dir)
package_directory="${_package_args[$((++index))]}"
[[ -n "${package_directory}" ]] ||
__sm.log.error "a single extracted directory name must follow keyword 'dir'"
;;
(archive_format)
archive_format="${_package_args[$((++index))]}"
[[ -n "${archive_format}" ]] ||
__sm.log.error "an archive format (tar.gz,tar.bz2,tar.xz,zip,...) must follow keyword 'archive_format'"
;;
(md5)
package_md5="${_package_args[$((++index))]}"
[[ -n "${package_md5}" ]] ||
__sm.log.error "an md5 sum string must follow keyword 'md5'"
;;
(force)
force_flag=1
;;
(static)
static_flag=1
__sm.package.configure.flags --static
;;
(shared)
shared_flag=1
__sm.package.configure.flags --enable-shared
;;
(licence)
extension_license
succeed
;;
(help)
__sm.package.usage
succeed
;;
(--with*|--enable*|--disable*)
__sm.package.configure.flags "${_token}"
;;
(*)
_ignored_args+=("${_token}")
;;
esac
done
__sm.package.init "${_ignored_args[@]}"
}
__sm.package.error()
{
trace_filter package || set -o xtrace
typeset _message _log _lines
_message="$1"
_log="$2"
_lines="${3:-50}"
if [[ -n ${_log} && -s "${_log}" ]]
then # Append tail of __sm.log.error log to the __sm.log.error message.
_message="${_message}\n\nTail of ${_log}:\n$( tail -n ${_lines} ${_log} )"
fi
__sm.log.error "\n${_message}"
}
__sm.package.define()
{
trace_filter package || set -o xtrace
typeset -g package_name package_version package_file package_dir package_url package_base_url \
package_docs_url package_patches_url package_md5_url bin_path packages_path source_path \
target_path archive_format
typeset key value
while (( $# > 0 ))
do
key="$1" && shift
value="$1"
if ! shift
then
if echo "$key" | grep '='
then
__sm.log.fail "Invalid key '${key}'; Most likely the '=' is supposed to be a space?"
else
__sm.log.fail "Value not specified for key '${key}'; They should be specified in key/value pairs :)"
fi
fi
case "$key" in
(name)
package_name="${value}"
;;
(version)
package_version="${value}"
;;
(file)
package_file="${value}"
;;
(dir)
package_dir="${value}"
;;
(url)
package_url="${value}"
;;
(base_url)
package_base_url="${value}"
;;
(docs_url)
package_docs_url="${value}"
;;
(patches_url)
package_patches_url="${value}"
;;
(md5_url)
package_md5_url="${value}"
;;
(bin_path)
bin_path="${value}"
;;
(packages_path)
packages_path="${value}"
;;
(source_path)
source_path="${value}"
;;
(target_path)
target_path="${value}"
;;
(archive_format)
archive_format="${value}"
;;
# TODO: Simplify into
#(+([[[:alnum:]]|])_path|name|version|url|md5_url)
# eval "${key}=${value}"
# ;;
(*)
__sm.log.fail "Unknown key '${key}' (value: ${value})."
;;
esac
done
}
__sm.package.configure.flags()
{
trace_filter package || set -o xtrace
typeset -ga configure_flags
typeset _flag
for _flag in "$@"
do
if ! __sm.string.contains "${_flag}" "${configure_flags[*]}"
then
configure_flags+=( "${_flag}" )
fi
done
}
__sm.package.configure.flag()
{
trace_filter package || set -o xtrace
typeset -ga configure_flags
typeset _key _value
_key="$1"
_value="$2"
if ! __sm.string.contains.key "${_key}" "${configure_flags[*]}"
then
configure_flags+=( "${_key}=${_value}" )
fi
}
__sm.package.make.flags()
{
trace_filter package || set -o xtrace
typeset -ga make_flags
typeset _flag
for _flag in "$@"
do
if ! __sm.string.contains "${_flag}" "${make_flags[*]}"
then
make_flags+=( "${_flag}" )
fi
done
}
__sm.package.package_dependencies()
{
trace_filter package || set -o xtrace
typeset -ga package_dependencies
typeset _flag
for _flag in "$@"
do
if ! __sm.string.contains "${_flag}" "${package_dependencies[*]}"
then
package_dependencies+=( "${_flag}" )
fi
done
}
__sm.package.set.cflags()
{
trace_filter package || set -o xtrace
export CFLAGS
if ! __sm.string.contains "-I${active_path}/include" "${CFLAGS}"
then
CFLAGS="-I${active_path}/include${CFLAGS:+ }${CFLAGS:-}"
fi
}
__sm.package.set.cpath()
{
trace_filter package || set -o xtrace
export CPATH
if ! __sm.string.contains "${active_path}/include" "${CPATH:-}"
then
CPATH="${CPATH:-}${CPATH:+ }${active_path}/include"
fi
}
__sm.package.set.ldflags()
{
trace_filter package || set -o xtrace
export LDFLAGS
if ! __sm.string.contains "-L${active_path}/lib" "${LDFLAGS}"
then
LDFLAGS="-L${active_path}/lib${LDFLAGS:+ }${LDFLAGS:-}"
fi
}
__sm.package.set.cc()
{
trace_filter package || set -o xtrace
export CC
if os is darwin && [[ -x /usr/bin/gcc-4.2 ]]
then
CC=/usr/bin/gcc-4.2
fi
}
__sm.package.exports()
{
export package_name packages_path package_name package_version archive_format \
package_file package_url package_md5_url packages_path bin_path source_path \
LDFLAGS CFLAGS package_default_version
}
__sm.package.install()
{
trace_filter package || set -o xtrace
case "${package_strategy:=gnu}" in
(gnu|binary|java)
__sm.package.${package_strategy}.install "$@"
;;
*)
__sm.log.fail "Unknown package strategy ${package_strategy}"
;;
esac
}
__sm.package.gnu.install()
{
trace_filter package || set -o xtrace
(( $# == 0 )) || __sm.package.cli $@
__sm.package.set.cflags
__sm.package.set.cpath
__sm.package.set.cc
__sm.package.set.ldflags
if __sm.package.versions.installed | grep -q "${package_version}" && (( force_flag != 1 ))
then
log "The ${package_name} ${package_version} package is already installed.
To force it to reinstall, call:\n\tsm ${package_name} package install force\n"
exit 0
fi
paths create "${source_path}"
paths enter "${source_path}"
if command exists "${package_name}_dependencies"
then
__sm.log.step "${package_name} ${package_version} ~ dependencies" \
"${package_name}_dependencies"
else
__sm.log.step "${package_name} ${package_version} ~ dependencies" \
__sm.package.dependencies
fi
if command exists "${package_name}_prefetch"
then
__sm.log.step "${package_name} ${package_version} ~ prefetch" \
"${package_name}_prefetch"
fi
if command exists "${package_name}_fetch"
then
__sm.log.step "${package_name} ${package_version} ~ fetch" \
"${package_name}_fetch"
else
__sm.log.step "${package_name} ${package_version} ~ fetch" \
__sm.package.fetch
fi
paths enter "${source_path}/${package_dir}"
if command exists "${package_name}_postfetch"
then
__sm.log.step "${package_name} ${package_version} ~ postfetch" \
"${package_name}_postfetch"
fi
if command exists "${package_name}_patch"
then
__sm.log.step "${package_name} ${package_version} ~ patch" \
"${package_name}_patch"
else
__sm.log.step "${package_name} ${package_version} ~ patch" \
__sm.package.patch
fi
if command exists "${package_name}_preconfigure"
then
__sm.log.step "${package_name} ${package_version} ~ preconfigure" \
"${package_name}_preconfigure"
fi
if command exists "${package_name}_configure"
then
"${package_name}_configure"
else
__sm.log.step "${package_name} ${package_version} ~ configure" \
__sm.package.configure
fi
if command exists "${package_name}_postconfigure"
then
__sm.log.step "${package_name} ${package_version} ~ postconfigure" \
"${package_name}_postconfigure"
fi
if command exists "${package_name}_build"
then
__sm.log.step "${package_name} ${package_version} ~ build" \
"${package_name}_build"
else
__sm.log.step "${package_name} ${package_version} ~ build" \
__sm.package.gnu.make
fi
if command exists "${package_name}_preinstall"
then
__sm.log.step "${package_name} ${package_version} ~ preinstall" \
"${package_name}_preinstall"
else
__sm.log.step "${package_name} ${package_version} ~ preinstall" \
__sm.package.preinstall
fi
versionedfs add \
path "${packages_path}" name "${package_name}" version "${package_version}" \
source "${install_path}"
if command exists "${package_name}_install"
then
__sm.log.step "${package_name} ${package_version} ~ install" \
"${package_name}_install"
else
__sm.log.step "${package_name} ${package_version} ~ install" \
__sm.package.make.install
fi
files link symbolic force \
from "${source_path}/${package_dir}" \
to "${install_path}/src"
if command exists "${package_name}_postinstall"
then
__sm.log.step "${package_name} ${package_version} ~ postinstall" \
"${package_name}_postinstall"
else
__sm.log.step "${package_name} ${package_version} ~ postinstall" \
__sm.package.postinstall
fi
if ! __sm.string.contains '__sm.package.update' "${FUNCNAME[*]}"
then
__sm.package.activate.first "${package_name}" "${package_version}"
fi
if command exists "${package_name}_postactivate"
then
__sm.log.step "${package_name} ${package_version} ~ postactivate" \
"${package_name}_postactivate"
fi
__sm.package.setup
}
__sm.package.init()
{
trace_filter package || set -o xtrace
typeset -g extension_patches_path
typeset -ga fhs_dirs
typeset default_configure_flags _flag
true ${package_name:=${extension}}
[[ -n "${package_name}" ]] || __sm.log.fail "Package name must be given.\n"
case "${package_name}" in
(*\=*) # exact version specifier
package_version="${package_name#*\=}"
package_name="${package_name%%\=*}"
;;
(*:*) # minimum version specifier
# TODO: concept of 'minimum' ;)
package_version="${package_name#*:}"
package_name="${package_name%%:*}"
;;
(*)
true "${package_version:="${2:-}"}" "${archive_format:="${3:-}"}"
;;
esac
if command exists "${package_name}_initialize"
then
__sm.string.contains "${package_name}_initialize" "${FUNCNAME[*]}" ||
"${package_name}_initialize"
fi
true \
"${source_path:="${sm_path}/src"}" \
"${archives_path:="${sm_path}/archives"}" \
${static_flag:=0}
__sm.package.exports
# Ensure that package_version is set at this point
for variable in version base_url md5_url user
do
if variable is empty "package_${variable}"
then
config read file defaults from ${package_name} \
key ${variable} into ${variable} prefix package
fi
done
for variable in website_url archive_format
do
if variable is empty "${variable}"
then
config read file defaults from ${package_name} \
key ${variable} into ${variable}
fi
done
config read file defaults from ${package_name} \
key package_dependencies prefix default
config read file defaults from ${package_name} \
key configure_flags prefix default
config read file defaults from ${package_name} \
key make_flags prefix default
__sm.package.package_dependencies "${default_package_dependencies[@]}"
__sm.package.configure.flags "${default_configure_flags[@]}"
__sm.package.make.flags "${default_make_flags[@]}"
true \
"${package_version:="${package_default_version}"}" \
"${package_dir:="${package_name}-${package_version}"}" \
"${init_scripts_path:="$(init_scripts_path)"}" \
"${archive_format:=tar.gz}" \
"${package_file:="${package_name}-${package_version}.${archive_format}"}" \
"${install_base_path:="${packages_path}/versions/${package_name}"}" \
"${install_path:="${install_base_path}/${package_version}"}"
__sm.package.configure.flag --prefix "${install_path}"
# This check should only happen in places that require a version...
#[[ -n "${package_version}" ]] ||
# __sm.log.fail "Package version must be specified.\n"\
# "(For example version=x.y.z set in extension's config/defaults file.)\n"
fhs_dirs=( bin etc include lib libexec sbin share man )
paths create "${active_path}"
for dir in ${fhs_dirs}
do
paths create "${active_path}/${dir}"
done
if user is root
then
true \
"${log_path:="/var/log/${package_name}"}" \
"${package_user:="${package_name}"}"
else
true \
"${log_path:="${active_path}/log"}" \
"${package_user:="$USER"}"
fi
extension_patches_path="${extension_path}/patches"
}
__sm.package.binary.install()
{
trace_filter package || set -o xtrace
NIY "Binary package strategy"
# TODO: fetch, extract, copy to install path.
}
__sm.package.java.install()
{
trace_filter package || set -o xtrace
NIY "Java package strategy"
# TODO: fetch, extract, copy to install path, setup java launcher.
}
__sm.package.fetch.md5()
{
trace_filter package || set -o xtrace
typeset -g packge_md5_url
typeset download_url
(( $# == 0 )) || __sm.package.cli $@
: "${package_file:="${package_name}-${package_version}.${archive_format}"}"
if [[ -z "${packge_md5_url:-}" ]]
then
for download_url in ${=package_base_url}
do
packge_md5_url="${packge_md5_url:-} ${download_url}/${package_file}.md5"
done
fi
[[ -n "${package_md5}" ]] || __sm.config.read "${package_name}" md5 "${package_file}" package_md5
[[ -n "${package_md5}" ]] ||
for download_url in ${=packge_md5_url}
do
curl -L "${download_url}" -o "${archives_path}/${package_file}.md5" 2>/dev/null ||
__sm.log.error "Fetching MD5 checksum from '${download_url}' failed."
package_md5=$(cat "${archives_path}/${package_file}.md5")
rm "${archives_path}/${package_file}.md5"
if (( ${#package_md5} == 32 ))
then
return 0
else
package_md5=""
fi
done
}
__sm.package.fetch()
{
trace_filter package || set -o xtrace
typeset -g package_file package_url
typeset _entries _url
typeset -a _args
(( $# == 0 )) || __sm.package.cli $@
true "${package_file:="${package_name}-${package_version}.${archive_format}"}"
if [[ -z "${package_url:-}" ]]
then
for _url in ${=package_base_url}
do
package_url="${package_url:-} ${_url}/${package_file}"
done
fi
if [[ -n "${scm_type:-}" ]]
then
_args+=( "scm_type" "${scm_type}" )
fi
__sm.package.fetch.md5
if [[ -n "${package_md5:-}" ]]
then
_args+=( "md5" "${package_md5}" )
fi
fetch_uris "${package_url}" "${source_path}/${package_dir}" ${_args[@]} || return 1
[[ -z "${__vcs_failed}" ]] || return 1
[[ -d "${source_path}/${package_dir}/${package_dir}" ]] || return 0
mv "${source_path}/${package_dir}/${package_dir}"/* "${source_path}/${package_dir}/"
rm -rf "${source_path}/${package_dir}/${package_dir}/"
}
__sm.package.update()
{
trace_filter package || set -o xtrace
(( $# == 0 )) || __sm.package.cli $@
# TODO: check if newer version exists, if so then...
if __sm.package.versions.installed | grep -q "${package_version}" \
&& [[ "${force_flag}" != "1" ]]
then
log "The latest version (${package_version}) of the ${package_name} package is already installed."
else
__sm.package.${package_strategy:=gnu}.install \
${package_name} ${package_version:-} ${archive_format:-} force
__sm.package.activate ${package_name} ${package_version}
fi
}
__sm.package.configure()
{
trace_filter package || set -o xtrace
typeset _command
command exists gcc || command exists cc || __sm.log.fail "No C compiler found."
if [[ -n "${configure_command}" ]]
then
_command="${configure_command}"
else
export PREFIX="${install_base_path}/${package_version}"
# package configure flag key --prefix "${install_path}"
__sm.package.configure.flag "--prefix" "${install_path}"
_command="./configure ${configure_flags[*]}"
[[ -x "${_command%% *}" ]] || return 0
fi
__sm.log.debug package "__sm.package.configure: ${_command}"
${=_command} > configure.log 2>&1 ||
__sm.package.error \
"Configuration of ${package_name} ${package_version} failed." \
"configure.log"
}
__sm.package.gnu.make()
{
trace_filter package || set -o xtrace
typeset _command
if [[ -n ${build_command:-} ]]
then
_command="${build_command}"
else
_command="make ${make_flags[@]:-"-j$(os cpu count)"}"
fi
__sm.log.debug package "__sm.package.gnu.make: ${_command}"
env | grep -E '^C.*=|PATH.*=|FLAGS.*=' | __sm.log.debug package -
${=_command} > build.log 2>&1 ||
__sm.package.error \
"Compilation of ${package_name} ${package_version} failed! " "$PWD/build.log"
}
__sm.package.preinstall()
{
trace_filter package || set -o xtrace
true # nothing to be done for now.
}
__sm.package.make.install()
{
trace_filter package || set -o xtrace
typeset _command
if [[ -n ${install_command:-} ]]
then
_command="${install_command}"
else
_command="make ${make_install_flags[@]:-install}"
fi
__sm.log.step "${package_name} ${package_version} ~ install"
${=_command} > make.install.log 2>&1 ||
__sm.package.error \
"Installation of ${package_name} ${package_version} failed! " \
"$PWD/make.install.log"
__sm.log.step success
}
__sm.package.postinstall()
{
trace_filter package || set -o xtrace
true
}
__sm.package.activate()
{
trace_filter package || set -o xtrace
(( $# == 0 )) || __sm.package.cli $@
versionedfs activate \
path "${packages_path}" name "${package_name}" version "${package_version}"
__sm.package.ldconfig "${package_name}"
__sm.package.setup "${package_name}"
}
__sm.package.setup()
{
trace_filter package || set -o xtrace
typeset _package
_package="${1:-${package_name}}"
__sm.package.profile.d "${_package}"
if __sm.module.is.loaded "internal/service"
then
__sm.service.setup "${_package}"
fi
if __sm.module.is.loaded "internal/database"
then
__sm.database.setup "${_package}"
fi
}
__sm.package.deactivate()
{
trace_filter package || set -o xtrace
(( $# == 0 )) || __sm.package.cli $@
__sm.log.step "${package_name} ${_version} ~ deactivate"
versionedfs deactivate \
path "${packages_path}" name "${package_name}"
__sm.log.step success
if ! __sm.string.contains '__sm.package.activate' "${FUNCNAME[*]}"
then
__sm.package.ldconfig "${_package}"
fi
}
__sm.package.activate.first()
{
trace_filter package || set -o xtrace
typeset _package _version
_package="${1:-}"
_version="${2:-}"
(( $# )) && shift || __sm.log.fail "Package name must be given as first parameter."
(( $# )) && shift || __sm.log.fail "Package version must be given as second parameter."
if paths exist "${install_path}"
then
__sm.package.activate "${_package}" "${_version}"
else
log "'${install_path}' not found; skipping activation."
fi
}
__sm.package.ldconfig()
{
trace_filter package || set -o xtrace
typeset _package _path _files _ldconfig
_package="${1:-${package_name}}"
_ldconfig="/sbin/ldconfig"
[[ -n "${_package}" ]] || __sm.log.fail "Package name must be given."
# paths exist "${packages_path}/versions/${_package}/active/lib" ||
# return 0 # no lib/ directory for activated package, no need to update ldconfig
user is root || return 0
# TODO: Figure out if solaris and freebsd have an analog to this?
if os is linux
then
if paths exist "/etc/ld.so.conf.d"
then
files write \
string "${active_path}/lib\n" \
to "/etc/ld.so.conf.d/sm.conf" \
mode 0444
fi
if [[ -d /selinux ]] && command exists restorecon
then
restorecon -R "${active_path}/lib" # -v ~ verbose
restorecon -R "${packages_path}/versions/${package_name}" # -v ~ verbose
fi
command exists "${_ldconfig}" || ldconfig="ldconfig"
__sm.log.step "${package_name} ${package_version} ~ ldconfig" \
"${_ldconfig}" "${active_path}/lib"
elif os is darwin
then # Cluster Fuck!
true
# This should be handled by the profile.d?
# _files=($(find "${packages_path}/versions/${_package}/active" -mindepth 1 -maxdepth 1 -type d))
# (( ${#_files[@]} > 0 )) && copy_files to "${packages_path}" "${_files[@]}"
fi
}
__sm.package.profile.d()
{
trace_filter package || set -o xtrace
typeset _package
_package="${1:-${package_name}}"
[[ -n "${_package}" ]] || __sm.log.fail "Package name must be given."
templates exist "profile.d.template" || return 0
__sm.log.step "Updating shell profile for ${_package}"
paths create "${profile_d_path}"
files create "${profile_path}"
templates install "profile.d" to "${profile_d_path}/${_package}.sh" mode 0755
__sm.log.step success
}
__sm.package.uninstall()
{
trace_filter package || set -o xtrace
case "${package_strategy:=gnu}" in
(gnu|binary|java)
__sm.package.${package_strategy}.uninstall "$@"
;;
*)
__sm.log.fail "Unknown package strategy ${package_strategy}"
;;
esac
}
__sm.package.gnu.uninstall()
{
trace_filter package || set -o xtrace
(( $# == 0 )) || __sm.package.cli $@
if __sm.package.is.active "${package_name}" "${package_version}"
then # Deactivate the package if active.
__sm.package.deactivate "${package_name}" "${package_version}"
fi
__sm.log.step "${package_name} ${package_version} ~ uninstall"
paths remove "${install_path}"
if __sm.module.is.loaded "internal/service"
then
__sm.service.uninstall "${_package}" # Remove any service reminants
fi
__sm.log.step success
}
__sm.package.patch()
{
trace_filter package || set -o xtrace
typeset _patches _patch _path _paths
_paths=(
"${extension_patches_path}"
"${extension_patches_path}/$(os type)"
"${extension_patches_path}/$(os type)/${package_version}"
)
for _path in "${_paths[@]}"
do
paths exists "${_path}" || continue # No patch path
_patches=( "${_path}"/*.patch )
if (( ${#_patches[@]} ))
then
__sm.package.patches.apply "${_patches[@]}"
fi
done
}
__sm.package.patches.apply()
{
trace_filter package || set -o xtrace
typeset _patch _patches
_patches=("$@")
(( $# )) && shift || __sm.log.fail "No patches were given."
for _patch in "${_patches[@]}"
do
[[ -f "${_patch}" && -s "${_patch}" ]] || continue
__sm.log.error "TODO: patch application is NIY (see __sm.package.patch())"
done
}
__sm.package.is.active()
{
trace_filter package || set -o xtrace
typeset _name _version _path
_name="${1:-}"
_version="${2:-}"
(( $# )) && shift || __sm.log.fail "No package name was given, or name is empty."
_path="${packages_path}/versions/${_name}"
if (( $# )) && shift
then # version was passed
[[ -d "${_path}/${_version}" ]]
else # version was not passed
[[ -L "${_path}/active" && -d $(readlink "${_path}/active") ]]
fi
}
__sm.package.docs()
{
trace_filter package || set -o xtrace
os open "${package_docs_url}"
}
__sm.package.website()
{
trace_filter package || set -o xtrace
os open "${package_website_url}"
}
__sm.package.dependencies()
{
trace_filter package || set -o xtrace
typeset dependency _dependencies _missing_dependencies IFS
_dependencies=(${package_dependencies[@]})
_missing_dependencies=()
unset package_dependencies
# TODO: improve dependency management.
for dependency in "${_dependencies[@]}"
do
if ! __sm.package.is.active ${dependency/-/ }
then
_missing_dependencies+=( ${dependency} )
fi
done
if [[ -n "${_missing_dependencies}" ]]
then
IFS=','
__sm.log.error "${extension} requires ${_missing_dependencies[*]}.\n
Please install via sm package module, and retry. Typically, this can be done as follows:\n
\tsm ${_missing_dependencies[*]} package install\n"
fi
}
__sm.package.info()
{
trace_filter package || set -o xtrace
(( $# == 0 )) || __sm.package.cli $@
typeset _installed _path package_md5 _installed
_path="${packages_path}/versions/${package_name}"