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