Version 1 (modified by BjarneDMat, 13 years ago) (diff) |
---|
Advanced Daily Administration of MacPorts
- Audience: advanced users
- Requires: MacPorts >=1.9.2
- Author: Bjarne D Mathiesen - macintosh _at_ mathiesen _dot_ info
Introduction
This is a dump of my scripts to administer MacPorts on a daily basis.
Please append comments, questions, and suggestions here.
The Scripts
Script 1: Installation
#!/bin/bash ################################################################################ # copyright Bjarne D Mathiesen # København ; Danmark ; Europa # macintosh .at. mathiesen .dot. info # date 04/07-2007 # revised 02/12-2007 implemented automatic patching of Portfiles # 28/12-2009 fixed the download link # modified source/build directory # removed sudo from commands # 18/06-2011 added default values for the parameters # updated path values for XCode4 # # this script is released under the BSD license # the author welcomes feedback and improvements # usage() { cat <<EOT purpose : to automate the whole install process \${1} : action [ install (default) , paths ] \${2} : install prefix ( default /macports ) \${3} : macports base version ( default 1.9.2 ) EOT } declare action=${1:-"install"} declare prefix=${2:-"/macports"} declare version=${3:-"1.9.2"} case ${action} in ######################## # setup the system paths 'paths') mkdir -p /etc/paths.d cp -np /etc/paths /etc/paths.orig mv -n /etc/paths /etc/paths.d/999macosx touch /etc/paths echo "${prefix}/bin" > /etc/paths.d/000macports echo "${prefix}/sbin" >> /etc/paths.d/000macports echo "/Developer/usr/bin" > /etc/paths.d/888developer echo "/Developer/usr/sbin" >> /etc/paths.d/888developer mkdir -p /etc/manpaths.d cp -np /etc/manpaths /etc/manpaths.orig mv -n /etc/manpaths /etc/manpaths.d/999macosx touch /etc/manpaths echo "${prefix}/share/man" > /etc/manpaths.d/000macports echo "/Developer/usr/share/man" > /etc/manpaths.d/888developer echo "/Developer/usr/X11/share/man" >> /etc/manpaths.d/888developer # path_helper is buggy under 10.5 #cp -npv /usr/libexec/path_helper /usr/libexec/path_helper.orig #cp -v path_helper /usr/libexec/ ;; ################## # install macports 'install') if [ ! -e MacPorts-${version}.tar.gz ] then curl -O --url "http://distfiles.macports.org/MacPorts/MacPorts-${version}.tar.gz" fi rm -rf ./MacPorts-${version} tar -zxf MacPorts-${version}.tar.gz cd MacPorts-${version} ./configure LDFLAGS=-L/Developer/SDKs/MacOSX10.6.sdk/usr/X11/lib --prefix=${prefix} make make install # update DarwinPorts itself ${prefix}/bin/port -d selfupdate # let's get bash ${prefix}/bin/port install bash ;; # default *) usage esac
Script 2: Updating
#!/macports/bin/bash # # usage: # ${1}: the macports install path # ( cd $( dirname ${0} ) echo -e "\n"'+----------------+' echo '| macportsupdate |' echo '+----------------+' declare installPath=${1:-'/macports'} declare rsyncMacportsOrg='/var/macports/sources/rsync.macports.org/release/ports' echo "selfupdating & syncing all repositories" ${installPath}/bin/port -d selfupdate cp -Rv newPorts/_resources \ ${installPath}${rsyncMacportsOrg} echo -e "\ncopy additional files to the ports" for filesDir in $(find portfiles -type d -name 'files') do mkdir -p ${installPath}${rsyncMacportsOrg}/${filesDir#*portfiles/} cp -Rv ${filesDir}/* \ ${installPath}${rsyncMacportsOrg}/${filesDir#*portfiles/} done echo -e "\npatching the portfiles" for portPatch in $(find portfiles -type f -name 'patch-Portfile') do patchFile=$( sed -En -e '1,1p' ${portPatch} | tr -s "\t" " " | cut -f2 -d ' ' ) patch -u <${portPatch} ${patchFile} done echo '' ${installPath}/bin/port outdated echo -e "\nupgrading the outdated ports" for outDated in $(${installPath}/bin/port outdated | sed -e '1,1d' | tr -s " \t" | cut -f 1 -d ' ') do ${installPath}/bin/port -cuRp upgrade ${outDated} done echo -e "\nremoving macport saved files" find ${installPath} -iname *.mpsaved -delete find ${installPath} -iname *.mp_* -delete echo -e "\nremoving inactive ports" ${installPath}/bin/port installed | sed -e '1,1d' -e '/active/d' | xargs -n2 ${installPath}/bin/port uninstall ) ; wait
Script 3: Copying a Port
#!/macports/bin/bash declare prefix=${2:-"/macports"} ( cd $( dirname ${0} ) declare -a info=( $( find "${prefix}"/var/macports/sources/rsync.macports.org/release/ports -iname "${1}" | tr '/' ' ' ) ) declare portName=${info[$(( ${#info[@]}-1 ))]} declare portCategory=${info[$(( ${#info[@]}-2 ))]} mkdir -p portfiles/${portCategory}/${portName} cp ${prefix}/var/macports/sources/rsync.macports.org/release/ports/${portCategory}/${portName}/Portfile \ portfiles/${portCategory}'/'${portName}/'Portfile.orig' ) ; wait
Script 4: Creating a Patch for a Port
#!/macports/bin/bash declare prefix=${1:-"/macports"} declare rsyncMacportsOrg="/var/macports/sources/rsync.macports.org/release/ports" ( cd $( dirname ${0} ) declare outputFile declare patchFile for port in $(find portfiles -name 'Portfile') do outputFile=${port%/*}/patch-${port##*/} rm ${outputFile} 2>/dev/null diff -u \ ${prefix}${rsyncMacportsOrg}/${port#*/} \ ${port} \ > ${outputFile} echo "created patch for ${port}" mv ${port} ${port}.OK done ) ; wait
Attachments (5)
-
updating.bash (1.5 KB) - added by BjarneDMat 13 years ago.
the updating script
-
cpPortfile.bash (527 bytes) - added by BjarneDMat 13 years ago.
the copy a Portfile script
-
portPatch.bash (509 bytes) - added by BjarneDMat 13 years ago.
the script for creating a patch
-
portDefaults (173 bytes) - added by BjarneDMat 4 years ago.
default values file
-
macports.bash (4.5 KB) - added by BjarneDMat 4 years ago.
Script 1: Installation
Download all attachments as: .zip