| 1 | [wiki:howto <- Back to the HOWTO section] |
| 2 | |
| 3 | = Advanced Daily Administration of MacPorts = |
| 4 | |
| 5 | * Audience: advanced users |
| 6 | * Requires: MacPorts >=1.9.2 |
| 7 | * Author: Bjarne D Mathiesen - macintosh _at_ mathiesen _dot_ info |
| 8 | |
| 9 | == Introduction == |
| 10 | |
| 11 | This is a dump of my scripts to administer MacPorts on a daily basis. |
| 12 | |
| 13 | Please append comments, questions, and suggestions here. |
| 14 | |
| 15 | |
| 16 | == The Scripts == |
| 17 | |
| 18 | === Script 1: '''Installation''' === |
| 19 | |
| 20 | {{{ |
| 21 | #!/bin/bash |
| 22 | |
| 23 | ################################################################################ |
| 24 | # copyright Bjarne D Mathiesen |
| 25 | # København ; Danmark ; Europa |
| 26 | # macintosh .at. mathiesen .dot. info |
| 27 | # date 04/07-2007 |
| 28 | # revised 02/12-2007 implemented automatic patching of Portfiles |
| 29 | # 28/12-2009 fixed the download link |
| 30 | # modified source/build directory |
| 31 | # removed sudo from commands |
| 32 | # 18/06-2011 added default values for the parameters |
| 33 | # updated path values for XCode4 |
| 34 | # |
| 35 | # this script is released under the BSD license |
| 36 | # the author welcomes feedback and improvements |
| 37 | # |
| 38 | |
| 39 | usage() { |
| 40 | cat <<EOT |
| 41 | purpose : to automate the whole install process |
| 42 | \${1} : action [ install (default) , paths ] |
| 43 | \${2} : install prefix ( default /macports ) |
| 44 | \${3} : macports base version ( default 1.9.2 ) |
| 45 | EOT |
| 46 | } |
| 47 | |
| 48 | declare action=${1:-"install"} |
| 49 | declare prefix=${2:-"/macports"} |
| 50 | declare version=${3:-"1.9.2"} |
| 51 | |
| 52 | case ${action} in |
| 53 | ######################## |
| 54 | # setup the system paths |
| 55 | 'paths') |
| 56 | |
| 57 | mkdir -p /etc/paths.d |
| 58 | cp -np /etc/paths /etc/paths.orig |
| 59 | mv -n /etc/paths /etc/paths.d/999macosx |
| 60 | touch /etc/paths |
| 61 | |
| 62 | echo "${prefix}/bin" > /etc/paths.d/000macports |
| 63 | echo "${prefix}/sbin" >> /etc/paths.d/000macports |
| 64 | |
| 65 | echo "/Developer/usr/bin" > /etc/paths.d/888developer |
| 66 | echo "/Developer/usr/sbin" >> /etc/paths.d/888developer |
| 67 | |
| 68 | mkdir -p /etc/manpaths.d |
| 69 | cp -np /etc/manpaths /etc/manpaths.orig |
| 70 | mv -n /etc/manpaths /etc/manpaths.d/999macosx |
| 71 | touch /etc/manpaths |
| 72 | |
| 73 | echo "${prefix}/share/man" > /etc/manpaths.d/000macports |
| 74 | echo "/Developer/usr/share/man" > /etc/manpaths.d/888developer |
| 75 | echo "/Developer/usr/X11/share/man" >> /etc/manpaths.d/888developer |
| 76 | |
| 77 | # path_helper is buggy under 10.5 |
| 78 | #cp -npv /usr/libexec/path_helper /usr/libexec/path_helper.orig |
| 79 | #cp -v path_helper /usr/libexec/ |
| 80 | |
| 81 | ;; |
| 82 | ################## |
| 83 | # install macports |
| 84 | 'install') |
| 85 | |
| 86 | if [ ! -e MacPorts-${version}.tar.gz ] |
| 87 | then |
| 88 | curl -O --url "http://distfiles.macports.org/MacPorts/MacPorts-${version}.tar.gz" |
| 89 | fi |
| 90 | |
| 91 | rm -rf ./MacPorts-${version} |
| 92 | tar -zxf MacPorts-${version}.tar.gz |
| 93 | |
| 94 | cd MacPorts-${version} |
| 95 | ./configure LDFLAGS=-L/Developer/SDKs/MacOSX10.6.sdk/usr/X11/lib --prefix=${prefix} |
| 96 | make |
| 97 | make install |
| 98 | |
| 99 | # update DarwinPorts itself |
| 100 | ${prefix}/bin/port -d selfupdate |
| 101 | |
| 102 | # let's get bash |
| 103 | ${prefix}/bin/port install bash |
| 104 | |
| 105 | ;; |
| 106 | # default |
| 107 | *) |
| 108 | usage |
| 109 | esac |
| 110 | }}} |
| 111 | |
| 112 | === Script 2: '''Updating''' === |
| 113 | |
| 114 | {{{ |
| 115 | #!/macports/bin/bash |
| 116 | |
| 117 | # |
| 118 | # usage: |
| 119 | # ${1}: the macports install path |
| 120 | # |
| 121 | |
| 122 | ( cd $( dirname ${0} ) |
| 123 | |
| 124 | echo -e "\n"'+----------------+' |
| 125 | echo '| macportsupdate |' |
| 126 | echo '+----------------+' |
| 127 | |
| 128 | declare installPath=${1:-'/macports'} |
| 129 | declare rsyncMacportsOrg='/var/macports/sources/rsync.macports.org/release/ports' |
| 130 | |
| 131 | echo "selfupdating & syncing all repositories" |
| 132 | ${installPath}/bin/port -d selfupdate |
| 133 | cp -Rv newPorts/_resources \ |
| 134 | ${installPath}${rsyncMacportsOrg} |
| 135 | |
| 136 | echo -e "\ncopy additional files to the ports" |
| 137 | for filesDir in $(find portfiles -type d -name 'files') |
| 138 | do |
| 139 | mkdir -p ${installPath}${rsyncMacportsOrg}/${filesDir#*portfiles/} |
| 140 | cp -Rv ${filesDir}/* \ |
| 141 | ${installPath}${rsyncMacportsOrg}/${filesDir#*portfiles/} |
| 142 | done |
| 143 | |
| 144 | echo -e "\npatching the portfiles" |
| 145 | for portPatch in $(find portfiles -type f -name 'patch-Portfile') |
| 146 | do |
| 147 | patchFile=$( sed -En -e '1,1p' ${portPatch} | tr -s "\t" " " | cut -f2 -d ' ' ) |
| 148 | patch -u <${portPatch} ${patchFile} |
| 149 | done |
| 150 | |
| 151 | echo '' |
| 152 | ${installPath}/bin/port outdated |
| 153 | |
| 154 | echo -e "\nupgrading the outdated ports" |
| 155 | for outDated in $(${installPath}/bin/port outdated | sed -e '1,1d' | tr -s " \t" | cut -f 1 -d ' ') |
| 156 | do |
| 157 | ${installPath}/bin/port -cuRp upgrade ${outDated} |
| 158 | done |
| 159 | |
| 160 | |
| 161 | echo -e "\nremoving macport saved files" |
| 162 | find ${installPath} -iname *.mpsaved -delete |
| 163 | find ${installPath} -iname *.mp_* -delete |
| 164 | |
| 165 | echo -e "\nremoving inactive ports" |
| 166 | ${installPath}/bin/port installed | sed -e '1,1d' -e '/active/d' | xargs -n2 ${installPath}/bin/port uninstall |
| 167 | |
| 168 | ) ; wait |
| 169 | }}} |
| 170 | |
| 171 | === Script 3: '''Copying a Port''' === |
| 172 | |
| 173 | {{{ |
| 174 | #!/macports/bin/bash |
| 175 | |
| 176 | declare prefix=${2:-"/macports"} |
| 177 | |
| 178 | ( cd $( dirname ${0} ) |
| 179 | |
| 180 | declare -a info=( $( find "${prefix}"/var/macports/sources/rsync.macports.org/release/ports -iname "${1}" | tr '/' ' ' ) ) |
| 181 | declare portName=${info[$(( ${#info[@]}-1 ))]} |
| 182 | declare portCategory=${info[$(( ${#info[@]}-2 ))]} |
| 183 | |
| 184 | mkdir -p portfiles/${portCategory}/${portName} |
| 185 | cp ${prefix}/var/macports/sources/rsync.macports.org/release/ports/${portCategory}/${portName}/Portfile \ |
| 186 | portfiles/${portCategory}'/'${portName}/'Portfile.orig' |
| 187 | |
| 188 | ) ; wait |
| 189 | }}} |
| 190 | |
| 191 | === Script 4: '''Creating a Patch for a Port''' === |
| 192 | |
| 193 | {{{ |
| 194 | #!/macports/bin/bash |
| 195 | |
| 196 | declare prefix=${1:-"/macports"} |
| 197 | declare rsyncMacportsOrg="/var/macports/sources/rsync.macports.org/release/ports" |
| 198 | |
| 199 | ( cd $( dirname ${0} ) |
| 200 | |
| 201 | declare outputFile |
| 202 | declare patchFile |
| 203 | |
| 204 | for port in $(find portfiles -name 'Portfile') |
| 205 | do |
| 206 | outputFile=${port%/*}/patch-${port##*/} |
| 207 | rm ${outputFile} 2>/dev/null |
| 208 | diff -u \ |
| 209 | ${prefix}${rsyncMacportsOrg}/${port#*/} \ |
| 210 | ${port} \ |
| 211 | > ${outputFile} |
| 212 | echo "created patch for ${port}" |
| 213 | mv ${port} ${port}.OK |
| 214 | done |
| 215 | |
| 216 | ) ; wait |
| 217 | }}} |
| 218 | |
| 219 | [wiki:howto <- Back to the HOWTO section] |