#!/bin/bash # prefer running as root if [ $(id -u) != "0" ]; then sudo bash "$0" "$@" exit $? fi echo "Install $(date)" >> .log DIR=$(dirname $0) PROGRAM=/usr/local/bin/comfortable-swipe CONF_PATH=/usr/local/share/comfortable-swipe.conf OLD_CONF_PATH=${XDG_CONFIG_HOME:-$HOME/.config}/comfortable-swipe.conf DCONF_PATH=$DIR/src/defaults.conf if [ -x "$(command -v $PROGRAM)" ]; then # stop any running comfortable-swipe if it exists systemctl stop comfortable-swipe.service >> .log 2>> .log systemctl disable comfortable-swipe.service >> .log 2>> .log fi mkdir -p $(dirname $CONF_PATH) # copy config file if [ ! -f $CONF_PATH ]; then if [ ! -f $OLD_CONF_PATH ]; then # old config file not found, create from scratch cp -a $DCONF_PATH $(dirname $CONF_PATH) >> .log 2>> .log else # old config file found, move to the new path echo "Configuration copied from $OLD_CONF_PATH to $CONF_PATH" cp -a $OLD_CONF_PATH $(dirname $CONF_PATH) >> .log 2>> .log fi else # config file found, ask user if overwrite echo "Old conf file found in $CONF_PATH" read -r -p "Keep the old conf file? (default: yes) [Y/n] " response response=${response,,} # tolower if [[ "$response" =~ ^(no|n)$ ]]; then read -r -p "Conf file will be overwritten. Are you sure? [Y/n] " response response=${response,,} if [[ "$response" =~ ^(yes|y)$ ]]; then cp -a $DCONF_PATH $(dirname $CONF_PATH) >> .log 2>> .log else echo "Installation aborted." >> .log exec echo "Installation aborted." fi fi fi # install with g++ echo "Installing..." echo " Install $(date)" >> .log echo "Running g++" >> .log g++ -std=c++11 -O2 $DIR/src/comfortable-swipe.cpp -lxdo -o $PROGRAM >> .log 2>> .log || exec echo "Installation aborted" # add as service SERVICE_PATH="/lib/systemd/system/comfortable-swipe.service" echo "[Unit] Description=Comfortable 3 or 4 finger gestures After=display-manager.service [Service] Environment=DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY ExecStart=$PROGRAM exec Restart=always RestartSec=2 [Install] WantedBy=multi-user.target" \ > $SERVICE_PATH # run immediately systemctl daemon-reload >> .log 2>> .log systemctl enable comfortable-swipe.service >> .log 2>> .log systemctl start comfortable-swipe.service >> .log 2>> .log echo "Installation successful" >> .log # prvide success message echo "" echo "Successfully installed comfortable-swipe. Try swiping and see if it works." echo "Configuration file is located at $CONF_PATH" echo "" echo "[Report bugs to https://github.com/Hikari9/comfortable-swipe-ubuntu/issues/new]" echo ""