-
Notifications
You must be signed in to change notification settings - Fork 31
/
install
executable file
·88 lines (75 loc) · 2.76 KB
/
install
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
#!/usr/bin/env bash
#
# installs g910-gkeys.
#
# options:
# -n: DO NOT enable and start systemd service.
# get system unit directory
START_SERVICE=y
SUPPORTED_KEYBOARDS=(de en fr si)
KEYBOARD=$(locale | grep LANG= | cut -d= -f2 | cut -d_ -f1)
UNIT_DIR=$(pkg-config systemd --variable=systemduserunitdir)
usage() {
echo "usage: ${0##*/} [-n]"
}
while getopts nl: opt ; do
case "$opt" in
n) START_SERVICE=n
;;
*) usage
exit 1
;;
esac
done
[[ ! " ${SUPPORTED_KEYBOARDS[*]} " =~ ${KEYBOARD} ]] &&
echo "Your system default language is $KEYBOARD, but it's not supported." &&
echo "You can try to run: python3 cli_layout_config_helpers.py --create" &&
echo "You need to add the created mapping to g910-gkeys.lib.data_mappers.char_uinput_mapper and" &&
echo "add your locale to g910-gkeys.lib.data_mappers.supported_configs, before installing again." &&
echo "The locale also have to be added to this install script 10:SUPPORTED_KEYBOARDS." &&
echo "Please open a feature request on github with your language:" &&
echo "https://github.com/JSubelj/g910-gkey-macro-support/issues/new/choose" &&
exit 1
# install via pip
pip install --log ./install.log -e ./
# make config dir
if [[ ! -d "$HOME"/.config/g910-gkeys ]]; then
mkdir "$HOME"/.config/g910-gkeys
fi
# check for existing config file
if [[ ! -f "$HOME"/.config/g910-gkeys/config.json ]]; then
if [[ -f /etc/g910-gkeys/config.json ]]; then
# if old config exist move it to new location (will need root privileges)
sudo mv /etc/g910-gkeys/config.json "$HOME"/.config/g910-gkeys/config.json
sudo chown "$USER":"$USER" "$HOME"/.config/g910-gkeys/config.json
else
# if not copy default config to config dir
cp ./etc/config.json "$HOME"/.config/g910-gkeys/config.json
fi
fi
# remove the unit from users home dir (for updates from 0.4.0)
if [[ -f "$HOME"/.config/systemd/user/g910-gkeys.service ]]; then
rm "$HOME"/.config/systemd/user/g910-gkeys.service
fi
# copy service unit to systemd user unit dir
if [[ -d "$UNIT_DIR" ]]; then
sudo cp ./etc/g910-gkeys.service "$UNIT_DIR"/g910-gkeys.service
fi
# copy udev rules
if [[ ! -f /etc/udev/rules.d/60-g910-gkeys.rules ]]; then
sudo cp ./etc/60-g910-gkeys.rules /etc/udev/rules.d/60-g910-gkeys.rules
fi
# enable uinput in kernel
if [[ ! -f /etc/modules-load.d/uinput-g910-gkeys.conf ]]; then
sudo cp ./etc/uinput-g910-gkeys.conf /etc/modules-load.d/uinput-g910-gkeys.conf
fi
# reload daemon
systemctl --user daemon-reload
# enable and start service if necessary
if [[ $START_SERVICE = y ]]; then
systemctl --user enable --now g910-gkeys.service
else
echo "g910-gkeys service was not started."
echo "You can enable/start it with this command: "
echo " systemctl --user enable --now g910-gkeys.service"
fi