1 | #!/usr/bin/env bash |
---|
2 | |
---|
3 | declare prefix='/opt/local' |
---|
4 | declare version=$( curl -fs --url 'https://raw.githubusercontent.com/macports/macports-base/master/config/RELEASE_URL' ) |
---|
5 | version=${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 | |
---|
30 | source ./portDefaults |
---|
31 | |
---|
32 | usage() { |
---|
33 | cat <<EOT |
---|
34 | |
---|
35 | purpose : 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 | |
---|
41 | EOT |
---|
42 | } |
---|
43 | |
---|
44 | declare action=${1:-"update"} |
---|
45 | [ ! -z ${2} ] && declare version=${2} |
---|
46 | |
---|
47 | case ${action} in |
---|
48 | ('-h'|'--help') |
---|
49 | usage |
---|
50 | exit |
---|
51 | esac |
---|
52 | |
---|
53 | if [[ ${EUID} -ne 0 ]] |
---|
54 | then |
---|
55 | cat <<EOT |
---|
56 | |
---|
57 | +------------------------------------------------+ |
---|
58 | | this script has to be run with root privileges I |
---|
59 | +------------------------------------------------+ |
---|
60 | please try again with "sudo ${0}" |
---|
61 | |
---|
62 | EOT |
---|
63 | usage |
---|
64 | exit |
---|
65 | fi |
---|
66 | |
---|
67 | case ${action} in |
---|
68 | |
---|
69 | ######################## |
---|
70 | # https://trac.macports.org/wiki/ProblemHotlist#reinstall-clt |
---|
71 | ('fixCLT') |
---|
72 | touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress |
---|
73 | softwareupdate -ia |
---|
74 | rm /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress |
---|
75 | |
---|
76 | ;; |
---|
77 | ######################## |
---|
78 | # |
---|
79 | ('select') |
---|
80 | while read -u 9 name selected options |
---|
81 | do |
---|
82 | options=( $( echo ${options} ) ) |
---|
83 | port select --set "${name}" ${options[@]: -2:1} |
---|
84 | done 9< <( port -q select --summary ) |
---|
85 | port select --summary |
---|
86 | |
---|
87 | ;; |
---|
88 | ######################## |
---|
89 | # update installed ports |
---|
90 | ('update') |
---|
91 | port -dN selfupdate |
---|
92 | port outdated |
---|
93 | port clean --work outdated |
---|
94 | port -cuNp upgrade outdated |
---|
95 | port -pN clean --work installed |
---|
96 | # port -pN reclaim |
---|
97 | |
---|
98 | ;; |
---|
99 | ######################## |
---|
100 | # setup the system paths |
---|
101 | ('setpaths') |
---|
102 | |
---|
103 | mkdir -p /etc/paths.d |
---|
104 | cp -np /etc/paths /etc/paths.orig |
---|
105 | mv -n /etc/paths /etc/paths.d/999macosx |
---|
106 | touch /etc/paths |
---|
107 | |
---|
108 | echo "${prefix}/bin" > /etc/paths |
---|
109 | echo "${prefix}/sbin" >> /etc/paths |
---|
110 | |
---|
111 | echo "/Applications/Xcode.app/Contents/Developer/usr/bin" > /etc/paths.d/888developer |
---|
112 | |
---|
113 | mkdir -p /etc/manpaths.d |
---|
114 | cp -np /etc/manpaths /etc/manpaths.orig |
---|
115 | mv -n /etc/manpaths /etc/manpaths.d/999macosx |
---|
116 | touch /etc/manpaths |
---|
117 | |
---|
118 | echo "${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 | |
---|
133 | if [ ! -e MacPorts-${version}.tar.gz ] |
---|
134 | then |
---|
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" |
---|
137 | fi |
---|
138 | |
---|
139 | rm -rf ./MacPorts-${version} |
---|
140 | tar -zxf MacPorts-${version}.tar.gz 2>/dev/null |
---|
141 | |
---|
142 | cd 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} |
---|
145 | CC=/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 |
---|
163 | cd .. |
---|
164 | rm -rf ./MacPorts-${version} |
---|
165 | |
---|
166 | ;; |
---|
167 | # default |
---|
168 | (*) |
---|
169 | usage |
---|
170 | esac |
---|
171 | |
---|
172 | ) ; wait |
---|