-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync_mirror.sh
executable file
·105 lines (86 loc) · 3.23 KB
/
sync_mirror.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
SCRIPT_DIR=$(readlink -e "$(dirname "${0}")")
SCHEMES_INDEX_URL=https://raw.githubusercontent.com/chriskempson/base16-schemes-source/master/list.yaml
TEMPLATES_INDEX_URL=https://raw.githubusercontent.com/chriskempson/base16-templates-source/master/list.yaml
SCHEMES_INDEX="${SCRIPT_DIR}"/schemes.yaml
SCHEMES_EXTRA_INDEX="${SCRIPT_DIR}"/schemes_extra.yaml
SCHEMES_EXTRA_DIR="${SCRIPT_DIR}"/schemes_extra
SCHEMES_WORKDIR="${SCRIPT_DIR}"/schemes.tmp
SCHEMES_RESULT_DIR="${SCRIPT_DIR}"/schemes
TEMPLATES_INDEX="${SCRIPT_DIR}"/templates.yaml
TEMPLATES_EXTRA_INDEX="${SCRIPT_DIR}"/templates_extra.yaml
TEMPLATES_RENAME="${SCRIPT_DIR}"/templates_rename.txt
TEMPLATES_EXTRA_DIR="${SCRIPT_DIR}"/templates_extra
TEMPLATES_WORKDIR="${SCRIPT_DIR}"/templates.tmp
TEMPLATES_RESULT_DIR="${SCRIPT_DIR}"/templates
GET_ASSET="${SCRIPT_DIR}/_get_asset.sh"
if [[ ${1:-} != '--extra-only' ]] ; then
curl "${SCHEMES_INDEX_URL}" -o "${SCHEMES_INDEX}"
mkdir -p "${SCHEMES_WORKDIR}"
if command -v parallel > /dev/null ; then
grep -hv '^#' "${SCHEMES_INDEX}" "${SCHEMES_EXTRA_INDEX}" | parallel "${GET_ASSET}" "${SCHEMES_WORKDIR}"
else
# shellcheck disable=SC2046
parallel-moreutils "${GET_ASSET}" "${SCHEMES_WORKDIR}" -- $(grep -hv '^#' "${SCHEMES_INDEX}" "${SCHEMES_EXTRA_INDEX}" )
fi
rsync -rv \
--delete \
--exclude=".git" \
--exclude=".github" \
--exclude=".travis.yml" \
--exclude="output" \
--exclude="circus/circus" \
--include="*/" \
--include="*/*.yml" \
--include="*/*.yaml" \
--exclude="*" \
"$SCHEMES_WORKDIR"/ "$SCHEMES_RESULT_DIR"
sync
sleep 0.001
echo 'Clean-up empty-dirs:'
find "$SCHEMES_RESULT_DIR" -type d -empty -print0 | xargs --null rmdir || true
echo 'Check-up (debug):'
find "$SCHEMES_RESULT_DIR" -type d -empty -print0 | xargs --null echo
echo ':: schemes done ::'
curl "${TEMPLATES_INDEX_URL}" -o "${TEMPLATES_INDEX}"
mkdir -p "${TEMPLATES_WORKDIR}"
if command -v parallel ; then
grep -hv '^#' "${TEMPLATES_INDEX}" "${TEMPLATES_EXTRA_INDEX}" | parallel "${GET_ASSET}" "${TEMPLATES_WORKDIR}"
else
# shellcheck disable=SC2046
parallel-moreutils "${GET_ASSET}" "${TEMPLATES_WORKDIR}" -- $(grep -hv '^#' "${TEMPLATES_INDEX}" "${TEMPLATES_EXTRA_INDEX}")
fi
while read -r line ; do
rename_from=$(cut -d: -f1 <<< "$line")
rename_to=$(cut -d: -f2 <<< "$line")
rm -r "${TEMPLATES_WORKDIR:?}/${rename_to}" || true
mv "${TEMPLATES_WORKDIR}/${rename_from}" "${TEMPLATES_WORKDIR}/${rename_to}"
done < <(sed -e 's/ -> /:/g' < "$TEMPLATES_RENAME")
rsync -rv \
--delete \
--exclude=".git" \
--include="*/" \
--include="*/templates/*" \
--exclude="*" \
"$TEMPLATES_WORKDIR"/ "$TEMPLATES_RESULT_DIR"
fi
if [[ -d "$SCHEMES_EXTRA_DIR" ]] ; then
echo ":: extra schemes:"
rsync -rv \
"$SCHEMES_EXTRA_DIR"/ "$SCHEMES_RESULT_DIR"
fi
echo ":: extra templates:"
for pre_build_script in "$TEMPLATES_EXTRA_DIR"/*/templates/pre_build.sh ; do
"${pre_build_script}"
done
rsync -rv \
"$TEMPLATES_EXTRA_DIR"/ "$TEMPLATES_RESULT_DIR"
sync
sleep 0.001
echo 'Clean-up empty dirs:'
find "$TEMPLATES_RESULT_DIR" -type d -empty -print0 | xargs --null rmdir || true
echo 'Check-up (debug):'
find "$TEMPLATES_RESULT_DIR" -type d -empty -print0 | xargs --null echo
echo ':: templates done ::'