Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: b1b4d0686e
Fetching contributors…

Cannot retrieve contributors at this time

executable file 282 lines (252 sloc) 10.694 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 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
#!/bin/bash
############################################################
# #
# lin - install Lunar modules #
# #
############################################################
# cast is part of the sorcery spell management utility #
# Copyright 2001 by Kyle Sallee #
############################################################
# #
# this WAS the cast script of a source based Linux distro, #
# calls Sorcerer GNU/Linux, or SGL. SGL is no longer #
# available with GPL license. Since this script was taken #
# before licensing scheme change, no legal problems I #
# guess. #
# #
# the code is re-written for Lunar. The previous Copyright #
# notices are kept; just in case some code is left :=) #
# Kagan Kongar <kongar@tsrsb.org.tr>, 20020519 #
# #
############################################################
# #
# Parts Copyrighted Jason Johnston 2002 under GPLv2 #
# #
# Parts Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
############################################################

# This enables alias expansion within lin and its children
# although this doesn't expand aliases within functions
# That is a limitation of bash and aliases
shopt -s expand_aliases

help() {
  cat << EOF
Lin installs single or multiple modules

Example: lin nano hdparm sudo
Usage: lin [parameters] [module]

Optional Parameters:

-c | --compile Ignore $INSTALL_CACHE and compiles
-d | --debug Enables debug messages
--deps Configure modules and determine dependencies,
-f | --from directory Specify an alternate for $SOURCE_CACHE
-h | --help Displays this help text
--opts '--enable-xxx' Add custom configure options to the module
-p | --probe Only lin if not already installed
-r | --reconfigure Select new dependencies for modules
-R | --resurrect Force to be unpacked from /var/cache/lunar
-s | --silent Decreases the level of message output
-v | --verbose Increases the level of message output
-w | --want version Try to install a different version that is
not in moonbase
EOF
  exit 1
}


main() {
  debug_msg "main ($@)"
  MODULES="$@"

  if echo $MODULES | grep -qw moonbase ; then
    # just update moonbase, no other modules
    if ! lget moonbase ; then
      exit 1
    fi
    # remove moonbase from MODULES and continue
    MODULES=$(echo $MODULES | sed 's/moonbase//g')
    if [ -z "$MODULES" ] ; then
      return
    fi
  fi

  if [ -z "$MODULES" ] ; then
    message "${MESSAGE_COLOR}Nothing to do!${DEFAULT_COLOR}"
    return
  fi

  # different approaches for multiple modules (start up downloads first)
  # and single modules (plain install)
  if [ -z "$SINGLE_MODULE" ] ; then

    if [ -z "$TEMP_DOWNLOAD_PIDS" ] ; then
      export TEMP_DOWNLOAD_PIDS=$(temp_create "download-pids")
      export TEMP_PREPAREDDEPS=$(temp_create "prepared-depends")
    fi
    export TEMP_CONFIGOPTS=$(temp_create "configopts")

    # pass 1 : run full dependency checking
    # This pass does configuration and dependency identification.
    if ! DEPS_ONLY=--deps build_depends $MODULES ; then
      temp_destroy $TEMP_DOWNLOAD_PIDS
      temp_destroy $TEMP_PREPAREDDEPS
      temp_destroy $TEMP_CONFIGOPTS
      verbose_msg "Unexpected errors, bailing out!"
      exit 1
    fi

    # pass 2 : hit the download manager button and grab a beer
    # this runs as a background process, so we are off to step #3 right away
    if [ -z "$DEPS_ONLY" ] ; then
      verbose_msg "Spawning download manager"

      # this code hurts more than it helps - it can stall forever (minutes)
      # even when just linning 2-3 modules
      # for M in $MODULES ; do
      # LIST="$(for D in `find_depends $M`; do if ! module_installed $D ; then echo $D ; fi ; done | uniq) $LIST"
      # done

      verbose_msg "download queue: $LIST $MODULES"
      for M in $LIST $MODULES; do
          THIS_TEMP=$(temp_create "$M.download.log")
          rm $THIS_TEMP
          SAFE_M=$(echo $M | md5sum | awk '{print $1}')
          eval TEMP_DOWNLOAD_LOG_$SAFE_M=$THIS_TEMP
      done
      (
          for M in $LIST $MODULES; do
              SAFE_M=$(echo $M | md5sum | awk '{print $1}')
              eval THIS_TEMP=\$TEMP_DOWNLOAD_LOG_$SAFE_M
              lget $M > $THIS_TEMP 2>&1 &
              echo "$M:`jobs -p`:$THIS_TEMP" >> $TEMP_DOWNLOAD_PIDS
              wait
done
      ) &

      # pass 3 : compile/install
      # no strange stuff should happen here anymore
      for MODULE in $MODULES ; do
        if ! module_installed $MODULE || [ ! -n "$PROBE" ] || ( [ -n "$PROBE" ] && [ "$PROBE_EXPIRED" == "on" ] && module_is_expired $MODULE ) ; then
          # 3 more conditions to stop processing this module:
          if module_held $MODULE ; then
            error_message "${LRM_COLOR}Notice:${DEFAULT_COLOR}${MESSAGE_COLOR} Skipping compile and install for held module ${MODULE_COLOR}$MODULE${DEFAULT_COLOR}"
            continue
          elif module_exiled $MODULE ; then
            error_message "${LRM_COLOR}Notice:${DEFAULT_COLOR}${MESSAGE_COLOR} Skipping compile and install for exiled module ${MODULE_COLOR}$MODULE${DEFAULT_COLOR}"
            continue
          elif ! module_license_accepted $MODULE ; then
            error_message "${LRM_COLOR}Notice:${DEFAULT_COLOR}${MESSAGE_COLOR} The license of module ${MODULE_COLOR}$MODULE${DEFAULT_COLOR}${MESSAGE_COLOR} is incompatible with the list of"
            error_message "allowed and/or rejected licenses. Please adjust the ACCEPTED_LICENSES or"
            error_message "REJECTED_LICENSES variables to include or not include the specific"
            error_message "license of this module.${DEFAULT_COLOR}"
            continue
          else
            # we're good now, start installing
            linING="/var/lock/installing.$MODULE"
            verbose_msg "starting lin \"$MODULE\""
            if ! ( SINGLE_MODULE=1 main $MODULE ) ; then
              if [ -e "$TMP_LIN_FAIL" ] ; then
                echo "$MODULE" >> $TMP_LIN_FAIL
              fi
              lin_EXIT_STATUS=1;
            else
              if [ -e "$TMP_LIN_SUCCESS" ] ; then
                echo "$MODULE" >> $TMP_LIN_SUCCESS
              fi
            fi
          fi
        fi
      done
    fi

    # cleanups that we need to do
    temp_destroy $TEMP_DOWNLOAD_PIDS
    temp_destroy $TEMP_PREPAREDDEPS
    temp_destroy $TEMP_CONFIGOPTS

    return $lin_EXIT_STATUS

  else
    # we are only doing one module, drop down to:
    MODULE=$MODULES
    unset RECONFIGURE

    if [ -z "$TEMP_DOWNLOAD_PIDS" ] ; then
      export TEMP_DOWNLOAD_PIDS=$(temp_create "download-pids")
      export TEMP_PREPAREDDEPS=$(temp_create "prepared-depends")
      export TEMP_CONFIGOPTS=$(temp_create "configopts")
      CLEAN_TEMP=1
    fi

    run_details $MODULE &&
    run_depends $MODULE &&
    WANT_VERSION= satisfy_depends $MODULE

    if [ -z "$DEPS_ONLY" ] ; then
      if ! module_held $MODULE ; then
        if [ -n "$PROBE" ] ; then
          # --probe install
          if ! module_installed $MODULE ; then
            if ! lin_module $MODULE ; then
              temp_destroy $TEMP_PREPAREDDEPS
if [ -n "$CLEAN_TEMP" ] ; then
temp_destroy $TEMP_DOWNLOAD_PIDS
temp_destroy $TEMP_CONFIGOPTS
fi
              exit 1
            fi
          elif [ "$PROBE_EXPIRED" == "on" ] && module_is_expired $MODULE ; then
            # probe install where module is expired
            verbose_msg "module \"$MODULE\" needs to be updated"
            if ! SINGLE_MODULE= lin_module $MODULE ; then
              temp_destroy $TEMP_PREPAREDDEPS
if [ -n "$CLEAN_TEMP" ] ; then
temp_destroy $TEMP_DOWNLOAD_PIDS
temp_destroy $TEMP_CONFIGOPTS
fi
              exit 1
            fi
          fi
        else
          # normal install - not probed
          if ! lin_module $MODULE ; then
            temp_destroy $TEMP_PREPAREDDEPS
if [ -n "$CLEAN_TEMP" ] ; then
temp_destroy $TEMP_DOWNLOAD_PIDS
temp_destroy $TEMP_CONFIGOPTS
fi
            exit 1
          fi
        fi
      else
        verbose_msg "Skipping held module \"$MODULE\""
      fi
    fi
    if [ -n "$CLEAN_TEMP" ] ; then
      temp_destroy $TEMP_DOWNLOAD_PIDS
      temp_destroy $TEMP_PREPAREDDEPS
      temp_destroy $TEMP_CONFIGOPTS
    fi
  fi
}


. /etc/lunar/config
. $BOOTSTRAP

GETOPT_ARGS=$(getopt -q -n lin -o "cdf:hprRsvV:w:" -l "compile,debug,deps,from:,help,opts:,probe,reconfigure,resurrect,silent,verbose,Version:,want:" -- "$@")

# the following trap makes sure all threads exit in case something weird
# happens:
trap "rm -f $(eval echo \$TEMP_PREPAREDDEPS \$TEMP_DOWNLOAD_PIDS \$INSTALLWATCHFILE) ; exit 1" CHLD INT TERM KILL

if [ -z "$?" ] ; then
  help | view_file
  exit
else
  eval set -- $GETOPT_ARGS
  export IFS="$STANDARD_IFS"
  
  root_check
  enviro_check
  set_priority
  
  while true ; do
    case "$1" in
      -c|--compile ) export COMPILE="$1" ; shift ;;
      -d|--debug ) (( LUNAR_DEBUG++ )) ; export LUNAR_DEBUG ; shift ;;
         --deps ) export DEPS_ONLY="$1" ; shift ;;
      -f|--from ) export SOURCE_CACHE=$2 ; shift 2 ;;
      -h|--help ) help ; exit ;;
         --opts ) export PASS_OPTS="$2" ; shift 2 ;;
      -p|--probe ) export PROBE="$1" ; shift ;;
      -r|--reconfigure ) export RECONFIGURE="$1" ; shift ;;
      -R|--resurrect ) export RESURRECT="$1" ; shift ;;
      -s|--silent ) export SILENT="$1" ; shift ;;
      -v|--verbose ) export VERBOSE="on" ; shift ;;
      -w|--want ) export WANT_VERSION=$2 ; shift 2 ;;
      --) shift ; break ;;
      *) help ; break ;;
    esac
  done

  if [ -n "$RESURRECT" ] ; then
    resurrect_modules $@
  else
    main $@
  fi
fi
Something went wrong with that request. Please try again.