Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 576 lines (456 sloc) 14.742 kb
#!/bin/sh
__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"
return 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"
__sm.log.step success
else
__sm.log.step "${package_name} ${package_version} ~ dependencies"
__sm.package.dependencies
__sm.log.step success
fi
if command exists "${package_name}_prefetch"
then
__sm.log.step "${package_name} ${package_version} ~ prefetch"
"${package_name}_prefetch"
__sm.log.step success
fi
if command exists "${package_name}_fetch"
then
__sm.log.step "${package_name} ${package_version} ~ fetch"
"${package_name}_fetch"
__sm.log.step success
else
__sm.log.step "${package_name} ${package_version} ~ fetch"
__sm.package.fetch
__sm.log.step success
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"
__sm.log.step success
fi
if command exists "${package_name}_patch"
then
__sm.log.step "${package_name} ${package_version} ~ patch"
"${package_name}_patch"
__sm.log.step success
else
__sm.log.step "${package_name} ${package_version} ~ patch"
__sm.package.patch
__sm.log.step success
fi
if command exists "${package_name}_preconfigure"
then
__sm.log.step "${package_name} ${package_version} ~ preconfigure"
"${package_name}_preconfigure"
__sm.log.step success
fi
if command exists "${package_name}_configure"
then
"${package_name}_configure"
else
__sm.log.step "${package_name} ${package_version} ~ configure"
__sm.package.configure
__sm.log.step success
fi
if command exists "${package_name}_postconfigure"
then
__sm.log.step "${package_name} ${package_version} ~ postconfigure"
"${package_name}_postconfigure"
__sm.log.step success
fi
if command exists "${package_name}_build"
then
__sm.log.step "${package_name} ${package_version} ~ build"
"${package_name}_build"
__sm.log.step success
else
__sm.log.step "${package_name} ${package_version} ~ build"
__sm.package.gnu.make
__sm.log.step success
fi
if command exists "${package_name}_preinstall"
then
__sm.log.step "${package_name} ${package_version} ~ preinstall"
"${package_name}_preinstall"
__sm.log.step success
else
__sm.log.step "${package_name} ${package_version} ~ preinstall"
__sm.package.preinstall
__sm.log.step success
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"
__sm.log.step success
else
__sm.log.step "${package_name} ${package_version} ~ install"
__sm.package.make.install
__sm.log.step success
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"
__sm.log.step success
else
__sm.log.step "${package_name} ${package_version} ~ postinstall"
__sm.package.postinstall
__sm.log.step success
fi
if ! __sm.string.contains.word '__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"
__sm.log.step success
fi
__sm.package.setup
}
__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.checksum()
{
trace_filter package || set -o xtrace
typeset download_url
(( $# == 0 )) || __sm.package.cli $@
true "${package_file:="${package_name}-${package_version}.${archive_format}"}"
if [[ -z "${package_checksum_url:-}" ]]
then
for download_url in ${=package_base_url}
do
package_checksum_url="${package_checksum_url:-} ${download_url}/${package_file}.checksum"
done
fi
[[ -n "${package_checksum}" ]] || __sm.config.read "${package_name}" checksum "${package_file}" package_checksum
[[ -n "${package_checksum}" ]] ||
for download_url in ${=package_checksum_url}
do
if [[ -f "${download_url}" ]]
then
__sm.file.copy "${download_url}" "${archives_path}/${package_file}" -f
else
# TODO: we can not relay on downloaded checksum, validate with another source ?
${curl} -L "${download_url}" -o "${archives_path}/${package_file}.checksum" 2>/dev/null ||
__sm.log.warn "Fetching checksum from '${download_url}' failed."
fi
package_checksum=$(cat "${archives_path}/${package_file}.checksum")
rm "${archives_path}/${package_file}.checksum"
if (( ${#package_checksum} == 32 ))
then
return 0
else
package_checksum=""
fi
done
}
__sm.package.fetch()
{
trace_filter package || set -o xtrace
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.checksum
if [[ -n "${package_checksum:-}" ]]
then _args+=( "checksum" "${package_checksum}" )
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.gnu.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
typeset -x PKG_CONFIG_PATH PREFIX
command exists gcc || command exists cc || __sm.log.fail "No C compiler found."
_command="${configure_command:-./configure}"
if [[ ! -x "${_command%% *}" ]]
then
__sm.log.debug package "Configure command '${_command%% *}' not available."
return 0
fi
__sm.package.configure.flag "--prefix" "${install_path}"
if "${_command%% *}" --help 2>/dev/null | \grep -- --sysconfdir >/dev/null
then
__sm.package.configure.flag "--sysconfdir" "/etc"
fi
_command="${_command} ${configure_flags[*]}"
__sm.log.debug package "__sm.package.configure: ${_command}"
PREFIX="${install_base_path}/${package_version}"
PKG_CONFIG_PATH=${active_path}/lib/pkgconfig
${=_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
if ! __sm.string.contains.word "-j" "${make_flags[*]}"
then
make_flags+=( "-j" "$(__sm.os.cpu.count)" )
fi
_command="make ${make_flags[@]}"
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
${=_command} > make.install.log 2>&1 ||
__sm.package.error \
"Installation of ${package_name} ${package_version} failed! " \
"$PWD/make.install.log"
}
__sm.package.postinstall()
{
trace_filter package || set -o xtrace
true
}
__sm.package.gnu.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.gnu.deactivate()
{
trace_filter package || set -o xtrace
(( $# == 0 )) || __sm.package.cli $@
__sm.log.step "${package_name} ${_version:-${package_version}} ~ deactivate"
versionedfs deactivate path "${packages_path}" name "${package_name}" >/dev/null
__sm.log.step success
if ! __sm.string.contains.word '__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"
if [[ -z "${_package}" ]]
then
__sm.log.fail "Package name must be given."
fi
# 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 __sm.os.type.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"
__sm.log.step success
elif __sm.os.type.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}}"
if [[ -z "${_package}" ]]
then
__sm.log.fail "Package name must be given."
fi
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.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}/$(__sm.os.type)"
"${extension_patches_path}/$(__sm.os.type)/${package_version}"
)
for _path in "${_paths[@]}"
do
paths exists "${_path}" || continue # No patch path
_patches=( ${_path}/*.patch ${_path}/*.diff )
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
patch -F 3 -p 1 -N -f < ${_patch} > patch.install.log 2>&1 ||
__sm.package.error \
"Patching of ${package_name} ${package_version} with ${_patch} failed! " \
"$PWD/patch.install.log"
done
}
Jump to Line
Something went wrong with that request. Please try again.