25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

56 satır
1.8KB

  1. #!/bin/bash
  2. # Function to set the path correct in the config files and store them in the correct location.
  3. replace_and_move() {
  4. # The ${GIT_DIR//\//\\\/} replaces '/' with '\/' as '/' is a control char in regex
  5. REPLACE_STR="s/\[\[path_to_repo\\]\\]/${GIT_DIR//\//\\\/}/g"
  6. OUTDIR="$DIRECTORY/$1"
  7. # Parse the file trough `sed` and write output to correct directory
  8. sed $REPLACE_STR $2/$1 > $OUTDIR
  9. echo "$1 script placed at $OUTDIR"
  10. }
  11. ###################
  12. # START OF SCRIPT #
  13. ###################
  14. # Check if XDG_CONFIG_HOME is set and select correct config file location.
  15. # See also: systemd.unit manual - section: UNIT FILE LOAD PATH
  16. if [[ -e $XDG_CONFIG_HOME ]]; then
  17. DIRECTORY=$XDG_CONFIG_HOME/systemd/user
  18. else
  19. DIRECTORY=$HOME/.config/systemd/user
  20. fi
  21. echo "The scripts will be put in $DIRECTORY"
  22. # The following git command will give the root of the current repo.
  23. GIT_DIR=`git rev-parse --show-toplevel`
  24. echo "Root of this git repo is: $GIT_DIR"
  25. if [[ -e $GIT_DIR/.venv/bin/python3 ]]; then
  26. echo "Found a virtual environment for Python in the repo"
  27. else
  28. echo "Pythons virtual environment not found at '$GIT_DIT/.venv'. "
  29. #There should be a setup.sh file in the directory that setups the virtual environment for python
  30. if [[ -f $GIT_DIR/setup.sh ]]; then
  31. echo "Have you tried running '$GIT_DIR/setup.sh'?"
  32. fi
  33. echo "I could install config files, but they whould not work. Aborting now"
  34. exit
  35. fi
  36. FILENAME="pythontaskcheck"
  37. FOLDERNAME="systemd_timer_files"
  38. MAPPATH="$GIT_DIR/$FOLDERNAME/"
  39. TIMERNAME="$FILENAME.timer"
  40. SERVICENAME="$FILENAME.service"
  41. replace_and_move $TIMERNAME $MAPPATH
  42. replace_and_move $SERVICENAME $MAPPATH
  43. echo "Enable $TIMERNAME for systemd"
  44. `systemctl --user enable $TIMERNAME`
  45. echo "Start $TIMERNAME for systemd"
  46. `systemctl --user start $TIMERNAME`