-
Notifications
You must be signed in to change notification settings - Fork 11
/
ssh-update-config
executable file
·59 lines (47 loc) · 1.24 KB
/
ssh-update-config
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
help() {
echo 'usage: (ssh-update-config|ssh-update-config-template)'
echo
echo ' Construct a new ~/.ssh/config from ~/.ssh/config.d.'
echo ' A backup of the current ~/.ssh/config is done'
echo ' automatically.'
echo
echo ' If called as `ssh-update-config` then:'
echo
echo ' * ~/.ssh/config.d/* is `cat`ed together and'
echo ' the result used as ~/.ssh/config'
echo
echo ' If called as `ssh-update-config-template` then:'
echo
echo ' * ~/.ssh/config.d/main.template is'
echo ' `source`d instead and the result written to'
echo ' ~/.ssh/config'
echo
echo ' ssh-update-config requires the `versioned_backup`'
echo ' script'
exit
}
if [ "$1" == "--help" ]; then
help
fi
error_and_exit() {
echo $1
exit -1
}
cat_template() {
echo "cat << EOT"
cat "$1"
echo EOT
}
config=~/.ssh/config
name=$( basename "$0" )
if [ -e $config ]; then
if ! versioned_backup $config ; then
error_and_exit "ERROR: failed to make backup of $config"
fi
fi
if [ "$name" == "ssh-update-config-template" ]; then
. ~/.ssh/config.d/main.template > ~/.ssh/config
else # we were called as ssh-update-config
cat ~/.ssh/config.d/* > ~/.ssh/config
fi