| 1 | #!/bin/sh |
|---|
| 2 | # |
|---|
| 3 | # Copyright (c) 2006,2008 Bryan L Blackburn. All rights reserved. |
|---|
| 4 | # |
|---|
| 5 | # Redistribution and use in source and binary forms, with or without |
|---|
| 6 | # modification, are permitted provided that the following conditions |
|---|
| 7 | # are met: |
|---|
| 8 | # 1. Redistributions of source code must retain the above copyright |
|---|
| 9 | # notice, this list of conditions and the following disclaimer. |
|---|
| 10 | # 2. Redistributions in binary form must reproduce the above copyright |
|---|
| 11 | # notice, this list of conditions and the following disclaimer in |
|---|
| 12 | # the documentation and/or other materials provided with the |
|---|
| 13 | # distribution. |
|---|
| 14 | # 3. Neither the name Bryan L Blackburn, nor the names of any contributors |
|---|
| 15 | # may be used to endorse or promote products derived from this software |
|---|
| 16 | # without specific prior written permission. |
|---|
| 17 | # |
|---|
| 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' |
|---|
| 19 | # AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|---|
| 20 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|---|
| 21 | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS |
|---|
| 22 | # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|---|
| 23 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|---|
| 24 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
|---|
| 25 | # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|---|
| 26 | # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
|---|
| 27 | # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
|---|
| 28 | # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 29 | # |
|---|
| 30 | |
|---|
| 31 | export PATH=/bin:/usr/bin:/sbin:/usr/sbin |
|---|
| 32 | |
|---|
| 33 | # Base filename for the disk image |
|---|
| 34 | IMGBASENAME="mproot" |
|---|
| 35 | |
|---|
| 36 | # subdir start of the chroot |
|---|
| 37 | CHROOTSUBDIR="mpchroot" |
|---|
| 38 | |
|---|
| 39 | # Name of the file containing all of MacPorts |
|---|
| 40 | MPTARBALL="macports_dist.tar.bz2" |
|---|
| 41 | |
|---|
| 42 | if [[ -n ${MPABDEBUG} ]]; then |
|---|
| 43 | HDIUTILDEBUG="-verbose" |
|---|
| 44 | else |
|---|
| 45 | HDIUTILDEBUG="-quiet" |
|---|
| 46 | fi |
|---|
| 47 | export HDIUTILDEBUG |
|---|
| 48 | |
|---|
| 49 | cd `dirname $0` |
|---|
| 50 | baseDir=`pwd -P` |
|---|
| 51 | chrootPath="${baseDir}/${CHROOTSUBDIR}" |
|---|
| 52 | cd - > /dev/null |
|---|
| 53 | |
|---|
| 54 | . ${baseDir}/mpab-functions |
|---|
| 55 | |
|---|
| 56 | command="buildports" |
|---|
| 57 | portlistFile="" |
|---|
| 58 | if [[ -n $1 ]]; then |
|---|
| 59 | command=$1 && shift |
|---|
| 60 | if [[ ${command} != "help" && ${command} != "mount" && |
|---|
| 61 | ${command} != "umount" && ${command} != "buildmp" && |
|---|
| 62 | ${command} != "rebuildmp" && ${command} != "buildports" ]]; then |
|---|
| 63 | printUsageAndExit |
|---|
| 64 | fi |
|---|
| 65 | if [[ ${command} == "buildports" && -n $1 ]]; then |
|---|
| 66 | portlistFile=$1 && shift |
|---|
| 67 | if [[ ! -e ${portlistFile} ]]; then |
|---|
| 68 | echo "File '${portlistFile}' not found" && echo |
|---|
| 69 | printUsageAndExit |
|---|
| 70 | fi |
|---|
| 71 | fi |
|---|
| 72 | if [[ ${command} == "help" || -n $1 ]]; then |
|---|
| 73 | printUsageAndExit |
|---|
| 74 | fi |
|---|
| 75 | fi |
|---|
| 76 | |
|---|
| 77 | checkDependencies ${baseDir} ${MPTARBALL} |
|---|
| 78 | returnValue=$? |
|---|
| 79 | if [[ ${returnValue} != 0 ]]; then |
|---|
| 80 | exit ${returnValue} |
|---|
| 81 | fi |
|---|
| 82 | |
|---|
| 83 | if [[ ${command} == "umount" ]]; then |
|---|
| 84 | umountChroot ${chrootPath} |
|---|
| 85 | exit 0 |
|---|
| 86 | fi |
|---|
| 87 | |
|---|
| 88 | if [[ ${command} == "mount" || ${command} == "buildmp" || |
|---|
| 89 | ${command} == "rebuildmp" || ${command} == "buildports" ]]; then |
|---|
| 90 | buildImages ${baseDir} ${chrootPath} ${IMGBASENAME} |
|---|
| 91 | mountChroot ${baseDir} ${chrootPath} ${IMGBASENAME} |
|---|
| 92 | if [[ $? == 0 && |
|---|
| 93 | ( ${command} == "buildmp" || ${command} == "rebuildmp" || |
|---|
| 94 | ${command} == "buildports" ) ]]; then |
|---|
| 95 | trap "exitFunction ${baseDir} ${chrootPath}" EXIT |
|---|
| 96 | exitMessage="Stopping..." |
|---|
| 97 | if [[ ${command} == "rebuildmp" ]]; then |
|---|
| 98 | rm -rf ${chrootPath}/opt/mports |
|---|
| 99 | rm -f ${chrootPath}/opt/local/bin/port |
|---|
| 100 | fi |
|---|
| 101 | buildMacPorts ${baseDir} ${chrootPath} ${MPTARBALL} |
|---|
| 102 | exitMessage="" |
|---|
| 103 | if [[ $? == 0 && ${command} == "buildports" ]]; then |
|---|
| 104 | if [[ -e ${portlistFile} ]]; then |
|---|
| 105 | cp -p ${portlistFile} ${chrootPath}/private/var/tmp/portlist |
|---|
| 106 | fi |
|---|
| 107 | exitMessage="Stopping..." |
|---|
| 108 | buildPorts ${baseDir} ${chrootPath} |
|---|
| 109 | exitMessage="" |
|---|
| 110 | fi |
|---|
| 111 | fi |
|---|
| 112 | fi |
|---|