Improve robustness of post-install script
[mono-project.git] / packaging / MacSDK / packaging / resources / postinstall
blob689fb5845d70481ec83a5609837d6fc47e95f8dc
1 #!/bin/sh -x
3 FW=/Library/Frameworks/Mono.framework
4 FW_CURRENT=${FW}/Versions/Current
5 CURRENT=`basename $(readlink ${FW_CURRENT})`
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
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
23 WHITELIST=$(cat "$(dirname "$0")/whitelist.txt")
24 MONO_COMMANDS_FILE=/etc/paths.d/mono-commands
25 FW_WHITELISTED_COMMANDS=${FW_CURRENT}/Commands
27 mkdir -p ${FW_WHITELISTED_COMMANDS}
28 mkdir -p $(dirname ${MONO_COMMANDS_FILE})
30 if test -e ${MONO_COMMANDS_FILE}; then
31 rm "${MONO_COMMANDS_FILE}"
34 echo "${FW_WHITELISTED_COMMANDS}" >> "${MONO_COMMANDS_FILE}"
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}"
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."
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}"
57 done
58 done
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 > "${FW_CURRENT}/postinstall-gdk-pixbuf-query-loaders.log" 2>&1 || true
65 # pango setup
66 mkdir -p pango
67 pango-querymodules > pango/pango.modules 2> "${FW_CURRENT}/postinstall-pango-querymodules.log" || true
68 pango-querymodules --update-cache >> "${FW_CURRENT}/postinstall-pango-querymodules.log" 2>&1 || true
69 fc-cache > "${FW_CURRENT}/postinstall-fc-cache.log" 2>&1 || true
71 cd ${FW_CURRENT}/lib/gtk-2.0/2.10.0
72 gtk-query-immodules-2.0 > immodules.cache 2> "${FW_CURRENT}/gtk-query-immodules-2.0.log" || true
75 # Delete older Monos
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
81 echo "Current:" $CURRENT >> /tmp/mono-installation
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
91 if [ -f $i/keep ]; then
92 echo "Keeping" $i "because of keep file" >> /tmp/mono-installation
93 continue
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
102 else
103 echo "rm -rf" $i >> /tmp/mono-installation
104 rm -rf $i
106 done
107 popd
109 # Mono framework should be owned by root
110 chown -R root:admin ${FW}