howto/AdvancedDailyAdm: macports.bash

File macports.bash, 4.5 KB (added by BjarneDMat, 3 years ago)

Script 1: Installation

Line 
1#!/usr/bin/env bash
2
3declare prefix='/opt/local'
4declare version=$( curl -fs --url 'https://raw.githubusercontent.com/macports/macports-base/master/config/RELEASE_URL' )
5version=${version##*/v}
6
7################################################################################
8# copyright Bjarne D Mathiesen
9#           Kors¿r ; Danmark ; Europa
10#           macintosh .at. mathiesen .dot. info
11# date      04/07-2007
12# revised   02/12-2007  implemented automatic patching of Portfiles
13#           28/12-2009  fixed the download link
14#                       modified source/build directory
15#                       removed sudo from commands
16#           18/06-2011  added default values for the parameters
17#                       updated path values for XCode4
18#           05/03-2017  added update to actions
19#           31/01-2018  added checkpaths & fixpaths
20#                       updated default values for the parameters
21#           02/03-2021  removed  fixpaths
22#                       reworked setpaths
23#                       added fixCLT
24#
25# this script is released under the OSS GPL v3 license
26# the author welcomes feedback and improvements
27#
28(   cd  $( dirname ${0} )
29
30source ./portDefaults
31
32usage() {
33cat <<EOT
34
35purpose : to automate the whole MacPorts install & update process
36\${1} : action                 [ update (default) , install , setpaths , checkpaths , select , fixCLT ]
37\${2} : macports base version  ( default ${version} ) only for install
38
39!!! the script has to be run with root privileges !!!
40
41EOT
42}
43
44declare action=${1:-"update"}
45[ ! -z ${2} ] && declare version=${2}
46
47case ${action} in
48('-h'|'--help')
49usage
50exit
51esac
52
53if [[ ${EUID} -ne 0 ]]
54then
55cat <<EOT
56
57+------------------------------------------------+
58| this script has to be run with root privileges I
59+------------------------------------------------+
60please try again with "sudo ${0}"
61
62EOT
63usage
64exit
65fi
66
67case ${action} in
68
69########################
70# https://trac.macports.org/wiki/ProblemHotlist#reinstall-clt
71('fixCLT')
72touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
73softwareupdate -ia
74rm /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
75
76;;
77########################
78#
79('select')
80while read -u 9 name selected options
81do
82    options=( $( echo ${options} ) )
83    port select --set "${name}" ${options[@]: -2:1}
84done 9< <( port -q select --summary )
85port select --summary
86
87;;
88########################
89# update installed ports
90('update')
91port -dN selfupdate
92port outdated
93port clean --work outdated
94port -cuNp upgrade outdated
95port -pN clean --work installed
96# port -pN reclaim
97
98;;
99########################
100# setup the system paths
101('setpaths')
102
103mkdir -p  /etc/paths.d
104cp    -np /etc/paths /etc/paths.orig
105mv    -n  /etc/paths /etc/paths.d/999macosx
106touch     /etc/paths
107
108echo "${prefix}/bin"        >  /etc/paths
109echo "${prefix}/sbin"       >> /etc/paths
110
111echo "/Applications/Xcode.app/Contents/Developer/usr/bin"   >  /etc/paths.d/888developer
112
113mkdir -p  /etc/manpaths.d
114cp    -np /etc/manpaths /etc/manpaths.orig
115mv    -n  /etc/manpaths /etc/manpaths.d/999macosx
116touch     /etc/manpaths
117
118echo "${prefix}/share/man"  > /etc/manpaths.d/000macports
119#echo "/Developer/usr/share/man"     >  /etc/manpaths.d/888developer
120#echo "/Developer/usr/X11/share/man" >> /etc/manpaths.d/888developer
121
122;;
123########################
124# check the system paths
125('checkpaths')
126/usr/libexec/path_helper
127
128;;
129##################
130# install macports
131('install')
132
133if [ ! -e MacPorts-${version}.tar.gz ]
134then
135    #https://github.com/macports/macports-base/releases/download/v2.7.0/MacPorts-2.7.0.tar.gz
136    curl -L -O --url "https://github.com/macports/macports-base/releases/download/v${version}/MacPorts-${version}.tar.gz"
137fi
138
139rm  -rf  ./MacPorts-${version}
140tar -zxf   MacPorts-${version}.tar.gz 2>/dev/null
141
142cd MacPorts-${version}
143#patch -p0 </Volumes/Bjarne/WebServer/MacPorts/newPorts/pathces/mp-base-no-progress-if-stdout-no-tty.patch
144#./configure LDFLAGS=-L/Developer/SDKs/MacOSX10.6.sdk/usr/X11/lib --prefix=${prefix}
145CC=/usr/bin/cc ./configure \
146     --prefix=/opt/local \
147     --with-install-user=root \
148     --with-install-group=admin \
149     --with-directory-mode=0755 \
150     --enable-readline \
151&& make SELFUPDATING=1 \
152&& make install SELFUPDATING=1
153
154# update MacPorts itself
155${prefix}/bin/port -dN selfupdate
156
157# let's get bash, zsh & nano
158${prefix}/bin/port -N install bash  && echo "${prefix}/bin/bash" >> /etc/shells
159${prefix}/bin/port -N install zsh   && echo "${prefix}/bin/zsh"  >> /etc/shells
160${prefix}/bin/port -N install nano
161
162# cleanup
163cd ..
164rm  -rf  ./MacPorts-${version}
165
166;;
167# default
168(*)
169usage
170esac
171
172) ; wait