-
-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·123 lines (98 loc) · 3.53 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·123 lines (98 loc) · 3.53 KB
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
118
119
120
121
122
123
#!/usr/bin/env bash
# Read arguments
ARG_EARLY=false
ARG_UPDATE=false
for arg in "$@"; do
case "$arg" in
early) ARG_EARLY=true ;;
update) ARG_UPDATE=true ;;
esac
done
# Determine system architecture
echo -e "Determining system architecture..."
BITS=$(getconf LONG_BIT)
case "$(uname -m)" in
x86_64) ARCH="x64" ;;
aarch64) ARCH="arm64" ;;
*) { echo "Architecture $(uname -m) running $BITS-bit operating system is not supported."; exit 1; } ;;
esac
[ "$BITS" -eq 64 ] || { echo "Architecture $ARCH running $BITS-bit operating system is not supported."; exit 1; }
echo "Architecture $ARCH running $BITS-bit operating system is supported."
# Download the latest .deb package
echo -e "\nDownloading the latest release..."
TMP_DIR=$(mktemp -d)
chmod 755 "$TMP_DIR"
JSON=$(wget -qO- "https://api.github.com/repos/leukipp/touchkio/releases" | tr -d '\r\n')
if $ARG_EARLY; then
DEB_REG='"prerelease":\s*(true|false).*?"browser_download_url":\s*"\K[^\"]*_'$ARCH'\.deb'
else
DEB_REG='"prerelease":\s*false.*?"browser_download_url":\s*"\K[^\"]*_'$ARCH'\.deb'
fi
DEB_URL=$(echo "$JSON" | grep -oP "$DEB_REG" | head -n 1)
DEB_PATH="${TMP_DIR}/$(basename "$DEB_URL")"
[ -z "$DEB_URL" ] && { echo "Download url for .deb file not found."; exit 1; }
wget --show-progress -q -O "$DEB_PATH" "$DEB_URL" || { echo "Failed to download the .deb file."; exit 1; }
# Install the latest .deb package
echo -e "\nInstalling the latest release..."
command -v apt &> /dev/null || { echo "Package manager apt was not found."; exit 1; }
sudo apt install -y "$DEB_PATH" || { echo "Installation of .deb file failed."; exit 1; }
# Create the systemd user service
echo -e "\nCreating systemd user service..."
SERVICE_NAME="touchkio.service"
SERVICE_FILE="$HOME/.config/systemd/user/$SERVICE_NAME"
mkdir -p "$(dirname "$SERVICE_FILE")" || { echo "Failed to create directory for $SERVICE_FILE."; exit 1; }
SERVICE_CONTENT="[Unit]
Description=TouchKio
After=graphical.target
Wants=network-online.target
[Service]
ExecStart=/usr/bin/touchkio
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=default.target"
if $ARG_UPDATE; then
if systemctl --user --quiet is-active "${SERVICE_NAME}"; then
systemctl --user restart "${SERVICE_NAME}"
echo "Existing $SERVICE_NAME restarted."
else
echo "Existing $SERVICE_NAME not running, start touchkio manually."
fi
exit 0
fi
SERVICE_CREATE=true
if [ -f "$SERVICE_FILE" ]; then
read -p "Service $SERVICE_FILE exists, overwrite? (y/N) " overwrite
[[ ${overwrite:-n} == [Yy]* ]] || SERVICE_CREATE=false
fi
if $SERVICE_CREATE; then
echo "$SERVICE_CONTENT" > "$SERVICE_FILE" || { echo "Failed to write to $SERVICE_FILE."; exit 1; }
systemctl --user enable "$(basename "$SERVICE_FILE")" || { echo "Failed to enable service $SERVICE_FILE."; exit 1; }
echo "Service $SERVICE_FILE enabled."
else
echo "Service $SERVICE_FILE not created."
fi
# Export display variables
echo -e "\nExporting display variables..."
if [ -z "$DISPLAY" ]; then
export DISPLAY=":0"
echo "DISPLAY was not set, defaulting to \"$DISPLAY\"."
else
echo "DISPLAY is set to \"$DISPLAY\"."
fi
if [ -z "$WAYLAND_DISPLAY" ]; then
export WAYLAND_DISPLAY="wayland-0"
echo "WAYLAND_DISPLAY was not set, defaulting to \"$WAYLAND_DISPLAY\"."
else
echo "WAYLAND_DISPLAY is set to \"$WAYLAND_DISPLAY\"."
fi
# Start the setup mode
read -p $'\nStart touchkio setup? (Y/n) ' setup
if [[ ${setup:-y} == [Yy]* ]]; then
echo "/usr/bin/touchkio --setup"
/usr/bin/touchkio --setup
else
echo "/usr/bin/touchkio"
/usr/bin/touchkio
fi
exit 0