[32702] branches/release_1_6/base/portmgr/dmg/postflight

jmpp at macports.org jmpp at macports.org
Fri Jan 11 09:20:09 PST 2008


Revision: 32702
          http://trac.macosforge.org/projects/macports/changeset/32702
Author:   jmpp at macports.org
Date:     2008-01-11 09:20:07 -0800 (Fri, 11 Jan 2008)

Log Message:
-----------

Protect all script variables with {} to be extra careful, we don't want this script failing over silly mistakes while we're tweaking users' shell configuration files.
I know this is unnecessary in many of the instances I'm taking into consideration with this commit, but in that case consider it a matter of policy.

Modified Paths:
--------------
    branches/release_1_6/base/portmgr/dmg/postflight

Modified: branches/release_1_6/base/portmgr/dmg/postflight
===================================================================
--- branches/release_1_6/base/portmgr/dmg/postflight	2008-01-11 17:09:43 UTC (rev 32701)
+++ branches/release_1_6/base/portmgr/dmg/postflight	2008-01-11 17:20:07 UTC (rev 32702)
@@ -53,58 +53,58 @@
 }
 
 # Through this command we write an environment variable to an appropriate shell configuration file,
-# backing up the original only if it exists and if it doesn't contain the $OUR_STRING identification string,
+# backing up the original only if it exists and if it doesn't contain the ${OUR_STRING} identification string,
 # which hints that we've already tweaked it and therefore already baked it up.
 function write_setting () {
-    if [ -f $HOME/.$CONF_FILE ] && ! grep "$OUR_STRING" $HOME/.$CONF_FILE > /dev/null 2>&1; then
-        /bin/cp -fp $HOME/.$CONF_FILE "$HOME/.$CONF_FILE.$BACKUP_SUFFIX" || {
+    if [ -f ${HOME}/.${CONF_FILE} ] && ! grep "${OUR_STRING}" ${HOME}/.${CONF_FILE} > /dev/null 2>&1; then
+        /bin/cp -fp ${HOME}/.${CONF_FILE} "${HOME}/.${CONF_FILE}.${BACKUP_SUFFIX}" || {
             echo "An attempt to backup your original configuration file failed! Please set your MacPorts compatible environment manually."
             update_macports
             exit 1
         }
-        echo -e "\n##\n# Your previous $HOME/.$CONF_FILE file was backed up as $HOME/.$CONF_FILE.$BACKUP_SUFFIX\n##" >> $HOME/.$CONF_FILE
+        echo -e "\n##\n# Your previous ${HOME}/.${CONF_FILE} file was backed up as ${HOME}/.${CONF_FILE}.${BACKUP_SUFFIX}\n##" >> ${HOME}/.${CONF_FILE}
     fi
-    echo -e "\n# $OUR_STRING adding an appropriate $1 variable for use with MacPorts." >> $HOME/.$CONF_FILE
-    case $1 in
+    echo -e "\n# ${OUR_STRING} adding an appropriate ${1} variable for use with MacPorts." >> ${HOME}/.${CONF_FILE}
+    case ${1} in
         PATH)
-            if [ "$CONF_FILE" == "profile" ]; then
-                echo "export PATH=$BINPATH:$SBINPATH:\$PATH" >> $HOME/.$CONF_FILE
-            elif [ "$CONF_FILE" == "tcshrc" ]; then
-                echo "setenv PATH $BINPATH:$SBINPATH:\$PATH" >> $HOME/.$CONF_FILE
+            if [ "${CONF_FILE}" == "profile" ]; then
+                echo "export PATH=${BINPATH}:${SBINPATH}:\$PATH" >> ${HOME}/.${CONF_FILE}
+            elif [ "${CONF_FILE}" == "tcshrc" ]; then
+                echo "setenv PATH ${BINPATH}:${SBINPATH}:\$PATH" >> ${HOME}/.${CONF_FILE}
             fi
             ;;
         MANPATH)
-            if [ "$CONF_FILE" == "profile" ]; then
-                echo "export MANPATH=$MANPAGES:\$MANPATH" >> $HOME/.$CONF_FILE
-            elif [ "$CONF_FILE" == "tcshrc" ]; then
-                echo "setenv MANPATH $MANPAGES:\$MANPATH" >> $HOME/.$CONF_FILE
+            if [ "${CONF_FILE}" == "profile" ]; then
+                echo "export MANPATH=${MANPAGES}:\$MANPATH" >> ${HOME}/.${CONF_FILE}
+            elif [ "${CONF_FILE}" == "tcshrc" ]; then
+                echo "setenv MANPATH ${MANPAGES}:\$MANPATH" >> ${HOME}/.${CONF_FILE}
             fi
             ;;
         DISPLAY)
-            if [ "$CONF_FILE" == "profile" ]; then
-                echo "export DISPLAY=:0" >> $HOME/.$CONF_FILE
-            elif [ "$CONF_FILE" == "tcshrc" ]; then
-                echo "setenv DISPLAY :0" >> $HOME/.$CONF_FILE
+            if [ "${CONF_FILE}" == "profile" ]; then
+                echo "export DISPLAY=:0" >> ${HOME}/.${CONF_FILE}
+            elif [ "${CONF_FILE}" == "tcshrc" ]; then
+                echo "setenv DISPLAY :0" >> ${HOME}/.${CONF_FILE}
             fi
             ;;
     esac
-    chown $USER $HOME/.$CONF_FILE || echo "Unable to switch your $HOME/.$CONF_FILE shell configuration file to your UID!"
-    echo -e "# Finished adapting your $1 environment variable for use with MacPorts.\n" >> $HOME/.$CONF_FILE
-    echo "An appropriate $1 variable has been added to your shell environment by the MacPorts installer."
+    chown ${USER} ${HOME}/.${CONF_FILE} || echo "Unable to switch your ${HOME}/.${CONF_FILE} shell configuration file to your UID!"
+    echo -e "# Finished adapting your ${1} environment variable for use with MacPorts.\n" >> ${HOME}/.${CONF_FILE}
+    echo "An appropriate ${1} variable has been added to your shell environment by the MacPorts installer."
 }
 
 
-echo "Checking the shell environment for user \"$USER\"..."
+echo "Checking the shell environment for user \"${USER}\"..."
 
 
 # Determine the user's shell, in order to choose an appropriate configuration file we'll be tweaking.
 # Exit nicely if the shell is any other than bash or tcsh, as that's considered non-standard.
-USHELL="$(basename "$SHELL" 2>/dev/null)" || {
+USHELL="$(basename "${SHELL}" 2>/dev/null)" || {
     echo "An attempt to determine your shell name failed! Please set your MacPorts compatible environment manually."
     update_macports
     exit 1
 }
-case "$USHELL" in
+case "${USHELL}" in
     tcsh)
         CONF_FILE=tcshrc
         LOGIN_FLAG=""
@@ -122,33 +122,33 @@
 
 
 # Adding our setting to the PATH variable if not already there:
-if $SHELL $LOGIN_FLAG -c "/usr/bin/printenv PATH" | grep $PREFIX > /dev/null 2>&1; then
+if ${SHELL} ${LOGIN_FLAG} -c "/usr/bin/printenv PATH" | grep ${PREFIX} > /dev/null 2>&1; then
     echo "Your shell already has the right PATH environment variable for use with MacPorts!"
 else
     write_setting PATH
 fi
 
 # We gather the path into a variable of our own for faster operation:
-ORIGINAL_MANPATH="$($SHELL $LOGIN_FLAG -c "/usr/bin/printenv MANPATH" 2>/dev/null)"
+ORIGINAL_MANPATH="$(${SHELL} ${LOGIN_FLAG} -c "/usr/bin/printenv MANPATH" 2>/dev/null)"
 # Adding out setting to the MANPATH variable only if it exists:
-if ! $SHELL $LOGIN_FLAG -c "/usr/bin/env | grep MANPATH" > /dev/null 2>&1 || \
+if ! ${SHELL} ${LOGIN_FLAG} -c "/usr/bin/env | grep MANPATH" > /dev/null 2>&1 || \
 # and following that, if it's not empty:
-  [ -z "$ORIGINAL_MANPATH" ] || \
+  [ -z "${ORIGINAL_MANPATH}" ] || \
 # or if it doesn't already contain our path:
-  echo "$ORIGINAL_MANPATH" | grep $MANPAGES > /dev/null 2>&1 || \
+  echo "${ORIGINAL_MANPATH}" | grep ${MANPAGES} > /dev/null 2>&1 || \
 # or if there's no empty component somewhere in the middle of it:
-  echo "$ORIGINAL_MANPATH" | grep :: > /dev/null 2>&1 || \
+  echo "${ORIGINAL_MANPATH}" | grep :: > /dev/null 2>&1 || \
 # or at the start of it:
-  [ -z "$(echo "$ORIGINAL_MANPATH" | awk -F : '{print $1}')" ] || \
+  [ -z "$(echo "${ORIGINAL_MANPATH}" | awk -F : '{print $1}')" ] || \
 # or at the end of it:
-  [ -z "$(echo "$ORIGINAL_MANPATH" | awk -F : '{print $NF}')" ]; then
+  [ -z "$(echo "${ORIGINAL_MANPATH}" | awk -F : '{print $NF}')" ]; then
     echo "Your shell already has the right MANPATH environment variable for use with MacPorts!"
 else
     write_setting MANPATH
 fi
 
 # Adding a DISPLAY variable only if we're running on Tiger or less and if it doesn't already exist:
-if (($(sw_vers -productVersion | awk -F . '{print $2}') >= 5)) || $SHELL $LOGIN_FLAG -c "/usr/bin/env | grep DISPLAY" > /dev/null 2>&1; then
+if (($(sw_vers -productVersion | awk -F . '{print $2}') >= 5)) || ${SHELL} ${LOGIN_FLAG} -c "/usr/bin/env | grep DISPLAY" > /dev/null 2>&1; then
     echo "Your shell already has the right DISPLAY environment variable for use with MacPorts!"
 else
     write_setting DISPLAY

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20080111/bb263f49/attachment-0001.html


More information about the macports-changes mailing list