File tree Expand file tree Collapse file tree 2 files changed +61
-7
lines changed
.devcontainer/customization Expand file tree Collapse file tree 2 files changed +61
-7
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ # This file contains some really simple functions that are useful when building up customization scripts.
4
+
5
+
6
+ # Checks if the git config has a user registered - and sets it up if not.
7
+ #
8
+ # Param 1: name
9
+ # Param 2: email
10
+ #
11
+ config_user () {
12
+ local gcn=$( git config --global user.name)
13
+ if [ -z " ${gcn} " ]; then
14
+ echo " Setting up git user / remote"
15
+ git config --global user.name " $1 "
16
+ git config --global user.email " $2 "
17
+
18
+ fi
19
+ }
20
+
21
+ # Checks if the git remote is configured - and sets it up if not. Fetches either way.
22
+ #
23
+ # Param 1: remote name
24
+ # Param 2: remote url
25
+ #
26
+ config_remote () {
27
+ local gr=$( git remote -v | grep $1 )
28
+ if [ -z " ${gr} " ]; then
29
+ git remote add $1 $2
30
+ fi
31
+ git fetch $1
32
+ }
33
+
34
+ # Setup special .ssh files
35
+ #
36
+ # Param 1: bash array, filenames relative to the customization directory that should be copied to ~/.ssh
37
+ setup_ssh () {
38
+ local files=(" $@ " )
39
+ for file in " ${files[@]} " ; then
40
+ local cfile=" /devcontainer-customization/${file} "
41
+ local hfile=" ~/.ssh/${file} "
42
+ if [ ! -f " ${hfile} " ]; then
43
+ echo " copying ${file} "
44
+ cp " ${cfile} " " ${hfile} "
45
+ chmod 600 " ${hfile} "
46
+ fi
47
+ done
48
+ ls ~ /.ssh
49
+ }
Original file line number Diff line number Diff line change @@ -7,14 +7,19 @@ If files with those names exist here, they will be called at the end of the norm
7
7
8
8
This is a good place to set things like ` git config --global user.name ` are set - and to handle any other files that are mounted via this directory.
9
9
10
- An example of a useful script might be :
10
+ To assist in doing so, ` source /.devcontainer-scripts/utils.sh ` will provide utility functions that may be useful - for example :
11
11
12
12
```
13
13
#!/bin/bash
14
- gcn=$(git config --global user.name)
15
- if [ -z "$gcn" ]; then
16
- git config --global user.name YOUR.NAME
17
- git config --global user.email YOUR.EMAIL
18
- git remote add PREFIX FORK_URL
19
- fi
14
+
15
+ source "/.devcontainer-scripts/utils.sh"
16
+
17
+ sshfiles=("config", "key.pub")
18
+
19
+ setup_ssh "${sshfiles[@]}"
20
+
21
+ config_user "YOUR NAME" "YOUR EMAIL"
22
+
23
+ config_remote "REMOTE NAME" "REMOTE URL"
24
+
20
25
```
You can’t perform that action at this time.
0 commit comments