sync 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. # Set the variable for synchronisation option, see above
  17. syncopt="remove"
  18. # Set commit message
  19. echo "Optionally enter a commit message, and hit return: "
  20. read commitmessage
  21. if [[ "$commitmessage" == "" ]]; then
  22. echo "using date as commit message"
  23. commitmessage="commit on $(date +%Y-%m-%d)"
  24. fi
  25. # Checking synchronisation option and giving feedback
  26. checkargs() {
  27. case "$1" in
  28. download)
  29. echo "Downloading and keep all large file content"
  30. ;;
  31. keep)
  32. echo "Keeping existing local large file content, do not downlad extra files"
  33. ;;
  34. remove)
  35. echo "Removing all local large file content"
  36. ;;
  37. *)
  38. usage
  39. ;;
  40. esac
  41. }
  42. checkargs "${syncopt}"
  43. checkerror() {
  44. err=$1
  45. msg=$2
  46. if [[ ${err} != 0 ]]; then
  47. echo "${msg}" >> ./.log/gin.log
  48. echo "${err}" >> ./.log/gin.log
  49. echo "${msg}"
  50. echo "Press [Enter] to close this window"
  51. read -r
  52. exit 1
  53. fi
  54. }
  55. # Set folder where script will be executed
  56. loc=$(dirname $0)
  57. projectdir=$(git -C ${loc} rev-parse --show-toplevel)
  58. pushd ${loc} > /dev/null
  59. # write log
  60. mkdir -p ./.log
  61. echo "$(date +'%Y-%m-%dT%H:%M:%S'): Sync script executed" >> ./.log/gin.log
  62. echo "intialise submodules"
  63. git submodule foreach gin init
  64. echo "Synchronising submodules"
  65. git submodule foreach gin commit . -m "$commitmessage"
  66. checkerror $? "Error occurred during 'gin commit'"
  67. git submodule foreach gin sync
  68. checkerror $? "Error occurred during 'gin sync'"
  69. git submodule foreach gin upload
  70. checkerror $? "Error occurred during 'gin upload'"
  71. ## remove uploaded (annexed) content
  72. if [[ "$syncopt" == "remove" ]]; then
  73. git submodule foreach gin remove-content
  74. checkerror $? "Error occurred during 'gin remove-content'"
  75. fi
  76. # get annexed content
  77. if [[ "${syncopt}" == "download" ]]; then
  78. git submodule foreach gin get-content .
  79. checkerror $? "Error occurred during 'gin get-content .'"
  80. fi
  81. echo "Synchronising main repository"
  82. gin commit . -m "$commitmessage"
  83. gin sync
  84. gin upload
  85. # remove uploaded (annexed) content
  86. if [[ "$syncopt" == "remove" ]]; then
  87. gin remove-content
  88. checkerror $? "Error occurred during 'gin remove-content' in main repo"
  89. fi
  90. # get annexed content
  91. if [[ "${syncopt}" == "download" ]]; then
  92. gin get-content .
  93. checkerror $? "Error occurred during 'gin get-content . in main repo'"
  94. fi