-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·39 lines (32 loc) · 1.22 KB
/
deploy.sh
File metadata and controls
executable file
·39 lines (32 loc) · 1.22 KB
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
#!/usr/bin/env bash
BASE="$(dirname "$(readlink -f "${0}")")"
die(){ error "$*"; exit 1; }
error(){ printf "\e[31m%s\e[0m\n" "$*" >&2; }
warn(){ printf "\e[33m%s\e[0m\n" "$*" >&2; }
# You can use another base or file by setting the
# environment DEPL_BASE or DEPL_FILE
DEPL_BASE="${DEPL_BASE:-${BASE}}"
DEPL_FILE="${DEPL_FILE:-${BASE}/deployment}"
[ -r "${DEPL_FILE}" ] || \
die "Deployment-file '${DEPL_FILE}' not readable."
# If git submodule is already able to handle --jobs, use parallel fetch!
# If not, update everything in serial way.
git -C "${DEPL_BASE}" config --local submodule.fetchJobs 0
git -C "${DEPL_BASE}" submodule update --init --recursive
grep -v --perl-regexp -- '^\s*#' "${DEPL_FILE}" \
| while read src dst ; do
src="${src//\~/${HOME}}"
dst="${dst//\~/${HOME}}"
mkdir -p -- "$(dirname -- "${dst}")"
# if file is a symbolic link, remove the old one
if [[ "$(readlink -f -- "${BASE}/${src}")" != "$(readlink -f -- "${dst}")" ]]; then
if [ -L "${dst}" ]; then
printf "Updating link '%s'\n old: '%s'\n new: '%s'\n" \
"${src}" \
"$(readlink -f -- "${BASE}/${src}")" \
"$(readlink -f -- "${dst}")"
rm -- "${dst}"
fi
[ ! -e "${dst}" ] && ln -s -- "${BASE}/${src}" "${dst}"
fi
done