[SM-Commit] GIT changes to master cauldron by Justin Boffemmyer (4ee4d55f3781d68b3d1803836a303b7922a12461)

Justin Boffemmyer scm at sourcemage.org
Mon Apr 5 10:33:33 EDT 2010


GIT changes to master cauldron by Justin Boffemmyer <flux at sourcemage.org>:

 enchantment/errorcodes            |  202 ++++++++++++++++++++++++++++----------
 enchantment/lib.install           |    6 -
 enchantment/lib.modules           |  188 +++++++++++++++++++++++++++++++++++
 enchantment/lib.potion            |   70 ++++++-------
 enchantment/libenchantment        |  166 +++----------------------------
 enchantment/shell/bin/enchantment |    4 
 enchantment/shell/functions       |    2 
 7 files changed, 399 insertions(+), 239 deletions(-)

New commits:
commit 4ee4d55f3781d68b3d1803836a303b7922a12461
Author: Justin Boffemmyer <flux at sourcemage.org>
Commit: Justin Boffemmyer <flux at sourcemage.org>

    enchantment: move module functions to lib.modules
    
    Extracted module-specific processing out to lib.modules and normalized
    the namespace. libenchantment is now a little cleaner, and it's easier
    to track what needs to be reimplemented for changes in module
    functionality.

commit 11195a97ea6aea9ea83c7a000e7c218396df523b
Author: Justin Boffemmyer <flux at sourcemage.org>
Commit: Justin Boffemmyer <flux at sourcemage.org>

    enchantment: error code definitions + organisation
    
    Massive implementation of missing enchantment error codes. Redefined
    some error codes for API conformance. Reorganised error codes for better
    maintainability.

diff --git a/enchantment/errorcodes b/enchantment/errorcodes
index c1c2798..d4ffffb 100644
--- a/enchantment/errorcodes
+++ b/enchantment/errorcodes
@@ -18,66 +18,126 @@
 #-------------------------------------------------------------------------------
 # ERROR definitions
 #-------------------------------------------------------------------------------
-# error codes
+# base error codes
 ERR_OK=0                  # everything is good
 ERR_FATAL=1               # fatal error (missing cauldron libs, etc.)
-ERR_STEP=2                # error in processing a step
-ERR_LIBCOLOR=3            # problem loading libcolor when it was requested
-ERR_MK_DIR=4              # couldn't make directory
-ERR_DIR_EXISTS=5          # directory already exists
-ERR_POTION_DIR=6          # potion directory is missing
-ERR_GET_HASH_FILE=7       # problem generating file checksum
-ERR_MK_HASH_FILE=8        # problem generating file checksum
-ERR_GET_PARTITIONS=9      # couldn't read partitions
-ERR_CHK_PARTITIONS=10     # couldn't store partitions
-ERR_GET_FILESYSTEMS=11    # couldn't read filesystems
-ERR_CHK_FILESYSTEMS=12    # couldn't store filesystems
-ERR_GET_MOUNT_POINTS=13   # couldn't read mount points
-ERR_CHK_MOUNT_POINTS=14   # couldn't store mount points
-ERR_FILE_NOT_FOUND=15     # requested file not found
-ERR_DIR_NOT_FOUND=16      # requested dir not found
-ERR_CACHE_FILE=17         # couldn't copy file into potion dir
-ERR_ARCHIVE_FORMAT=18     # unknown archive format
-ERR_ARCHIVE=19            # could not build archive of potion
-ERR_COMPRESS=20           # could not compress potion archive
-ERR_MODULE_SCRIPT=21      # could not process module script
-ERR_MODULE_ENTER=22       # could not process module entry
-ERR_MODULE_EXIT=23        # could not process module exit
+ERR_MK_DIR=2              # couldn't make directory
+ERR_DIR_EXISTS=3          # directory already exists
+ERR_FILE_NOT_FOUND=5      # requested file not found
+ERR_DIR_NOT_FOUND=6       # requested dir not found
+
+# libenchantment base
+ERR_LOAD_LIBRARY=10       # could not load enchantment library
+ERR_PREPARE=11            # could not initialize enchantment
+ERR_CLEANUP=12            # could not clean up after finishing
+
+# libenchantment module processing
+ERR_GET_CURRENT=20        # could not get current module
+ERR_GET_NEXT=21           # could not get next module
+ERR_GET_PREV=22           # could not get previous module
+ERR_SET_CURRENT=24        # could not set current module
+ERR_SET_NEXT=25           # could not set next module
+ERR_SET_PREV=26           # could not set previous module
+
+# history
+ERR_HISTORY_BACK=31       # could not go back in install history
+ERR_HISTORY_FORWARD=32    # could not go forward in install history
+
+# lib.chroot
+ERR_CHROOT_INIT=40        # could not initialize chroot
+ERR_CHROOT_NOT_INIT=41    # tried to use the chroot but its not initialized
+ERR_CHROOT_UNDEF=42       # chroot command undefined
+ERR_CHROOT_EXEC=43        # could not execute chroot command
+ERR_CHROOT_DONE=44        # could not properly clean up chroot
 
 # lib.i18n keymap
-ERR_KEYMAP_EXIT=50
-ERR_KEYMAP_PREFIX=51
-ERR_KEYMAP_LIST=52
-ERR_KEYMAP_LIST_SIZE=53
-ERR_KEYMAP_INPUT=54
-ERR_KEYMAP_LOAD=55
-ERR_KEYMAP_SAVE=56
+ERR_KEYMAP_EXIT=50        # keymap processing finished
+ERR_KEYMAP_PREFIX=51      # invalid keymap prefix
+ERR_KEYMAP_LIST=52        # keymap list empty or not provided
+ERR_KEYMAP_LIST_SIZE=53   # invalid list size provided
+ERR_KEYMAP_INPUT=54       # invalid user input
+ERR_KEYMAP_LOAD=55        # could not load selected keymap
+ERR_KEYMAP_SAVE=56        # could not save selected keymap
+
+# lib.install
+ERR_INSTALL_DIR=60        # could not install directory
+ERR_INSTALL_FILE=61       # could not install file
+ERR_INSTALL_CACHES=62     # could not install spell caches
+ERR_INSTALL_SOURCES=63    # could not install spell sources
+ERR_INSTALL_KERNEL=64     # could not install kernel image
+ERR_INSTALL_KMODS=65      # could not install kernel modules
+ERR_INSTALL_DEPMOD=66     # could not perform depmod in install
+
+# lib.module
+ERR_MODULE_NONE=70        # no modules found
+ERR_MODULE_SCRIPT=71      # could not process module script
+ERR_MODULE_ENTER=72       # could not process module entry
+ERR_MODULE_EXIT=73        # could not process module exit
+ERR_MODULE_GET_NUM=74     # could not get number of current module
+
+# lib.potion base
+ERR_POTION_CHECK_STATE=80       # could not process installer state
+ERR_POTION_DIR=81               # potion directory is missing
+ERR_POTION_CACHE_FILE=82        # couldn't copy file into potion dir
+ERR_POTION_ARCHIVE_FORMAT=83    # unknown archive format
+ERR_POTION_ARCHIVE=84           # could not build archive of potion
+ERR_POTION_COMPRESS=85          # could not compress potion archive
+
+# lib.potion gets
+ERR_POTION_GET_HASHSUM=90       # could not read hashsum of file
+ERR_POTION_GET_BOOTLOADER=91    # could not read bootloader config
+ERR_POTION_GET_CONFS=92         # could not read target system configs
+ERR_POTION_GET_FILESYSTEMS=93   # could not read filesystems
+ERR_POTION_GET_KERNEL=94        # could not read kernel config
+ERR_POTION_GET_MOUNT_POINTS=95  # could not read mount points
+ERR_POTION_GET_OPT_SPELLS=96    # could not read optional spell selection
+ERR_POTION_GET_PARTITIONS=97    # could not read partitions
+ERR_POTION_GET_USERS=98         # could not read user/group config
+
+# lib.potion checks
+ERR_POTION_SET_HASHSUM=100      # could not store hashsum of file
+ERR_POTION_CHK_BOOTLOADER=101   # could not store bootloader config
+ERR_POTION_CHK_CONFS=102        # could not store target system configs
+ERR_POTION_CHK_FILESYSTEMS=104  # could not store filesystems
+ERR_POTION_CHK_KERNEL=104       # could not store kernel config
+ERR_POTION_CHK_MOUNT_POINTS=105 # could not store mount points
+ERR_POTION_CHK_OPT_SPELLS=106   # could not store optional spell selection
+ERR_POTION_CHK_PARTITIONS=107   # could not store partitions
+ERR_POTION_CHK_USERS=108        # could not store user/group config
 
 # error messages
 ERR_MSGS=(
+          # base error  codes
           "operation succeeded"                             # ERR_OK
           "fatal error"                                     # ERR_FATAL
-          "not a recognized step"                           # ERR_STEP
-          "libcolor requested but couldn't load libcolor"   # ERR_LIBCOLOR
           "could not make directory"                        # ERR_MK_DIR
           "directory already exists"                        # ERR_DIR_EXISTS
-          "potion directory is missing"                     # ERR_POTION_DIR
-          "could not generate hashsum of file"              # ERR_MK_HASH_FILE
-          "could not read partitions"                       # ERR_GET_PARTITIONS
-          "could not store partitions"                      # ERR_CHK_PARTITIONS
-          "could not read filesystems"                      # ERR_GET_FILESYSTEMS
-          "could not store filesystems"                     # ERR_CHK_FILESYSTEMS
-          "could not read mount points"                     # ERR_GET_MOUNT_POINTS
-          "could not store mount points"                    # ERR_CHK_MOUNT_POINTS
           "file not found"                                  # ERR_FILE_NOT_FOUND
           "directory not found"                             # ERR_DIR_NOT_FOUND
-          "could not cache file"                            # ERR_CACHE_FILE
-          "unknown archive format"                          # ERR_ARCHIVE_FORMAT
-          "could not create potion archive"                 # ERR_ARCHIVE
-          "could not compress potion archive"               # ERR_COMPRESS
-          "could not process module script"                 # ERR_MODULE_SCRIPT
-          "could not process module entry"                  # ERR_MODULE_ENTER
-          "could not process module exit"                   # ERR_MODULE_EXIT
+
+          # libenchantment base
+          "could not load enchantment library"              # ERR_LOAD_LIBRARY
+          "could not initialize enchantment"                # ERR_PREPARE
+          "could not clean up after finishing"              # ERR_CLEANUP
+
+          # libenchantment module processing
+          "could not get current module"                    # ERR_GET_CURRENT
+          "could not get next module"                       # ERR_GET_NEXT
+          "could not get previous module"                   # ERR_GET_PREV
+          "could not set current module"                    # ERR_SET_CURRENT
+          "could not set next module"                       # ERR_SET_NEXT
+          "could not set previous module"                   # ERR_SET_PREV
+
+          # history
+          "could not go back in install history"            # ERR_HISTORY_BACK
+          "could not go forward in install history"         # ERR_HISTORY_FORWARD
+
+          # lib.chroot
+          "could not initialize chroot"                     # ERR_CHROOT_INIT
+          "tried to use the chroot but its not initialized" # ERR_CHROOT_NOT_INIT
+          "chroot command undefined"                        # ERR_CHROOT_UNDEF
+          "could not execute chroot command"                # ERR_CHROOT_EXEC
+          "could not properly clean up chroot"              # ERR_CHROOT_DONE
 
           # lib.i18n keymap
           "keymap processing finished"                      # ERR_KEYMAP_EXIT
@@ -87,6 +147,53 @@ ERR_MSGS=(
           "invalid user input"                              # ERR_KEYMAP_INPUT
           "could not load selected keymap"                  # ERR_KEYMAP_LOAD
           "could not save selected keymap"                  # ERR_KEYMAP_SAVE
+
+          # lib.install
+          "could not install directory"                     # ERR_INSTALL_DIR
+          "could not install file"                          # ERR_INSTALL_FILE
+          "could not install spell caches"                  # ERR_INSTALL_CACHES
+          "could not install spell sources"                 # ERR_INSTALL_SOURCES
+          "could not install kernel image"                  # ERR_INSTALL_KERNEL
+          "could not install kernel modules"                # ERR_INSTALL_KMODS
+          "could not perform depmod in install"             # ERR_INSTALL_DEPMOD
+
+          # lib.module
+          "no modules found"                                # ERR_MODULE_NONE
+          "could not process module script"                 # ERR_MODULE_SCRIPT
+          "could not process module entry"                  # ERR_MODULE_ENTER
+          "could not process module exit"                   # ERR_MODULE_EXIT
+          "could not get number of current module"          # ERR_MODULE_GET_NUM
+
+          # lib.potion base
+          "could not process installer state"               # ERR_POTION_CHECK_STATE
+          "potion directory is missing"                     # ERR_POTION_DIR
+          "could not cache file"                            # ERR_POTION_CACHE_FILE
+          "unknown archive format"                          # ERR_POTION_ARCHIVE_FORMAT
+          "could not create potion archive"                 # ERR_POTION_ARCHIVE
+          "could not compress potion archive"               # ERR_POTION_COMPRESS
+
+          # lib.potion gets
+          "could not read hashsum of file"                  # ERR_POTION_GET_HASHSUM
+          "could not read bootloader config"                # ERR_POTION_GET_BOOTLOADER
+          "could not read target system configs"            # ERR_POTION_GET_CONFS
+          "could not read filesystems"                      # ERR_POTION_GET_FILESYSTEMS
+          "could not read kernel config"                    # ERR_POTION_GET_KERNEL
+          "could not read mount points"                     # ERR_POTION_GET_MOUNT_POINTS
+          "could not read optional spell selection"         # ERR_POTION_GET_OPT_SPELLS
+          "could not read partitions"                       # ERR_POTION_GET_PARTITIONS
+          "could not read user/group config"                # ERR_POTION_GET_USERS
+
+          # lib.potion checks
+          "could not store hashsum of file"                 # ERR_POTION_SET_HASHSUM
+          "could not store bootloader config"               # ERR_POTION_CHK_BOOTLOADER
+          "could not store target system configs"           # ERR_POTION_CHK_CONFS
+          "could not store filesystems"                     # ERR_POTION_CHK_FILESYSTEMS
+          "could not store kernel config"                   # ERR_POTION_CHK_KERNEL
+          "could not store mount points"                    # ERR_POTION_CHK_MOUNT_POINTS
+          "could not store optional spell selection"        # ERR_POTION_CHK_OPT_SPELLS
+          "could not store partitions"                      # ERR_POTION_CHK_PARTITIONS
+          "could not store user/group config"               # ERR_POTION_CHK_USERS
+
           )
 
 #-------------------------------------------------------------------------------
@@ -108,4 +215,3 @@ ERR_MSGS=(
 #-------------------------------------------------------------------------------
 
 # vim:ai:tw=80:tabstop=2:softtabstop=2:shiftwidth=2:expandtab
-
diff --git a/enchantment/lib.install b/enchantment/lib.install
index 16310ce..0d2ecc2 100644
--- a/enchantment/lib.install
+++ b/enchantment/lib.install
@@ -124,15 +124,15 @@ function enchant_install_kernel() {
   local kvers="${3:-$ENCHANT_ISO_KVERS}"
 
   # copy the kernel over
-  enchant_install_file "$kernel" "$target_kernel" || return $ERR_KERNEL
+  enchant_install_file "$kernel" "$target_kernel" || return $ERR_INSTALL_KERNEL
 
   # copy the modules over
   enchant_install_dir "$kmods/$kvers" "$target_kmods/$(basename $kmods)" ||
-      return $ERR_KERNEL_MODULES
+      return $ERR_INSTALL_KMODS
 
   # make sure that the proper dep info is generated on the target system
   depmod -a -b "$target_kmods/$kvers" "$kvers" ||
-    return $ERR_KERNEL_DEPMOD
+    return $ERR_INSTALL_DEPMOD
 
   return $ERR_OK
 }
diff --git a/enchantment/lib.modules b/enchantment/lib.modules
new file mode 100644
index 0000000..90c2cb7
--- /dev/null
+++ b/enchantment/lib.modules
@@ -0,0 +1,188 @@
+#!/bin/bash
+#-------------------------------------------------------------------------------
+##
+##=head1 SYNOPSIS
+##
+##  Module (install step) processing functions
+##
+##=head1 DESCRIPTION
+##
+##  Provides the functions responsible for listing modules and processing
+##  module scripts.
+##
+##=head1 COPYRIGHT
+##
+##  Copyright 2010 The Cauldron Team
+##
+##=head1 FUNCTIONS
+##
+##=over 4
+##
+#-------------------------------------------------------------------------------
+
+#-------------------------------------------------------------------------------
+##
+## Returns a list of all modules recognized for the current installation, pruned
+## of duplicates and the special "error" module. Expects $ENCHANT_INSTALLER to
+## be set by the installer which is calling this function, and for that
+## installer to have a 'modules' file (see the implementation of the shell
+## installer for an example).
+##
+#-------------------------------------------------------------------------------
+function enchant_modules_list() {
+  local output=()
+  local module=""
+
+  # make sure the installer's modules file exists
+  [[ -f "$ENCHANT_DATA/$INSTALLER/modules" ]] || return $ERR_MODULE_FILE
+
+  # for all modules, if the module isn't "error" and it isn't already in the
+  # output list, append it to the output list
+  for module in $(cut -d: -f1 "$ENCHANT_DATA/$INSTALLER/modules")
+  do
+    if [[ "$module" != "error" ]]
+    then
+      if ! $(echo "${output[@]}" | grep -q "$module")
+      then
+        output=( "${output[@]}" "$module" )
+      fi
+    fi
+  done
+
+  echo "${output[@]}"
+
+  return $ERR_OK
+}
+
+#-------------------------------------------------------------------------------
+##
+## Returns the number of the current module to perform during the installation.
+## Expects $ENCHANT_INSTALLER to be set by the installer which is calling this
+## function, and for that installer to have a 'modules' file (see the
+## implementation of the shell installer for an example).
+##
+#-------------------------------------------------------------------------------
+function enchant_modules_number() {
+  local num="$(grep -n -m1 \"^$(enchant_get_current):\" $ENCHANT_INSTALLER/modules)"
+
+  if [[ -z "$num" ]]
+  then
+    return $ERR_MODULE_GET_NUM
+  fi
+
+  echo "$num" | cut -d: -f1 || return $ERR_MODULE_GET_NUM
+
+  return $ERR_OK
+}
+
+#-------------------------------------------------------------------------------
+##
+## Returns the total number of modules to perform during the installation
+##
+#-------------------------------------------------------------------------------
+function enchant_modules_total() {
+  local total="$(enchant_modules_list | wc -l)"
+
+  if [[ "$total" -eq 0 || -z "$total" ]]
+  then
+    return $ERR_MODULE_NONE
+  fi
+
+  echo "$total"
+
+  return $ERR_OK
+}
+
+#-------------------------------------------------------------------------------
+##
+## Processes the module entry functions. This is used to provide extra
+## functionality upon entering a module (usually preparatory work, like creating
+## module-specific temp files, etc.)
+##
+#-------------------------------------------------------------------------------
+function enchant_modules_enter() {
+  local module="$(cat $ENCHANT_STATUS)"
+  local script=""
+
+  for script in "$ENCHANT_MODULES/$module/enter"/*
+  do
+    if [[ -f "$script" ]]
+    then
+      /bin/bash "$script" || return $ERR_MODULE_SCRIPT
+    fi
+  done
+
+  return $ERR_OK
+}
+
+#-------------------------------------------------------------------------------
+##
+## Processes the module exit functions. This is used to provide extra
+## functionality upon exiting a module, usually things like writing data to the
+## module's temp files, etc.
+##
+#-------------------------------------------------------------------------------
+function enchant_modules_exit() {
+  local module="$(cat $ENCHANT_STATUS)"
+  local script=""
+
+  for script in "$ENCHANT_MODULES/$module/exit"/*
+  do
+    if [[ -f "$script" ]]
+    then
+      /bin/bash "$script" || return $ERR_MODULE_SCRIPT
+    fi
+  done
+
+  return $ERR_OK
+}
+
+#-------------------------------------------------------------------------------
+## @param potion to process for
+##
+## Processes the module potion functions. This is used to do automated installs
+## using pre-made potions (from previous installs or composed ahead of time). It
+## runs scripted versions of what the user would have done manually in each
+## module.
+##
+#-------------------------------------------------------------------------------
+function enchant_modules_potion() {
+  local module="$(cat $ENCHANT_STATUS)"
+  local potion="$1"
+  local script=""
+
+  [[ -d "$potion" ]] || $ERR_DIR_NOT_FOUND
+
+  for script in "$ENCHANT_MODULES/$module/potion"/*
+  do
+    if [[ -f "$script" ]]
+    then
+      /bin/bash "$script" "$potion" || return $ERR_MODULE_SCRIPT
+    fi
+  done
+
+  return $ERR_OK
+}
+
+#-------------------------------------------------------------------------------
+##=back
+##
+##=head1 LICENSE
+##
+## This software is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This software is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this software; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+##
+#-------------------------------------------------------------------------------
+
+# vim:ai:tw=80:tabstop=2:softtabstop=2:shiftwidth=2:expandtab
diff --git a/enchantment/lib.potion b/enchantment/lib.potion
index 4ec2fee..ec09781 100644
--- a/enchantment/lib.potion
+++ b/enchantment/lib.potion
@@ -116,7 +116,7 @@ function enchant_potion_get_hashsum() {
   [[ -f "$file" ]] || return $ERR_FILE_NOT_FOUND
 
   cut -d' ' -f1 "$ENCHANT_POTION/$potion/${file##*/}.${hashfunc##*/}" ||
-    return $ERR_GET_HASHSUM
+    return $ERR_POTION_GET_HASHSUM
 
   return $ERR_OK
 }
@@ -138,7 +138,7 @@ function enchant_potion_set_hashsum() {
   [[ -f "$file" ]] || return $ERR_FILE_NOT_FOUND
 
   "$hashfunc" "$file" > "$ENCHANT_POTION/$potion/${file##*/}.${hashfunc##*/}" ||
-    return $ERR_SET_HASHSUM
+    return $ERR_POTION_SET_HASHSUM
 
   return $ERR_OK
 }
@@ -164,11 +164,11 @@ function enchant_potion_cache_file() {
   if [[ "$sum" != "$(enchant_potion_get_hashsum $file $potion)" ]]
   then
     # generate and store the (new) hashsum of the file
-    enchant_potion_set_hashsum "$file" "$potion" || return $ERR_SET_HASHSUM
+    enchant_potion_set_hashsum "$file" "$potion" || return $ERR_POTION_SET_HASHSUM
   fi
 
   # store the file itself
-  cp -f "$file" "$ENCHANT_POTION/$potion/${file##*/}" || return $ERR_CACHE_FILE
+  cp -f "$file" "$ENCHANT_POTION/$potion/${file##*/}" || return $ERR_POTION_CACHE_FILE
 
   return $ERR_OK
 }
@@ -193,7 +193,7 @@ function enchant_potion_get_partitions() {
   # for every line, if the 2nd field exactly matches one of excl, skip it
   # otherwise, store the filesystem (field 3) to the temp file
   gawk -v i="$excl" '{if(match(i,$2)) next; else print $1}' $mounts > \
-    $ENCHANT_POTION/partitions || return $ERR_GET_PARTITIONS
+    $ENCHANT_POTION/partitions || return $ERR_POTION_GET_PARTITIONS
 
   return $ERR_OK
 }
@@ -210,13 +210,13 @@ function enchant_potion_check_partitions() {
   local parts="$ENCHANT_POTION/filesystems"
   local potion="${1:-$ENCHANT_POTION_CURRENT}"
 
-  enchant_potion_get_filesystems || return $ERR_GET_PARTITIONS
+  enchant_potion_get_filesystems || return $ERR_POTION_GET_PARTITIONS
 
   # if there isn't a stored copy of the mount points, or if the stored copy
   # differs from what we currently have, then store the current set
   if [[ ! -f "$potion_parts" || "$(cat $potion_parts)" != "$(cat $parts)" ]]
   then
-    cp -f "$parts" > "$potion_parts" || return $ERR_CHK_PARTITIONS
+    cp -f "$parts" > "$potion_parts" || return $ERR_POTION_CHK_PARTITIONS
   fi
 
   return $ERR_OK
@@ -242,7 +242,7 @@ function enchant_potion_get_filesystems() {
   # for every line, if the 2nd field exactly matches one of excl, skip it
   # otherwise, store the filesystem (field 3) to the temp file
   gawk -v i="$excl" '{if(match(i,$2)) next; else print $3}' $mounts > \
-    $ENCHANT_POTION/filesystems || return $ERR_GET_FILESYSTEMS
+    $ENCHANT_POTION/filesystems || return $ERR_POTION_GET_FILESYSTEMS
 
   return $ERR_OK
 }
@@ -259,13 +259,13 @@ function enchant_potion_check_filesystems() {
   local fs="$ENCHANT_POTION/filesystems"
   local potion="${1:-$ENCHANT_POTION_CURRENT}"
 
-  enchant_potion_get_filesystems || return $ERR_GET_FILESYSTEMS
+  enchant_potion_get_filesystems || return $ERR_POTION_GET_FILESYSTEMS
 
   # if there isn't a stored copy of the mount points, or if the stored copy
   # differs from what we currently have, then store the current set
   if [[ ! -f "$potion_fs" || "$(cat $potion_fs)" != "$(cat $fs)" ]]
   then
-    cp -f "$fs" > "$potion_fs" || return $ERR_CHK_FILESYSTEMS
+    cp -f "$fs" > "$potion_fs" || return $ERR_POTION_CHK_FILESYSTEMS
   fi
 
   return $ERR_OK
@@ -291,7 +291,7 @@ function enchant_potion_get_mount_points() {
   # for every line, if the 2nd field exactly matches one of excl, skip it
   # otherwise, store the mount point (field 2) to the temp file
   gawk -v i="$excl" '{if(match(i,$2)) next; else print $2}' $mounts > \
-    $ENCHANT_POTION/mount_points || return $ERR_GET_MOUNT_POINTS
+    $ENCHANT_POTION/mount_points || return $ERR_POTION_GET_MOUNT_POINTS
 
   return $ERR_OK
 }
@@ -309,13 +309,13 @@ function enchant_potion_check_mount_points() {
   local mounts="$ENCHANT_POTION/mount_points"
   local potion="${1:-$ENCHANT_POTION_CURRENT}"
 
-  enchant_potion_get_mount_points || return $ERR_GET_MOUNT_POINTS
+  enchant_potion_get_mount_points || return $ERR_POTION_GET_MOUNT_POINTS
 
   # if there isn't a stored copy of the mount points, or if the stored copy
   # differs from what we currently have, then store the current set
   if [[ ! -f "$potion_mounts" || "$(cat $potion_mounts)" != "$(cat $mounts)" ]]
   then
-    cp -f "$mounts" > "$potion_mounts" || return $ERR_CHK_MOUNT_POINTS
+    cp -f "$mounts" > "$potion_mounts" || return $ERR_POTION_CHK_MOUNT_POINTS
   fi
 
   return $ERR_OK
@@ -334,7 +334,7 @@ function enchant_potion_check_kernel_config() {
 
   [[ -f "$kernel_config" ]] || return $ERR_FILE_NOT_FOUND
 
-  enchant_potion_cache_file "$kernel_config" "$potion" || return $ERR_CACHE_FILE
+  enchant_potion_cache_file "$kernel_config" "$potion" || return $ERR_POTION_CACHE_FILE
 
   return $ERR_OK
 }
@@ -352,7 +352,7 @@ function enchant_potion_check_kernel() {
 
   [[ -f "$kernels" ]] || return $ERR_FILE_NOT_FOUND
 
-  enchant_potion_cache_file "$kernels" "$potion" || return $ERR_CACHE_FILE
+  enchant_potion_cache_file "$kernels" "$potion" || return $ERR_POTION_CACHE_FILE
 
   return $ERR_OK
 }
@@ -370,7 +370,7 @@ function enchant_potion_check_spell_sources() {
 
   [[ -f "$spells" ]] || return $ERR_FILE_NOT_FOUND
 
-  enchant_potion_cache_file "$spells" "$potion" || return $ERR_CACHE_FILE
+  enchant_potion_cache_file "$spells" "$potion" || return $ERR_POTION_CACHE_FILE
 
   return $ERR_OK
 }
@@ -388,7 +388,7 @@ function enchant_potion_check_bootloader() {
 
   [[ -f "$bootloaders" ]] || return $ERR_FILE_NOT_FOUND
 
-  enchant_potion_cache_file "$bootloaders" "$potion" || return $ERR_CACHE_FILE
+  enchant_potion_cache_file "$bootloaders" "$potion" || return $ERR_POTION_CACHE_FILE
 
   return $ERR_OK
 }
@@ -409,7 +409,7 @@ function enchant_potion_check_confs() {
     conf="$ENCHANT_TARGET/$conf"
     [[ -f "$file" ]] || return $ERR_FILE_NOT_FOUND
 
-    enchant_potion_cache_file "$conf" "$potion" || return $ERR_CACHE_FILE
+    enchant_potion_cache_file "$conf" "$potion" || return $ERR_POTION_CACHE_FILE
   done
 
   return $ERR_OK
@@ -431,7 +431,7 @@ function enchant_potion_check_users() {
     file="$ENCHANT_TARGET/$file"
     [[ -f "$file" ]] || return $ERR_FILE_NOT_FOUND
 
-    enchant_potion_cache_file "$file" "$potion" || return $ERR_CACHE_FILE
+    enchant_potion_cache_file "$file" "$potion" || return $ERR_POTION_CACHE_FILE
   done
 
   return $ERR_OK
@@ -443,17 +443,17 @@ function enchant_potion_check_users() {
 ## Checks various state data for updates during the install.
 ##
 #-------------------------------------------------------------------------------
-function enchant_check_state() {
+function enchant_potion_check_state() {
   local potion="${1:-$ENCHANT_POTION_CURRENT}"
 
-  enchant_potion_check_partitions "$potion" || return $ERR_CHECK_PARTITIONS
-  enchant_potion_check_filesystems "$potion" || return $ERR_CHECK_FILESYSTEMS
-  enchant_potion_check_mount_points "$potion" || return $ERR_CHECK_MOUNT_POINTS
-  enchant_potion_check_opt_spells "$potion" || return $ERR_CHECK_OPT_SPELLS
-  enchant_potion_check_kernel "$potion" || return $ERR_CHECK_KERNEL
-  enchant_potion_check_bootloader "$potion" || return $ERR_CHECK_BOOTLOADER
-  enchant_potion_check_confs "$potion" || return $ERR_CHECK_CONFS
-  enchant_potion_check_users "$potion" || return $ERR_CHECK_USERS
+  enchant_potion_check_partitions "$potion" || return $ERR_POTION_CHK_PARTITIONS
+  enchant_potion_check_filesystems "$potion" || return $ERR_POTION_CHK_FILESYSTEMS
+  enchant_potion_check_mount_points "$potion" || return $ERR_POTION_CHK_MOUNT_POINTS
+  enchant_potion_check_opt_spells "$potion" || return $ERR_POTION_CHK_OPT_SPELLS
+  enchant_potion_check_kernel "$potion" || return $ERR_POTION_CHK_KERNEL
+  enchant_potion_check_bootloader "$potion" || return $ERR_POTION_CHK_BOOTLOADER
+  enchant_potion_check_confs "$potion" || return $ERR_POTION_CHK_CONFS
+  enchant_potion_check_users "$potion" || return $ERR_POTION_CHK_USERS
 
   return $ERR_OK
 }
@@ -475,20 +475,20 @@ function enchant_potion_bottle() {
   # package the potion into a compressed archive
   case "$ENCHANT_ARCHIVE" in
     "tar" )
-      tar cf "${output}.tar" "$ENCHANT_POTION/$potion"/* || return $ERR_ARCHIVE
+      tar cf "${output}.tar" "$ENCHANT_POTION/$potion"/* || return $ERR_POTION_ARCHIVE
       [[ -n "$ENCHANT_COMPRESS" ]] && "$ENCHANT_COMPRESS" "${output}.tar" ||
-        return $ERR_COMPRESS
+        return $ERR_POTION_COMPRESS
       ;;
     "cpio" )
       (
         cd "$potion"
-        find * | cpio -H newc -o > "${output}.io" || return $ERR_ARCHIVE
+        find * | cpio -H newc -o > "${output}.io" || return $ERR_POTION_ARCHIVE
         [[ -n "$ENCHANT_COMPRESS" ]] && "$ENCHANT_COMPRESS" "${output}.io" ||
-          return $ERR_COMPRESS
+          return $ERR_POTION_COMPRESS
       )
       ;;
     * )
-      return $ERR_ARCHIVE_FORMAT
+      return $ERR_POTION_ARCHIVE_FORMAT
   esac
 
   return $ERR_OK
@@ -514,7 +514,7 @@ function enchant_potion_quaff() {
   local endmod="$3"
 
   # get the list of modules to operate on
-  local list="$(enchant_get_modules)"
+  local list="$(enchant_modules_list)"
 
   # if the start module is given as the module name, get it's positional number
   if [[ "$start" = [a-z]* ]]
@@ -533,7 +533,7 @@ function enchant_potion_quaff() {
   for ((i < endmod; i++))
   do
     local module="${list[i]}"
-    enchant_module_potion "$module" "$potion"
+    enchant_modules_potion "$module" "$potion"
   done
 
   return $ERR_OK
diff --git a/enchantment/libenchantment b/enchantment/libenchantment
index bba44c1..95159dc 100755
--- a/enchantment/libenchantment
+++ b/enchantment/libenchantment
@@ -79,6 +79,7 @@ function enchant_load_library() {
 enchant_load_library "lib.chroot"
 enchant_load_library "lib.i18n"
 enchant_load_library "lib.install"
+enchant_load_library "lib.modules"
 enchant_load_library "lib.potion"
 
 #-------------------------------------------------------------------------------
@@ -116,30 +117,6 @@ function enchant_cleanup() {
 
 #-------------------------------------------------------------------------------
 ##
-## Returns a list of all modules recognized for the current installation, pruned
-## of duplicates and the special "error" module.
-##
-#-------------------------------------------------------------------------------
-function enchant_get_modules() {
-  local output=( )
-  local module
-
-  for module in $(cut -d: -f1 "$ENCHANT_DATA/modules")
-  do
-    if [[ "$module" != "error" ]]
-    then
-      if ! $(echo ${output[*]} | grep -q "$module")
-      then
-        output=( ${output[*]} "$module" )
-      fi
-    fi
-  done
-
-  echo ${output[@]}
-}
-
-#-------------------------------------------------------------------------------
-##
 ## Determines and returns the current module in the installation procedure.
 ##
 #-------------------------------------------------------------------------------
@@ -161,14 +138,14 @@ function enchant_get_current() {
 ##
 #-------------------------------------------------------------------------------
 function enchant_set_current() {
-  local module=$1
+  local module="$1"
 
-  if ! $(enchant_get_modules | grep -q $module)
+  if ! $(enchant_modules_list | grep -q "$module")
   then
     return $ERR_SET_CURRENT
   fi
 
-  enchant_module_exit || return $ERR_MODULE_EXIT
+  enchant_modules_exit || return $ERR_MODULE_EXIT
 
   # if the max history size has been reached, then we drop the oldest item
   if [[ "$(wc -l < $ENCHANT_BACK)" -ge "$ENCHANT_HISTORY_SIZE" ]]
@@ -180,12 +157,12 @@ function enchant_set_current() {
   echo "$module" >> "$ENCHANT_BACK" || return $ERR_SET_CURRENT
 
   # check the installation state
-  enchant_check_state || return $ERR_CHECK_STATE
+  enchant_potion_check_state || return $ERR_POTION_CHECK_STATE
 
   # set the current module
   echo "$module" > "$ENCHANT_STATUS" || return $ERR_SET_CURRENT
 
-  enchant_module_enter || return $ERR_MODULE_ENTER
+  enchant_modules_enter || return $ERR_MODULE_ENTER
 
   return $ERR_OK
 }
@@ -282,24 +259,24 @@ function enchant_set_prev() {
 #-------------------------------------------------------------------------------
 function enchant_back() {
   # if the back history is empty, then we can't go back
-  [[ "$(wc -l < $ENCHANT_BACK)" -eq 0 ]] && return $ERR_BACK
+  [[ "$(wc -l < $ENCHANT_BACK)" -eq 0 ]] && return $ERR_HISTORY_BACK
 
   # if the max forward history size has been reached
   if [[ "$(wc -l < $ENCHANT_FORWARD)" -ge "$ENCHANT_HISTORY_SIZE" ]]
   then
     # then we drop the oldest item from the forward history
-    sed -i '1d' "$ENCHANT_FORWARD" || return $ERR_BACK
+    sed -i '1d' "$ENCHANT_FORWARD" || return $ERR_HISTORY_BACK
   fi
 
   # copy the current status to the forward history, so we can go forward to
   # where we are after we jump back
-  enchant_get_current >> "$ENCHANT_FORWARD" || return $ERR_BACK
+  enchant_get_current >> "$ENCHANT_FORWARD" || return $ERR_HISTORY_BACK
 
   # set the current step to be the one we are jumping to
-  tail -n 1 "$ENCHANT_BACK" > "$ENCHANT_STATUS" || return $ERR_BACK
+  tail -n 1 "$ENCHANT_BACK" > "$ENCHANT_STATUS" || return $ERR_HISTORY_BACK
 
   # remove the step we jumped to from the back history
-  sed -i '$d' "$ENCHANT_BACK" || return $ERR_BACK
+  sed -i '$d' "$ENCHANT_BACK" || return $ERR_HISTORY_BACK
 
   return $ERR_OK
 }
@@ -314,140 +291,29 @@ function enchant_back() {
 #-------------------------------------------------------------------------------
 function enchant_forward() {
   # if the forward history is empty, then we can't go forward
-  [[ "$(wc -l < $ENCHANT_FORWARD)" -eq 0 ]] && return $ERR_FORWARD
+  [[ "$(wc -l < $ENCHANT_FORWARD)" -eq 0 ]] && return $ERR_HISTORY_FORWARD
 
   # if the max back history size has been reached
   if [[ "$(wc -l < $ENCHANT_BACK)" -ge "$ENCHANT_HISTORY_SIZE" ]]
   then
     # then we drop the oldest item from the back history
-    sed -i '1d' "$ENCHANT_BACK" || return $ERR_FORWARD
+    sed -i '1d' "$ENCHANT_BACK" || return $ERR_HISTORY_FORWARD
   fi
 
   # copy the current status to the back history, so we can go back to where we
   # are after we jump forward
-  enchant_get_current >> "$ENCHANT_BACK" || return $ERR_FORWARD
+  enchant_get_current >> "$ENCHANT_BACK" || return $ERR_HISTORY_FORWARD
 
   # set the current step to be the one we are jumping to
-  tail -n 1 "$ENCHANT_FORWARD" > "$ENCHANT_STATUS" || return $ERR_FORWARD
+  tail -n 1 "$ENCHANT_FORWARD" > "$ENCHANT_STATUS" || return $ERR_HISTORY_FORWARD
 
   # remove the step we jumped to from the forward history
-  sed -i '$d' "$ENCHANT_FORWARD" || return $ERR_FORWARD
+  sed -i '$d' "$ENCHANT_FORWARD" || return $ERR_HISTORY_FORWARD
 
   return $ERR_OK
 }
 
 #-------------------------------------------------------------------------------
-##
-## Returns the number of the current module to perform during the installation.
-## Expects $ENCHANT_INSTALLER to be set by the installer which is calling this
-## function, and for that installer to have a 'modules' file (see the
-## implementation of the shell installer for an example).
-##
-#-------------------------------------------------------------------------------
-function enchant_get_num() {
-  local num="$(grep -n -m1 \"^$(enchant_get_current):\" $ENCHANT_INSTALLER/modules)"
-
-  if [[ -z "$num" ]]
-  then
-    return $ERR_GET_NUM
-  fi
-
-  echo "$num" | cut -d: -f1 || return $ERR_GET_NUM
-
-  return $ERR_OK
-}
-
-#-------------------------------------------------------------------------------
-##
-## Returns the total number of modules to perform during the installation
-##
-#-------------------------------------------------------------------------------
-function enchant_get_total() {
-  local total="$(enchant_get_modules | wc -l)"
-
-  if [[ "$total" -eq 0 || -z $total ]]
-  then
-    return $ERR_TOTAL_ZERO
-  fi
-
-  echo "$total"
-
-  return $ERR_OK
-}
-
-#-------------------------------------------------------------------------------
-##
-## Processes the module entry functions. This is used to provide extra
-## functionality upon entering a module (usually preparatory work, like creating
-## module-specific temp files, etc.)
-##
-#-------------------------------------------------------------------------------
-function enchant_module_enter() {
-  local module="$(cat $ENCHANT_STATUS)"
-  local script=""
-
-  for script in "$ENCHANT_MODULES/$module/enter"/*
-  do
-    if [[ -f "$script" ]]
-    then
-      /bin/bash "$script" || return $ERR_MODULE_SCRIPT
-    fi
-  done
-
-  return $ERR_OK
-}
-
-#-------------------------------------------------------------------------------
-##
-## Processes the module exit functions. This is used to provide extra
-## functionality upon exiting a module, usually things like writing data to the
-## module's temp files, etc.
-##
-#-------------------------------------------------------------------------------
-function enchant_module_exit() {
-  local module="$(cat $ENCHANT_STATUS)"
-  local script=""
-
-  for script in "$ENCHANT_MODULES/$module/exit"/*
-  do
-    if [[ -f "$script" ]]
-    then
-      /bin/bash "$script" || return $ERR_MODULE_SCRIPT
-    fi
-  done
-
-  return $ERR_OK
-}
-
-#-------------------------------------------------------------------------------
-## @param potion to process for
-##
-## Processes the module potion functions. This is used to do automated installs
-## using pre-made potions (from previous installs or composed ahead of time). It
-## runs scripted versions of what the user would have done manually in each
-## module.
-##
-#-------------------------------------------------------------------------------
-function enchant_module_potion() {
-  local module="$(cat $ENCHANT_STATUS)"
-  local potion="$1"
-  local script=""
-
-  [[ -d "$potion" ]] || $ERR_DIR_NOT_FOUND
-
-  for script in "$ENCHANT_MODULES/$module/potion"/*
-  do
-    if [[ -f "$script" ]]
-    then
-      /bin/bash "$script" "$potion" || return $ERR_MODULE_SCRIPT
-    fi
-  done
-
-  return $ERR_OK
-}
-
-
-#-------------------------------------------------------------------------------
 ##=back
 ##
 ##=head1 LICENSE
diff --git a/enchantment/shell/bin/enchantment b/enchantment/shell/bin/enchantment
index 867af70..c05388d 100755
--- a/enchantment/shell/bin/enchantment
+++ b/enchantment/shell/bin/enchantment
@@ -64,8 +64,8 @@ function enchant_shell_command_prompt() {
 
   local current="current:$(enchant_get_current)"
   local next="next:$(enchant_get_next)"
-  local num="$(enchant_get_num)"
-  local total="$(enchant_get_total)"
+  local num="$(enchant_modules_number)"
+  local total="$(enchant_modules_total)"
 
   echo -n "[$current $next $num/$total] "
   echo -n "For a list of commands, type "
diff --git a/enchantment/shell/functions b/enchantment/shell/functions
index cf10f65..cc5d6d7 100644
--- a/enchantment/shell/functions
+++ b/enchantment/shell/functions
@@ -71,7 +71,7 @@ function enchant_shell_modules() {
   local col_width="0"
 
   # get the list of modules
-  list=( $(enchant_get_modules) )
+  list=( $(enchant_modules_list) )
 
   [[ "${#list[*]}" -eq 0 ]] && return $ERR_MODULE_NONE
 



More information about the SM-Commit mailing list