-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathinstall_service.sh
88 lines (74 loc) · 4.04 KB
/
install_service.sh
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
#!/bin/bash
source non_sudo_check.sh
# INHERIT VARS
if [ -z "$CONFIG_FILE_DIR_PATH" ]; then
CONFIG_FILE_DIR_PATH="/usr/share/asus-numberpad-driver"
fi
if [ -z "$LAYOUT_NAME" ]; then
LAYOUT_NAME="up5401ea"
fi
if [ -z "$LOGS_DIR_PATH" ]; then
LOGS_DIR_PATH="/var/log/asus-numberpad-driver"
fi
echo "Systemctl service"
echo
read -r -p "Do you want install systemctl service? [y/N]" RESPONSE
case "$RESPONSE" in [yY][eE][sS]|[yY])
SERVICE_FILE_PATH=asus_numberpad_driver.service
SERVICE_X11_FILE_PATH=asus_numberpad_driver.x11.service
SERVICE_INSTALL_FILE_NAME="[email protected]"
SERVICE_INSTALL_DIR_PATH="/usr/lib/systemd/user"
XDG_RUNTIME_DIR=$(echo $XDG_RUNTIME_DIR)
DBUS_SESSION_BUS_ADDRESS=$(echo $DBUS_SESSION_BUS_ADDRESS)
XAUTHORITY=$(echo $XAUTHORITY)
DISPLAY=$(echo $DISPLAY)
XDG_SESSION_TYPE=$(echo $XDG_SESSION_TYPE)
ERROR_LOG_FILE_PATH="$LOGS_DIR_PATH/error.log"
echo
echo "LAYOUT_NAME: $LAYOUT_NAME"
echo "CONFIG_FILE_DIR_PATH: $CONFIG_FILE_DIR_PATH"
echo
echo "env var DISPLAY: $DISPLAY"
echo "env var AUTHORITY: $XAUTHORITY"
echo "env var XDG_RUNTIME_DIR: $XDG_RUNTIME_DIR"
echo "env var DBUS_SESSION_BUS_ADDRESS: $DBUS_SESSION_BUS_ADDRESS"
echo "env var XDG_SESSION_TYPE: $XDG_SESSION_TYPE"
echo
echo "ERROR LOG FILE: $ERROR_LOG_FILE_PATH"
echo
if [ "$XDG_SESSION_TYPE" = "x11" ]; then
cat "$SERVICE_X11_FILE_PATH" | LAYOUT_NAME=$LAYOUT_NAME CONFIG_FILE_DIR_PATH="$CONFIG_FILE_DIR_PATH/" DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS ERROR_LOG_FILE_PATH=$ERROR_LOG_FILE_PATH envsubst '$LAYOUT_NAME $CONFIG_FILE_DIR_PATH $DISPLAY $XAUTHORITY $XDG_RUNTIME_DIR $DBUS_SESSION_BUS_ADDRESS $ERROR_LOG_FILE_PATH' | sudo tee "$SERVICE_INSTALL_DIR_PATH/$SERVICE_INSTALL_FILE_NAME" >/dev/null
elif [ "$XDG_SESSION_TYPE" = "wayland" ]; then
echo "Unfortunatelly you will not be able use feature: Disabling Touchpad (e.g. Fn+special key) disables NumberPad aswell, at this moment is supported only X11)"
cat "$SERVICE_FILE_PATH" | LAYOUT_NAME=$LAYOUT_NAME CONFIG_FILE_DIR_PATH="$CONFIG_FILE_DIR_PATH/" DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS ERROR_LOG_FILE_PATH=$ERROR_LOG_FILE_PATH envsubst '$LAYOUT_NAME $CONFIG_FILE_DIR_PATH $DISPLAY $XAUTHORITY $XDG_RUNTIME_DIR $DBUS_SESSION_BUS_ADDRESS $ERROR_LOG_FILE_PATH' | sudo tee "$SERVICE_INSTALL_DIR_PATH/$SERVICE_INSTALL_FILE_NAME" >/dev/null
else
cat "$SERVICE_FILE_PATH" | LAYOUT_NAME=$LAYOUT_NAME CONFIG_FILE_DIR_PATH="$CONFIG_FILE_DIR_PATH/" DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS ERROR_LOG_FILE_PATH=$ERROR_LOG_FILE_PATH envsubst '$LAYOUT_NAME $CONFIG_FILE_DIR_PATH $DISPLAY $XAUTHORITY $XDG_RUNTIME_DIR $DBUS_SESSION_BUS_ADDRESS $ERROR_LOG_FILE_PATH' | sudo tee "$SERVICE_INSTALL_DIR_PATH/$SERVICE_INSTALL_FILE_NAME" >/dev/null
fi
if [[ $? != 0 ]]; then
echo "Something went wrong when moving the asus_numberpad_driver.service"
exit 1
else
echo "Asus numberpad driver service placed"
fi
systemctl --user daemon-reload
if [[ $? != 0 ]]; then
echo "Something went wrong when was called systemctl daemon reload"
exit 1
else
echo "Systemctl daemon reloaded"
fi
systemctl enable --user asus_numberpad_driver@$USER.service
if [[ $? != 0 ]]; then
echo "Something went wrong when enabling the asus_numberpad_driver.service"
exit 1
else
echo "Asus numberpad driver service enabled"
fi
systemctl restart --user asus_numberpad_driver@$USER.service
if [[ $? != 0 ]]; then
echo "Something went wrong when starting the asus_numberpad_driver.service"
exit 1
else
echo "Asus numberpad driver service started"
fi
esac