#!/bin/bash # Function to set the path correct in the config files and store them in the correct location. replace_and_move() { # The ${GIT_DIR//\//\\\/} replaces '/' with '\/' as '/' is a control char in regex REPLACE_STR="s/\[\[path_to_repo\\]\\]/${GIT_DIR//\//\\\/}/g" OUTDIR="$DIRECTORY/$1" # Parse the file trough `sed` and write output to correct directory sed $REPLACE_STR $2/$1 > $OUTDIR echo "$1 script placed at $OUTDIR" } ################### # START OF SCRIPT # ################### # Check if XDG_CONFIG_HOME is set and select correct config file location. # See also: systemd.unit manual - section: UNIT FILE LOAD PATH if [[ -e $XDG_CONFIG_HOME ]]; then DIRECTORY=$XDG_CONFIG_HOME/systemd/user else DIRECTORY=$HOME/.config/systemd/user fi echo "The scripts will be put in $DIRECTORY" # The following git command will give the root of the current repo. GIT_DIR=`git rev-parse --show-toplevel` echo "Root of this git repo is: $GIT_DIR" if [[ -e $GIT_DIR/.venv/bin/python3 ]]; then echo "Found a virtual environment for Python in the repo" else echo "Pythons virtual environment not found at '$GIT_DIT/.venv'. " #There should be a setup.sh file in the directory that setups the virtual environment for python if [[ -f $GIT_DIR/setup.sh ]]; then echo "Have you tried running '$GIT_DIR/setup.sh'?" fi echo "I could install config files, but they whould not work. Aborting now" exit fi FILENAME="pythontaskcheck" FOLDERNAME="systemd_timer_files" MAPPATH="$GIT_DIR/$FOLDERNAME/" TIMERNAME="$FILENAME.timer" SERVICENAME="$FILENAME.service" replace_and_move $TIMERNAME $MAPPATH replace_and_move $SERVICENAME $MAPPATH echo "Reload systemd deamon" `systemctl --user daemon-reload` echo "Enable $TIMERNAME for systemd" `systemctl --user enable $TIMERNAME` echo "Start $TIMERNAME for systemd" `systemctl --user start $TIMERNAME`