template_init.command 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/usr/bin/env bash
  2. #
  3. # update template submodules manually
  4. # run once in the main folder after the template has been made by tonic
  5. # Set folder where script will be executed
  6. #loc=$(dirname $0)
  7. #projectdir=$(git -C ${loc} rev-parse --show-toplevel)
  8. #
  9. #pushd ${loc} > /dev/null
  10. # get info for gin remote information
  11. GINinfo="$(gin remotes)"
  12. Gitadress="$(echo $GINinfo | cut -d'/' -f3)"
  13. Orga="$(echo $GINinfo | cut -d'/' -f4)"
  14. repo2="$(echo $GINinfo | cut -d'/' -f5)"
  15. repo="$(echo $repo2 | cut -d' ' -f1)"
  16. reposhort="$(echo "${repo/.main}")"
  17. # readme text
  18. readmetext="$Gitadress/$Orga/$repo is the parent directory"
  19. echo "readme will be $readmetext"
  20. echo "erase master branch and go to main if there is a main branch"
  21. git checkout main
  22. git branch -D master
  23. # initialise submodules
  24. git submodule update --init --recursive
  25. # if the template was not initialise before, let's do it
  26. if test -f "03_data/001_data/README_data.md" ;
  27. then
  28. echo "submodules in place, happy working!"
  29. else
  30. echo "setting up the template for the first time !"
  31. # add readme files, and folders
  32. echo "$readmetext" >> 03_data/001_data/README_data.md
  33. echo "$readmetext" >> 04_data_analysis/010_code/README_analysiscode.md
  34. echo "$readmetext" >> 05_figures/990_shared_figures/README_figures.md
  35. echo "$readmetext" >> 03_data/001_data/README_data.md
  36. echo "$readmetext" >> 06_dissemination/README_DISSEMINATION.md
  37. mkdir 06_dissemination/01_reports_conferences
  38. mkdir 06_dissemination/02_manuscripts
  39. mkdir 06_dissemination/03_other
  40. touch 06_dissemination/01_reports_conferences/.gitkeep
  41. touch 06_dissemination/02_manuscripts/.gitkeep
  42. touch 06_dissemination/03_other/.gitkeep
  43. # add labcommons submodule
  44. git submodule add "../labcommons" 07_misc/labcommons
  45. # push submodule content
  46. git submodule foreach gin init
  47. git submodule foreach gin commit . -m initial commit from template
  48. git submodule foreach gin upload
  49. # delete file telling the initialisation need to be done
  50. rm "00repo_needs_initialisation00.txt"
  51. # arrange parent repository (no rewriting history for security issue)
  52. gin commit . -m "initialisation"
  53. gin upload .
  54. # add submodule to PI repo
  55. # get labreports repo and write new folder for the project
  56. cd ../
  57. gin get ""$Orga""/labreports""
  58. cd labreports
  59. mkdir "$reposhort"
  60. mkdir "$reposhort/05_figures"
  61. # add 2 submodule for figures and dissemination files there
  62. git submodule add "../$reposhort.05_figures_990_shared_figures.git" ""$reposhort"/05_figures/990_shared_figures"
  63. git submodule add "../$reposhort.06_dissemination" ""$reposhort"/06_dissemination"
  64. # add a file to tell the user/script to initialise the submodules next time.
  65. echo "submodules need intitialisation due to project $repo " >> "initialise.txt"
  66. # push changes on the server and remove the repo from the computer.
  67. gin commit . -m "added project $reposhort"
  68. gin upload
  69. cd ../
  70. rm -rf labreports
  71. fi