use patchelf to reset RPATH within bundled libraries so that the runtime linker will...
[ardour.git] / tools / linux_packaging / uninstall.sh.in
1 #!/bin/sh
2
3 ######################################
4 #
5 #       Ardour/Mixbus bundle uninstaller
6 #       Todd Naugle
7 #
8 #####################################
9
10
11 PGM_NAME="%REPLACE_PGM%"
12 PGM_VENDOR="%REPLACE_VENDOR%"
13 PGM_VERSION="%REPLACE_VERSION%"
14 PGM_BUILD="%REPLACE_BUILD%"
15 PGM_BUILDTYPE="%REPLACE_TYPE%"
16
17 INSTALL_DEST_BASE=/opt
18 USER_BIN_DIR="/usr/local/bin"
19
20 UNINSTALLER="$(readlink -f "$0")"
21
22 USER_NAME=$(logname)
23
24
25 #### Derived Variables ####
26 if [ -z "${PGM_BUILDTYPE}" ]; then
27         PGM_PATH=${INSTALL_DEST_BASE}/${PGM_NAME}-${PGM_VERSION}_${PGM_BUILD}
28         ICON_NAME="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}"                    #no dash between name and version since dash seperates vendor from program
29         MENU_FILE="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}.desktop"    #no dash between name and version since dash seperates vendor from program
30         DESKTOP_LINK_FILE="${PGM_NAME}_${PGM_VERSION}.desktop"
31 else
32         PGM_PATH=${INSTALL_DEST_BASE}/${PGM_NAME}-${PGM_VERSION}_${PGM_BUILD}-${PGM_BUILDTYPE}
33         ICON_NAME="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}_${PGM_BUILDTYPE}"                   #no dash between name and version since dash seperates vendor from program
34         MENU_FILE="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}_${PGM_BUILDTYPE}.desktop"   #no dash between name and version since dash seperates vendor from program
35         DESKTOP_LINK_FILE="${PGM_NAME}_${PGM_VERSION}_${PGM_BUILDTYPE}.desktop"
36 fi
37
38 MENU_FILE_PATH="${PGM_PATH}/share/${MENU_FILE}"
39
40
41 #############################
42 # Check for root privileges
43 #############################
44
45 SUPER=""
46
47 if [ "$(id -u)" != "0" ]; then
48
49         if ! which sudo > /dev/null;
50         then
51                 echo ""
52                 echo "Attempting to uninstall using su"
53                 echo "Please enter root password below"
54                 echo ""
55
56                 if ! su -c "${UNINSTALLER}";
57                 then
58                         echo ""
59                         echo "!!! ERROR !!!"
60                         echo ""
61                         echo "This uninstaller requires root privileges. It is currently not"
62                         echo "running as root AND an attempt to use su failed."
63                         echo ""
64                         echo "Please correct this by installing and configuring sudo or running"
65                         echo "the uninstaller as root (su -c)."
66                         echo ""
67                         read -p "Press ENTER to exit uninstaller:" BLAH
68                         exit 1
69                 fi
70                 exit
71         fi
72
73         if ! sudo date;
74         then
75                 echo ""
76                 echo "Attempting to uninstall using su"
77                 echo "Please enter root password below"
78                 echo ""
79
80                 if ! su -c "${UNINSTALLER}";
81                 then
82                         echo ""
83                         echo "!!! ERROR !!!"
84                         echo ""
85                         echo "This uninstaller requires root privileges. It is currently not"
86                         echo "running as root AND an attempt to use both sudo and su failed."
87                         echo ""
88                         echo "Please correct this by installing and configuring sudo or running"
89                         echo "the uninstaller as root (su -c)."
90                         echo ""
91                         read -p "Press ENTER to exit uninstaller:" BLAH
92                         exit 1
93                 fi
94                 exit
95         fi
96         SUPER="sudo"
97 fi
98
99 #######################
100 # Check for xdg utils
101 #######################
102 HAS_XDG="T"
103
104 #load the file that contains the translated names of the users directories
105 if [ -e /home/${USER_NAME}/.config/user-dirs.dirs ]; then
106         . /home/${USER_NAME}/.config/user-dirs.dirs
107 fi
108
109 if [ "$(id -u)" != "0" ]; then
110         USER_DESKTOP_DIR=${XDG_DESKTOP_DIR:-$HOME/Desktop}
111 else
112         #running as root with su makes this more difficult
113         DESKTOP_FOLDER=$(echo ${XDG_DESKTOP_DIR:-$HOME/Desktop} | awk -F/ '{print $NF}')
114         USER_DESKTOP_DIR="/home/${USER_NAME}/${DESKTOP_FOLDER}"
115 fi
116
117 XDG_MENU_VER=$(xdg-desktop-menu --version 2> /dev/null)
118 if [ -z "$XDG_MENU_VER" ];
119 then
120         echo "System does not have xdg-desktop-menu installed"
121         HAS_XDG="F"
122 fi
123
124 XDG_ICON_VER=$(xdg-icon-resource --version 2> /dev/null)
125 if [ -z "$XDG_ICON_VER" ];
126 then
127         echo "System does not have xdg-icon-resource installed"
128         HAS_XDG="F"
129 fi
130
131
132 #############
133 # Uninstall
134 #############
135
136 if [ -d ${PGM_PATH} ];
137 then
138         echo ""
139         echo "Removing existing ${PGM_NAME} installation at ${PGM_PATH}"
140         echo ""
141
142         if [ "T" = ${HAS_XDG} ];
143         then
144                 ${SUPER} xdg-desktop-menu uninstall ${MENU_FILE_PATH}
145                 ${SUPER} xdg-icon-resource uninstall --size 16 ${ICON_NAME}
146                 ${SUPER} xdg-icon-resource uninstall --size 22 ${ICON_NAME}
147                 ${SUPER} xdg-icon-resource uninstall --size 32 ${ICON_NAME}
148                 ${SUPER} xdg-icon-resource uninstall --size 48 ${ICON_NAME}
149
150                 if [ -e /usr/share/icons/hicolor/scalable/apps/${ICON_NAME}.svg ]; 
151                 then
152                         ${SUPER} rm -f /usr/share/icons/hicolor/scalable/apps/${ICON_NAME}.svg
153                 fi
154         fi
155
156         if [ -e ${USER_DESKTOP_DIR}/${DESKTOP_LINK_FILE} ];
157         then
158                 ${SUPER} rm -f ${USER_DESKTOP_DIR}/${DESKTOP_LINK_FILE}
159         fi
160
161         # delete the bin link if it is linked to this version
162         if [ -e "${USER_BIN_DIR}/${PGM_NAME}3" ]; 
163         then
164                 BIN_LINK_TARGET=$(readlink "${USER_BIN_DIR}/${PGM_NAME}3")
165                 BIN_LINK_TARGET_DIR=$(dirname "${BIN_LINK_TARGET}")
166
167                 if [ "${BIN_LINK_TARGET_DIR}" = "${PGM_PATH}/bin" ];
168                 then
169                         ${SUPER} rm -f "${USER_BIN_DIR}/${PGM_NAME}3"
170                 fi
171         fi
172         
173
174         # delete the old package
175         ${SUPER} rm -rf ${PGM_PATH}
176         ${SUPER} rm -f $0
177 else
178         echo ""
179         echo "!!! FAILURE !!! - install path ${PGM_PATH} does not exist."
180         echo ""
181 fi