Ensure '/etc/paths.d' exists (it doesn't on clean macOS Sierra installations)
[mono.git] / bockbuild / MacSDK / packaging / resources / postinstall
1 #!/bin/sh -x
2
3 FW=/Library/Frameworks/Mono.framework
4 FW_CURRENT=${FW}/Versions/Current
5 CURRENT=`basename $(readlink ${FW_CURRENT})`
6
7 # Remove PCL assemblies that we installed from Mono 3.1.1
8 LICENSE="Portable Class Library Reference Assemblies License-07JUN2013.docx"
9 if [ -f "$FW/External/xbuild-frameworks/.NETPortable/$LICENSE" ]; then
10     echo "Removing PCL because we're upgrading from 3.1.1" >> /tmp/mono-installation
11     rm -rf $FW/External/xbuild-frameworks/.NETPortable
12 fi
13
14 # Remove /usr/local/bin/pkg-config if it's a symlink to the Mono-installed one
15 PKG_CONFIG_LINK="/usr/local/bin/pkg-config"
16 if [ -L $PKG_CONFIG_LINK ]; then
17     location=`readlink $PKG_CONFIG_LINK`
18     case "$location" in
19     *Mono.framework*) rm $PKG_CONFIG_LINK;;
20     esac
21 fi
22
23 WHITELIST=$(cat "$(dirname "$0")/whitelist.txt")
24 MONO_COMMANDS_FILE=/etc/paths.d/mono-commands
25 FW_WHITELISTED_COMMANDS=${FW_CURRENT}/Commands
26
27 mkdir ${FW_WHITELISTED_COMMANDS}
28 mkdir /etc/paths.d
29
30 if test -e ${MONO_COMMANDS_FILE}; then
31     rm "${MONO_COMMANDS_FILE}"
32 fi
33
34 echo "${FW_WHITELISTED_COMMANDS}" >> "${MONO_COMMANDS_FILE}"
35
36 if [ -d "${FW}"/Commands ]; then
37     for i in ${WHITELIST}; do
38         if test -e "${FW}/Commands/${i}"; then
39             ln -s "${FW}/Commands/${i}" "${FW_WHITELISTED_COMMANDS}/${i}"
40         fi
41     done;
42 else
43     echo "${FW}/Commands does not exist"
44     echo "Can not add command links to $PATH."
45 fi
46
47 if [ -d ${FW_CURRENT} ]; then
48     cd ${FW_CURRENT}/share/man
49     for i in ${WHITELIST}; do
50         for j in $(ls man*/${i}.*); do
51             if test ! -e "/usr/local/share/man/${j}"; then
52                 ln -sf "${FW_CURRENT}/share/man/${j}" "/usr/local/share/man/${j}"
53             fi
54         done
55     done
56
57     cd ${FW_CURRENT}/etc
58     # Make sure we run the files we lay down, and not other stuff installed on the system
59     export PATH=${FW_CURRENT}/bin:$PATH
60     # gtk+ setup
61     gdk-pixbuf-query-loaders --update-cache
62     # pango setup
63     mkdir -p pango
64     pango-querymodules >  pango/pango.modules
65     pango-querymodules --update-cache
66     fc-cache
67
68     cd ${FW_CURRENT}/lib/gtk-2.0/2.10.0
69     gtk-query-immodules-2.0 > immodules.cache
70 fi
71
72 # Delete older Monos
73 #
74 # - keep if the major version is different
75 # - keep if 'Versions/x.y.z/keep' exists
76 # - Keep if it is greater than $CURRENT
77 #
78 echo "Current:" $CURRENT >> /tmp/mono-installation
79
80 pushd ${FW}/Versions
81 for i in `ls -d *`; do
82     result=`echo "${i:0:1} == ${CURRENT:0:1}" | bc`
83     if [ $result -ne 1 ]; then
84         echo "keeping" $i "because it has a different major version" >> /tmp/mono-installation
85         continue
86     fi
87
88     if [ -f $i/keep ]; then
89         echo "Keeping" $i "because of keep file" >> /tmp/mono-installation
90         continue
91     fi
92
93     # A magical bit of Perl: http://stackoverflow.com/a/7366753/494990
94     result=$(perl -e '($a,$b)=@ARGV; for ($a,$b) {s/(\d+)/sprintf "%5d", $1/ge}; print $a cmp $b;' $i $CURRENT)
95     if [ $result -ge 0 ]; then
96         echo "Skipping" $i "because $i >= $CURRENT" >> /tmp/mono-installation
97         continue
98
99     else
100         echo "rm -rf" $i >> /tmp/mono-installation
101         rm -rf $i
102     fi
103 done
104 popd
105
106 # Mono framework should be owned by root
107 chown -R root:admin ${FW}