template_init.command 3.5 KB

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