Changeset 38037


Ignore:
Timestamp:
Jul 4, 2008, 2:58:10 AM (11 years ago)
Author:
raimue@…
Message:

portmgr/dmg/postflight:
Copy the postflight script from the release_1_6 branch so the changes will not be lost or forgotten

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/portmgr/dmg/postflight

    r31681 r38037  
    11#!/bin/bash
     2# -*- coding: utf-8; mode: shell-script-mode; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=sh:et:sw=4:ts=4:sts=4
    23#
    3 # Copyright (c) 2007 Juan Manuel Palacios <jmpp@macports.org>
    4 # Copyright (c) 2005 Ole Guldberg Jensen <olegb@opendarwin.org>
    5 # Copyright (c) 2005 Dr. Ernie Prabhakar <drernir@opendarwin.org>
    6 # Copyright (c) 2005 Matt Anton <matt@opendarwin.org>
     4# Copyright (c) 2002-2007 Juan Manuel Palacios <jmpp@macports.org>, The MacPorts Project.
    75# All rights reserved.
    86#
     
    1513#    notice, this list of conditions and the following disclaimer in the
    1614#    documentation and/or other materials provided with the distribution.
     15# 3. Neither the name of Apple, Inc., The MacPorts Project nor the
     16#    names of its contributors may be used to endorse or promote products
     17#    derived from this software without specific prior written permission.
    1718#
    18 # THIS SOFTWARE IS PROVIDED BY Eric Melville AND CONTRIBUTORS ``AS IS'' AND
     19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
    1920# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    2021# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    21 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     22# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
    2223# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    2324# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     
    3233
    3334
    34 BINPATH=/opt/local/bin
    35 SBINPATH=/opt/local/sbin
     35#set -x
     36
     37# Script identification ('cause more often than not the svn Id is not expanded):
     38VERSION=1.7.0
     39
     40# Abstraction variables:
     41PREFIX=/opt/local
     42BINPATH=${PREFIX}/bin
     43SBINPATH=${PREFIX}/sbin
     44MANPAGES=${PREFIX}/share/man
     45TIMESTAMP=$(date +"%Y-%m-%d_at_%H:%M:%S")
     46BACKUP_SUFFIX=macports-saved_${TIMESTAMP}
     47OUR_STRING="MacPorts Installer addition on ${TIMESTAMP}"
    3648
    3749
    38 echo -e "\nChecking the PATH variable for $USER...\n"
     50# Command to update the MacPorts installation through "selfupdate":
     51function update_macports {
     52    echo "Synchronizing the MacPorts installation with the project's rsync server..."
     53    if ! ${BINPATH}/port -v selfupdate; then
     54        echo "An attempt to synchronize your recent MacPorts installation with the project's rsync server failed!"
     55        echo "Please run 'sudo port -d selfupdate' manually to find out the cause of the error."
     56    else
     57        echo "Successful!"
     58    fi
     59}
    3960
    40 # No need to do any path adjustments if we're on Leopard, as we already install our path configs into /etc/paths.d/ and /etc/manpaths.d/
    41 if [ $(sw_vers -productVersion | awk -F . '{print $2}') -eq 5 ]; then
    42     echo "No need to adjust the PATH and MANPATH environment variables on Leopard!"
    43     exit 0
     61# Through this command we write an environment variable to an appropriate shell configuration file,
     62# backing up the original only if it exists and if it doesn't contain the ${OUR_STRING} identification string,
     63# which hints that we've already tweaked it and therefore already baked it up.
     64function write_setting () {
     65    if [ -f ${HOME}/.${CONF_FILE} ] && ! grep "${OUR_STRING}" ${HOME}/.${CONF_FILE} > /dev/null; then
     66        echo "Backing up your ${HOME}/.${CONF_FILE} shell confguration file as ${HOME}/.${CONF_FILE}.${BACKUP_SUFFIX} before adapting it for MacPorts."
     67        /bin/cp -fp ${HOME}/.${CONF_FILE} "${HOME}/.${CONF_FILE}.${BACKUP_SUFFIX}" || {
     68            echo "An attempt to backup your original configuration file failed! Please set your MacPorts compatible environment manually."
     69            update_macports
     70            exit 1
     71        }
     72        echo -e "\n##\n# Your previous ${HOME}/.${CONF_FILE} file was backed up as ${HOME}/.${CONF_FILE}.${BACKUP_SUFFIX}\n##" >> ${HOME}/.${CONF_FILE}
     73    fi
     74    echo -e "\n# ${OUR_STRING}: adding an appropriate ${1} variable for use with MacPorts." >> ${HOME}/.${CONF_FILE}
     75    echo "${ENV_COMMAND} ${1}${ASSIGN}${2}" >> ${HOME}/.${CONF_FILE}
     76    echo -e "# Finished adapting your ${1} environment variable for use with MacPorts.\n" >> ${HOME}/.${CONF_FILE}
     77    chown ${USER} ${HOME}/.${CONF_FILE} || echo "Warning: unable to adapt permissions on your ${HOME}/.${CONF_FILE} shell configuration file!"
     78    echo "An appropriate ${1} variable has been added to your shell environment by the MacPorts installer."
     79}
     80
     81
     82echo "The MacPorts Project, postflight script version ${VERSION}: checking the shell environment for user \"${USER}\"."
     83
     84
     85# Determine the user's shell, in order to choose an appropriate configuration file we'll be tweaking.
     86# Exit nicely if the shell is any other than bash or tcsh, as that's considered non-standard.
     87USHELL=$(dscl . -read /users/${USER} shell | awk -F'/' '{print $NF}') || {
     88    echo "An attempt to determine your shell name failed! Please set your MacPorts compatible environment manually."
     89    update_macports
     90    exit 1
     91}
     92case "${USHELL}" in
     93    tcsh)
     94        echo "Detected the tcsh shell."
     95        LOGIN_FLAG=""
     96        ENV_COMMAND="setenv"
     97        ASSIGN=" "
     98        CONF_FILE=tcshrc
     99        ;;
     100    bash)
     101        echo "Detected the bash shell."
     102        LOGIN_FLAG="-l"
     103        ENV_COMMAND="export"
     104        ASSIGN="="
     105        CONF_FILE=profile
     106        ;;
     107    *)
     108        echo "Unknown shell ($USHELL)! Please set your MacPorts compatible environment manually."
     109        update_macports
     110        exit 0
     111        ;;
     112esac
     113
     114
     115# Adding our setting to the PATH variable if not already there:
     116if ${SHELL} ${LOGIN_FLAG} -c "/usr/bin/printenv PATH" | grep ${PREFIX} > /dev/null; then
     117    echo "Your shell already has the right PATH environment variable for use with MacPorts!"
     118else
     119    write_setting PATH "${BINPATH}:${SBINPATH}:\$PATH"
    44120fi
    45121
    46 if $SHELL -c "/usr/bin/printenv PATH" | grep -c $BINPATH > /dev/null; then
    47     echo "You already have the right PATH!"
     122# We gather the path into a variable of our own for faster operation:
     123ORIGINAL_MANPATH="$(${SHELL} ${LOGIN_FLAG} -c "/usr/bin/printenv MANPATH")"
     124# Adding out setting to the MANPATH variable only if it exists:
     125if ! ${SHELL} ${LOGIN_FLAG} -c "/usr/bin/env | grep MANPATH" > /dev/null || \
     126# and following that, if it's not empty:
     127  [ -z "${ORIGINAL_MANPATH}" ] || \
     128# or if it doesn't already contain our path:
     129  echo "${ORIGINAL_MANPATH}" | grep ${MANPAGES} > /dev/null || \
     130# or if there's no empty component somewhere in the middle of it:
     131  echo "${ORIGINAL_MANPATH}" | grep :: > /dev/null || \
     132# or at the start of it:
     133  [ -z "$(echo "${ORIGINAL_MANPATH}" | awk -F : '{print $1}')" ] || \
     134# or at the end of it:
     135  [ -z "$(echo "${ORIGINAL_MANPATH}" | awk -F : '{print $NF}')" ]; then
     136    echo "Your shell already has the right MANPATH environment variable for use with MacPorts!"
    48137else
    49     USHELL=`basename $SHELL`
    50     echo "Setting the PATH of $USHELL for $USER in ${HOME:=/Users/$USER}..."
    51     case $USHELL in
    52         *csh)
    53             # we backup the original
    54             /bin/cp -fp $HOME/.cshrc $HOME/.cshrc.mpsaved
    55             echo "#" >> $HOME/.cshrc
    56             echo "# Your previous .cshrc (if any) is saved as .cshrc.mpsaved" >> $HOME/.cshrc
    57             echo "# Setting the path for MacPorts." >> $HOME/.cshrc
    58             echo "set path=($BINPATH $SBINPATH" '$path'")" >> $HOME/.cshrc
    59             chown $USER $HOME/.cshrc
    60             echo "Finished modifying $HOME/.cshrc"
    61         ;;
    62         *sh)
    63             # we backup the original
    64             /bin/cp -fp $HOME/.profile $HOME/.profile.mpsaved
    65             echo "#" >> $HOME/.profile
    66             echo "# Your previous .profile  (if any) is saved as .profile.mpsaved" >> $HOME/.profile
    67             echo "# Setting the path for MacPorts." >> $HOME/.profile
    68             echo "export PATH=$BINPATH:$SBINPATH:\$PATH" >> $HOME/.profile
    69             chown $USER $HOME/.profile
    70             echo "Finished modifying $HOME/.profile"
    71         ;;
    72         *)
    73             echo "Unknown shell! Please set your own PATH manually."
    74         ;;
    75     esac
     138    write_setting MANPATH "${MANPAGES}:\$MANPATH"
     139fi
     140
     141# Adding a DISPLAY variable only if we're running on Tiger or less and if it doesn't already exist:
     142if (($(sw_vers -productVersion | awk -F . '{print $2}') >= 5)) || ${SHELL} ${LOGIN_FLAG} -c "/usr/bin/env | grep DISPLAY" > /dev/null; then
     143    echo "Your shell already has the right DISPLAY environment variable for use with MacPorts!"
     144else
     145    write_setting DISPLAY ":0"
    76146fi
    77147
    78148
    79 # Run selfupdate:
    80 export PATH=$BINPATH:$PATH
    81 echo -e "\nSelfupdating The MacPorts system...\n"
    82 port -d selfupdate
    83 if [ $? != 0 ]; then
    84     echo "An attempt to synchronize your recent MacPorts installation with the rsync server failed, please run 'port -d selfupdate' manually to find out the cause of the error."
    85     exit 1
    86 fi
    87 
    88 
    89 # Postflight script is done with its job!
    90 echo -e "\nYou have succesfully installed the MacPorts system.\n"
    91 echo "Launch a terminal and try it out!"
    92 echo -e "Read the port manual page for help.\n"
     149# Postflight script is done with its job, update MacPorts and exit gracefully!
     150update_macports
     151echo "You have succesfully installed the MacPorts system, launch a terminal and try it out!"
     152echo "Read the port(1) manual page and http://guide.macports.org for help, http://www.macports.org/contact.php if you need to get in touch with The MacPorts Project."
     153exit 0
Note: See TracChangeset for help on using the changeset viewer.