aboutsummaryrefslogtreecommitdiffstats
path: root/uninstall.sh
blob: 8771658e79bb31d59a96bcac93abd5b359e1bcd6 (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
#!/bin/sh
#
#   razercfg uninstaller
#
#   Copyright (C) 2014-2019 Michael Buesch <m@bues.ch>
#
#   This program is free software; you can redistribute it and/or
#   modify it under the terms of the GNU General Public License
#   as published by the Free Software Foundation; either version 2
#   of the License, or (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.


die()
{
	echo "$*"
	exit 1
}

# $1=message
ask()
{
	read -p "$*? [Y/n]" ok
	[ "$ok" = "y" -o "$ok" = "Y" -o \
	  "$ok" = "1" -o "$ok" = "" ] && return 0
	return 1
}

# $1=file/dir
uninstall()
{
	local path="$1"

	ask "Delete $path" || return
	rm -r "$path" || die "Failed to delete '$path'"
}

# $1=prefix
uninstall_prefix()
{
	local prefix="$1"

	for f in /bin/pyrazer.py /bin/pyrazer.pyc /bin/pyrazer.pyo\
		 /bin/razercfg\
		 /bin/qrazercfg\
		 /bin/qrazercfg-applet\
		 /bin/razer-gamewrapper\
		 /lib/tmpfiles.d/razerd.conf\
		 /sbin/razerd /bin/razerd\
		 /share/applications/razercfg.desktop; do

		local path="${prefix}${f}"
		[ -e "$path" -o -h "$path" ] || continue
		uninstall "$path"
	done

	for f in "$prefix"/lib/python*/*-packages/pyrazer\
		 "$prefix"/lib/python*/*-packages/razercfg-*.egg-info\
		 "$prefix"/lib/librazer.so*\
		 "$prefix"/share/icons/hicolor/scalable/apps/razercfg*.svg; do

		local path="$f"
		[ -e "$path" -o -h "$path" ] || continue
		uninstall "$path"
	done
}

uninstall_global()
{
	for f in /etc/razer.conf /etc/init.d/razerd /etc/rc*.d/*razerd\
		 /etc/pm/sleep.d/*-razer\
		 /etc/udev/rules.d/*-razer-udev.rules\
		 "$(pkg-config --variable=udevdir udev)/rules.d/*-razer.rules"\
		 /lib/udev/rules.d/*-razer.rules\
		 /usr/lib/udev/rules.d/*-razer.rules\
		 /etc/systemd/system/razerd.service\
		 "$(pkg-config --variable=systemdsystemunitdir systemd)/razerd.service"\
		 /lib/systemd/system/razerd.service\
		 /usr/lib/systemd/system/razerd.service; do

		local path="$f"
		[ -e "$path" -o -h "$path" ] || continue
		uninstall "$path"
	done
}

help()
{
	echo "Usage: uninstall.sh PREFIX"
	echo
	echo "PREFIX is the prefix where razercfg was installed to."
	echo "This usually is /usr/local or /usr"
	echo
	echo "So an example uninstall call might look like this:"
	echo "  ./uninstall.sh /usr/local"
}

if [ $# -eq 0 ]; then
	PREFIX="/usr/local"
elif [ $# -eq 1 ]; then
	if [ "$1" = "-h" -o "$1" = "--help" ]; then
		help
		exit 0
	fi
	PREFIX="$1"
else
	help
	exit 1
fi

uninstall_prefix "$PREFIX"
uninstall_global
exit 0
bues.ch cgit interface