summaryrefslogtreecommitdiff
path: root/tools/linux_packaging/uninstall.sh.in
blob: 7e86b2bc115f4ca8f50eb8eb164b11cd6c796153 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/sh

######################################
#
#	Ardour/Mixbus bundle uninstaller
#	Todd Naugle
#
#####################################


PGM_NAME="%REPLACE_PGM%"
PGM_VENDOR="%REPLACE_VENDOR%"
PGM_VERSION="%REPLACE_VERSION%"
PGM_BUILD="%REPLACE_BUILD%"
PGM_BUILDTYPE="%REPLACE_TYPE%"

INSTALL_DEST_BASE=/opt


#### Derived Variables ####
if [ -z "${PGM_BUILDTYPE}" ]; then
	PGM_PATH=${INSTALL_DEST_BASE}/${PGM_NAME}-${PGM_VERSION}_${PGM_BUILD}
	ICON_NAME="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}"			#no dash between name and version since dash seperates vendor from program
	MENU_FILE="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}.desktop"	#no dash between name and version since dash seperates vendor from program
	DESKTOP_LINK_FILE="${PGM_NAME}_${PGM_VERSION}.desktop"
else
	PGM_PATH=${INSTALL_DEST_BASE}/${PGM_NAME}-${PGM_VERSION}_${PGM_BUILD}-${PGM_BUILDTYPE}
	ICON_NAME="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}_${PGM_BUILDTYPE}"			#no dash between name and version since dash seperates vendor from program
	MENU_FILE="${PGM_VENDOR}-${PGM_NAME}_${PGM_VERSION}_${PGM_BUILDTYPE}.desktop"	#no dash between name and version since dash seperates vendor from program
	DESKTOP_LINK_FILE="${PGM_NAME}_${PGM_VERSION}_${PGM_BUILDTYPE}.desktop"
fi

MENU_FILE_PATH="${PGM_PATH}/share/${MENU_FILE}"


#############################
# Check for root privileges
#############################

SUPER=""

if [ "$(id -u)" != "0" ]; then

	if ! which sudo > /dev/null;
	then
		echo ""
		echo "!!! ERROR !!!"
		echo ""
		echo "The uninstaller requires root privileges. It is currently not"
		echo "running as root AND the program sudo is missing from this system."
		echo ""
		echo "Please correct this by running the uninstaller as root or"
		echo "installing and configuring sudo."
		echo ""
		read -p "Press ENTER to exit uninstaller:" BLAH
		exit 1
	fi

	if ! sudo date;
	then
		echo ""
		echo "!!! ERROR !!!"
		echo ""
		echo "Either you don't know the root password or the user is not allowed to sudo"
		echo "Please correct this and run the uninstaller again"
		echo "(hint: use visudo to edit sudoers file or run the installer as root)"
		echo ""
		read -p "Press ENTER to exit uninstaller:" BLAH
		exit 1
	fi
	SUPER="sudo"
fi

#######################
# Check for xdg utils
#######################
HAS_XDG="T"

XDG_MENU_VER=$(xdg-desktop-menu --version 2> /dev/null)
if [ -z "$XDG_MENU_VER" ];
then
	echo "System does not have xdg-desktop-menu installed"
	HAS_XDG="F"
fi

XDG_ICON_VER=$(xdg-icon-resource --version 2> /dev/null)
if [ -z "$XDG_ICON_VER" ];
then
	echo "System does not have xdg-icon-resource installed"
	HAS_XDG="F"
fi


#############
# Uninstall
#############

if [ -d ${PGM_PATH} ];
then
	echo ""
	echo "Removing existing ${PGM_NAME} installation at ${PGM_PATH}"
	echo ""

	if [ "T" = ${HAS_XDG} ];
	then
		${SUPER} xdg-desktop-menu uninstall ${MENU_FILE_PATH}
		${SUPER} xdg-icon-resource uninstall --size 16 ${ICON_NAME}
		${SUPER} xdg-icon-resource uninstall --size 22 ${ICON_NAME}
		${SUPER} xdg-icon-resource uninstall --size 32 ${ICON_NAME}
		${SUPER} xdg-icon-resource uninstall --size 48 ${ICON_NAME}

		if [ -e /usr/share/icons/hicolor/scalable/apps/${ICON_NAME}.svg ]; 
		then
			${SUPER} rm -f /usr/share/icons/hicolor/scalable/apps/${ICON_NAME}.svg
		fi
	fi

	if [ -e ~/Desktop/${DESKTOP_LINK_FILE} ];
	then
		${SUPER} rm -f ~/Desktop/${DESKTOP_LINK_FILE}
	fi

	# delete the old package
	${SUPER} rm -rf ${PGM_PATH}
	${SUPER} rm -f $0
else
	echo ""
	echo "!!! FAILURE !!! - install path ${PGM_PATH} does not exist."
	echo ""
fi