INIT-sync 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env bash
  2. #
  3. # Initialise or Upload changes from inside repository
  4. # using GIN CLI
  5. # Works with submodules and repo made by tonic v1 (not copying submodules content).
  6. # needs git config to be set
  7. # needs SSH access to GIN
  8. # future dvt using datalad will allow use of non-GIN repositories
  9. # logic: template has a specific file to label it needs initialisation.
  10. # if this file is present, code 1 is done: template_initialisation
  11. # if it is absent but submodules are empty, code 2 is done: submodule_initialisation
  12. # if none of the above code 3 is done: synchronisation
  13. # Set folder where script will be executed
  14. loc=$(dirname $0)
  15. projectdir=$(git -C ${loc} rev-parse --show-toplevel)
  16. pushd ${loc} > /dev/null
  17. ## set gin server and remote
  18. if ! gin remotes; then
  19. sh .scripts/setginserver
  20. else
  21. echo gin remote set
  22. fi
  23. #login if needed
  24. if ! gin info; then
  25. echo "set gin login"
  26. gin login
  27. else
  28. echo "gin logged"
  29. fi
  30. ## code 1
  31. if test -f "00repo_needs_initialisation00.txt" ;
  32. then
  33. echo "running project repository initiation (first run)"
  34. sh .scripts/template_init.command
  35. fi
  36. ## code 2
  37. if grep -q 06_dissemination ".gitmodules";
  38. then
  39. if (test -f "06_dissemination/README_DISSEMINATION.md") ;
  40. then
  41. echo "submodules are initialised"
  42. else
  43. echo "initialising submodules"
  44. gin git submodule update --init --recursive
  45. gin git submodule foreach gin init
  46. fi
  47. else
  48. echo "not a tonic repo, please initialise submodules manually if there are any"
  49. fi
  50. ## code 3
  51. usage() {
  52. echo "$0 <sync-option>"
  53. echo
  54. echo "<sync-option> The sync option defines what to do with the content of large files."
  55. echo " It should be one of the following values:"
  56. echo " download - Download all large file content from the server"
  57. echo " keep - Keep all large file content but do not download missing large files"
  58. echo " remove - Do not download large files and remove existing local large file content"
  59. exit 1
  60. }
  61. # Set the variable for synchronisation option, see above
  62. syncopt="remove"
  63. echo "start synchronisation in "$syncopt" mode, close window to cancel. change mode by changing the code in a text application"
  64. sh .scripts/GIN-SYNC