<pre style='margin:0'>
Joshua Root (jmroot) pushed a commit to branch release-2.4
in repository macports-base.

</pre>
<p><a href="https://github.com/macports/macports-base/commit/b757252809f44e3a98208534f917c420c3a90078">https://github.com/macports/macports-base/commit/b757252809f44e3a98208534f917c420c3a90078</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit b757252809f44e3a98208534f917c420c3a90078
</span>Author: Barry Scott <barry@barrys-emacs.org>
AuthorDate: Fri Feb 3 11:21:12 2017 +0000

<span style='display:block; white-space:pre;color:#404040;'>    Never run installing user's profile code as root
</span><span style='display:block; white-space:pre;color:#404040;'>    
</span><span style='display:block; white-space:pre;color:#404040;'>    Replace all cases of ${USHELL} -l with /usr/bin/su commands.
</span><span style='display:block; white-space:pre;color:#404040;'>    First use is commented explaining each steps purpose.
</span><span style='display:block; white-space:pre;color:#404040;'>    
</span><span style='display:block; white-space:pre;color:#404040;'>    Use printenv VAR | tail -n 1 to make sure that only the VAR's value is passed on.
</span><span style='display:block; white-space:pre;color:#404040;'>    It is not uncommon for profiles to print information to stdout.
</span><span style='display:block; white-space:pre;color:#404040;'>    
</span><span style='display:block; white-space:pre;color:#404040;'>    Refactor the MANPATH logic to use su and the tr|grep idium to look at for a path.
</span><span style='display:block; white-space:pre;color:#404040;'>    
</span><span style='display:block; white-space:pre;color:#404040;'>    Delete all the logic for DISPLAY as its not required in any supported macOS
</span><span style='display:block; white-space:pre;color:#404040;'>    version that MacPorts supports.
</span><span style='display:block; white-space:pre;color:#404040;'>    
</span><span style='display:block; white-space:pre;color:#404040;'>    Replace hardtab with spaces
</span><span style='display:block; white-space:pre;color:#404040;'>    (cherry picked from commit 70495b172f1f47203c4d60b376200bde8c9e64a9)
</span>---
 portmgr/dmg/postflight.in | 36 +++++++++++++++---------------------
 1 file changed, 15 insertions(+), 21 deletions(-)

<span style='display:block; white-space:pre;color:#808080;'>diff --git a/portmgr/dmg/postflight.in b/portmgr/dmg/postflight.in
</span><span style='display:block; white-space:pre;color:#808080;'>index a2e23d4..750553f 100755
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/portmgr/dmg/postflight.in
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/portmgr/dmg/postflight.in
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -126,7 +126,7 @@ function delete_old_tcl_package_link {
</span>     # delete old link if present
     if [[ -e "${OLD_TCL_PACKAGE_DIR}/macports1.0" ]]; then
         rm -vrf "${OLD_TCL_PACKAGE_DIR}/macports1.0"
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        fi
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    fi
</span> 
     # delete old macports1.0 link from new tcl package dir if present
     if [[ -L "${TCL_PACKAGE_PATH}/macports1.0" ]]; then
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -251,41 +251,35 @@ case "${USHELL}" in
</span>         ;;
 esac
 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span> # Adding our setting to the PATH variable if not already there:
<span style='display:block; white-space:pre;background:#ffe0e0;'>-if "${USHELL}" ${LOGIN_FLAG} -c "/usr/bin/printenv PATH" | tr ":" "\n" | grep "^${BINPATH}$" > /dev/null; then
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+# Run as the $USER: /usr/bin/su $USER -l
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+# Run a command in the shell: -c "/usr/bin/printenv PATH"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+# Only process the last line output (profile may print info): tail -n 1
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+# Output each path on its own line: tr ":" "\n"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+# Look for exactly the BINPATH: grep "^${BINPATH}$"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+if /usr/bin/su "${USER}" -l -c "/usr/bin/printenv PATH" | tail -n 1 | tr ":" "\n" | grep "^${BINPATH}$" > /dev/null; then
</span>     echo "Your shell already has the right PATH environment variable for use with MacPorts!"
 else
     write_setting PATH "\"${BINPATH}:${SBINPATH}:\$PATH\""
 fi
 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-# We gather the path into a variable of our own for faster operation:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-ORIGINAL_MANPATH="$("${USHELL}" ${LOGIN_FLAG} -c "/usr/bin/printenv MANPATH")"
</span> # Adding our setting to the MANPATH variable only if it exists:
<span style='display:block; white-space:pre;background:#ffe0e0;'>-if ! "${USHELL}" ${LOGIN_FLAG} -c "/usr/bin/env | grep MANPATH" > /dev/null || \
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-# and following that, if it's not empty:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-  [[ -z "${ORIGINAL_MANPATH}" ]] || \
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-# or if it doesn't already contain our path:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-  echo "${ORIGINAL_MANPATH}" | grep "${MANPAGES}" > /dev/null || \
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-# or if there's no empty component somewhere in the middle of it:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-  echo "${ORIGINAL_MANPATH}" | grep :: > /dev/null || \
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-# or at the start of it:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-  [[ -z "$(echo "${ORIGINAL_MANPATH}" | awk -F : '{print $1}')" ]] || \
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-# or at the end of it:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-  [[ -z "$(echo "${ORIGINAL_MANPATH}" | awk -F : '{print $NF}')" ]]; then
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-    echo "Your shell already has the right MANPATH environment variable for use with MacPorts!"
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-else
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-    write_setting MANPATH "\"${MANPAGES}:\$MANPATH\""
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+if /usr/bin/su "${USER}" -l -c "/usr/bin/printenv MANPATH" > /dev/null; then
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    # check for MANPAGES already in MANPATH
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if /usr/bin/su "${USER}" -l -c "/usr/bin/printenv MANPATH" | tail -n 1 | tr ":" "\n" | grep "^${MANPAGES}$" >/dev/null; then
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        echo "Your shell already has the right MANPATH environment variable for use with MacPorts!"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    else
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        write_setting MANPATH "\"${MANPAGES}:\$MANPATH\""
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    fi
</span> fi
 
 # Adding a DISPLAY variable only if we're running on Tiger or less and if it doesn't already exist:
<span style='display:block; white-space:pre;background:#ffe0e0;'>-if (($(sw_vers -productVersion | awk -F . '{print $2}') >= 5)) || "${USHELL}" ${LOGIN_FLAG} -c "/usr/bin/env | grep DISPLAY" > /dev/null; then
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+if (($(sw_vers -productVersion | awk -F . '{print $2}') >= 5)) || /usr/bin/su "${USER}" -l -c "/usr/bin/printenv DISPLAY" > /dev/null > /dev/null; then
</span>     echo "Your shell already has the right DISPLAY environment variable for use with MacPorts!"
 else
     write_setting DISPLAY ":0"
 fi
 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span> # Postflight script is done with its job, update MacPorts and exit gracefully!
 update_macports
 echo "You have successfully installed the MacPorts system. Launch a terminal and try it out!"
</pre><pre style='margin:0'>

</pre>