GIN-sync 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. git submodule foreach gin init
  56. echo "Synchronising submodules"
  57. git submodule foreach gin commit . -m "$commitmessage"
  58. checkerror $? "Error occurred during 'gin commit'"
  59. git submodule foreach gin sync
  60. checkerror $? "Error occurred during 'gin sync'"
  61. 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. gin commit . -m "$commitmessage"
  75. gin sync
  76. gin upload
  77. # remove uploaded (annexed) content
  78. if [[ "$syncopt" == "remove" ]]; then
  79. gin remove-content
  80. checkerror $? "Error occurred during 'gin remove-content' in main repo"
  81. fi
  82. # get annexed content
  83. if [[ "${syncopt}" == "download" ]]; then
  84. gin get-content .
  85. checkerror $? "Error occurred during 'gin get-content . in main repo'"
  86. fi