From 8f79f92a88a7a87f2b64ed9d84581ea84d12a4fa Mon Sep 17 00:00:00 2001 From: steve Date: Thu, 19 Oct 2006 17:04:18 +0000 Subject: [PATCH] 2006-10-19 17:04:17 by steve Portability fixups for using a non-bash shell. Patches from Eric Lemoine. --- AUTHORS | 1 + hooks/centos4/40-setup-networking | 4 ++-- hooks/centos4/50-setup-hostname | 4 ++-- hooks/common.sh | 21 +++++++++++++-------- hooks/debian/40-setup-networking | 6 +++--- hooks/debian/50-setup-hostname | 4 ++-- hooks/gentoo/40-setup-networking | 6 +++--- hooks/gentoo/50-setup-hostname | 4 ++-- hooks/ubuntu/40-setup-networking | 8 ++++---- hooks/ubuntu/50-setup-hostname | 4 ++-- 10 files changed, 34 insertions(+), 28 deletions(-) diff --git a/AUTHORS b/AUTHORS index 082dd78..677e2fd 100644 --- a/AUTHORS +++ b/AUTHORS @@ -28,6 +28,7 @@ Contributions Eric Lemoine < - Improved binary detection and good suggestions. + - Better portability for non-bash shells. Radu Spineanu - Supplied many small tweaks, bugfixes, and suggestions. diff --git a/hooks/centos4/40-setup-networking b/hooks/centos4/40-setup-networking index 4cfbc57..02f59c4 100755 --- a/hooks/centos4/40-setup-networking +++ b/hooks/centos4/40-setup-networking @@ -35,7 +35,7 @@ mkdir -p ${prefix}/etc/sysconfig/network-scripts/ # # Test for static vs. DHCP # -if [[ -z "${dhcp}" ]]; then +if [ -z "${dhcp}" ]; then # # Setup the initial interface @@ -95,4 +95,4 @@ EOF # # Log our finish # -logMessage Script $0 finished \ No newline at end of file +logMessage Script $0 finished diff --git a/hooks/centos4/50-setup-hostname b/hooks/centos4/50-setup-hostname index 7c10f8f..6c03aa2 100755 --- a/hooks/centos4/50-setup-hostname +++ b/hooks/centos4/50-setup-hostname @@ -39,7 +39,7 @@ echo ${hostname} > ${prefix}/etc/mailname # Fixup the /etc/hosts file upon the new image for # machines with static IPs # -if [[ -z "${dhcp}" ]]; then +if [ -z "${dhcp}" ]; then # Non-IPv6 stuff. grep -v '\(::\|IPv6\)' /etc/hosts > ${prefix}/etc/hosts @@ -56,7 +56,7 @@ fi # # Allow the host system to know the IP address of our new guest. # -if [[ -z "${dhcp}" ]]; then +if [ -z "${dhcp}" ]; then if ( grep ${hostname} /etc/hosts > /dev/null ) ; then diff --git a/hooks/common.sh b/hooks/common.sh index e431241..d577687 100644 --- a/hooks/common.sh +++ b/hooks/common.sh @@ -16,7 +16,7 @@ # # If we're running verbosely show a message, otherwise swallow it. # -function logMessage +logMessage () { message="$*" @@ -35,10 +35,15 @@ function logMessage # assert () { - line=$1; - shift; + lineno="?" - if ! [ $* ] ; then + if [ -n "${LINENO}" ]; then + # our shell defines variable LINENO, great! + lineno=$1 + shift + fi + + if [ ! $* ] ; then echo "assert failed: $0:$lineno [$*]" exit fi @@ -48,7 +53,7 @@ assert () # # Install a Debian package via apt-get. # -function installDebianPackage +installDebianPackage () { prefix=$1 package=$2 @@ -81,7 +86,7 @@ function installDebianPackage # # Remove a Debian package. # -function removeDebianPackage +removeDebianPackage () { prefix=$1 package=$2 @@ -113,7 +118,7 @@ function removeDebianPackage # # Install a CentOS4 package via yum # -function installCentOS4Package +installCentOS4Package () { prefix=$1 package=$2 @@ -146,7 +151,7 @@ function installCentOS4Package # # TODO: STUB # -function installGentooPackage +installGentooPackage () { prefix=$1 package=$2 diff --git a/hooks/debian/40-setup-networking b/hooks/debian/40-setup-networking index 7f9e279..8dd944e 100755 --- a/hooks/debian/40-setup-networking +++ b/hooks/debian/40-setup-networking @@ -35,7 +35,7 @@ mkdir -p ${prefix}/etc/network # # A function to setup DHCP for our new image. # -function setupDynamicNetworking +setupDynamicNetworking () { # # The host is using DHCP. @@ -65,7 +65,7 @@ E_O_DHCP # # A function to setup static IP addresses for our new image. # -function setupStaticNetworking +setupStaticNetworking () { # # if $p2p is set then add a "pointtopoint" setting. @@ -131,7 +131,7 @@ E_O_STATIC # # Call the relevant function # -if [[ -z "${dhcp}" ]]; then +if [ -z "${dhcp}" ]; then logMessage "Setting up static networking" setupStaticNetworking diff --git a/hooks/debian/50-setup-hostname b/hooks/debian/50-setup-hostname index ed21768..3e1a565 100755 --- a/hooks/debian/50-setup-hostname +++ b/hooks/debian/50-setup-hostname @@ -39,7 +39,7 @@ echo ${hostname} > ${prefix}/etc/mailname # Fixup the /etc/hosts file upon the new image for # machines with static IPs # -if [[ -z "${dhcp}" ]]; then +if [ -z "${dhcp}" ]; then # Non-IPv6 stuff. grep -v '\(::\|IPv6\)' /etc/hosts > ${prefix}/etc/hosts @@ -56,7 +56,7 @@ fi # # Allow the host system to know the IP address of our new guest. # -if [[ -z "${dhcp}" ]]; then +if [ -z "${dhcp}" ]; then if ( grep ${hostname} /etc/hosts > /dev/null ) ; then diff --git a/hooks/gentoo/40-setup-networking b/hooks/gentoo/40-setup-networking index fa337d2..0d9c5c0 100755 --- a/hooks/gentoo/40-setup-networking +++ b/hooks/gentoo/40-setup-networking @@ -34,7 +34,7 @@ mkdir -p ${prefix}/etc/conf.d # # A function to setup DHCP for our new image. # -function setupDynamicNetworking +setupDynamicNetworking () { # # The host is using DHCP. @@ -55,7 +55,7 @@ E_O_DHCP # # A function to setup static IP addresses for our new image. # -function setupStaticNetworking +setupStaticNetworking () { # # if $p2p is set then add a "pointtopoint" setting. @@ -104,7 +104,7 @@ E_O_STATIC # # Call the relevant function # -if [[ -z "${dhcp}" ]]; then +if [ -z "${dhcp}" ]; then logMessage "Setting up static networking" setupStaticNetworking diff --git a/hooks/gentoo/50-setup-hostname b/hooks/gentoo/50-setup-hostname index 1991ba5..abaa216 100755 --- a/hooks/gentoo/50-setup-hostname +++ b/hooks/gentoo/50-setup-hostname @@ -46,7 +46,7 @@ echo DNSDOMAIN=\"${domain}\" >> ${prefix}/etc/conf.d/domainname # Fixup the /etc/hosts file upon the new image for # machines with static IPs # -if [[ -z "${dhcp}" ]]; then +if [ -z "${dhcp}" ]; then # Non-IPv6 stuff. grep -v '\(::\|IPv6\)' /etc/hosts > ${prefix}/etc/hosts @@ -63,7 +63,7 @@ fi # # Allow the host system to know the IP address of our new guest. # -if [[ -z "${dhcp}" ]]; then +if [ -z "${dhcp}" ]; then if ( grep ${hostname} /etc/hosts > /dev/null ) ; then diff --git a/hooks/ubuntu/40-setup-networking b/hooks/ubuntu/40-setup-networking index 821927e..eb51a40 100755 --- a/hooks/ubuntu/40-setup-networking +++ b/hooks/ubuntu/40-setup-networking @@ -35,7 +35,7 @@ mkdir -p ${prefix}/etc/network # # A function to setup DHCP for our new image. # -function setupDynamicNetworking +setupDynamicNetworking () { # # The host is using DHCP. @@ -65,7 +65,7 @@ E_O_DHCP # # A function to setup static IP addresses for our new image. # -function setupStaticNetworking +setupStaticNetworking () { # # We have a static IP address @@ -120,7 +120,7 @@ E_O_STATIC # # Call the relevant function # -if [[ -z "${dhcp}" ]]; then +if [ -z "${dhcp}" ]; then logMessage "Setting up static networking" setupStaticNetworking @@ -133,4 +133,4 @@ fi # # Log our finish # -logMessage Script $0 finished \ No newline at end of file +logMessage Script $0 finished diff --git a/hooks/ubuntu/50-setup-hostname b/hooks/ubuntu/50-setup-hostname index ed21768..3e1a565 100755 --- a/hooks/ubuntu/50-setup-hostname +++ b/hooks/ubuntu/50-setup-hostname @@ -39,7 +39,7 @@ echo ${hostname} > ${prefix}/etc/mailname # Fixup the /etc/hosts file upon the new image for # machines with static IPs # -if [[ -z "${dhcp}" ]]; then +if [ -z "${dhcp}" ]; then # Non-IPv6 stuff. grep -v '\(::\|IPv6\)' /etc/hosts > ${prefix}/etc/hosts @@ -56,7 +56,7 @@ fi # # Allow the host system to know the IP address of our new guest. # -if [[ -z "${dhcp}" ]]; then +if [ -z "${dhcp}" ]; then if ( grep ${hostname} /etc/hosts > /dev/null ) ; then