sync 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/usr/bin/env bash
  2. #
  3. # Upload changes from inside repository using GIN CLI
  4. # Works with submodules.
  5. # Assumes gin init was performed or the repository was downloaded via gin get
  6. usage() {
  7. echo "$0 <sync-option>"
  8. echo
  9. echo "<sync-option> The sync option defines what to do with the content of large files."
  10. echo " It should be one of the following values:"
  11. echo " download - Download all large file content from the server"
  12. echo " keep - Keep all large file content but do not download missing large files"
  13. echo " remove - Do not download large files and remove existing local large file content"
  14. exit 1
  15. }
  16. syncopt="remove"
  17. echo "Optionally enter a commit message, and hit return: "
  18. read commitmessage
  19. if [[ "$commitmessage" == "" ]]; then
  20. echo "using date as commit message"
  21. commitmessage="commit on $(date +%Y-%m-%d)"
  22. fi
  23. checkargs() {
  24. case "$1" in
  25. download)
  26. echo "Downloading and keep all large file content"
  27. ;;
  28. keep)
  29. echo "Keeping existing local large file content, do not downlad extra files"
  30. ;;
  31. remove)
  32. echo "Removing all local large file content"
  33. ;;
  34. *)
  35. usage
  36. ;;
  37. esac
  38. }
  39. checkargs "${syncopt}"
  40. checkerror() {
  41. err=$1
  42. msg=$2
  43. if [[ ${err} != 0 ]]; then
  44. echo "${msg}" >> ./.log/gin.log
  45. echo "${err}" >> ./.log/gin.log
  46. echo "${msg}"
  47. echo "Press [Enter] to close this window"
  48. read -r
  49. exit 1
  50. fi
  51. }
  52. loc=$(dirname $0)
  53. projectdir=$(git -C ${loc} rev-parse --show-toplevel)
  54. pushd ${loc} > /dev/null
  55. mkdir -p ./.log
  56. echo "$(date +'%Y-%m-%dT%H:%M:%S'): Sync script executed" >> ./.log/gin.log
  57. echo "intialise submodules"
  58. git submodule foreach gin init
  59. echo "Synchronising submodules"
  60. git submodule foreach gin commit . -m "$commitmessage"
  61. checkerror $? "Error occurred during 'gin commit'"
  62. git submodule foreach gin sync
  63. checkerror $? "Error occurred during 'gin sync'"
  64. git submodule foreach gin upload
  65. checkerror $? "Error occurred during 'gin upload'"
  66. ## remove uploaded (annexed) content
  67. if [[ "$syncopt" == "remove" ]]; then
  68. git submodule foreach gin remove-content
  69. checkerror $? "Error occurred during 'gin remove-content'"
  70. fi
  71. # get annexed content
  72. if [[ "${syncopt}" == "download" ]]; then
  73. git submodule foreach gin get-content .
  74. checkerror $? "Error occurred during 'gin get-content .'"
  75. fi
  76. echo "Synchronising main repository"
  77. gin commit . -m "$commitmessage"
  78. gin sync
  79. gin upload
  80. # remove uploaded (annexed) content
  81. if [[ "$syncopt" == "remove" ]]; then
  82. gin remove-content
  83. checkerror $? "Error occurred during 'gin remove-content' in main repo"
  84. fi
  85. # get annexed content
  86. if [[ "${syncopt}" == "download" ]]; then
  87. gin get-content .
  88. checkerror $? "Error occurred during 'gin get-content . in main repo'"
  89. fi