Skip to content
Newer
Older
100755 577 lines (457 sloc) 14.4 KB
0821b4e @mpapis extract gnu strategy
mpapis authored Apr 19, 2012
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:-}" ]]
32fbaa5 @mpapis Merge branch 'master' of github.com:sm/sm
mpapis authored Apr 19, 2012
245 then _args+=( "checksum" "${package_checksum}" )
246 fi
0821b4e @mpapis extract gnu strategy
mpapis authored Apr 19, 2012
247
248 fetch_uris "${package_url}" "${source_path}/${package_dir}" ${_args[@]} || return 1
249
250 [[ -z "${__vcs_failed}" ]] || return 1
251
252 [[ -d "${source_path}/${package_dir}/${package_dir}" ]] || return 0
253
254 mv "${source_path}/${package_dir}/${package_dir}"/* "${source_path}/${package_dir}/"
255
256 rm -rf "${source_path}/${package_dir}/${package_dir}/"
257 }
258
259 __sm.package.gnu.update()
260 {
261 trace_filter package || set -o xtrace
262 (( $# == 0 )) || __sm.package.cli $@
263
264 # TODO: check if newer version exists, if so then...
265 if __sm.package.versions.installed | grep -q "${package_version}" \
266 && [[ "${force_flag}" != "1" ]]
267 then
268 log "The latest version (${package_version}) of the ${package_name} package is already installed."
269 else
270 __sm.package.${package_strategy:=gnu}.install \
271 ${package_name} ${package_version:-} ${archive_format:-} force
272 __sm.package.activate ${package_name} ${package_version}
273 fi
274 }
275
276 __sm.package.configure()
277 {
278 trace_filter package || set -o xtrace
279 typeset _command
280 typeset -x PKG_CONFIG_PATH PREFIX
281
282 command exists gcc || command exists cc || __sm.log.fail "No C compiler found."
283
284 _command="${configure_command:-./configure}"
285
286 if [[ ! -x "${_command%% *}" ]]
287 then
288 __sm.log.debug package "Configure command '${_command%% *}' not available."
289 return 0
290 fi
291
292 __sm.package.configure.flag "--prefix" "${install_path}"
293 if "${_command%% *}" --help 2>/dev/null | \grep -- --sysconfdir >/dev/null
294 then
295 __sm.package.configure.flag "--sysconfdir" "/etc"
296 fi
297
298 _command="${_command} ${configure_flags[*]}"
299 __sm.log.debug package "__sm.package.configure: ${_command}"
300
301 PREFIX="${install_base_path}/${package_version}"
302 PKG_CONFIG_PATH=${active_path}/lib/pkgconfig
303
304 ${=_command} > configure.log 2>&1 ||
305 __sm.package.error \
306 "Configuration of ${package_name} ${package_version} failed." \
307 "configure.log"
308 }
309
310 __sm.package.gnu.make()
311 {
312 trace_filter package || set -o xtrace
313
314 typeset _command
315
316 if [[ -n ${build_command:-} ]]
317 then
318 _command="${build_command}"
319 else
320 if ! __sm.string.contains.word "-j" "${make_flags[*]}"
321 then
322 make_flags+=( "-j" "$(__sm.os.cpu.count)" )
323 fi
324 _command="make ${make_flags[@]}"
325 fi
326
327 __sm.log.debug package "__sm.package.gnu.make: ${_command}"
328 env | grep -E '^C.*=|PATH.*=|FLAGS.*=' | __sm.log.debug package -
329
330 ${=_command} > build.log 2>&1 ||
331 __sm.package.error \
332 "Compilation of ${package_name} ${package_version} failed! " "$PWD/build.log"
333 }
334
335 __sm.package.preinstall()
336 {
337 trace_filter package || set -o xtrace
338 true # nothing to be done for now.
339 }
340
341 __sm.package.make.install()
342 {
343 trace_filter package || set -o xtrace
344 typeset _command
345
346 if [[ -n ${install_command:-} ]]
347 then
348 _command="${install_command}"
349 else
350 _command="make ${make_install_flags[@]:-install}"
351 fi
352
353 ${=_command} > make.install.log 2>&1 ||
354 __sm.package.error \
355 "Installation of ${package_name} ${package_version} failed! " \
356 "$PWD/make.install.log"
357 }
358
359 __sm.package.postinstall()
360 {
361 trace_filter package || set -o xtrace
362 true
363 }
364
365 __sm.package.gnu.activate()
366 {
367 trace_filter package || set -o xtrace
368 (( $# == 0 )) || __sm.package.cli $@
369
370 versionedfs activate \
371 path "${packages_path}" name "${package_name}" version "${package_version}"
372
373 __sm.package.ldconfig "${package_name}"
374 __sm.package.setup "${package_name}"
375 }
376
377 __sm.package.setup()
378 {
379 trace_filter package || set -o xtrace
380 typeset _package
381 _package="${1:-${package_name}}"
382
383 __sm.package.profile.d "${_package}"
384
385 if __sm.module.is.loaded "internal/service"
386 then
387 __sm.service.setup "${_package}"
388 fi
389
390 if __sm.module.is.loaded "internal/database"
391 then
392 __sm.database.setup "${_package}"
393 fi
394 }
395
396 __sm.package.gnu.deactivate()
397 {
398 trace_filter package || set -o xtrace
399
400 (( $# == 0 )) || __sm.package.cli $@
401
402 __sm.log.step "${package_name} ${_version} ~ deactivate"
403
404 versionedfs deactivate \
405 path "${packages_path}" name "${package_name}"
406
407 __sm.log.step success
408
409 if ! __sm.string.contains.word '__sm.package.activate' "${FUNCNAME[*]}"
410 then
411 __sm.package.ldconfig "${_package}"
412 fi
413 }
414
415 __sm.package.activate.first()
416 {
417 trace_filter package || set -o xtrace
418
419 typeset _package _version
420
421 _package="${1:-}"
422 _version="${2:-}"
423
424 (( $# )) && shift || __sm.log.fail "Package name must be given as first parameter."
425 (( $# )) && shift || __sm.log.fail "Package version must be given as second parameter."
426
427 if paths exist "${install_path}"
428 then
429 __sm.package.activate "${_package}" "${_version}"
430 else
431 log "'${install_path}' not found; skipping activation."
432 fi
433 }
434
435 __sm.package.ldconfig()
436 {
437 trace_filter package || set -o xtrace
438
439 typeset _package _path _files _ldconfig
440
441 _package="${1:-${package_name}}"
442 _ldconfig="/sbin/ldconfig"
443
444 if [[ -z "${_package}" ]]
445 then
446 __sm.log.fail "Package name must be given."
447 fi
448
449 # paths exist "${packages_path}/versions/${_package}/active/lib" ||
450 # return 0 # no lib/ directory for activated package, no need to update ldconfig
451
452 user is root || return 0
453
454 # TODO: Figure out if solaris and freebsd have an analog to this?
455 if __sm.os.type.is linux
456 then
457 if paths exist "/etc/ld.so.conf.d"
458 then
459 files write \
460 string "${active_path}/lib\n" \
461 to "/etc/ld.so.conf.d/sm.conf" \
462 mode 0444
463 fi
464
465 if [[ -d /selinux ]] && command exists restorecon
466 then
467 restorecon -R "${active_path}/lib" # -v ~ verbose
468 restorecon -R "${packages_path}/versions/${package_name}" # -v ~ verbose
469 fi
470
471 command exists "${_ldconfig}" || ldconfig="ldconfig"
472
473 __sm.log.step "${package_name} ${package_version} ~ ldconfig"
474 "${_ldconfig}" "${active_path}/lib"
475 __sm.log.step success
476
477 elif __sm.os.type.is darwin
478 then # Cluster Fuck!
479 true
480 # This should be handled by the profile.d?
481 # _files=($(find "${packages_path}/versions/${_package}/active" -mindepth 1 -maxdepth 1 -type d))
482 # (( ${#_files[@]} > 0 )) && copy_files to "${packages_path}" "${_files[@]}"
483 fi
484 }
485
486 __sm.package.profile.d()
487 {
488 trace_filter package || set -o xtrace
489
490 typeset _package
491
492 _package="${1:-${package_name}}"
493
494 if [[ -z "${_package}" ]]
495 then
496 __sm.log.fail "Package name must be given."
497 fi
498
499 templates exist "profile.d.template" || return 0
500
501 __sm.log.step "Updating shell profile for ${_package}"
502
503 paths create "${profile_d_path}"
504 files create "${profile_path}"
505
506 templates install "profile.d" to "${profile_d_path}/${_package}.sh" mode 0755
507
508 __sm.log.step success
509 }
510
511 __sm.package.gnu.uninstall()
512 {
513 trace_filter package || set -o xtrace
514
515 (( $# == 0 )) || __sm.package.cli $@
516
517 if __sm.package.is.active "${package_name}" "${package_version}"
518 then # Deactivate the package if active.
519 __sm.package.deactivate "${package_name}" "${package_version}"
520 fi
521
522 __sm.log.step "${package_name} ${package_version} ~ uninstall"
523
524 paths remove "${install_path}"
525
526 if __sm.module.is.loaded "internal/service"
527 then
528 __sm.service.uninstall "${_package}" # Remove any service reminants
529 fi
530
531 __sm.log.step success
532 }
533
534 __sm.package.patch()
535 {
536 trace_filter package || set -o xtrace
537
538 typeset _patches _patch _path _paths
539
540 _paths=(
541 "${extension_patches_path}"
542 "${extension_patches_path}/$(__sm.os.type)"
543 "${extension_patches_path}/$(__sm.os.type)/${package_version}"
544 )
545
546 for _path in "${_paths[@]}"
547 do
548 paths exists "${_path}" || continue # No patch path
549
550 _patches=( ${_path}/*.patch ${_path}/*.diff )
551 if (( ${#_patches[@]} ))
552 then
553 __sm.package.patches.apply "${_patches[@]}"
554 fi
555 done
556 }
557
558 __sm.package.patches.apply()
559 {
560 trace_filter package || set -o xtrace
561
562 typeset _patch _patches
563
564 _patches=("$@")
565
566 (( $# )) && shift || __sm.log.fail "No patches were given."
567
568 for _patch in "${_patches[@]}"
569 do
570 [[ -f "${_patch}" && -s "${_patch}" ]] || continue
571 patch -F 3 -p 1 -N -f < ${_patch} > patch.install.log 2>&1 ||
572 __sm.package.error \
573 "Patching of ${package_name} ${package_version} with ${_patch} failed! " \
574 "$PWD/patch.install.log"
575 done
576 }
Something went wrong with that request. Please try again.