template_init.command 3.4 KB

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