entrypoint.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/bash
  2. APP_NAME="TFA-Bot.exe"
  3. APP_DIR="/app/TFA-Bot/TFA-Bot/bin/Release"
  4. APP_DIR_DEBUG="/app/TFA-Bot/TFA-Bot/bin/Debug"
  5. BUILD_DIR="/app/TFA-Bot"
  6. BUILD_CONF="Release"
  7. [ -z "$BOTURL" ] && echo "BOTURL Google Spreadsheet URL missing" && exit 1;
  8. function build
  9. {
  10. cd $BUILD_DIR
  11. git pull
  12. mono ../nuget.exe restore TFA-Bot.sln
  13. msbuild -property:Configuration=$BUILD_CONF -property:GitCommit=$(git rev-parse HEAD) TFA-Bot.sln
  14. }
  15. exitcode=-1
  16. until [ $exitcode -eq 0 ]
  17. do
  18. startdate="$(date +%s)"
  19. cd $APP_DIR
  20. mono $APP_NAME
  21. exitcode=$?
  22. enddate="$(date +%s)"
  23. echo "EXIT CODE = $exitcode"
  24. elapsed_seconds="$(expr $enddate - $startdate)"
  25. echo "Elapsed seconds $elapsed_seconds"
  26. if [ $exitcode -eq 2 ] #Restart
  27. then
  28. echo "RESTART"
  29. elif [ $exitcode -eq 4 ] #Previous version
  30. then
  31. echo "PREVIOUS VERSION"
  32. cp -fv $APP_NAME_previous $APP_NAME
  33. elif [ $exitcode -eq 3 ] #Update
  34. then
  35. echo "SOFTWARE UPDATE"
  36. BUILD_CONF="Release"
  37. cp -fv $APP_NAME $APP_NAME_previous
  38. build
  39. elif [ $exitcode -eq 5 ] #MONO ARGS
  40. then
  41. if [ -f $APP_DIR/mono_args.txt ]; then
  42. BUILD_CONF="Debug"
  43. build
  44. MONOARGS="$(< $APP_DIR/mono_args.txt)"
  45. echo "RUN WITH MONO ARGS: $MONOARGS"
  46. cd $APP_DIR_DEBUG
  47. mono $MONOARGS $APP_NAME
  48. fi
  49. elif [ $exitcode -eq 0 ] #Shutdown
  50. then
  51. echo "SHUTDOWN"
  52. fi
  53. if [ $elapsed_seconds -lt 30 ] #been running for less than 30 seconds
  54. then
  55. sleep 10 # delay to protect against eating the CPU resourses with infinate loop
  56. fi
  57. done
  58. echo "BASH: terminate $exitcode"