-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.sh
executable file
·79 lines (67 loc) · 1.27 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
set -e
shopt -s nullglob
shopt -s globstar
log() {
echo "${FUNCNAME[1]}:" "$@"
}
deploy_files() {
local dir="$1"
local dest="$2"
local prefix="${3-.}"
if ! [ -d "$dir" ]; then
log "Skipping '$dir'"
return
fi
log "Deploying '$dir'"
pushd "$dir" >/dev/null
for d in **/; do
mkdir -p "$dest/${prefix}$d"
done
for f in **/*; do
if ! [ -e "$dest/${prefix}$f" ]; then
ln -s -v $(readlink -f "$f") "$dest/${prefix}$f"
fi
done
popd >/dev/null
}
sync_files() {
local dir="$1"
local dest="$2"
local prefix="${3-.}"
if ! [ -d "$dir" ]; then
log "Skipping '$dir'"
return
fi
log "Syncing '$dir'"
pushd "$dir" >/dev/null
for f in **/*; do
if ! [ -h "$dest/${prefix}$f" ] \
&& [ -f "$dest/${prefix}$f" ] \
&& cmp -s "$f" "$dest/${prefix}$f" ; then
ln -s -f -v $(readlink -f "$f") "$dest/${prefix}$f"
fi
done
popd >/dev/null
}
run() {
local mode="$1"
local dir="$2"
if ! [ -d "$dir" ]; then
log "Skipping '$dir'"
return
fi
log "Context is '$dir'"
pushd "$dir" >/dev/null
mkdir -p "$HOME/bin"
"${mode}_files" bin "$HOME/bin" ""
"${mode}_files" config "$HOME" "."
popd >/dev/null
}
cd "$(dirname "$0")"
run deploy "local/$(hostname)"
run deploy common
if [ "$1" = "sync" ]; then
run sync "local/$(hostname)"
run sync common
fi