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