[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH] Re: d-l: please warn on missing files specified by lh_config



On Sun, Nov 04, 2007 at 01:22:01PM -0500, Justin Pryzby wrote:

>  . the abundant commandline parameters can be handled together with
>    "eval".  Some of them should be separate (eg. when the argument is
>    a file and its existence can be checked).  If it's agreed that this
>    is a change in the right direction I can provide further patches
>    which can be expected to considerably reduce rather than increase
>    the code size.
Attached is a patch against current GIT effecting substation reduction
in the size of argument parsing code.
-------------- next part --------------
--- /tmp/lh_config	2007-11-05 00:28:57.000000000 -0500
+++ /usr/bin/lh_config	2007-11-05 00:42:23.000000000 -0500
@@ -19,7 +19,6 @@
 
 # Setting static variables
 DESCRIPTION="create configuration for live-helper(7)"
-HELP="FIXME"
 USAGE="${PROGRAM} [--apt apt|aptitude]\n\
 \t    [--apt-ftp-proxy URL]\n\
 \t    [--apt-http-proxy URL]\n\
@@ -105,6 +104,23 @@
 \t    [--username NAME]\n\
 \t    [--verbose]"
 
+# Set LH_$1=$2.
+doarg2 ()
+{
+	a=`echo "${1#--}" |
+		tr '[[:lower:]]' '[[:upper:]]' |
+		tr '-' '_'`
+	eval "LH_$a=$2"
+}
+
+# Set LH_$1=$2 and conditionally warn about nonexistence of $2.
+doargf ()
+{
+	doarg2 "$@"
+	[ -f "$2" ] && return
+	echo "$0: warning: $2 doesn't exist" >&2
+}
+
 Local_arguments ()
 {
 	ARGUMENTS="$(getopt --longoptions apt:,apt-ftp-proxy:,apt-http-proxy:,apt-pdiffs:,apt-pipeline:,apt-recommends:,apt-secure:,bootstrap:,cache:,cache-indices:,cache-packages:,cache-stages:,debconf-frontend:,debconf-nowarnings:,debconf-priority:,genisoimage:,initramfs:,losetup:,mode:,root-command:,tasksel:,includes:,templates:,architecture:,bootstrap-config:,bootstrap-flavour:,bootstrap-keyring:,distribution:,mirror-bootstrap:,mirror-bootstrap-security:,mirror-binary:,mirror-binary-security:,sections:,chroot-filesystem:,union-filesystem:,exposed-root:,hooks:,interactive:,keyring-packages:,language:,linux-flavours:,linux-packages:,packages:,packages-lists:,tasks:,security:,symlinks:,sysvinit:,binary-images:,binary-indices:,bootappend-install:,bootappend-live:,bootloader:,chroot-build:,debian-installer:,debian-installer-daily:,encryption:,grub-splash:,hostname:,iso-application:,iso-preparer:,iso-publisher:,iso-volume:,memtest:,net-root-filesystem:,net-root-mountoptions:,net-root-path:,net-root-server:,net-cow-filesystem:,net-cow-mountoptions:,net-cow-path:,net-cow-server:,syslinux-splash:,syslinux-timeout:,syslinux-menu:,username:,source:,source-images:,breakpoints,conffile:,debug,force,help,quiet,usage,verbose,version --name=${PROGRAM} --options a:f:d:m:l:k:p:b:e:s:c:huv --shell sh -- "${@}")"
@@ -119,475 +135,205 @@
 
 	while true
 	do
+		arg=$1
 		case "${1}" in
 			# config/common
-			--apt)
-				LH_APT="${2}"
-				shift 2
-				;;
-
-			--apt-ftp-proxy)
-				LH_APT_FTP_PROXY="${2}"
-				shift 2
-				;;
-
-			--apt-http-proxy)
-				LH_APT_HTTP_PROXY="${2}"
-				shift 2
-				;;
-
-			--apt-pdiffs)
-				LH_APT_PDIFFS="${2}"
-				shift 2
-				;;
-
-			--apt-pipeline)
-				LH_APT_PIPELINE="${2}"
-				shift 2
-				;;
-
-			--apt-recommends)
-				LH_APT_RECOMMENDS="${2}"
-				shift 2
-				;;
-
-			--apt-secure)
-				LH_APT_SECURE="${2}"
-				shift 2
-				;;
-
-			--bootstrap)
-				LH_BOOTSTRAP="${2}"
-				shift 2
-				;;
-
-			--cache)
-				LH_CACHE="${2}"
-				shift 2
-				;;
-
-			--cache-indices)
-				LH_CACHE_INDICES="${2}"
-				shift 2
-				;;
-
-			--cache-packages)
-				LH_CACHE_PACKAGES="${2}"
-				shift 2
-				;;
-
-			--cache-stages)
-				LH_CACHE_STAGES="${2}"
-				shift 2
-				;;
-
-			--debconf-frontend)
-				LH_DEBCONF_FRONTEND="${2}"
-				shift 2
-				;;
-
-			--debconf-nowarnings)
-				LH_DEBCONF_NOWARNINGS="${2}"
-				shift 2
-				;;
-
-			--debconf-priority)
-				LH_DEBCONF_PRIORITY="${2}"
-				shift 2
-				;;
-
-			--initramfs)
-				LH_INITRAMFS="${2}"
-				shift 2
-				;;
-
-			--losetup)
-				LH_LOSETUP="${2}"
-				shift 2
-				;;
-
-			--mode)
-				LH_MODE="${2}"
-				shift 2
-				;;
-
-			--root-command)
-				LH_ROOT_COMMAND="${2}"
-				shift 2
-				;;
-
-			--tasksel)
-				LH_TASKSEL="${2}"
-				shift 2
+			--apt|--apt-ftp-proxy|--apt-http-proxy)
+				doarg2 "$1" "$2"
+				shift
 				;;
 
-			--includes)
-				LH_INCLUDES="${2}"
-				shift 2
+			--apt-pdiffs|--apt-pipeline|--apt-recommends)
+				doarg2 "$@"
+				shift
 				;;
 
-			--templates)
-				LH_TEMPLATES="${2}"
-				shift 2
+			--apt-secure|--bootstrap)
+				doarg2 "$@"
+				shift
 				;;
 
-			--breakpoints)
-				LH_BREAKPOINTS="enabled"
+			--cache|--cache-indices|--cache-packages|--cache-stages)
+				doarg2 "$@"
 				shift
 				;;
 
-			--debug)
-				LH_DEBUG="enabled"
+			--debconf-frontend|--debconf-nowarnings|--debconf-priority)
+				doarg2 "$@"
 				shift
 				;;
 
-			--force)
-				LH_FORCE="enabled"
+			--initramfs|--losetup|--mode|--root-command|--tasksel)
+				doarg2 "$@"
 				shift
 				;;
 
-			--quiet)
-				LH_QUIET="enabled"
+			--includes|--templates)
+				doarg2 "$@"
 				shift
 				;;
 
-			--verbose)
-				LH_VERBOSE="enabled"
-				shift
+			--breakpoints|--debug|--force|--quiet|--verbose)
+				doarg2 "$1" enabled
 				;;
 
 			-v|--version)
 			 	Version
-				shift
 				;;
 
 			# config/bootstrap
 			-a|--architecture)
 				LH_ARCHITECTURE="${2}"
-				shift 2
+				shift
 				;;
 
 			--bootstrap-config)
-				LH_BOOTSTRAP_CONFIG="${2}"
-				shift 2
+				doargf "$@"
+				shift
 				;;
 
-			-f|--bootstrap-flavour)
-				LH_BOOTSTRAP_FLAVOUR="${2}"
-				shift 2
+			--bootstrap-keyring|--sections)
+				doarg2 "$@"
+				shift
 				;;
 
-			--bootstrap-keyring)
-				LH_BOOTSTRAP_KEYRING="${2}"
-				shift 2
+			-f|--bootstrap-flavour)
+				LH_BOOTSTRAP_FLAVOUR="${2}"
+				shift
 				;;
 
 			-d|--distribution)
 				LH_DISTRIBUTION="${2}"
-				shift 2
+				shift
 				;;
 
 			-m|--mirror-bootstrap)
 				LH_MIRROR_BOOTSTRAP="${2}"
-				shift 2
-				;;
-
-			--mirror-bootstrap-security)
-				LH_MIRROR_BOOTSTRAP_SECURITY="${2}"
-				shift 2
-				;;
-
-			--mirror-binary)
-				LH_MIRROR_BINARY="${2}"
-				shift 2
-				;;
-
-			--mirror-binary-security)
-				LH_MIRROR_BINARY_SECURITY="${2}"
-				shift 2
+				shift
 				;;
 
-			--sections)
-				LH_SECTIONS="${2}"
-				shift 2
+			--mirror-bootstrap-security|--mirror-binary|--mirror-binary-security)
+				doarg2 "$@"
+				shift
 				;;
 
 			# config/chroot
-			--chroot-filesystem)
-				LH_CHROOT_FILESYSTEM="${2}"
-				shift 2
-				;;
-
-			--union-filesystem)
-				LH_UNION_FILESYSTEM="${2}"
-				shift 2
-				;;
-
-			--exposed-root)
-				LH_EXPOSED_ROOT="${2}"
-				shift 2
-				;;
-
-			--hooks)
-				LH_HOOKS="${2}"
-				shift 2
-				;;
-
-			--interactive)
-				LH_INTERACTIVE="${2}"
-				shift 2
+			--chroot-filesystem|--union-filesystem|--exposed-root)
+				doarg2 "$@"
+				shift
 				;;
 
-			--keyring-packages)
-				LH_KEYRING_PACKAGES="${2}"
-				shift 2
+			--interactive|--keyring-packages)
+				doarg2 "$@"
+				shift
 				;;
 
 			-l|--language)
 				LH_LANGUAGE="${2}"
-				shift 2
+				shift
 				;;
 
 			-k|--linux-flavours)
 				LH_LINUX_FLAVOURS="${2}"
-				shift 2
-				;;
-
-			--linux-packages)
-				LH_LINUX_PACKAGES="${2}"
-				shift 2
+				shift
 				;;
 
-			--packages)
-				LH_PACKAGES="${2}"
-				shift 2
+			--linux-packages|--packages|--tasks|--security|--symlinks|--sysvinit)
+				doarg2 "$@"
+				shift
 				;;
 
 			-p|--packages-lists)
 				LH_PACKAGES_LISTS="${2}"
-				shift 2
-				;;
-
-			--tasks)
-				LH_TASKS="${2}"
-				shift 2
-				;;
-
-			--security)
-				LH_SECURITY="${2}"
-				shift 2
-				;;
-
-			--symlinks)
-				LH_SYMLINKS="${2}"
-				shift 2
-				;;
-
-			--sysvinit)
-				LH_SYSVINIT="${2}"
-				shift 2
+				shift
 				;;
 
 			# config/binary
 			-b|--binary-images)
 				LH_BINARY_IMAGES="${2}"
-				shift 2
-				;;
-
-			--binary-indices)
-				LH_BINARY_INDICES="${2}"
-				shift 2
-				;;
-
-			--bootappend-live)
-				LH_BOOTAPPEND_LIVE="${2}"
-				shift 2
-				;;
-
-			--bootappend-install)
-				LH_BOOTAPPEND_INSTALL="${2}"
-				shift 2
-				;;
-
-			--bootloader)
-				LH_BOOTLOADER="${2}"
-				shift 2
-				;;
-
-			--chroot-build)
-				LH_CHROOT_BUILD="${2}"
-				shift 2
+				shift
 				;;
 
-			--debian-installer)
-				LH_DEBIAN_INSTALLER="${2}"
-				shift 2
+			--binary-indices|--bootappend-live|--bootappend-install)
+				doarg2 "$@"
+				shift
 				;;
 
-			--debian-installer-daily)
-				LH_DEBIAN_INSTALLER_DAILY="${2}"
-				shift 2
+			--bootloader|--chroot-build|--debian-installer|--debian-installer-daily)
+				doarg2 "$@"
+				shift
 				;;
 
 			-e|--encryption)
 				LH_ENCRYPTION="${2}"
-				shift 2
-				;;
-
-			--grub-splash)
-				LH_GRUB_SPLASH="${2}"
-				shift 2
-				;;
-
-			--hostname)
-				LH_HOSTNAME="${2}"
-				shift 2
-				;;
-
-			--iso-application)
-				LH_ISO_APPLICATION="${2}"
-				shift 2
-				;;
-
-			--iso-preparer)
-				LH_ISO_PREPARER="${2}"
-				shift 2
-				;;
-
-			--iso-publisher)
-				LH_ISO_PUBLISHER="${2}"
-				shift 2
-				;;
-
-			--iso-volume)
-				LH_ISO_VOLUME="${2}"
-				shift 2
-				;;
-
-			--memtest)
-				LH_MEMTEST="${2}"
-				shift 2
-				;;
-
-			--net-root-filesystem)
-				LH_NET_ROOT_FILESYSTEM="${2}"
-				shift 2
-				;;
-
-			--net-root-mountoptions)
-				LH_NET_ROOT_MOUNTOPTIONS="${2}"
-				shift 2
+				shift
 				;;
 
-			--net-root-path)
-				LH_NET_ROOT_PATH="${2}"
-				shift 2
+			--grub-splash|--hooks)
+				doargf "$@"
+				shift
 				;;
 
-			--net-root-server)
-				LH_NET_ROOT_SERVER="${2}"
-				shift 2
+			--hostname|--memtest|--username)
+				doarg2 "$@"
+				shift
 				;;
 
-			--net-cow-filesystem)
-				LH_NET_COW_FILESYSTEM="${2}"
-				shift 2
+			--iso-application|--iso-preparer|--iso-publisher|--iso-volume)
+				doarg2 "$@"
+				shift
 				;;
-
-			--net-cow-mountoptions)
-				LH_NET_COW_MOUNTOPTIONS="${2}"
-				shift 2
+			
+			--net-root-filesystem|--net-root-mountoptions)
+				doarg2 "$@"
+				shift
 				;;
 
-			--net-cow-path)
-				LH_NET_COW_PATH="${2}"
-				shift 2
+			--net-root-path|--net-root-server|--net-cow-filesystem)
+				doarg2 "$@"
+				shift
 				;;
 
-			--net-cow-server)
-				LH_NET_COW_SERVER="${2}"
-				shift 2
+			--net-cow-mountoptions|--net-cow-path|--net-cow-server)
+				doarg2 "$@"
+				shift
 				;;
 
 			--syslinux-splash)
-				LH_SYSLINUX_SPLASH="${2}"
-				shift 2
-				;;
-
-			--syslinux-timeout)
-				LH_SYSLINUX_TIMEOUT="${2}"
-				shift 2
-				;;
-
-			--syslinux-menu)
-				LH_SYSLINUX_MENU="${2}"
-				shift 2
+				doargf "$@"
+				shift
 				;;
 
-			--username)
-				LH_USERNAME="${2}"
-				shift 2
+			--syslinux-timeout|--syslinux-menu)
+				doarg2 "$@"
+				shift
 				;;
 
 			# config/source
 			--source)
 				LH_SOURCE="${2}"
-				shift 2
+				shift
 				;;
 
 			-s|--source-images)
 				LH_SOURCE_IMAGES="${2}"
-				shift 2
-				;;
-
-			# other
-			--breakpoints)
-				LH_BREAKPOINTS="enabled"
 				shift
 				;;
 
 			-c|--conffile)
 				LH_CONFFILE="${2}"
-				shift 2
-				;;
-
-			--debug)
-				LH_DEBUG="enabled"
-				shift
-				;;
-
-			--force)
-				LH_FORCE="enabled"
 				shift
 				;;
 
 			-h|--help)
 				Help
-				shift
-				;;
-
-			--quiet)
-				LH_QUIET="enabled"
-				shift
 				;;
 
 			-u|--usage)
 				Usage
-				shift
-				;;
-
-			--verbose)
-				LH_VERBOSE="enabled"
-				shift
-				;;
-
-			-v|--version)
-				Version
-				shift
 				;;
 
 			--)
-				shift
 				break
 				;;
 
@@ -596,6 +342,11 @@
 				exit 1
 				;;
 		esac
+
+		shift || {
+			echo "$0: error: option requires an argument: $arg"
+			exit 2
+		} >&2
 	done
 }
 


Reply to: