-
Notifications
You must be signed in to change notification settings - Fork 31
/
uninstall
executable file
·82 lines (70 loc) · 2.48 KB
/
uninstall
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
#!/bin/bash
#
# uninstall g910-gkeys.
#
# options:
# -d --dry-run Only print what would be done
PIPCMD=""
DRYRUN=""
UNIT_DIR=$(pkg-config systemd --variable=systemduserunitdir)
OPTIONS=$(getopt -l "dry-run" -o "d" -- "$@")
eval set -- "$OPTIONS"
usage() {
echo "usage: ${0##*/}" [-d]$'\n'
echo " -d --dry-run Only print what would be done"
echo Exiting.
}
while true; do
case "$1" in
-d|--dry-run) DRYRUN="echo"
;;
--)
break;;
esac
shift
done
[[ $DRYRUN = "echo" ]] && ${DRYRUN} Running dry...
# determine if we should use pip or pip3, pip3 being preferred
for p in pip pip3; do
type "$p" &>/dev/null && PIPCMD="$p"
done
# stop and disable service
if [[ $DRYRUN = "echo" ]]; then
${DRYRUN} sudo systemctl disable --now g910-gkeys # <= 0.3.0
${DRYRUN} systemctl --user disable --now g910-gkeys # >= 0.4.0
else
${DRYRUN} sudo systemctl disable --now g910-gkeys &>/dev/null # <= 0.3.0
${DRYRUN} systemctl --user disable --now g910-gkeys &>/dev/null # >= 0.4.0
fi
# remove pip package
if [[ -n "$PIPCMD" ]]; then
PIPLST=$($PIPCMD list | grep 'g910-gkeys' | cut -d " " -f 1)
[[ -n "$PIPLST" ]] &&
${DRYRUN} ${PIPCMD} uninstall -q "$PIPLST" &&
[[ $DRYRUN = "" ]] && echo "Uninstalled $PIPCMD files"
fi
# remove service unit <= 0.3.0
if [[ -f /etc/systemd/system/g910-gkeys.service ]]; then
${DRYRUN} sudo rm /etc/systemd/system/g910-gkeys.service &&
[[ $DRYRUN = "" ]] && echo "Removed service unit /etc/systemd/system/g910-gkeys.service"
fi
# remove service unit >= 0.4.0
if [[ -f "$HOME"/.config/systemd/user/g910-gkeys.service ]]; then
${DRYRUN} rm "$HOME"/.config/systemd/user/g910-gkeys.service &&
[[ $DRYRUN = "" ]] && echo "Removed service unit $HOME/.config/systemd/user/g910-gkeys.service"
fi
# remove service unit >= 0.4.1
if [[ -f "$UNIT_DIR"/g910-gkeys.service ]]; then
${DRYRUN} rm "$UNIT_DIR"/g910-gkeys.service &&
[[ $DRYRUN = "" ]] && echo "Removed service unit $UNIT_DIR/g910-gkeys.service"
fi
# remove udev rules
if [[ -f /etc/udev/rules.d/60-g910-gkeys.rules ]]; then
${DRYRUN} sudo rm /etc/udev/rules.d/60-g910-gkeys.rules &&
[[ $DRYRUN = "" ]] && echo "Removed udev rules /etc/udev/rules.d/60-g910-gkeys.rules"
fi
# remove uinput config for kernel
if [[ -f /etc/modules-load.d/uinput-g910-gkeys.conf ]]; then
${DRYRUN} sudo rm /etc/modules-load.d/uinput-g910-gkeys.conf &&
[[ $DRYRUN = "" ]] && echo "Removed uinput config /etc/modules-load.d/uinput-g910-gkeys.conf"
fi