template_init.command 3.6 KB

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