Skip to content
This repository
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 172 lines (161 sloc) 4.58 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
#!/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_checksum

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

  __package_commands=(
    "is active"
    "is installed"
    "configure flag"
    "configure flags"
    "make install"
    "activate first"
  )

  if __sm.command.detect "$*" "${__package_commands[@]}"
  then
    _command="${__sm_command_dotted}"
    shift "${__sm_command_words}"
  else
    __sm.log.fail "No command given.\nUsage: \nfiles <command> ..."
  fi

  case "${_command}" in
    (define)
      _params+=( "$@" )
      shift $#
      ;;
  esac


  while (( $# ))
  do
    _token="$1" && shift
    case "${_token}" in
      (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'"
        ;;
      (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'"
        ;;
      (checksum)
        package_checksum="$1"
        (( $# )) && shift || __sm.log.fail "a package checksum sum must follow keyword 'checksum'. Format: '{type},{checksum}'"
        ;;
      (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
    (cli|make|make.install|is.active|is.installed|install|uninstall|info|configure|configure.flags|reset)
      __sm.package.${_command} "${_params[@]}"
      ;;
    (configure.flag)
      __sm.package.configure.flag "${_key}" "${_params[@]}"
      ;;
    (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|activate.first|deactivate)
      __sm.package.${_command} "${package_name}" "${package_version}"
      ;;
    (initialize)
      typeset -a package_dependencies configure_flags
      __sm.package.init
      ;;
    (error)
      [[ -n "${_message}" ]] || __sm.log.fail "Message must be given for package error."
      __sm.package.error "${_params[@]}" "${_log}" "${_lines}"
      ;;
    (*)
      __sm.log.fail "Unknown package command '${_token}'"
  esac
}
Something went wrong with that request. Please try again.