Queer European MD passionate about IT

run_me.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. # This file must be executable, otherwise the service cannot run it.
  3. # Run `python_script` while exit code of script is 65.
  4. # At each iteration, pull news from repository and update dependencies.
  5. # Get current directory
  6. this_script_directory=$(cd `dirname $0` && pwd)
  7. # Import variables from my_config.sh
  8. # `$python_virtual_environment`: python virtual environment directory
  9. # containing `python` and `pip`
  10. # `$python_script`: complete path to python script to be run
  11. # `$pull_from_repository`: boolean
  12. # if set to true, at each iteration pull from origin
  13. # `$key`: complete path to private key used to pull
  14. source $this_script_directory/my_config.sh;
  15. # Ensure the success of importing procedure:
  16. ## variables of interest should be non-zero (`-z`)
  17. if [ -z "${python_virtual_environment}" ];
  18. then
  19. printf "Please set in \"my_config.sh\" the path to bot python \
  20. virtual environment\n\
  21. \n\
  22. Example:\n\
  23. python_virtual_environment=\"path/to/virtual/env\"\n\
  24. ";
  25. exit;
  26. fi
  27. if [ -z "${python_script}" ];
  28. then
  29. printf "Please set in \"my_config.sh\" the path to python script to be run \
  30. \n\
  31. Example:\n\
  32. python_script=\"path/to/python/script.py\"\n\
  33. ";
  34. exit;
  35. elif [ ! -e "${python_script}" ];
  36. then
  37. printf "File $python_script does not exist\n\
  38. Please point to a valid file.\n\
  39. Example:\n\
  40. python_script=\"path/to/python/script.py\"\n\
  41. ";
  42. fi
  43. if [ -z "${key}" ];
  44. then
  45. printf "Please set in \"my_config.sh\" the path to key\n\
  46. \n\
  47. Example:\n\
  48. key=\"path/to/key.pvt\"\n\
  49. ";
  50. exit;
  51. fi
  52. if [ -z ${pull_from_repository} ];
  53. then
  54. printf "Please set in \"my_config.sh\" a variable named \
  55. `pull_from_repository`, set to either `true` or `false`.\n\n\
  56. Example:\n\
  57. pull_from_repository=true\n\
  58. ";
  59. exit;
  60. fi
  61. echo "Python script will be run while it exits with value===65.";
  62. i=65;
  63. while [ $i -eq 65 ]
  64. do
  65. if [ $pull_from_repository = true ];
  66. then
  67. echo "Pulling from remote origin.";
  68. eval `ssh-agent -s`;
  69. ssh-add $key;
  70. git pull;
  71. eval `ssh-agent -k`;
  72. fi
  73. echo "Updating dependencies";
  74. "$python_virtual_environment/pip" install --upgrade --no-cache-dir \
  75. --no-deps davteutil davtelepot;
  76. echo "Running python script";
  77. "$python_virtual_environment/python" "$python_script";
  78. i=$?;
  79. done