11#! /bin/bash
22CURRENT_DIR=$( pwd)
3-
4- echo " copying defaults"
5- echo " getting nhse repo template"
6- echo " Cloning $REPO into $DEST "
3+ update_from_template=" ${UPDATEFROMTEMPLATE:- true} "
74
85REPO=https://github.com/NHSDigital/nhs-notify-repository-template.git
96DEST=$HOME /nhsengland/repository-template
107CURRENT_TIMESTAMP=$( date +%Y%m%d%H%M%S)
118CHECKOUT_BRANCH=" devcontainer-base"
129UPDATE_BRANCH=" updating-the-default-files-$CURRENT_TIMESTAMP "
1310
14- mkdir -p $DEST
15- echo " created destination directory $DEST "
16- echo " Cloning repository from $REPO to $DEST "
17- git clone -b $CHECKOUT_BRANCH $REPO $DEST
18- echo " cloned repository $REPO branch $CHECKOUT_BRANCH to $DEST "
11+ get_repo_template (){
12+ echo " copying defaults"
13+ echo " getting nhse repo template"
14+ echo " Cloning $REPO into $DEST "
15+ mkdir -p $DEST
16+ echo " created destination directory $DEST "
17+ echo " Cloning repository from $REPO to $DEST "
18+ git clone -b $CHECKOUT_BRANCH $REPO $DEST
19+ echo " cloned repository $REPO branch $CHECKOUT_BRANCH to $DEST "
1920
20- CURRENT_BRANCH=$( git symbolic-ref --short HEAD)
21- echo " current branch is $CURRENT_BRANCH "
22- git switch -C $UPDATE_BRANCH
21+ CURRENT_BRANCH=$( git symbolic-ref --short HEAD)
22+ echo " current branch is $CURRENT_BRANCH "
23+ git switch -C $UPDATE_BRANCH
24+ }
2325
2426copy_folder_if_not_exists (){
2527 local FOLDER=$1
@@ -29,47 +31,96 @@ copy_folder_if_not_exists(){
2931 echo " Copied $FOLDER " \
3032 || echo " Not copying $FOLDER , already exist"
3133}
32- copy_folder_if_not_exists " .github"
33- copy_folder_if_not_exists " docs"
34- copy_folder_if_not_exists " infrastructure"
35- copy_folder_if_not_exists " .vscode"
36-
37- \c p -rf $DEST /scripts ./
38- \c p -f $DEST /Makefile ./
39- \c p -f $DEST /.tool-versions ./
40- \c p -f $DEST /.editorconfig ./
41- \c p -f $DEST /.gitattributes ./
42- \c p -f $DEST /.gitignore ./
43- \c p -f $DEST /.gitleaksignore ./
44- \c p --update=none $DEST /VERSION ./
45- \c p --update=none $DEST /README.md ./
46- \c p --update=none $DEST /LICENCE.md ./
47-
48- echo " $REPO template complete"
49-
50- echo " reload shell"
51- source ~ /.zshrc
52- echo " reloaded shell"
53-
54- export PATH=" ${ASDF_DATA_DIR:- $HOME / .asdf} /shims:$PATH "
55- # echo "running make config"
56- # make config
57- # echo "make config complete"
58-
59- cd $CURRENT_DIR
60-
61- echo " sorting certs"
62- sudo cp -r --update=none /home/ca-certificates/. /usr/local/share/ca-certificates
63- sudo update-ca-certificates
64- echo " sorted certs"
65-
66-
67- echo " configuring ohmyzsh"
68- echo ' export PATH="${ASDF_DATA_DIR:-$HOME/.asdf}/shims:$PATH"' >> ~ /.zshrc
69- sed -i " /plugins=/c\plugins=(git ssh-agent sudo terraform dirhistory)" ~ /.zshrc
70- cat ~ /.zshrc
71- echo " configured ohmyzsh"
72-
73- echo " adding gpg tty to zshrc"
74- echo ' export GPG_TTY=$(tty)' >> ~ /.zshrc
75- echo " added gpg tty to zshrc"
34+
35+ copy_folder_overwrite (){
36+ local FOLDER=$1
37+ echo " copying folder $FOLDER "
38+ \c p -rf $DEST /$FOLDER ./
39+ echo " Copied $FOLDER "
40+ }
41+
42+ copy_file_overwrite (){
43+ local FILE=$1
44+ echo " copying file $FILE "
45+ \c p -f $DEST /$FILE ./
46+ echo " Copied $FILE "
47+ }
48+
49+ copy_file_dont_overwrite (){
50+ local FILE=$1
51+ echo " checking for file $FILE "
52+ \c p --update=none $DEST /$FILE ./
53+ echo " Copied $FILE if it did not exist"
54+ }
55+
56+ update_from_template (){
57+ copy_folder_if_not_exists " .github"
58+ copy_folder_if_not_exists " docs"
59+ copy_folder_if_not_exists " infrastructure"
60+ copy_folder_if_not_exists " .vscode"
61+
62+ copy_folder_overwrite " scripts"
63+
64+ copy_file_overwrite " Makefile"
65+ copy_file_overwrite " .tool-versions"
66+ copy_file_overwrite " .editorconfig"
67+ copy_file_overwrite " .gitattributes"
68+ copy_file_overwrite " .gitignore"
69+ copy_file_overwrite " .gitleaksignore"
70+
71+ copy_file_dont_overwrite " VERSION"
72+ copy_file_dont_overwrite " README.md"
73+ copy_file_dont_overwrite " LICENCE.md"
74+
75+ echo " $REPO template update complete"
76+ }
77+
78+ update_from_template_if_enabled (){
79+ if [ " ${update_from_template} " == " true" ]; then
80+ echo " Updating from template as per configuration"
81+ get_repo_template
82+ update_from_template
83+ else
84+ echo " Skipping update from template as per configuration"
85+ fi
86+ }
87+
88+ reload_shell (){
89+ echo " reload shell"
90+ source ~ /.zshrc
91+ echo " reloaded shell"
92+ }
93+
94+ add_asdf_to_path (){
95+ echo " adding asdf to path"
96+ export PATH=" ${ASDF_DATA_DIR:- $HOME / .asdf} /shims:$PATH "
97+ echo " added asdf to path"
98+ }
99+
100+ sort_certs (){
101+ sudo cp -r --update=none /home/ca-certificates/. /usr/local/share/ca-certificates
102+ sudo update-ca-certificates
103+ echo " sorted certs"
104+ }
105+
106+ configure_ohmyzsh (){
107+ echo " configuring ohmyzsh"
108+ echo ' export PATH="${ASDF_DATA_DIR:-$HOME/.asdf}/shims:$PATH"' >> ~ /.zshrc
109+ sed -i " /plugins=/c\plugins=(git ssh-agent sudo terraform dirhistory)" ~ /.zshrc
110+ cat ~ /.zshrc
111+ echo " configured ohmyzsh"
112+ }
113+
114+ add_gpg_tty_to_zshrc (){
115+ echo " adding gpg tty to zshrc"
116+ echo ' export GPG_TTY=$(tty)' >> ~ /.zshrc
117+ echo " added gpg tty to zshrc"
118+ }
119+
120+ update_from_template_if_enabled
121+ reload_shell
122+ add_asdf_to_path
123+ sort_certs
124+ configure_ohmyzsh
125+ add_gpg_tty_to_zshrc
126+ cd $CURRENT_DIR
0 commit comments