Fixes for the 'xamarin' profile.
[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
29 if test -e ${MONO_COMMANDS_FILE}; then
30     rm "${MONO_COMMANDS_FILE}"
31 fi
32
33 echo "${FW_WHITELISTED_COMMANDS}" >> "${MONO_COMMANDS_FILE}"
34
35 if [ -d "${FW}"/Commands ]; then
36     for i in ${WHITELIST}; do
37         if test -e "${FW}/Commands/${i}"; then
38             ln -s "${FW}/Commands/${i}" "${FW_WHITELISTED_COMMANDS}/${i}"
39         fi
40     done;
41 else
42     echo "${FW}/Commands does not exist"
43     echo "Can not add command links to $PATH."
44 fi
45
46 if [ -d ${FW_CURRENT} ]; then
47     cd ${FW_CURRENT}/share/man
48     for i in ${WHITELIST}; do
49         for j in $(ls man*/${i}.*); do
50             if test ! -e "/usr/local/share/man/${j}"; then
51                 ln -sf "${FW_CURRENT}/share/man/${j}" "/usr/local/share/man/${j}"
52             fi
53         done
54     done
55
56     cd ${FW_CURRENT}/etc
57     # Make sure we run the files we lay down, and not other stuff installed on the system
58     export PATH=${FW_CURRENT}/bin:$PATH
59     # gtk+ setup
60     gdk-pixbuf-query-loaders --update-cache
61     # pango setup
62     mkdir -p pango
63     pango-querymodules >  pango/pango.modules
64     pango-querymodules --update-cache
65     fc-cache
66
67     cd ${FW_CURRENT}/lib/gtk-2.0/2.10.0
68     gtk-query-immodules-2.0 > immodules.cache
69 fi
70
71 # Delete older Monos
72 #
73 # - keep if the major version is different
74 # - keep if 'Versions/x.y.z/keep' exists
75 # - Keep if it is greater than $CURRENT
76 #
77 echo "Current:" $CURRENT >> /tmp/mono-installation
78
79 pushd ${FW}/Versions
80 for i in `ls -d *`; do
81     result=`echo "${i:0:1} == ${CURRENT:0:1}" | bc`
82     if [ $result -ne 1 ]; then
83         echo "keeping" $i "because it has a different major version" >> /tmp/mono-installation
84         continue
85     fi
86
87     if [ -f $i/keep ]; then
88         echo "Keeping" $i "because of keep file" >> /tmp/mono-installation
89         continue
90     fi
91
92     # A magical bit of Perl: http://stackoverflow.com/a/7366753/494990
93     result=$(perl -e '($a,$b)=@ARGV; for ($a,$b) {s/(\d+)/sprintf "%5d", $1/ge}; print $a cmp $b;' $i $CURRENT)
94     if [ $result -ge 0 ]; then
95         echo "Skipping" $i "because $i >= $CURRENT" >> /tmp/mono-installation
96         continue
97
98     else
99         echo "rm -rf" $i >> /tmp/mono-installation
100         rm -rf $i
101     fi
102 done
103 popd
104
105 # Mono framework should be owned by root
106 chown -R root:admin ${FW}