Changes between Initial Version and Version 1 of howto/AdvancedDailyAdm


Ignore:
Timestamp:
Jun 27, 2011, 5:14:10 PM (13 years ago)
Author:
BjarneDMat
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • howto/AdvancedDailyAdm

    v1 v1  
     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
     11This is a dump of my scripts to administer MacPorts on a daily basis.
     12
     13Please 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
     39usage() {
     40cat <<EOT
     41purpose : 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 )
     45EOT
     46}
     47
     48declare action=${1:-"install"}
     49declare prefix=${2:-"/macports"}
     50declare version=${3:-"1.9.2"}
     51
     52case ${action} in
     53########################
     54# setup the system paths
     55'paths')
     56
     57mkdir -p  /etc/paths.d
     58cp    -np /etc/paths /etc/paths.orig
     59mv    -n  /etc/paths /etc/paths.d/999macosx
     60touch     /etc/paths
     61
     62echo "${prefix}/bin"        >  /etc/paths.d/000macports
     63echo "${prefix}/sbin"       >> /etc/paths.d/000macports
     64
     65echo "/Developer/usr/bin"   >  /etc/paths.d/888developer
     66echo "/Developer/usr/sbin"  >> /etc/paths.d/888developer
     67
     68mkdir -p  /etc/manpaths.d
     69cp    -np /etc/manpaths /etc/manpaths.orig
     70mv    -n  /etc/manpaths /etc/manpaths.d/999macosx
     71touch     /etc/manpaths
     72
     73echo "${prefix}/share/man"  > /etc/manpaths.d/000macports
     74echo "/Developer/usr/share/man"     >  /etc/manpaths.d/888developer
     75echo "/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
     86if [ ! -e MacPorts-${version}.tar.gz ]
     87then
     88    curl -O --url "http://distfiles.macports.org/MacPorts/MacPorts-${version}.tar.gz"
     89fi
     90
     91rm  -rf  ./MacPorts-${version}
     92tar -zxf   MacPorts-${version}.tar.gz
     93
     94cd MacPorts-${version}
     95./configure LDFLAGS=-L/Developer/SDKs/MacOSX10.6.sdk/usr/X11/lib --prefix=${prefix}
     96make
     97make 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*)
     108usage
     109esac
     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
     124echo -e "\n"'+----------------+'
     125echo        '| macportsupdate |'
     126echo        '+----------------+'
     127
     128declare installPath=${1:-'/macports'}
     129declare rsyncMacportsOrg='/var/macports/sources/rsync.macports.org/release/ports'
     130
     131echo    "selfupdating & syncing all repositories"
     132${installPath}/bin/port -d selfupdate
     133cp -Rv  newPorts/_resources \
     134        ${installPath}${rsyncMacportsOrg}
     135
     136echo -e "\ncopy additional files to the ports"
     137for filesDir in $(find portfiles -type d -name 'files')
     138do
     139    mkdir -p ${installPath}${rsyncMacportsOrg}/${filesDir#*portfiles/}
     140    cp -Rv ${filesDir}/* \
     141           ${installPath}${rsyncMacportsOrg}/${filesDir#*portfiles/}
     142done
     143
     144echo -e "\npatching the portfiles"
     145for portPatch in $(find portfiles -type f -name 'patch-Portfile')
     146do
     147    patchFile=$( sed -En -e '1,1p' ${portPatch} | tr -s "\t" " " | cut -f2 -d ' ' )
     148    patch -u <${portPatch} ${patchFile}
     149done
     150
     151echo ''
     152${installPath}/bin/port outdated
     153
     154echo -e "\nupgrading the outdated ports"
     155for outDated in $(${installPath}/bin/port outdated | sed -e '1,1d' | tr -s " \t" | cut -f 1 -d ' ')
     156do
     157    ${installPath}/bin/port -cuRp upgrade ${outDated}
     158done
     159
     160
     161echo -e "\nremoving macport saved files"
     162find ${installPath} -iname *.mpsaved -delete
     163find ${installPath} -iname *.mp_* -delete
     164
     165echo -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
     176declare prefix=${2:-"/macports"}
     177
     178(   cd  $( dirname ${0} )
     179
     180declare -a info=( $( find "${prefix}"/var/macports/sources/rsync.macports.org/release/ports -iname "${1}" | tr '/' ' ' ) )
     181declare portName=${info[$(( ${#info[@]}-1 ))]}
     182declare portCategory=${info[$(( ${#info[@]}-2 ))]}
     183
     184mkdir -p portfiles/${portCategory}/${portName}
     185cp ${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
     196declare prefix=${1:-"/macports"}
     197declare rsyncMacportsOrg="/var/macports/sources/rsync.macports.org/release/ports"
     198
     199(   cd $( dirname ${0} )
     200
     201declare outputFile
     202declare patchFile
     203
     204for port in $(find portfiles -name 'Portfile')
     205do
     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
     214done
     215
     216) ; wait
     217}}}
     218
     219[wiki:howto <- Back to the HOWTO section]