template_init.command 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. # go on main branch
  12. git checkout main
  13. GINinfo="$(gin remotes)"
  14. Gitadress="$(echo $GINinfo | cut -d'/' -f3)"
  15. Orga="$(echo $GINinfo | cut -d'/' -f4)"
  16. repo2="$(echo $GINinfo | cut -d'/' -f5)"
  17. repo="$(echo $repo2 | cut -d' ' -f1)"
  18. reposhort="$(echo "${repo/.main}")"
  19. # readme text
  20. readmetext="$Gitadress/$Orga/$repo is the parent directory"
  21. echo "readme will be $readmetext"
  22. # initialise submodules
  23. git submodule update --init --recursive
  24. # if the template was not initialise before, let's do it
  25. if test -f "03_data/001_data/README_data.md" ;
  26. then
  27. echo "submodules in place, happy working!"
  28. else
  29. echo "setting up the template for the first time !"
  30. # add readme files, and folders
  31. echo "$readmetext" >> 03_data/001_data/README_data.md
  32. echo "$readmetext" >> 04_data_analysis/010_code/README_analysiscode.md
  33. echo "$readmetext" >> 05_figures/990_shared_figures/README_figures.md
  34. echo "$readmetext" >> 03_data/001_data/README_data.md
  35. echo "$readmetext" >> 06_dissemination/README_DISSEMINATION.md
  36. mkdir 06_dissemination/01_reports_conferences
  37. mkdir 06_dissemination/02_manuscripts
  38. mkdir 06_dissemination/03_other
  39. touch 06_dissemination/01_reports_conferences/.gitkeep
  40. touch 06_dissemination/02_manuscripts/.gitkeep
  41. touch 06_dissemination/03_other/.gitkeep
  42. # add labcommons submodule
  43. git submodule add "ssh://$Gitadress/$Orga/"labcommons"" testlabcommons
  44. # push submodule content
  45. git submodule foreach gin init
  46. git submodule foreach gin commit . -m initial commit from template
  47. git submodule foreach gin upload
  48. # delete file telling the initialisation need to be done
  49. rm "00repo_needs_initialisation00.txt"
  50. # arrange parent repository
  51. gin commit .
  52. git checkout --orphan newbranch
  53. git add -A
  54. git commit -m "created from template"
  55. git branch -D main
  56. git branch -m master
  57. git push -f origin master
  58. # add submodule to PI repo
  59. # get labreports repo and write new folder for the project
  60. cd ../
  61. gin get ""$Orga""/labreports""
  62. cd labreports
  63. mkdir "$reposhort"
  64. mkdir "$reposhort/05_figures"
  65. # add 2 submodule for figures and dissemination files there
  66. git submodule add "../$reposhort.05_figures_990_shared_figures.git" ""$reposhort"/05_figures/990_shared_figures"
  67. git submodule add "../$reposhort.06_dissemination" ""$reposhort"/06_dissemination"
  68. # add a file to tell the user/script to initialise the submodules next time.
  69. echo "submodules need intitialisation due to project $repo " >> "initialise.txt"
  70. # push changes on the server and remove the repo from the computer.
  71. gin commit . -m "added project $reposhort"
  72. gin upload
  73. cd ../
  74. rm -rf labreports
  75. fi