-
Notifications
You must be signed in to change notification settings - Fork 0
/
inject.sh
executable file
·69 lines (50 loc) · 1.4 KB
/
inject.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
#!/bin/bash
# Script to sync files from servers folder to container.
DIR="$(dirname "$(readlink -f "$0")")"
if [ "$#" -ne 2 ]; then
echo "READ THE CODE"
exit 1
fi
ctid=$1
server_template=$2
ct_private=$(vzlist -a1o private "$ctid")
sync() {
template_sync=$1
source_dir="${DIR}/servers/${template_sync}/"
dest_dir="${ct_private}/"
if [[ "$dest_dir" == "/" ]]; then
echo "Avoiding a sync to '/' !"
exit 1
fi
echo "Syncing ${template_sync} from '${source_dir}' to '${dest_dir}'."
if [[ ! -d "$source_dir" ]]; then
echo "Directory '${source_dir}' not found !"
exit 1
fi
if [[ ! -d "$dest_dir" ]]; then
echo "Directory '${dest_dir}' not found !"
exit 1
fi
rsync -rv "$source_dir" "$dest_dir"
echo "Done syncing '${template_sync}'"
}
install() {
local template="$1"
inject_requirements "$template"
sync "$template"
}
inject_requirements() {
local template=$1
local requirement=$(cat "${DIR}/requirements.txt" | grep "^$template:" | cut -d ':' -f 2 | head -n 1)
if [[ -n "$requirement" ]]; then
install "$requirement"
fi
}
# Remove any old content in /etc/vz-template
rm -rf "${ct_private}/etc/vz-template/"
# Sync generic file to container
sync "global"
if [[ "$server_template" != "global" ]]; then
# Sync template with nested dependencies
install "$server_template"
fi