sync 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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="2"
  17. checkargs() {
  18. case "$1" in
  19. 0)
  20. echo "Downloading and keep all large file content"
  21. ;;
  22. 1)
  23. echo "Keeping existing local large file content, do not downlad extra files"
  24. ;;
  25. 2)
  26. echo "Removing all local large file content"
  27. ;;
  28. *)
  29. usage
  30. ;;
  31. esac
  32. }
  33. checkargs "${syncopt}"
  34. checkerror() {
  35. err=$1
  36. msg=$2
  37. if [[ ${err} != 0 ]]; then
  38. echo "${msg}" >> ./log/gin.log
  39. echo "${err}" >> ./log/gin.log
  40. echo "${msg}"
  41. echo "Press [Enter] to close this window"
  42. read -r
  43. exit 1
  44. fi
  45. }
  46. loc=$(dirname $0)
  47. projectdir=$(git -C ${loc} rev-parse --show-toplevel)
  48. pushd ${loc} > /dev/null
  49. mkdir -p ./log
  50. echo "$(date -r seconds): Sync script executed" >> ./log/gin.log
  51. echo "Synchronising submodules"
  52. git submodule foreach gin sync
  53. checkerror $? "Error occurred during 'gin sync'"
  54. git submodule foreach gin commit .
  55. checkerror $? "Error occurred during 'gin commit'"
  56. git submodule foreach gin upload
  57. checkerror $? "Error occurred during 'gin upload'"
  58. ## remove uploaded (annexed) content
  59. if [[ "$syncopt" > 1 ]]; then
  60. git submodule foreach gin remove-content
  61. checkerror $? "Error occurred during 'gin remove-content'"
  62. fi
  63. # get annexed content
  64. if [[ "${syncopt}" <1 ]]; then
  65. git submodule foreach gin get-content .
  66. checkerror $? "Error occurred during 'gin get-content .'"
  67. fi
  68. echo "Synchronising main repository"
  69. gin sync
  70. gin commit .
  71. gin upload
  72. # remove uploaded (annexed) content
  73. if [[ "$syncopt" > 1 ]]; then
  74. gin remove-content
  75. checkerror $? "Error occurred during 'gin remove-content' in main repo"
  76. fi
  77. # get annexed content
  78. if [[ "${syncopt}" <1 ]]; then
  79. gin get-content .
  80. checkerror $? "Error occurred during 'gin get-content . in main repo'"
  81. fi