source: branches/gsoc08-privileges/base/portmgr/dmg/postflight @ 38096

Last change on this file since 38096 was 38096, checked in by pmagrath@…, 11 years ago

Merged revisions 38033,38037-38038,38040 via svnmerge from
https://svn.macosforge.org/repository/macports/trunk/base

........

r38033 | raimue@… | 2008-07-04 00:49:00 +0100 (Fri, 04 Jul 2008) | 3 lines


port/port.tcl:
Document depends: and depends_*: from r37909

........

r38037 | raimue@… | 2008-07-04 03:58:10 +0100 (Fri, 04 Jul 2008) | 3 lines


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

........

r38038 | raimue@… | 2008-07-04 05:30:56 +0100 (Fri, 04 Jul 2008) | 4 lines


port1.0/portextract.tcl:
If the $distfile exists in $filespath, use it from there as it was not fetched
to the distpath in this case.

........

r38040 | raimue@… | 2008-07-04 05:59:54 +0100 (Fri, 04 Jul 2008) | 3 lines


portmgr/dmg/postflight:
Remove old non-compressed man pages on install

........

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 7.5 KB
Line 
1#!/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
3#
4# Copyright (c) 2002-2007 Juan Manuel Palacios <jmpp@macports.org>, The MacPorts Project.
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    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.
18#
19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
23# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29# SUCH DAMAGE.
30#
31# postflight
32# $Id: postflight 38096 2008-07-06 15:21:25Z pmagrath@macports.org $
33
34
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}"
48
49
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}
60
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
81function cleanup_man () {
82    # Remove old non-compressed man pages
83    echo -e "\nRemoving old man pages..."
84    MAN1="port.1"
85    MAN5="macports.conf.5"
86    MAN7="portfile.7 portstyle.7 porthier.7 portgroup.7"
87    for m in ${MAN1}; do rm -vf ${MANPAGES}/man1/$m ; done
88    for m in ${MAN5}; do rm -vf ${MANPAGES}/man5/$m ; done
89    for m in ${MAN7}; do rm -vf ${MANPAGES}/man7/$m ; done
90    echo -e "Done.\n"
91}
92
93
94echo "The MacPorts Project, postflight script version ${VERSION}: checking the shell environment for user \"${USER}\"."
95
96# Remove old stuff
97cleanup_man
98
99# Determine the user's shell, in order to choose an appropriate configuration file we'll be tweaking.
100# Exit nicely if the shell is any other than bash or tcsh, as that's considered non-standard.
101USHELL=$(dscl . -read /users/${USER} shell | awk -F'/' '{print $NF}') || {
102    echo "An attempt to determine your shell name failed! Please set your MacPorts compatible environment manually."
103    update_macports
104    exit 1
105}
106case "${USHELL}" in
107    tcsh)
108        echo "Detected the tcsh shell."
109        LOGIN_FLAG=""
110        ENV_COMMAND="setenv"
111        ASSIGN=" "
112        CONF_FILE=tcshrc
113        ;;
114    bash)
115        echo "Detected the bash shell."
116        LOGIN_FLAG="-l"
117        ENV_COMMAND="export"
118        ASSIGN="="
119        CONF_FILE=profile
120        ;;
121    *)
122        echo "Unknown shell ($USHELL)! Please set your MacPorts compatible environment manually."
123        update_macports
124        exit 0
125        ;;
126esac
127
128
129# Adding our setting to the PATH variable if not already there:
130if ${SHELL} ${LOGIN_FLAG} -c "/usr/bin/printenv PATH" | grep ${PREFIX} > /dev/null; then
131    echo "Your shell already has the right PATH environment variable for use with MacPorts!"
132else
133    write_setting PATH "${BINPATH}:${SBINPATH}:\$PATH"
134fi
135
136# We gather the path into a variable of our own for faster operation:
137ORIGINAL_MANPATH="$(${SHELL} ${LOGIN_FLAG} -c "/usr/bin/printenv MANPATH")"
138# Adding out setting to the MANPATH variable only if it exists:
139if ! ${SHELL} ${LOGIN_FLAG} -c "/usr/bin/env | grep MANPATH" > /dev/null || \
140# and following that, if it's not empty:
141  [ -z "${ORIGINAL_MANPATH}" ] || \
142# or if it doesn't already contain our path:
143  echo "${ORIGINAL_MANPATH}" | grep ${MANPAGES} > /dev/null || \
144# or if there's no empty component somewhere in the middle of it:
145  echo "${ORIGINAL_MANPATH}" | grep :: > /dev/null || \
146# or at the start of it:
147  [ -z "$(echo "${ORIGINAL_MANPATH}" | awk -F : '{print $1}')" ] || \
148# or at the end of it:
149  [ -z "$(echo "${ORIGINAL_MANPATH}" | awk -F : '{print $NF}')" ]; then
150    echo "Your shell already has the right MANPATH environment variable for use with MacPorts!"
151else
152    write_setting MANPATH "${MANPAGES}:\$MANPATH"
153fi
154
155# Adding a DISPLAY variable only if we're running on Tiger or less and if it doesn't already exist:
156if (($(sw_vers -productVersion | awk -F . '{print $2}') >= 5)) || ${SHELL} ${LOGIN_FLAG} -c "/usr/bin/env | grep DISPLAY" > /dev/null; then
157    echo "Your shell already has the right DISPLAY environment variable for use with MacPorts!"
158else
159    write_setting DISPLAY ":0"
160fi
161
162
163# Postflight script is done with its job, update MacPorts and exit gracefully!
164update_macports
165echo "You have succesfully installed the MacPorts system, launch a terminal and try it out!"
166echo "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."
167exit 0
Note: See TracBrowser for help on using the repository browser.