Version 3 (modified by BjarneDMat, 4 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 0: Default Values
declare prefix='/opt/local' declare version='2.6.4'
Script 1: Installation
#!/usr/bin/env bash ################################################################################ # copyright Bjarne D Mathiesen # Korsør ; 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 # 05/03-2017 added update to actions # 31/01-2018 added checkpaths & fixpaths # updated default values for the parameters # 02/03-2021 removed fixpaths # reworked setpaths # added fixCLT # # this script is released under the OSS GPL v3 license # the author welcomes feedback and improvements # ( cd $( dirname ${0} ) source ./portDefaults usage() { cat <<EOT purpose : to automate the whole install process \${1} : action [ update (default) , install , setpaths , checkpaths , select , fixCLT ] \${2} : macports base version ( default ${version} ) only for install EOT } declare action=${1:-"update"} [ ! -z ${2} ] && declare version=${2} case ${action} in ######################## # https://trac.macports.org/wiki/ProblemHotlist#reinstall-clt ('fixCLT') touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress softwareupdate -ia rm /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress ;; ######################## # ('select') while read -u 9 name selected options do options=( $( echo ${options} ) ) port select --set "${name}" ${options[@]: -2:1} done 9< <( port -q select --summary ) port select --summary ;; ######################## # update installed ports ('update') port -dN selfupdate port outdated port clean --work outdated port -cuNp upgrade outdated port -pN clean --work installed # port -pN reclaim ;; ######################## # setup the system paths ('setpaths') 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 echo "${prefix}/sbin" >> /etc/paths echo "/Applications/Xcode.app/Contents/Developer/usr/bin" > /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 ;; ######################## # check the system paths ('checkpaths') /usr/libexec/path_helper ;; ################## # install macports ('install') if [ ! -e MacPorts-${version}.tar.gz ] then curl -O --url "https://distfiles.macports.org/MacPorts/MacPorts-${version}.tar.gz" fi rm -rf ./MacPorts-${version} tar -zxf MacPorts-${version}.tar.gz cd MacPorts-${version} #patch -p0 </Volumes/Bjarne/WebServer/MacPorts/newPorts/pathces/mp-base-no-progress-if-stdout-no-tty.patch #./configure LDFLAGS=-L/Developer/SDKs/MacOSX10.6.sdk/usr/X11/lib --prefix=${prefix} ./configure --prefix=${prefix} make make install # update MacPorts itself ${prefix}/bin/port -dN selfupdate # let's get bash, zsh & nano ${prefix}/bin/port -N install bash zsh nano # cleanup rm -rf ./MacPorts-${version} ;; # default (*) usage esac ) ; wait
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