GIN-sync 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/usr/bin/env bash
  2. #
  3. # Upload changes from inside repository using GIN CLI
  4. # Works with submodules.
  5. # needs git config to be set and user should be logged in
  6. # needs submodules and main repo to be initialised (gin init)
  7. # Checking synchronisation option and giving feedback
  8. checkargs() {
  9. case "$1" in
  10. download)
  11. echo "Downloading and keep all large file content"
  12. ;;
  13. keep)
  14. echo "Keeping existing local large file content, do not downlad extra files"
  15. ;;
  16. remove)
  17. echo "Removing all local large file content"
  18. ;;
  19. *)
  20. usage
  21. ;;
  22. esac
  23. }
  24. checkargs "${syncopt}"
  25. checkerror() {
  26. err=$1
  27. msg=$2
  28. if [[ ${err} != 0 ]]; then
  29. echo "${msg}" >> ./.log/gin.log
  30. echo "${err}" >> ./.log/gin.log
  31. echo "${msg}"
  32. echo "Press [Enter] to close this window"
  33. read -r
  34. exit 1
  35. fi
  36. }
  37. # Set commit message
  38. echo "Optionally enter a commit message, and hit return: "
  39. read commitmessage
  40. if [[ "$commitmessage" == "" ]]; then
  41. echo "using date as commit message"
  42. commitmessage="commit on $(date +%Y-%m-%d)"
  43. fi
  44. # write log
  45. mkdir -p ./.log
  46. echo "$(date +'%Y-%m-%dT%H:%M:%S'): Sync script executed" >> ./.log/gin.log
  47. # create empty .gitmodules if it does not exist
  48. FILE=.gitmodules
  49. if [ -f "$FILE" ]; then
  50. echo "$FILE already exists."
  51. else
  52. touch "$FILE"
  53. fi
  54. echo "intialise submodules"
  55. gin git submodule foreach gin init
  56. echo "Synchronising submodules"
  57. gin git submodule foreach gin commit . -m "$commitmessage"
  58. checkerror $? "Error occurred during 'gin commit'"
  59. gin git submodule foreach gin sync
  60. checkerror $? "Error occurred during 'gin sync'"
  61. gin git submodule foreach gin upload
  62. checkerror $? "Error occurred during 'gin upload'"
  63. ## remove uploaded (annexed) content
  64. if [[ "$syncopt" == "remove" ]]; then
  65. git submodule foreach gin remove-content
  66. checkerror $? "Error occurred during 'gin remove-content'"
  67. fi
  68. # get annexed content
  69. if [[ "${syncopt}" == "download" ]]; then
  70. git submodule foreach gin get-content .
  71. checkerror $? "Error occurred during 'gin get-content .'"
  72. fi
  73. echo "Synchronising main repository"
  74. # add content
  75. gin commit . -m "$commitmessage"
  76. # add submodule changes
  77. gin git commit . --amend -m "$commitmessage"
  78. # upload files
  79. gin sync
  80. gin upload
  81. # remove uploaded (annexed) content
  82. if [[ "$syncopt" == "remove" ]]; then
  83. gin remove-content
  84. checkerror $? "Error occurred during 'gin remove-content' in main repo"
  85. fi
  86. # get annexed content
  87. if [[ "${syncopt}" == "download" ]]; then
  88. gin get-content .
  89. checkerror $? "Error occurred during 'gin get-content . in main repo'"
  90. fi