Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 576 lines (456 sloc) 14.717 kb
0821b4e @mpapis extract gnu strategy
mpapis authored
1 #!/bin/sh
2
3 __sm.package.gnu.install()
4 {
5 trace_filter package || set -o xtrace
6
7 (( $# == 0 )) || __sm.package.cli $@
8
9 __sm.package.set.cflags
10 __sm.package.set.cpath
11 __sm.package.set.cc
12 __sm.package.set.ldflags
13
14 if __sm.package.versions.installed | grep -q "${package_version}" && (( force_flag != 1 ))
15 then
16 log "The ${package_name} ${package_version} package is already installed.
17 To force it to reinstall, call:\n\tsm ${package_name} package install force\n"
18 return 0
19 fi
20
21 paths create "${source_path}"
22
23 paths enter "${source_path}"
24
25 if command exists "${package_name}_dependencies"
26 then
27 __sm.log.step "${package_name} ${package_version} ~ dependencies"
28 "${package_name}_dependencies"
29 __sm.log.step success
30 else
31 __sm.log.step "${package_name} ${package_version} ~ dependencies"
32 __sm.package.dependencies
33 __sm.log.step success
34 fi
35
36 if command exists "${package_name}_prefetch"
37 then
38 __sm.log.step "${package_name} ${package_version} ~ prefetch"
39 "${package_name}_prefetch"
40 __sm.log.step success
41 fi
42
43 if command exists "${package_name}_fetch"
44 then
45 __sm.log.step "${package_name} ${package_version} ~ fetch"
46 "${package_name}_fetch"
47 __sm.log.step success
48 else
49 __sm.log.step "${package_name} ${package_version} ~ fetch"
50 __sm.package.fetch
51 __sm.log.step success
52 fi
53
54 paths enter "${source_path}/${package_dir}"
55
56 if command exists "${package_name}_postfetch"
57 then
58 __sm.log.step "${package_name} ${package_version} ~ postfetch"
59 "${package_name}_postfetch"
60 __sm.log.step success
61 fi
62
63 if command exists "${package_name}_patch"
64 then
65 __sm.log.step "${package_name} ${package_version} ~ patch"
66 "${package_name}_patch"
67 __sm.log.step success
68 else
69 __sm.log.step "${package_name} ${package_version} ~ patch"
70 __sm.package.patch
71 __sm.log.step success
72 fi
73
74 if command exists "${package_name}_preconfigure"
75 then
76 __sm.log.step "${package_name} ${package_version} ~ preconfigure"
77 "${package_name}_preconfigure"
78 __sm.log.step success
79 fi
80
81 if command exists "${package_name}_configure"
82 then
83 "${package_name}_configure"
84 else
85 __sm.log.step "${package_name} ${package_version} ~ configure"
86 __sm.package.configure
87 __sm.log.step success
88 fi
89
90 if command exists "${package_name}_postconfigure"
91 then
92 __sm.log.step "${package_name} ${package_version} ~ postconfigure"
93 "${package_name}_postconfigure"
94 __sm.log.step success
95 fi
96
97 if command exists "${package_name}_build"
98 then
99 __sm.log.step "${package_name} ${package_version} ~ build"
100 "${package_name}_build"
101 __sm.log.step success
102 else
103 __sm.log.step "${package_name} ${package_version} ~ build"
104 __sm.package.gnu.make
105 __sm.log.step success
106 fi
107
108 if command exists "${package_name}_preinstall"
109 then
110 __sm.log.step "${package_name} ${package_version} ~ preinstall"
111 "${package_name}_preinstall"
112 __sm.log.step success
113 else
114 __sm.log.step "${package_name} ${package_version} ~ preinstall"
115 __sm.package.preinstall
116 __sm.log.step success
117 fi
118
119 versionedfs add \
120 path "${packages_path}" name "${package_name}" version "${package_version}" \
121 source "${install_path}"
122
123 if command exists "${package_name}_install"
124 then
125 __sm.log.step "${package_name} ${package_version} ~ install"
126 "${package_name}_install"
127 __sm.log.step success
128 else
129 __sm.log.step "${package_name} ${package_version} ~ install"
130 __sm.package.make.install
131 __sm.log.step success
132 fi
133
134 files link symbolic force \
135 from "${source_path}/${package_dir}" \
136 to "${install_path}/src"
137
138 if command exists "${package_name}_postinstall"
139 then
140 __sm.log.step "${package_name} ${package_version} ~ postinstall"
141 "${package_name}_postinstall"
142 __sm.log.step success
143 else
144 __sm.log.step "${package_name} ${package_version} ~ postinstall"
145 __sm.package.postinstall
146 __sm.log.step success
147 fi
148
149 if ! __sm.string.contains.word '__sm.package.update' "${FUNCNAME[*]}"
150 then
151 __sm.package.activate.first "${package_name}" "${package_version}"
152 fi
153
154 if command exists "${package_name}_postactivate"
155 then
156 __sm.log.step "${package_name} ${package_version} ~ postactivate"
157 "${package_name}_postactivate"
158 __sm.log.step success
159 fi
160
161 __sm.package.setup
162 }
163
164 __sm.package.binary.install()
165 {
166 trace_filter package || set -o xtrace
167 NIY "Binary package strategy"
168 # TODO: fetch, extract, copy to install path.
169 }
170
171 __sm.package.java.install()
172 {
173 trace_filter package || set -o xtrace
174 NIY "Java package strategy"
175 # TODO: fetch, extract, copy to install path, setup java launcher.
176 }
177
178 __sm.package.fetch.checksum()
179 {
180 trace_filter package || set -o xtrace
181 typeset download_url
182 (( $# == 0 )) || __sm.package.cli $@
183 true "${package_file:="${package_name}-${package_version}.${archive_format}"}"
184
185 if [[ -z "${package_checksum_url:-}" ]]
186 then
187 for download_url in ${=package_base_url}
188 do
189 package_checksum_url="${package_checksum_url:-} ${download_url}/${package_file}.checksum"
190 done
191 fi
192
193 [[ -n "${package_checksum}" ]] || __sm.config.read "${package_name}" checksum "${package_file}" package_checksum
194 [[ -n "${package_checksum}" ]] ||
195 for download_url in ${=package_checksum_url}
196 do
197 if [[ -f "${download_url}" ]]
198 then
199 __sm.file.copy "${download_url}" "${archives_path}/${package_file}" -f
200 else
201 # TODO: we can not relay on downloaded checksum, validate with another source ?
202 ${curl} -L "${download_url}" -o "${archives_path}/${package_file}.checksum" 2>/dev/null ||
203 __sm.log.warn "Fetching checksum from '${download_url}' failed."
204 fi
205
206 package_checksum=$(cat "${archives_path}/${package_file}.checksum")
207
208 rm "${archives_path}/${package_file}.checksum"
209
210 if (( ${#package_checksum} == 32 ))
211 then
212 return 0
213 else
214 package_checksum=""
215 fi
216 done
217 }
218
219 __sm.package.fetch()
220 {
221 trace_filter package || set -o xtrace
222
223 typeset _entries _url
224 typeset -a _args
225
226 (( $# == 0 )) || __sm.package.cli $@
227 true "${package_file:="${package_name}-${package_version}.${archive_format}"}"
228
229 if [[ -z "${package_url:-}" ]]
230 then
231 for _url in ${=package_base_url}
232 do
233 package_url="${package_url:-} ${_url}/${package_file}"
234 done
235 fi
236
237 if [[ -n "${scm_type:-}" ]]
238 then
239 _args+=( "scm_type" "${scm_type}" )
240 fi
241
242 __sm.package.fetch.checksum
243
244 if [[ -n "${package_checksum:-}" ]]
245 then _args+=( "checksum" "${package_checksum}" ) ; fi
246
247 fetch_uris "${package_url}" "${source_path}/${package_dir}" ${_args[@]} || return 1
248
249 [[ -z "${__vcs_failed}" ]] || return 1
250
251 [[ -d "${source_path}/${package_dir}/${package_dir}" ]] || return 0
252
253 mv "${source_path}/${package_dir}/${package_dir}"/* "${source_path}/${package_dir}/"
254
255 rm -rf "${source_path}/${package_dir}/${package_dir}/"
256 }
257
258 __sm.package.gnu.update()
259 {
260 trace_filter package || set -o xtrace
261 (( $# == 0 )) || __sm.package.cli $@
262
263 # TODO: check if newer version exists, if so then...
264 if __sm.package.versions.installed | grep -q "${package_version}" \
265 && [[ "${force_flag}" != "1" ]]
266 then
267 log "The latest version (${package_version}) of the ${package_name} package is already installed."
268 else
269 __sm.package.${package_strategy:=gnu}.install \
270 ${package_name} ${package_version:-} ${archive_format:-} force
271 __sm.package.activate ${package_name} ${package_version}
272 fi
273 }
274
275 __sm.package.configure()
276 {
277 trace_filter package || set -o xtrace
278 typeset _command
279 typeset -x PKG_CONFIG_PATH PREFIX
280
281 command exists gcc || command exists cc || __sm.log.fail "No C compiler found."
282
283 _command="${configure_command:-./configure}"
284
285 if [[ ! -x "${_command%% *}" ]]
286 then
287 __sm.log.debug package "Configure command '${_command%% *}' not available."
288 return 0
289 fi
290
291 __sm.package.configure.flag "--prefix" "${install_path}"
292 if "${_command%% *}" --help 2>/dev/null | \grep -- --sysconfdir >/dev/null
293 then
294 __sm.package.configure.flag "--sysconfdir" "/etc"
295 fi
296
297 _command="${_command} ${configure_flags[*]}"
298 __sm.log.debug package "__sm.package.configure: ${_command}"
299
300 PREFIX="${install_base_path}/${package_version}"
301 PKG_CONFIG_PATH=${active_path}/lib/pkgconfig
302
303 ${=_command} > configure.log 2>&1 ||
304 __sm.package.error \
305 "Configuration of ${package_name} ${package_version} failed." \
306 "configure.log"
307 }
308
309 __sm.package.gnu.make()
310 {
311 trace_filter package || set -o xtrace
312
313 typeset _command
314
315 if [[ -n ${build_command:-} ]]
316 then
317 _command="${build_command}"
318 else
319 if ! __sm.string.contains.word "-j" "${make_flags[*]}"
320 then
321 make_flags+=( "-j" "$(__sm.os.cpu.count)" )
322 fi
323 _command="make ${make_flags[@]}"
324 fi
325
326 __sm.log.debug package "__sm.package.gnu.make: ${_command}"
327 env | grep -E '^C.*=|PATH.*=|FLAGS.*=' | __sm.log.debug package -
328
329 ${=_command} > build.log 2>&1 ||
330 __sm.package.error \
331 "Compilation of ${package_name} ${package_version} failed! " "$PWD/build.log"
332 }
333
334 __sm.package.preinstall()
335 {
336 trace_filter package || set -o xtrace
337 true # nothing to be done for now.
338 }
339
340 __sm.package.make.install()
341 {
342 trace_filter package || set -o xtrace
343 typeset _command
344
345 if [[ -n ${install_command:-} ]]
346 then
347 _command="${install_command}"
348 else
349 _command="make ${make_install_flags[@]:-install}"
350 fi
351
352 ${=_command} > make.install.log 2>&1 ||
353 __sm.package.error \
354 "Installation of ${package_name} ${package_version} failed! " \
355 "$PWD/make.install.log"
356 }
357
358 __sm.package.postinstall()
359 {
360 trace_filter package || set -o xtrace
361 true
362 }
363
364 __sm.package.gnu.activate()
365 {
366 trace_filter package || set -o xtrace
367 (( $# == 0 )) || __sm.package.cli $@
368
369 versionedfs activate \
370 path "${packages_path}" name "${package_name}" version "${package_version}"
371
372 __sm.package.ldconfig "${package_name}"
373 __sm.package.setup "${package_name}"
374 }
375
376 __sm.package.setup()
377 {
378 trace_filter package || set -o xtrace
379 typeset _package
380 _package="${1:-${package_name}}"
381
382 __sm.package.profile.d "${_package}"
383
384 if __sm.module.is.loaded "internal/service"
385 then
386 __sm.service.setup "${_package}"
387 fi
388
389 if __sm.module.is.loaded "internal/database"
390 then
391 __sm.database.setup "${_package}"
392 fi
393 }
394
395 __sm.package.gnu.deactivate()
396 {
397 trace_filter package || set -o xtrace
398
399 (( $# == 0 )) || __sm.package.cli $@
400
401 __sm.log.step "${package_name} ${_version} ~ deactivate"
402
403 versionedfs deactivate \
404 path "${packages_path}" name "${package_name}"
405
406 __sm.log.step success
407
408 if ! __sm.string.contains.word '__sm.package.activate' "${FUNCNAME[*]}"
409 then
410 __sm.package.ldconfig "${_package}"
411 fi
412 }
413
414 __sm.package.activate.first()
415 {
416 trace_filter package || set -o xtrace
417
418 typeset _package _version
419
420 _package="${1:-}"
421 _version="${2:-}"
422
423 (( $# )) && shift || __sm.log.fail "Package name must be given as first parameter."
424 (( $# )) && shift || __sm.log.fail "Package version must be given as second parameter."
425
426 if paths exist "${install_path}"
427 then
428 __sm.package.activate "${_package}" "${_version}"
429 else
430 log "'${install_path}' not found; skipping activation."
431 fi
432 }
433
434 __sm.package.ldconfig()
435 {
436 trace_filter package || set -o xtrace
437
438 typeset _package _path _files _ldconfig
439
440 _package="${1:-${package_name}}"
441 _ldconfig="/sbin/ldconfig"
442
443 if [[ -z "${_package}" ]]
444 then
445 __sm.log.fail "Package name must be given."
446 fi
447
448 # paths exist "${packages_path}/versions/${_package}/active/lib" ||
449 # return 0 # no lib/ directory for activated package, no need to update ldconfig
450
451 user is root || return 0
452
453 # TODO: Figure out if solaris and freebsd have an analog to this?
454 if __sm.os.type.is linux
455 then
456 if paths exist "/etc/ld.so.conf.d"
457 then
458 files write \
459 string "${active_path}/lib\n" \
460 to "/etc/ld.so.conf.d/sm.conf" \
461 mode 0444
462 fi
463
464 if [[ -d /selinux ]] && command exists restorecon
465 then
466 restorecon -R "${active_path}/lib" # -v ~ verbose
467 restorecon -R "${packages_path}/versions/${package_name}" # -v ~ verbose
468 fi
469
470 command exists "${_ldconfig}" || ldconfig="ldconfig"
471
472 __sm.log.step "${package_name} ${package_version} ~ ldconfig"
473 "${_ldconfig}" "${active_path}/lib"
474 __sm.log.step success
475
476 elif __sm.os.type.is darwin
477 then # Cluster Fuck!
478 true
479 # This should be handled by the profile.d?
480 # _files=($(find "${packages_path}/versions/${_package}/active" -mindepth 1 -maxdepth 1 -type d))
481 # (( ${#_files[@]} > 0 )) && copy_files to "${packages_path}" "${_files[@]}"
482 fi
483 }
484
485 __sm.package.profile.d()
486 {
487 trace_filter package || set -o xtrace
488
489 typeset _package
490
491 _package="${1:-${package_name}}"
492
493 if [[ -z "${_package}" ]]
494 then
495 __sm.log.fail "Package name must be given."
496 fi
497
498 templates exist "profile.d.template" || return 0
499
500 __sm.log.step "Updating shell profile for ${_package}"
501
502 paths create "${profile_d_path}"
503 files create "${profile_path}"
504
505 templates install "profile.d" to "${profile_d_path}/${_package}.sh" mode 0755
506
507 __sm.log.step success
508 }
509
510 __sm.package.gnu.uninstall()
511 {
512 trace_filter package || set -o xtrace
513
514 (( $# == 0 )) || __sm.package.cli $@
515
516 if __sm.package.is.active "${package_name}" "${package_version}"
517 then # Deactivate the package if active.
518 __sm.package.deactivate "${package_name}" "${package_version}"
519 fi
520
521 __sm.log.step "${package_name} ${package_version} ~ uninstall"
522
523 paths remove "${install_path}"
524
525 if __sm.module.is.loaded "internal/service"
526 then
527 __sm.service.uninstall "${_package}" # Remove any service reminants
528 fi
529
530 __sm.log.step success
531 }
532
533 __sm.package.patch()
534 {
535 trace_filter package || set -o xtrace
536
537 typeset _patches _patch _path _paths
538
539 _paths=(
540 "${extension_patches_path}"
541 "${extension_patches_path}/$(__sm.os.type)"
542 "${extension_patches_path}/$(__sm.os.type)/${package_version}"
543 )
544
545 for _path in "${_paths[@]}"
546 do
547 paths exists "${_path}" || continue # No patch path
548
549 _patches=( ${_path}/*.patch ${_path}/*.diff )
550 if (( ${#_patches[@]} ))
551 then
552 __sm.package.patches.apply "${_patches[@]}"
553 fi
554 done
555 }
556
557 __sm.package.patches.apply()
558 {
559 trace_filter package || set -o xtrace
560
561 typeset _patch _patches
562
563 _patches=("$@")
564
565 (( $# )) && shift || __sm.log.fail "No patches were given."
566
567 for _patch in "${_patches[@]}"
568 do
569 [[ -f "${_patch}" && -s "${_patch}" ]] || continue
570 patch -F 3 -p 1 -N -f < ${_patch} > patch.install.log 2>&1 ||
571 __sm.package.error \
572 "Patching of ${package_name} ${package_version} with ${_patch} failed! " \
573 "$PWD/patch.install.log"
574 done
575 }
Something went wrong with that request. Please try again.