[Lunar-commits] <lunar> Sync with theedge - mostly cleanups/indentation. alias menu.

Auke Kok sofar at lunar-linux.org
Mon Jul 2 04:43:15 CEST 2012


commit 2c4aa9670380ca98f1118a25e732719953c10269
Author: Auke Kok <sofar at lunar-linux.org>
Date:   Sun Mar 18 20:39:46 2007 +0000

    Sync with theedge - mostly cleanups/indentation. alias menu.
---
 bin/lvu                                       |   20 ++---
 etc/lunar/config                              |   15 ++--
 sbin/lrm                                      |    7 ++
 sbin/lunar                                    |   13 ++-
 sbin/lvis                                     |    2 +-
 var/lib/lunar/functions/config.lunar          |  116 ++++++++++++-------------
 var/lib/lunar/functions/depends.lunar         |    2 +-
 var/lib/lunar/functions/download.lunar        |   97 +++++++++++----------
 var/lib/lunar/functions/modules.lunar         |    4 +-
 var/lib/lunar/menu/alias.menu                 |   85 ++++++++++++++++++
 var/lib/lunar/plugins/download-generic.plugin |    4 +-
 11 files changed, 234 insertions(+), 131 deletions(-)

diff --git a/bin/lvu b/bin/lvu
index daa8036..b931f0c 100755
--- a/bin/lvu
+++ b/bin/lvu
@@ -743,26 +743,26 @@ show_info() {
 diff_module() {
   if [ "$ZLOCAL_OVERRIDES" != "on" ]; then
     message "can't diff modules without ZLOCAL_OVERRIDES=on"
-	exit 1
+    exit 1
   fi
   if [ -z "$1" ]; then
     message "diff requires a single module name"
-	exit 1
+    exit 1
   fi
   if ! run_details "$1" ; then
       message "diff requires an existing module"
       exit 1
   else
     if echo $SECTION | grep -q '^zlocal' ; then
-	  ZLOCAL_OVERRIDES=off NZSECTION=$(find_section $1)
-	  if echo $NZSECTION | grep -q '^zlocal' ; then
-	    unset SECTION
-	  fi
-	else
-	  message "no local copy of \"$MODULE\" exists"
-	  exit 1
+      ZLOCAL_OVERRIDES=off NZSECTION=$(find_section $1)
+      if echo $NZSECTION | grep -q '^zlocal' ; then
+        unset SECTION
+      fi
+    else
+      message "no local copy of \"$MODULE\" exists"
+      exit 1
     fi
-	ZSECTION=$(echo "$SECTION/" | sed 's/^zlocal\///g;s/\/$//')
+    ZSECTION=$(echo "$SECTION/" | sed 's/^zlocal\///g;s/\/$//')
     echo diff a/$NZSECTION/$MODULE b/$NZSECTION/$MODULE
     diff -Nur $MOONBASE/$NZSECTION/$MODULE $MOONBASE/zlocal/$ZSECTION/$MODULE --exclude ".svn" --exclude "CVS" | \
     grep -v ^diff | sed "s:$MOONBASE/$NZSECTION/:a/$NZSECTION/:g;s:$MOONBASE/zlocal/$ZSECTION/:b/$NZSECTION/:g"
diff --git a/etc/lunar/config b/etc/lunar/config
index 19a52c1..e6dc023 100755
--- a/etc/lunar/config
+++ b/etc/lunar/config
@@ -80,9 +80,10 @@ export        DIALOGRC=/etc/lunar/dialogrc
 
       MOONBASE_URL[0]=http://lunar-linux.org/lunar/
       MOONBASE_URL[1]=http://download.lunar-linux.org/lunar/
-	 
+
             PATCH_URL=http://download.lunar-linux.org/lunar/patches/
-	    
+           MIRROR_URL=http://download.lunar-linux.org/lunar/mirrors/
+
               TRACKED="/bin /boot /etc /lib /sbin /usr /var /opt/lunar"
 
                TMPDIR=${TMPDIR:-/tmp}
@@ -111,13 +112,9 @@ export        DIALOGRC=/etc/lunar/dialogrc
         MESSAGE_COLOR="${CYAN}"
         DEFAULT_COLOR="${DEFAULT}"
 
-        TAB_ENTER_IFS="	
-"
-        ENTER_IFS="
-"
-	STANDARD_IFS=" 	
-"
-
+        TAB_ENTER_IFS=$'\t\n'
+        ENTER_IFS=$'\n'
+        STANDARD_IFS=$' \t\n'
 
 for FUNCTION in $FUNCTIONS/*.lunar ; do
   . $FUNCTION
diff --git a/sbin/lrm b/sbin/lrm
index 44a92fa..a0a2c38 100755
--- a/sbin/lrm
+++ b/sbin/lrm
@@ -195,6 +195,13 @@ lrm_module() {
   else
     verbose_msg "removing module from dependency listing and configs"
     remove_depends $MODULE
+    # remove alias if required
+    for ALIAS in `cut -d: -f1 $MOONBASE/aliases`; do
+      if [ "$(get_local_config `echo LUNAR_ALIAS_${ALIAS:1}`)" == "$MODULE" ]; then
+        verbose_msg "removing alias mapping from \"$ALIAS\" to \"$MODULE\""
+        unset_local_config `echo LUNAR_ALIAS_${ALIAS:1}`
+      fi
+    done
     # restart xinetd after xinetd.confs have been removed by lrm...
     if [ -n "$SERVICES" -a -n "$XINETD" ] ; then
       verbose_msg "restarting xinetd"
diff --git a/sbin/lunar b/sbin/lunar
index b099e5d..2feebdc 100755
--- a/sbin/lunar
+++ b/sbin/lunar
@@ -431,7 +431,8 @@ maintenance_menu() {
     N_HELP="Check all modules but do not fix the internal state"
     D_HELP="Check and fix the dependency database of lunar"
     P_HELP="Prune old sources and install/compile logs"
-    
+    A_HELP="Change selected or select new alias mappings"
+
     COMMAND=`$DIALOG  --title "Maintenance Menu"                         \
                       --ok-label      "Select"                           \
                       --cancel-label  "Exit"                             \
@@ -443,16 +444,20 @@ maintenance_menu() {
                       "F"     "Fix everything"                 "$F_HELP" \
                       "N"     "Check everything but don't fix" "$N_HELP" \
                       "D"     "Fix dependencies"               "$D_HELP" \
-		      "P"     "Prune old sources and logs"     "$P_HELP"`
+                      "P"     "Prune old sources and logs"     "$P_HELP" \
+                      "A"     "Select or Change Aliases"       "$A_HELP"`
   do
     case $COMMAND in
      F)  lunar fix          ;;
      N)  lunar nofix        ;;
      D)  lunar fixdepends   ;;
      P)  lunar prune        ;;
+     A)  select_aliases     ;;
     esac
-    message "${MESSAGE_COLOR}Press enter to return...${DEFAULT_COLOR}"
-    read
+    if [ $COMMAND != "A" ] ; then
+      message "${MESSAGE_COLOR}Press enter to return...${DEFAULT_COLOR}"
+      read
+    fi
   done
 }
 
diff --git a/sbin/lvis b/sbin/lvis
index 92f369c..49a7ddf 100755
--- a/sbin/lvis
+++ b/sbin/lvis
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 ############################################################
 # Copyright 2001 by Kyle Sallee                            #
 ############################################################
diff --git a/var/lib/lunar/functions/config.lunar b/var/lib/lunar/functions/config.lunar
index 91e7e54..67f59af 100644
--- a/var/lib/lunar/functions/config.lunar
+++ b/var/lib/lunar/functions/config.lunar
@@ -20,49 +20,49 @@
 
 set_config()
 {
-  local LINE NEW
-  debug_msg "set_config ($@)"
+	local LINE NEW
+	debug_msg "set_config ($@)"
 
 	LINE=$(grep -w "$2=.*" $1)
-  if [ "$1" == "$LOCAL_CONFIG" ] ; then
-    NEW=$(printf "%16s=%s" "$2" "$3")
-  else
-    NEW="$2=\"$3\""
-  fi
-
-  # on-demand creation
-  if [ ! -f $1 ] ; then
-    touch $1
-  fi
-
-  lock_file $1 &&
-  if [ -n "$LINE" ] ; then
-    # make sure we escape those ':' characters:
-    LINE=$(echo $LINE | sed 's/:/\\:/g')
-    NEW=$(echo $NEW | sed 's/:/\\:/g')
-    sedit "s:$LINE:$NEW:" $1
-  else
-    echo "$NEW" >> $1
-  fi
-  unlock_file $1
+	if [ "$1" == "$LOCAL_CONFIG" ] ; then
+		NEW=$(printf "%16s=%s" "$2" "$3")
+	else
+		NEW="$2=\"$3\""
+	fi
+
+	# on-demand creation
+	if [ ! -f $1 ] ; then
+		touch $1
+	fi
+
+	lock_file $1 &&
+	if [ -n "$LINE" ] ; then
+		# make sure we escape those ':' characters:
+		LINE=$(echo $LINE | sed 's/:/\\:/g')
+		NEW=$(echo $NEW | sed 's/:/\\:/g')
+		sedit "s:$LINE:$NEW:" $1
+	else
+		echo "$NEW" >> $1
+	fi
+	unlock_file $1
 }
 
 
 unset_config()
 {
-  debug_msg "unset_config ($@)"
-  
-  # on-demand creation
-  if [ ! -f $1 ] ; then
-    touch $1
-  fi
-
-  lock_file $1 &&
-  if [ -n "$2" ] ; then
-    # make sure we escape those ':' characters:
-    sedit "/^[ ]*$2=/d" $1
-  fi
-  unlock_file $1
+	debug_msg "unset_config ($@)"
+
+	# on-demand creation
+	if [ ! -f $1 ] ; then
+		touch $1
+	fi
+
+	lock_file $1 &&
+	if [ -n "$2" ] ; then
+		# make sure we escape those ':' characters:
+		sedit "/^[ ]*$2=/d" $1
+	fi
+	unlock_file $1
 }
 
 
@@ -70,62 +70,62 @@ get_config()
 {
 	if [[ -f $1 ]] ; then
 		grep -w "$2=.*" $1 | cut -d= -f2- | sed -e 's/^"//' -e 's/"$//'
-  fi
+	fi
 }
 
 
 set_local_config()
 {
-  debug_msg "set_local_config ($@)"
-  set_config "$LOCAL_CONFIG" "$1" "$2"
+	debug_msg "set_local_config ($@)"
+	set_config "$LOCAL_CONFIG" "$1" "$2"
 }
 
 
 unset_local_config()
 {
-  debug_msg "unset_local_config ($@)"
-  unset_config "$LOCAL_CONFIG" "$1"
+	debug_msg "unset_local_config ($@)"
+	unset_config "$LOCAL_CONFIG" "$1"
 }
 
 
 get_local_config() {
-  get_config "$LOCAL_CONFIG" "$1"
+	get_config "$LOCAL_CONFIG" "$1"
 }
 
 
 set_module_config()
 {
-  debug_msg "set_module_config ($@)"
-  if [ -n "$MODULE" ] ; then
-    set_config "$DEPENDS_CONFIG/$MODULE" "$1" "$2"
-  fi
+	debug_msg "set_module_config ($@)"
+	if [ -n "$MODULE" ] ; then
+		set_config "$DEPENDS_CONFIG/$MODULE" "$1" "$2"
+	fi
 }
 
 
 unset_module_config()
 {
-  debug_msg "unset_module_config ($@)"
-  if [ -n "$MODULE" ] ; then
-    unset_config "$DEPENDS_CONFIG/$MODULE" "$1"
-  fi
+	debug_msg "unset_module_config ($@)"
+	if [ -n "$MODULE" ] ; then
+		unset_config "$DEPENDS_CONFIG/$MODULE" "$1"
+	fi
 }
 
 
 get_module_config()
 {
-  debug_msg "get_module_config ($@)"
-  if [ -n "$MODULE" ] ; then
-    get_config "$DEPENDS_CONFIG/$MODULE" "$1"
-  fi
+	debug_msg "get_module_config ($@)"
+	if [ -n "$MODULE" ] ; then
+		get_config "$DEPENDS_CONFIG/$MODULE" "$1"
+	fi
 }
 
 
 get_other_module_config()
 {
-  debug_msg "get_other_module_config ($@)"
-  if [ -n "$1" ] ; then
-    get_config "$DEPENDS_CONFIG/$1" "$2"
-  fi
+	debug_msg "get_other_module_config ($@)"
+	if [ -n "$1" ] ; then
+		get_config "$DEPENDS_CONFIG/$1" "$2"
+	fi
 }
 
 
diff --git a/var/lib/lunar/functions/depends.lunar b/var/lib/lunar/functions/depends.lunar
index e6f3a25..1cc886b 100644
--- a/var/lib/lunar/functions/depends.lunar
+++ b/var/lib/lunar/functions/depends.lunar
@@ -21,7 +21,7 @@
 ############################################################
 
 
-# function : find_depends 
+# function : find_depends
 # usage    : find_depends "module name"
 # purpose  : recursive dependency finder, no need to be installed
 function find_depends() {
diff --git a/var/lib/lunar/functions/download.lunar b/var/lib/lunar/functions/download.lunar
index f3c6b19..ba16417 100644
--- a/var/lib/lunar/functions/download.lunar
+++ b/var/lib/lunar/functions/download.lunar
@@ -84,13 +84,13 @@ download_module() {
 				break
 			fi
 		fi
-		
+
 		# silly that this exists:
 		if [ "$CLEAR_CACHE" == "on" ] ; then
 			verbose_msg "clearing source cache copy of \"$SRC\""
 			rm -f $SOURCE_CACHE/$SRC 2>/dev/null
 		fi
-		
+
 		add_url() {
 			if [ -n "$1" ]; then
 				if ! echo " $ALL_URLS " | grep -q " $1 "; then
@@ -98,54 +98,63 @@ download_module() {
 				fi
 			fi
 		}
-		
-		if plugin_call SOURCE_NEEDREFRESH ${URLS[0]} $SRC $SOURCE_CACHE || [ ! -f $SOURCE_CACHE/$SRC ] ; then
-			# check for cache?
-			message "${MESSAGE_COLOR}Downloading source file" \
-				"${FILE_COLOR}$SRC${DEFAULT_COLOR}" \
-				"${MESSAGE_COLOR}for module" \
-				"${MODULE_COLOR}${MODULE}${DEFAULT_COLOR}"
-
-		    if [ -n "$BASE_URL" ] ; then
-				# in case -u was passed:
-		        ALL_URLS=$BASE_URL
-			else
-				# compose a list of URLS
-				ALL_URLS=
-				add_url $FRESORT_URL
-				for URL in $URLS ; do
-					add_url $URL
-					if [ "$EXHAUSTIVE" == "on" ]; then
-						# scan for hits against known clusters of mirrors
-						for MLIST in $MIRRORS/*; do
-							for ALT in $(sed 's/.*\t\([^\t]*\)$/\1/g' $MLIST | grep -v "^Custom$"); do
-								if [ "${URL:0:${#ALT}}" == "$ALT" ] ; then
-									# compose the list of valid mirrors
-									REST=${URL:${#ALT}}
-									for HIT in $(sed 's/.*\t\([^\t]*\)$/\1/g' $MLIST); do
-										add_url ${HIT}${REST}
-									done
-								fi
-							done
-						done
-					fi
-				done
-				add_url $LRESORT_URL
-			fi
 
-			for URL in $ALL_URLS; do
-				# and download
-				if download_url $URL $SRC $SOURCE_CACHE ; then
-					break
-				fi
-			done
-		else
+		if ! plugin_call SOURCE_NEEDREFRESH ${URLS[0]} $SRC $SOURCE_CACHE && [ -f $SOURCE_CACHE/$SRC ] ; then
 			# break out of the loop if the cache has it:
 			verbose_msg "Skipping download of \"$SRC\" (in cache)"
 			continue
 		fi
+
+		# check for cache?
+		message "${MESSAGE_COLOR}Downloading source file" \
+			"${FILE_COLOR}$SRC${DEFAULT_COLOR}" \
+			"${MESSAGE_COLOR}for module" \
+			"${MODULE_COLOR}${MODULE}${DEFAULT_COLOR}"
+
+		if [ -n "$BASE_URL" ] ; then
+			# in case -u was passed:
+			ALL_URLS=$BASE_URL
+		else
+			# compose a list of URLS
+			ALL_URLS=
+			add_url $FRESORT_URL
+			for URL in $URLS ; do
+				add_url $URL
+				if [ "$EXHAUSTIVE" != "on" ]; then
+					continue
+				fi
+
+				# scan for hits against known clusters of mirrors
+				for MLIST in $MIRRORS/*; do
+					for ALT in $(sed 's/.*\t\([^\t]*\)$/\1/g' $MLIST | grep -v "^Custom$"); do
+						if [ "${URL:0:${#ALT}}" == "$ALT" ] ; then
+							# compose the list of valid mirrors
+							REST=${URL:${#ALT}}
+							for HIT in $(sed 's/.*\t\([^\t]*\)$/\1/g' $MLIST); do
+								add_url ${HIT}${REST}
+							done
+						fi
+					done
+				done
+			done
+			add_url $LRESORT_URL
+		fi
+
+		for URL in $ALL_URLS; do
+			# and download
+			if download_url $URL $SRC $SOURCE_CACHE ; then
+				# done for this file!
+				FAILED=1
+				break
+			fi
+		done
+		if [ ${FAILED:-0} == 0 ] ; then
+			FAILALL=1
+		fi
+
 	done
-) 
+	return ${FAILALL:-0}
+)
 }
 
 
diff --git a/var/lib/lunar/functions/modules.lunar b/var/lib/lunar/functions/modules.lunar
index 30d7c86..00824b6 100644
--- a/var/lib/lunar/functions/modules.lunar
+++ b/var/lib/lunar/functions/modules.lunar
@@ -280,7 +280,7 @@ run_module_file() {
 		. $SCRIPT_DIRECTORY/$2.$PLATFORM
 	elif [[ -e "$SCRIPT_DIRECTORY/$2" ]]; then
 		. $SCRIPT_DIRECTORY/$2
-	fi    
+	fi
 }
 
 
@@ -297,7 +297,7 @@ module_installed()
 # usage    : module_held $MODULE
 # purpose  : check if $MODULE is held
 module_held() {
-  debug_msg "module_held ($@)"
+	debug_msg "module_held ($@)"
 	grep -q "^$1:[[:digit:]]*:held:" $MODULE_STATUS
 }
 
diff --git a/var/lib/lunar/menu/alias.menu b/var/lib/lunar/menu/alias.menu
new file mode 100644
index 0000000..3760d1b
--- /dev/null
+++ b/var/lib/lunar/menu/alias.menu
@@ -0,0 +1,85 @@
+############################################################
+#                                                          #
+# This code is written for Lunar Linux, see                #
+# http://lunar-linux.org                                   #
+#                                                          #
+############################################################
+#                                                          #
+# Copyright 2007 (c) GPLv2 - Auke Kok                      #
+#                                                          #
+############################################################
+
+
+alias_menu_list_aliases()
+{
+	for A in `cut -d: -f1 $MOONBASE/aliases`; do
+		echo ${A:1}
+		CHOICE=$(get_local_config `echo LUNAR_ALIAS_${A:1}`)
+		if [ -n "$CHOICE" ] ; then
+			echo "$CHOICE"
+		else
+			echo "[unset]"
+		fi
+	done
+}
+
+
+alias_menu_list_alias_choices()
+{
+	echo "None"
+	echo "None"
+	if [ -z "$(get_local_config `echo LUNAR_ALIAS_$1`)" ] ; then
+		echo "on"
+	else
+		echo "off"
+	fi
+	IFS=$STANDARD_IFS
+	for C in `grep "^%$1:" $MOONBASE/aliases | cut -d: -f2`; do
+		echo "$C"
+		echo "$C"
+		if [ $(get_local_config `echo LUNAR_ALIAS_$1`) == "$C" ] ; then
+			echo "on"
+		else
+			echo "off"
+		fi
+	done
+}
+
+
+select_aliases()
+{
+	export IFS=$ENTER_IFS
+
+	while true ; do
+		DEFAULT=${CHOICE}
+		CHOICE=`$DIALOG --title "Select Lunar Aliases" \
+		                --ok-label "Select" \
+		                --cancel-label "Close" \
+		                --default-item "$DEFAULT" \
+		                --menu "" 0 0 0 \
+		                $(alias_menu_list_aliases)`
+		if [ $? != 0 ]; then
+			return
+		fi
+
+		# modify an alias
+		DEFAULT=$(get_local_config `echo LUNAR_ALIAS_$CHOICE`)
+		if [ -z "$DEFAULT" ] ; then
+			DEFAULT="None"
+		fi
+		ACHOICE=`$DIALOG --title "Select Lunar Aliases" \
+		                 --ok-label "Select" \
+		                 --cancel-label "Close" \
+		                 --default-item "$DEFAULT" \
+		                 --radiolist "" 0 0 0 \
+		                 $(alias_menu_list_alias_choices $CHOICE)`
+		if [ $? == 0 ]; then
+			# modify it
+			if [ "$ACHOICE" != "None" ] ; then
+				set_local_config `echo LUNAR_ALIAS_$CHOICE` "$ACHOICE"
+			else
+				unset_local_config `echo LUNAR_ALIAS_$CHOICE`
+			fi
+		fi
+	done
+}
diff --git a/var/lib/lunar/plugins/download-generic.plugin b/var/lib/lunar/plugins/download-generic.plugin
index 65ff793..298a611 100644
--- a/var/lib/lunar/plugins/download-generic.plugin
+++ b/var/lib/lunar/plugins/download-generic.plugin
@@ -67,12 +67,12 @@ plugin_source_download_generic()  {
       verbose_msg "download of \"$2\" successful"
     else
       rm -f $TMP_FILE
-	  return 1
+      return 1
     fi
   else
     # don't report errors against cache misses
     if [ "$URL" != "$LRESORT_URL/" ]; then
-    activity_log "lget" "$MODULE" "$VERSION" "failed" "broken URL: \"$URL$2\""
+      activity_log "lget" "$MODULE" "$VERSION" "failed" "broken URL: \"$URL$2\""
     fi
     return 1
   fi


More information about the Lunar-commits mailing list