-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdeploy.sh
executable file
·55 lines (41 loc) · 1.38 KB
/
deploy.sh
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
#!/bin/bash
smilepath=$( cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
set -u
hosts=$(cat ~/.ssh/config | sed -n '/Host\s[^*]/ p' | cut -d ' ' -f 2-)
update_dotfiles() {
local host=$1
local smilepath=$2
local destpath=$3
rsync -az --delete "$smilepath" "$host:${destpath%/*}"
if [ $? -eq 0 ]; then
echo "updated"
# TODO launch install without download for private servers
ssh -o ConnectTimeout=1 $host "$destpath/install.sh > /dev/null 2>&1" > /dev/null 2>&1
ssh -o ConnectTimeout=1 $host "echo $host > ~/.box-name" > /dev/null 2>&1
return 0
fi
echo "not updated, error during rsync"
return 1
}
run() {
local host=$1
ssh -o ConnectTimeout=1 $host "echo zoo > /dev/null 2>&1" > /dev/null 2>&1
test $? -eq 0 || return 1
destpath=$(ssh -o ConnectTimeout=1 $host "cat .smile.conf 2> /dev/null" 2> /dev/null)
result=$?
destpath=${destpath##*=}
local message
if [ $result -eq 0 ]; then
message="$host: dotfiles installed in $destpath"
message="$message ... $(update_dotfiles "$host" "$smilepath" "$destpath")"
else
message="$host: no dotfiles found"
message="$message ... $(update_dotfiles "$host" "$smilepath" "~/${smilepath##*/}")"
fi
printf "%s\n" "$message"
}
export -f update_dotfiles
while read -ru 3 host; do
run "$host" &
done 3<<< "$hosts"
wait