Skip to content
This repository
tag: 0.10.0
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 239 lines (231 sloc) 5.926 kb
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
#!/bin/sh

# TODO: Rework this into a 1.0.0 module API
#
# ## package install
#
# Performs all package installation steps based on selected strategy:
# preinstall
#
# if gnu:
# prefetch
# fetch
# preextract
# extract
# prepatch
# patch
# preconfigure
# configure
# prebuild
# build
# preinstall
# install
# preactivate
# activate
# service setup, if service module is loaded
#
# if binary:
# prefetch
# fetch
# preextract
# extract
# preinstall
# install
# preactivate
# activate
# service setup, if service module is loaded
#
# postinstall
#
package()
{
  trace_filter package || set -o xtrace
  typeset -g package_name package_version package_base_url package_file \
    package_user archive_format package_md5 package_sha256 package_sha512

  typeset _token _subcommand _command _logfile _lines _key _log _message
  typeset -a _params
  _lines=50

  while (( $# ))
  do
    _token="$1" && shift
    case "${_token}" in
      (cli|install|uninstall|info)
        _command="${_token}"
        ;;
      (is)
        _command=is
        case "$1" in
          (active|installed)
            _subcommand="$1"
            shift
            ;;
          (*)
            __sm.log.fail "A valid command must follow keyword is; {active|installed}"
            ;;
        esac
        ;;
      (log)
        _log="$1"
        (( $# )) && shift || __sm.log.fail "Log file path/name must be given following keyword 'log'"
        ;;
      (lines)
        _lines="$1"
        (( $# )) && shift || __sm.log.fail "Number of lines to show must be given following keyword 'lines'"
        ;;
      (message)
        _message="$1"
        (( $# )) && shift || __sm.log.fail "Message must be given following keyword 'message'"
        ;;
      (configure)
        _command=configure
        case "$1" in
          (flag|flags)
            _subcommand="$1"
            shift
            ;;
          (*)
            if [[ -n "$1" ]]
            then
              __sm.log.fail "Unknown configure param '$1'."
          fi
            continue
            ;;
        esac
        ;;
      (make)
        _command=make
        if [[ "$1" == install ]]
        then
          _subcommand="install"
          shift
        fi
        ;;
      (activate)
        _command=activate
        if [[ "$1" == first ]]
        then
          _subcommand=first
          shift
        fi
        ;;
      (initialize)
        _command=initialize
        ;;
      (define)
        _command=define
        _params+=("$@")
        break
        ;;
      (key)
        _key="$1"
        (( $# )) && shift || __sm.log.fail "Key name must follow keyword 'key'"
        ;;
      (name)
        package_name="$1"
        (( $# )) && shift || __sm.log.fail "a package name must follow keyword 'name'"
        ;;
      (version)
        package_version="$1"
        (( $# )) && shift || __sm.log.fail "a package version must follow keyword 'version'"
        ;;
      (base_url)
        package_base_url="$1"
        (( $# )) && shift || __sm.log.fail "a package base_url must follow keyword 'base_url'"
        ;;
      (file)
        package_file="$1"
        (( $# )) && shift || __sm.log.fail "a package file name must follow keyword 'file'"
        ;;
      (user)
        package_user="$1"
        (( $# )) && shift || __sm.log.fail "a package user name must follow keyword 'user'"
        ;;
      (archive_format)
        archive_format="$1"
        (( $# )) && shift || __sm.log.fail "a package archive_format must follow keyword 'archive_format'"
        ;;
      (md5)
        package_md5="$1"
        (( $# )) && shift || __sm.log.fail "a package md5 sum must follow keyword 'md5'"
        ;;
      (sha256)
        package_sha256="$1"
        (( $# )) && shift || __sm.log.fail "a package sha256 key must follow keyword 'sha256'"
        ;;
      (sha512)
        package_sha512="$1"
        (( $# )) && shift || __sm.log.fail "a package sha512 key must follow keyword 'sha512'"
        ;;
      (*)
        _params+=("${_token}")
        ;;
    esac
  done

  true ${package_name:=${extension}}

  [[ -n "${package_name}" ]] || __sm.log.fail "Package name must be set/given"

  case "${_command}" in
    (make)
      case "$_subcommand" in
        (install)
          __sm.package.make.install
          ;;
        (*)
          __sm.package.make "${_params[@]}"
          ;;
      esac
      ;;
    (is)
      case "$_subcommand" in
        (active|installed)
          __sm.package.is.${_subcommand} "${_params[@]}"
          ;;
      esac
      ;;
    (install|uninstall|info)
      __sm.package.${_command} "${_params[@]}"
      ;;
    (configure)
      case "${_subcommand}" in
        (flag)
          __sm.package.configure.flag "${_key}" "${_params[@]}"
          ;;
        (flags)
          __sm.package.configure.flags "${_params[@]}"
          ;;
        (*)
          __sm.package.configure
          ;;
      esac
      ;;
    (define)
      [[ -n "${_params}" ]] || __sm.log.fail "No '{key} {value}' pairs given."
      if array is even _params
      then
        __sm.package.define "${_params[@]}"
      else
        __sm.log.fail "Every key must have an associated value."
      fi
      ;;
    (activate)
      if [[ "${_subcommand}" == "first" ]]
      then
        __sm.package.activate.first "${package_name}" "${package_version}"
      else
        __sm.package.activate "${package_name}" "${package_version}"
      fi
      ;;
    (initialize)
      declare -a package_dependencies
      declare -a configure_flags
      __sm.package.init
      ;;
    (error)
      [[ -n "${_message}" ]] || __sm.log.fail "Message must be given for package error."
      __sm.package.error "${_params[@]}" "${_log}" "${_lines}"
      ;;
    (cli)
      __sm.package.cli "${_params[@]}"
      ;;
    (*)
      __sm.log.fail "Unknown package command '${_token}'"
  esac
}

Something went wrong with that request. Please try again.