[wiki:howto <- Back to the HOWTO section] = 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=$( curl -fs --url 'https://raw.githubusercontent.com/macports/macports-base/master/config/RELEASE_URL' ) version=${version##*/v} }}} === 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 < /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 -L -O --url "https://github.com/macports/macports-base/releases/download/v${version}/MacPorts-${version}.tar.gz" fi rm -rf ./MacPorts-${version} tar -zxf MacPorts-${version}.tar.gz 2>/dev/null cd MacPorts-${version} CC=/usr/bin/cc ./configure \ --prefix=/opt/local \ --with-install-user=root \ --with-install-group=admin \ --with-directory-mode=0755 \ --enable-readline \ && make SELFUPDATING=1 \ && make install SELFUPDATING=1 # update MacPorts itself ${prefix}/bin/port -dN selfupdate # let's get bash, zsh & nano ${prefix}/bin/port -N install bash && echo "${prefix}/bin/bash" >> /etc/shells ${prefix}/bin/port -N install zsh && echo "${prefix}/bin/zsh" >> /etc/shells ${prefix}/bin/port -N install nano # cleanup cd .. rm -rf ./MacPorts-${version} ;; # default (*) usage esac ) ; wait }}} === Script 2: '''Updating''' === {{{ #!/usr/bin/env bash # # usage: # ${1}: the macports install path # ( cd $( dirname ${0} ) echo -e "\n"'+----------------+' echo '| macportsupdate |' echo '+----------------+' declare installPath=${1:-'/opt/local'} 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''' === {{{ #!/usr/bin/env bash source ./portDefaults ( 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''' === {{{ #!/usr/bin/env bash source ./portDefaults source ./defaultPaths ( 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 }}} [wiki:howto <- Back to the HOWTO section]