forked from asus-linux-drivers/asus-wmi-hotkeys-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_service.sh
78 lines (65 loc) · 3.51 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
#!/usr/bin/env bash
source non_sudo_check.sh
# INHERIT VARS
if [ -z "$CONFIG_FILE_DIR_PATH" ]; then
CONFIG_FILE_DIR_PATH="/usr/share/asus-wmi-hotkeys-driver"
fi
if [ -z "$LOGS_DIR_PATH" ]; then
LOGS_DIR_PATH="/var/log/asus-wmi-hotkeys-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_BASE_NAME=asus_wmi_hotkeys_driver
SERVICE_FILE_PATH=$SERVICE_BASE_NAME.service
SERVICE_X11_FILE_PATH=$SERVICE_BASE_NAME.x11.service
SERVICE_INSTALL_FILE_NAME="asus_wmi_hotkeys_driver.service"
SERVICE_INSTALL_DIR_PATH="/lib/systemd/system"
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" | 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 '$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
cat "$SERVICE_FILE_PATH" | 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 '$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" | 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 '$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
sudo systemctl daemon-reload
if [[ $? != 0 ]]; then
echo "Something went wrong when was called systemctl daemon reload"
exit 1
else
echo "Systemctl daemon reloaded"
fi
sudo systemctl enable $SERVICE_BASE_NAME.service
if [[ $? != 0 ]]; then
echo "Something went wrong when enabling the $SERVICE_BASE_NAME"
exit 1
else
echo "Service $SERVICE_BASE_NAME enabled"
fi
sudo systemctl restart $SERVICE_BASE_NAME.service
if [[ $? != 0 ]]; then
echo "Something went wrong when starting the $SERVICE_BASE_NAME"
exit 1
else
echo "Service $SERVICE_BASE_NAME started"
fi
esac