Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #32 from cavalier38/enforce_state

Enforce issue #24
  • Loading branch information...
commit 96a3a190784aa03243747b79d9403af46fa9b839 2 parents 96793b0 + c6ea3aa
Auke Kok sofar authored
6 libs/check.lunar
View
@@ -88,11 +88,11 @@ fix_depends () {
if [ -n "$1" ] ; then
LIST="$@"
else
- LIST=$(grep -v moonbase: "$MODULE_STATUS" | cut -d: -f1 | sort )
+ LIST=$(list_installed | fgrep -v -x moonbase)
fi
for MODULE in $LIST ; do
- module_exiled $MODULE || rework_module $MODULE
+ rework_module $MODULE
done
}
@@ -103,7 +103,7 @@ run_fix() {
MODULES=$*
if [ -z "$MODULES" ] ; then
- MODULES=$(list_installed | grep -v moonbase)
+ MODULES=$(list_installed | fgrep -v -x moonbase)
fi
if [[ -n "$FIXDEPENDS" ]] ; then
11 libs/depends.lunar
View
@@ -236,7 +236,16 @@ run_depends() {
fi
# this is shortcut case s1) as discussed in lunar-dev ML
- if module_installed $DEP && [ -z "$2" -a -z "$3" ] ; then
+ if module_enforced $DEP ; then
+ verbose_msg "Enforcing optional dependency \"$DEP\""
+ add_depends "$MODULE" "$DEP" "on" "optional" "$2" "$3"
+ # don't check depends if there are already checked
+ if grep -q "^$DEP\$" "$TEMP_PREPAREDDEPS" 2>/dev/null ; then
+ return 0
+ fi
+ lin --deps $DEP
+ echo "$DEP" >> $TEMP_PREPAREDDEPS
+ elif module_installed $DEP && [ -z "$2" -a -z "$3" ] ; then
verbose_msg "Auto-adding optional dependency \"$DEP\""
add_depends "$MODULE" "$DEP" "on" "optional" "$2" "$3"
# don't check depends if there are already checked
4 libs/main.lunar
View
@@ -94,7 +94,7 @@ rebuild() {
message "${MESSAGE_COLOR}Running FIX on all modules${DEFAULT_COLOR}"
run_fix
- LIST=$(grep ":installed:" "$MODULE_STATUS" | cut -d: -f1 | grep -v moonbase | grep -v "$LUNAR_MODULE")
+ LIST=$(list_installed | fgrep -v -x -e moonbase -e "$LUNAR_MODULE")
message "${MESSAGE_COLOR}Sorting modules by dependency${DEFAULT_COLOR}"
QUEUE=$(sort_by_dependency $LIST)
@@ -192,7 +192,7 @@ resurrect() {
if module_held $MODULE ; then
VERSION=$(installed_version $MODULE)
- STATUS=held
+ STATUS="installed+held"
lrm --keepconfig $MODULE
elif module_installed $MODULE ; then
lrm --keepconfig $MODULE
2  libs/misc.lunar
View
@@ -176,7 +176,7 @@ find_pam_aware() {
[ "$MODULE" != "Linux-PAM" ]; then
echo $MODULE
fi
- done < $MODULE_STATUS
+ done
}
182 libs/modules.lunar
View
@@ -10,7 +10,9 @@
# list_sections, list_modules, list_installed #
# check_module_index, run_details #
# module_installed, module_held, module_exiled #
-# hold_modules, unhold_modules #
+# module_enforced, hold_modules, unhold_modules #
+# exile_modules, unexile_modules, enforce_modules #
+# unenforce_modules #
# 20020528 #
# 20030113 merging more functions in here - sofar #
# 20030417 adding hold routines - sofar #
@@ -79,8 +81,8 @@ list_moonbase() {
# usage : list_installed
# purpose : return a list of installed (or held) modules
list_installed() {
- debug_msg "list_installed ($@)"
- grep -e ":installed:" -e ":held:" "$MODULE_STATUS" | cut -d: -f1 | sort
+ debug_msg "list_installed ($@)"
+ sed "s/:[[:digit:]]*:\\([^:]\\++\\)\\?\\(installed\\|held\\)\\(+[^:]\\+\\)\\?:.*$//" "$MODULE_STATUS"
}
@@ -296,7 +298,9 @@ run_module_file() {
# purpose : check if $MODULE is installed (or held)
module_installed()
{
- grep -q "^$1:[[:digit:]]*:installed:\|^$1:[[:digit:]]*:held:" "$MODULE_STATUS"
+ debug_msg "module_installed ($@)"
+
+ has_module_state $1 "(installed|held)"
}
@@ -304,8 +308,9 @@ module_installed()
# usage : module_held $MODULE
# purpose : check if $MODULE is held
module_held() {
- debug_msg "module_held ($@)"
- grep -q "^$1:[[:digit:]]*:held:" "$MODULE_STATUS"
+ debug_msg "module_held ($@)"
+
+ has_module_state $1 "held"
}
@@ -375,7 +380,18 @@ module_license_accepted() {
# purpose : check if $MODULE is exiled
module_exiled() {
debug_msg "module_exiled ($@)"
- $(cut -d: -f1,3 "$MODULE_STATUS" | grep -q "^$1:exiled")
+
+ has_module_state $1 "exiled"
+}
+
+
+# function : module_exiled
+# usage : module_exiled $MODULE
+# purpose : check if $MODULE is exiled
+module_enforced() {
+ debug_msg "module_enforced ($@)"
+
+ has_module_state $1 "enforced"
}
@@ -411,8 +427,11 @@ hold_modules() {
lock_file $MODULE_STATUS_BACKUP &&
lock_file $MODULE_STATUS &&
for MODULE in "$@" ; do
- awk -F: -v mod=$MODULE '{if ($1==mod && $3 == "installed") {print $1":"$2":held:"$4":"$5} else print;}' "$MODULE_STATUS" > $MODULE_STATUS_BACKUP
- cp $MODULE_STATUS_BACKUP $MODULE_STATUS
+ if ! module_installed $MODULE; then
+ error_message "${PROBLEM_COLOR}Cannot hold not installed module ${MODULE_COLOR}$MODULE${DEFAULT_COLOR}"
+ else
+ add_module_state $MODULE "held"
+ fi
done
unlock_file $MODULE_STATUS
unlock_file $MODULE_STATUS_BACKUP
@@ -430,8 +449,7 @@ unhold_modules () {
lock_file $MODULE_STATUS_BACKUP &&
lock_file $MODULE_STATUS &&
for MODULE in "$@" ; do
- awk -F: -v mod=$MODULE '{if ($1==mod && $3 == "held") {print $1":"$2":installed:"$4":"$5} else print;}' "$MODULE_STATUS" > $MODULE_STATUS_BACKUP
- cp $MODULE_STATUS_BACKUP $MODULE_STATUS
+ remove_module_state $MODULE "held"
done
unlock_file $MODULE_STATUS
unlock_file $MODULE_STATUS_BACKUP
@@ -452,8 +470,7 @@ exile_modules() {
if $(module_installed $MODULE); then
error_message "${PROBLEM_COLOR}Cannot exile installed module ${MODULE_COLOR}$MODULE${DEFAULT_COLOR}"
else
- echo "$MODULE::exiled::" >> $MODULE_STATUS_BACKUP
- cp $MODULE_STATUS_BACKUP $MODULE_STATUS
+ change_module_state $MODULE "exiled" "(installed|held|enforced)"
fi
done
unlock_file $MODULE_STATUS
@@ -472,8 +489,43 @@ unexile_modules () {
lock_file $MODULE_STATUS_BACKUP &&
lock_file $MODULE_STATUS &&
for MODULE in "$@" ; do
- grep -v "^$MODULE:" "$MODULE_STATUS" > $MODULE_STATUS_BACKUP
- cp $MODULE_STATUS_BACKUP $MODULE_STATUS
+ remove_module_state $MODULE "exiled"
+ done
+ unlock_file $MODULE_STATUS
+ unlock_file $MODULE_STATUS_BACKUP
+ fi
+}
+
+
+# function : enforce_modules
+# usage : enforce_modules $MODULE [$MODULE....]
+# purpose : enforce module selection
+enforce_modules() {
+ local MODULE
+ debug_msg "enforce_modules ($@)"
+ if [[ -n "$1" ]] ; then
+ lock_file $MODULE_STATUS_BACKUP &&
+ lock_file $MODULE_STATUS &&
+ for MODULE in "$@" ; do
+ change_module_state $MODULE "enforced" "exiled"
+ done
+ unlock_file $MODULE_STATUS
+ unlock_file $MODULE_STATUS_BACKUP
+ fi
+}
+
+
+# function : unenforce_modules
+# usage : unenforce_modules $MODULE [$MODULE....]
+# purpose : remove enforced module selection
+unenforce_modules () {
+ local MODULE
+ debug_msg "unenforce_modules ($@)"
+ if [ -n "$1" ] ; then
+ lock_file $MODULE_STATUS_BACKUP &&
+ lock_file $MODULE_STATUS &&
+ for MODULE in "$@" ; do
+ remove_module_state $MODULE "enforced"
done
unlock_file $MODULE_STATUS
unlock_file $MODULE_STATUS_BACKUP
@@ -485,6 +537,8 @@ unexile_modules () {
# usage : remove_module; but $MODULE must be defined earlier
# purpose : removed a module from the MODULE_STATUS files, no source removal
remove_module() {
+ local OLD_STATE
+
debug_msg "remove_module ($@)"
# catch this on new boxes:
@@ -495,17 +549,24 @@ remove_module() {
verbose_msg "updating lunar state files after module removal"
lock_file $MODULE_STATUS_BACKUP &&
lock_file $MODULE_STATUS &&
- grep -v "^$1:" "$MODULE_STATUS" > $MODULE_STATUS_BACKUP
- cp $MODULE_STATUS_BACKUP $MODULE_STATUS
+ {
+ OLD_STATE=$(get_module_state $1 "(installed|held)")
+ grep -v "^$1:" "$MODULE_STATUS" > $MODULE_STATUS_BACKUP
+ if [ -n "$OLD_STATE" ]; then
+ echo "$1::$OLD_STATE::" >> $MODULE_STATUS_BACKUP
+ fi
+ cp $MODULE_STATUS_BACKUP $MODULE_STATUS
+ }
unlock_file $MODULE_STATUS
unlock_file $MODULE_STATUS_BACKUP
}
# function: add_module
-# usage : add_module <module_name>
+# usage : add_module <module_name> <state> <version> <size>
# purpose : adds the 1st parameter as the module name to the MODULE_STATUS files
add_module() {
+ local OLD_STATE
debug_msg "add_module ($@)"
# catch this on new boxes:
@@ -516,16 +577,78 @@ add_module() {
verbose_msg "updating lunar state files after module installation"
lock_file $MODULE_STATUS_BACKUP &&
lock_file $MODULE_STATUS &&
- if [ -s $MODULE_STATUS ]; then
- grep -v "^$1:" "$MODULE_STATUS_BACKUP" > $MODULE_STATUS 2>/dev/null
- fi &&
- echo "$1:$(date -u +%Y%m%d):$2:$3:$4" >> $MODULE_STATUS &&
- cp $MODULE_STATUS $MODULE_STATUS_BACKUP
+ {
+ OLD_STATE=$(get_module_state $1 $2)
+ grep -v "^$1:" "$MODULE_STATUS" > $MODULE_STATUS_BACKUP
+ if [ -n "$OLD_STATE" ]; then
+ OLD_STATE="+$OLD_STATE"
+ fi
+ echo "$1:$(date -u +%Y%m%d):$2$OLD_STATE:$3:$4" >> $MODULE_STATUS_BACKUP &&
+ cp $MODULE_STATUS_BACKUP $MODULE_STATUS
+ }
unlock_file $MODULE_STATUS
unlock_file $MODULE_STATUS_BACKUP
}
+# function: add_module_state
+# usage : add_module_state <module_name> <state>
+# purpose : adds <state> to the module. add an empty new line to the MODULE_STATUS files if net there yet
+# pre : the MODULE_STATUS files need to be locked
+add_module_state() {
+ debug_msg "add_module_state ($@)"
+
+ awk -F: -v mod="$1" -v state="$2" 'BEGIN {OFS=FS ; ret=0} ; $1==mod {if ($3 !~ /(^|\+)'"$2"'(\+|$)/) {$3=$3"+"state} ret=1} ; {print} ; END {exit ret}' "$MODULE_STATUS" > $MODULE_STATUS_BACKUP &&
+ echo "$MODULE::$2::" >> $MODULE_STATUS_BACKUP
+ cp $MODULE_STATUS_BACKUP $MODULE_STATUS
+}
+
+
+# function: remove_module_state
+# usage : remove_module_state <module_name> <state>
+# purpose : removes <state> from the module. remove the line completely from the MODULE_STATUS files if no state left
+# pre : the MODULE_STATUS files need to be locked
+remove_module_state() {
+ debug_msg "remove_module_state ($@)"
+
+ awk -F: -v mod="$1" 'BEGIN {OFS=FS} ; $1==mod {$3=gensub(/(^|\+)('"$2"'\+)+|((^|\+)'"$2"')+$/,"\\1","g",$3) ; if ($3=="") {next}} ; {print}' "$MODULE_STATUS" > $MODULE_STATUS_BACKUP &&
+ cp $MODULE_STATUS_BACKUP $MODULE_STATUS
+}
+
+
+# function: change_module_state
+# usage : change_module_state <module_name> <new_state> <old_state>
+# purpose : removes <old_state> from the module and adds <new_state> to the module. add an empty new line to the MODULE_STATUS files if net there yet
+# pre : the MODULE_STATUS files need to be locked
+change_module_state() {
+ debug_msg "change_module_state ($@)"
+
+ awk -F: -v mod="$1" -v state="$2" 'BEGIN {OFS=FS ; ret=0} ; $1==mod {{$3=gensub(/(^|\+)('"$3"'\+)+|((^|\+)'"$3"')+$/,"\\1","g",$3) ; if ($3=="") {$3=state} ; if ($3 !~ /(^|\+)'"$2"'(\+|$)/) {$3=$3"+"state}} ret=1} ; {print} ; END {exit ret}' "$MODULE_STATUS" > $MODULE_STATUS_BACKUP &&
+ echo "$MODULE::$2::" >> $MODULE_STATUS_BACKUP
+ cp $MODULE_STATUS_BACKUP $MODULE_STATUS
+}
+
+
+# function: has_module_state
+# usage : has_module_state <module_name> <state>
+# purpose : checks for the presence of <state> the MODULE_STATUS file
+has_module_state() {
+ debug_msg "has_module_state ($@)"
+
+ grep -q "^$1:[[:digit:]]*:\\([^:]\\++\\)\\?$2\\(+[^:]\\+\\)\\?:" "$MODULE_STATUS"
+}
+
+
+# function: get_module_state
+# usage : get_module_state <module_name> <state>
+# purpose : get the state of the module leaving out <state>
+get_module_state() {
+ debug_msg "get_module_state ($@)"
+
+ awk -F: -v mod="$1" '$1==mod {print gensub(/(^|\+)('"$2"'\+)+|((^|\+)'"$2"')+$/,"\\1","g",$3)}' "$MODULE_STATUS"
+}
+
+
# function : purge_modules
# usage : purge_modules
# purpose : purge modules that were removed from moonbase
@@ -538,7 +661,7 @@ purge_modules() {
error_message "${PROBLEM_COLOR}Error: ${DEFAULT_COLOR}${MESSAGE_COLOR} your moonbase seems damaged. Re-lin moonbase to fix.${DEFAULT_COLOR}"
exit 1
fi
- for MODULE in $(list_installed | grep -v "^moonbase$") ; do
+ for MODULE in $(list_installed | fgrep -v -x moonbase) ; do
(
if ! run_details $MODULE &> /dev/null ; then
message "${MODULE_COLOR}$MODULE${DEFAULT_COLOR}${MESSAGE_COLOR} was removed from ${FILE_COLOR}${MOONBASE}${DEFAULT_COLOR}"
@@ -560,10 +683,13 @@ module_is_expired() {
if [ -z "$MODULE" ] ; then
MODULE=$1
fi
- LINE=$(grep "^$MODULE:" "$MODULE_STATUS" | grep -v "^moonbase" | awk -F: '{print "IDATE="$2" STATUS="$3" IVERSION="$4}')
- eval $LINE
- if run_details $MODULE &> /dev/null ; then
- if [[ "$STATUS" == "installed" ]] ; then
+ if [ "$MODULE" == moonbase ] ; then
+ return 255
+ fi
+ LINE=$(awk -F: -v mod=$MODULE '$1==mod && $3 ~ /(^|\+)installed(\+|$)/ {print "IDATE="$2" IVERSION="$4}' "$MODULE_STATUS")
+ if [ -n "$LINE" ] ; then
+ eval $LINE
+ if run_details $MODULE &> /dev/null ; then
if [[ "$VERSION" != "$IVERSION" ]] || [[ -z "$IDATE" ]] ||
(( "$UPDATED" > "$IDATE" )) ; then
return 0
12 libs/recovery.lunar
View
@@ -51,12 +51,18 @@ rebuild_status_files() {
VERSION=$(echo $MODULE_NAME | cut -d "-" -f "$COUNTS"-)
SIZE=$(find_module_size $REAL_NAME $VERSION)
DATE=$(ls -l $INSTALL_LOGS/$REAL_NAME-$VERSION --time-style=+%Y%m%d | awk '{print $6}')
- remove_module "$REAL_NAME" &&
# adjusted add_module code that echos the DATE field ;^)
lock_file $MODULE_STATUS &&
lock_file $MODULE_STATUS_BACKUP &&
- echo "$REAL_NAME:$DATE:installed:$VERSION:$SIZE" >>$MODULE_STATUS &&
- cat "$MODULE_STATUS" >$MODULE_STATUS_BACKUP &&
+ {
+ OLD_STATE=$(get_module_state $REAL_NAME "installed")
+ grep -v "^$REAL_NAME:" "$MODULE_STATUS" > $MODULE_STATUS_BACKUP
+ if [ -n "$OLD_STATE" ]; then
+ OLD_STATE="+$OLD_STATE"
+ fi
+ echo "$REAL_NAME:$DATE:installed$OLD_STATE:$VERSION:$SIZE" >> $MODULE_STATUS_BACKUP &&
+ cp $MODULE_STATUS_BACKUP $MODULE_STATUS
+ }
unlock_file $MODULE_STATUS_BACKUP &&
unlock_file $MODULE_STATUS &&
6 libs/sizes.lunar
View
@@ -27,7 +27,7 @@ find_module_size() {
local SIZE
unset SIZE
[ -e "$MODULE_STATUS" ] &&
- SIZE=`grep "^$1\:" "$MODULE_STATUS" | cut -d ":" -f 5-5`
+ SIZE=$(sed -n "s/^$1:.*://p" "$MODULE_STATUS")
[ -n "$SIZE" ] && echo ${SIZE} || false
}
@@ -42,14 +42,14 @@ find_module_size() {
module_size $1 $VERSION && return
# no :( lets dig through logs
- [ -e "$INSTALL_LOGS/$MODULE-$VERSION" ] &&
+ [ -e "$INSTALL_LOGS/$1-$VERSION" ] &&
while read LINE
do
[ -f "$LINE" ] &&
SIZE0=`du "$LINE" |
cut -f 1-1` &&
SIZE=$((SIZE0+SIZE))
- done <$INSTALL_LOGS/$MODULE-$VERSION &&
+ done <$INSTALL_LOGS/$1-$VERSION &&
echo ${SIZE}KB ||
message "${PROBLEM_COLOR}Install log for $1 is not found${DEFAULT_COLOR}"
}
10 man/lunar.8
View
@@ -6,7 +6,7 @@ lunar \- menu\-driven software package management utility
-d|--debug|-h|--help|-v|--verbose
.PP
.B lunar
-[prune|renew|update|rebuild|optimize|fix|nofix|fixdepends|resurrect|install|remove|hold|unhold|exile|unexile]
+[prune|renew|update|rebuild|optimize|fix|nofix|fixdepends|resurrect|install|remove|hold|unhold|exile|unexile|enforce|unenforce]
.SH "COPYRIGHT"
.if n lunar(8) is Copyright (C) 2002-2003 Terry Chan with portions copyrighted by previous authors 2001\-2002
.if t lunar(8) is Copyright \(co 2002-2003 Terry Chan with portions copyrighted by previous authors 2001\-2002
@@ -107,6 +107,14 @@ Prevents a module from being installed or resurrected. Perhaps because you've in
.IP
Removes a module from exiled status.
.PP
+.I enforce
+.IP
+Automatically select yes for optional dependency to this module.
+.PP
+.I unenforce
+.IP
+Removes a module from enforce list.
+.PP
.SH "REQUIREMENTS"
.I lunar
requires a connection to the Internet
22 prog/lunar
View
@@ -61,6 +61,8 @@ hold module(s) Place a hold on a checklist of modules
unhold module(s) Remove a hold on a checklist of modules
exile module(s) Remove a module a/o prevent it from being resurrected
unexile module(s) Allows a module to be compiled|resurrected again
+enforce module(s) Enforce optinal selection on a list of modules
+unenforce module(s) Remove enforce on a list of modules
EOF
exit 1
}
@@ -273,20 +275,18 @@ select_pkgs() {
make_hold_checklist() {
- for LINE in $(sort "$MODULE_STATUS_BACKUP") ; do
+ for LINE in $(grep -E '[:+](installed|held)[:+]' "$MODULE_STATUS_BACKUP" | sort) ; do
(
MODULE=$(echo "$LINE" | cut -d: -f1)
STATUS=$(echo "$LINE" | cut -d: -f3)
VERSION=$(echo "$LINE" | cut -d: -f4)
- if [ "$STATUS" == "installed" ] || [ "$STATUS" == "held" ] ; then
- [ "$STATUS" == "held" ] && HELD="on" || HELD="off"
- SHORT="Short description unavailable"
- if run_details $MODULE &> /dev/null ; then
- echo $MODULE
- echo $VERSION
- echo $HELD
- echo $SHORT
- fi
+ echo "$STATUS" | grep -q -E '[:+]held[:+]' && HELD="on" || HELD="off"
+ SHORT="Short description unavailable"
+ if run_details $MODULE &> /dev/null ; then
+ echo $MODULE
+ echo $VERSION
+ echo $HELD
+ echo $SHORT
fi
)
done
@@ -847,6 +847,8 @@ else
unhold ) shift && unhold_modules $@ ;;
exile ) shift && exile_modules $@ ;;
unexile ) shift && unexile_modules $@ ;;
+ enforce ) shift && enforce_modules $@ ;;
+ unenforce ) shift && unenforce_modules $@ ;;
*) main ;;
esac
fi
11 prog/lvu
View
@@ -64,6 +64,7 @@ conflicts display conflicting files
moonalyze analyze the current moonbase for common issues
held display held modules
exiled display exiled modules
+enforced display enforced modules
expired display a list of modules which need an update
info module display terse summary information about module
@@ -1259,7 +1260,7 @@ main() {
installed)
if [ -z "$2" ] ; then
- grep -E ':(installed|held):' "$MODULE_STATUS" | view_file
+ grep -E '[:+](installed|held)[:+]' "$MODULE_STATUS" | view_file
elif [ -n "$(installed_version $2)" ] ; then
echo "$(installed_version $2)"
else
@@ -1269,11 +1270,15 @@ main() {
;;
held)
- grep ":held:" "$MODULE_STATUS" | cut -d: -f1
+ grep -E '[:+]held[:+]' "$MODULE_STATUS" | cut -d: -f1
;;
exiled)
- grep ":exiled:" "$MODULE_STATUS" | cut -d: -f1
+ grep -E '[:+]exiled[:+]' "$MODULE_STATUS" | cut -d: -f1
+ ;;
+
+ enforced)
+ grep -E '[:+]enforced[:+]' "$MODULE_STATUS" | cut -d: -f1
;;
expired)
Please sign in to comment.
Something went wrong with that request. Please try again.