Newer
Older

Théo - Le Filament
committed
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
#!/bin/sh
set -e
ODOO_ROOT_DIR=${ODOO_ROOT_DIR:-'/opt/odoo'}
SAVE_COMMITS_DIR=${SAVE_COMMITS_DIR:-'/opt/odoo_commits'}
SAVE_COMMITS_FILENAME=${SAVE_COMMITS_FILENAME:-'custom_addons'}
TMP_REPO_PATH='/tmp/repo'
save_commit() {
repo="$1"
commit="$2"
module="$3"
dst="$4"
echo "${repo};${commit};${module};${dst}" >> "${SAVE_COMMITS_DIR}/${SAVE_COMMITS_FILENAME}"
}
repo="$1"
shift
ref="$1"
shift
dst="$1"
shift
modules="$@"
set +e
git clone --single-branch --branch "${ref}" --depth 1 "${repo}" "${TMP_REPO_PATH}"
if [ "$?" != 0 ]; then
git clone "${repo}" "${TMP_REPO_PATH}"
fi
set -e
git -C "${TMP_REPO_PATH}" checkout "${ref}"
commit="$(git -C /tmp/repo rev-parse HEAD)"
if [ -n "$modules" ]; then
for module in $modules; do
mv "${TMP_REPO_PATH}/${module}" "${ODOO_ROOT_DIR}/${dst}/"
save_commit "$repo" "$commit" "$module" "$dst"
done
else
module="$(basename $dst)"
mkdir -p "/${ODOO_ROOT_DIR}/${dst}"
mv ${TMP_REPO_PATH}/* "${ODOO_ROOT_DIR}/${dst}/"
save_commit "$repo" "$commit" "$module" "$dst"
fi
rm -r "${TMP_REPO_PATH}"