Add some lua scripts
[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 MAJOR_VERSION="%REPLACE_MAJOR_VERSION%"
11
12 PGM_NAME="%REPLACE_PGM%"
13 PGM_VENDOR="%REPLACE_VENDOR%"
14 PGM_VERSION="%REPLACE_VERSION%"
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}
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_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         else
72                 sudo -k # make sudo forget about cached credentials
73         fi
74
75         if ! sudo date;
76         then
77                 echo ""
78                 echo "Attempting to uninstall using su"
79                 echo "Please enter root password below"
80                 echo ""
81
82                 if ! su -c "${UNINSTALLER}";
83                 then
84                         echo ""
85                         echo "!!! ERROR !!!"
86                         echo ""
87                         echo "This uninstaller requires root privileges. It is currently not"
88                         echo "running as root AND an attempt to use both sudo and su failed."
89                         echo ""
90                         echo "Please correct this by installing and configuring sudo or running"
91                         echo "the uninstaller as root (su -c)."
92                         echo ""
93                         read -p "Press ENTER to exit uninstaller:" BLAH
94                         exit 1
95                 fi
96                 exit
97         fi
98         SUPER="sudo"
99 fi
100
101 #######################
102 # Check for xdg utils
103 #######################
104 HAS_XDG="T"
105
106 #load the file that contains the translated names of the users directories
107 if [ -e /home/${USER_NAME}/.config/user-dirs.dirs ]; then
108         . /home/${USER_NAME}/.config/user-dirs.dirs
109 fi
110
111 if [ "$(id -u)" != "0" ]; then
112         USER_DESKTOP_DIR=${XDG_DESKTOP_DIR:-$HOME/Desktop}
113 else
114         #running as root with su makes this more difficult
115         DESKTOP_FOLDER=$(echo ${XDG_DESKTOP_DIR:-$HOME/Desktop} | awk -F/ '{print $NF}')
116         USER_DESKTOP_DIR="/home/${USER_NAME}/${DESKTOP_FOLDER}"
117 fi
118
119 XDG_MENU_VER=$(xdg-desktop-menu --version 2> /dev/null)
120 if [ -z "$XDG_MENU_VER" ];
121 then
122         echo "System does not have xdg-desktop-menu installed"
123         HAS_XDG="F"
124 fi
125
126 XDG_ICON_VER=$(xdg-icon-resource --version 2> /dev/null)
127 if [ -z "$XDG_ICON_VER" ];
128 then
129         echo "System does not have xdg-icon-resource installed"
130         HAS_XDG="F"
131 fi
132
133
134 #############
135 # Uninstall
136 #############
137
138 if [ -d ${PGM_PATH} ];
139 then
140         echo ""
141         echo "Removing existing ${PGM_NAME} installation at ${PGM_PATH}"
142         echo ""
143
144         if [ "T" = ${HAS_XDG} ];
145         then
146                 ${SUPER} xdg-desktop-menu uninstall ${MENU_FILE_PATH}
147                 ${SUPER} xdg-icon-resource uninstall --size 16 ${ICON_NAME}
148                 ${SUPER} xdg-icon-resource uninstall --size 22 ${ICON_NAME}
149                 ${SUPER} xdg-icon-resource uninstall --size 32 ${ICON_NAME}
150                 ${SUPER} xdg-icon-resource uninstall --size 48 ${ICON_NAME}
151                 ${SUPER} xdg-icon-resource uninstall --size 256 ${ICON_NAME}
152
153                 if [ -e /usr/share/icons/hicolor/scalable/apps/${ICON_NAME}.svg ]; 
154                 then
155                         ${SUPER} rm -f /usr/share/icons/hicolor/scalable/apps/${ICON_NAME}.svg
156                 fi
157         fi
158
159         if [ -e ${USER_DESKTOP_DIR}/${DESKTOP_LINK_FILE} ];
160         then
161                 ${SUPER} rm -f ${USER_DESKTOP_DIR}/${DESKTOP_LINK_FILE}
162         fi
163
164         # delete the bin link if it is linked to this version
165         if [ -e "${USER_BIN_DIR}/${PGM_NAME}${MAJOR_VERSION}" ]; 
166         then
167                 BIN_LINK_TARGET=$(readlink "${USER_BIN_DIR}/${PGM_NAME}${MAJOR_VERSION}")
168                 BIN_LINK_TARGET_DIR=$(dirname "${BIN_LINK_TARGET}")
169
170                 if [ "${BIN_LINK_TARGET_DIR}" = "${PGM_PATH}/bin" ];
171                 then
172                         ${SUPER} rm -f "${USER_BIN_DIR}/${PGM_NAME}${MAJOR_VERSION}"
173                 fi
174         fi
175         
176
177         # delete the old package
178         ${SUPER} rm -rf ${PGM_PATH}
179         ${SUPER} rm -f $0
180 else
181         echo ""
182         echo "!!! FAILURE !!! - install path ${PGM_PATH} does not exist."
183         echo ""
184 fi