124 lines
3.5 KiB
Bash
Executable File
124 lines
3.5 KiB
Bash
Executable File
#!/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
|