-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathchip.sh
More file actions
executable file
·106 lines (98 loc) · 3.55 KB
/
chip.sh
File metadata and controls
executable file
·106 lines (98 loc) · 3.55 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
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
105
106
#!/bin/bash
if [ ! -f ./core-modules.yaml ]; then
echo "No core module configuration found, creating one from defaults..."
cp ./core-modules.yaml.default ./core-modules.yaml
fi
for dir in ./modules/*; do
str+=" -f ${dir}/compose.yml"
if [ ! -f $dir/config.env ]; then
echo "No module configuration found for module ${dir%%:*}, creating one from defaults..."
cp $dir/config.env.default $dir/config.env
fi
done
docker compose -f docker-compose-base.yml ${str} config > /tmp/chiptemp
modules=($(docker run --rm -v "/tmp":/workdir mikefarah/yq '.services.* | key + ":" + .expose[0]' chiptemp))
rm /tmp/chiptemp
core_modules=($(docker run --rm -v "${PWD}":/workdir mikefarah/yq '.* | key + ":" + .' core-modules.yaml))
# If setup.env does not exist, create an empty setup.env
[ -f setup.env ] || touch setup.env
> setup.env
for module in ${modules[@]}; do
name=${module%%:*}
name=${name//-/_}
name=$( echo $name | tr '[:lower:]' '[:upper:]')
echo ${name}=${module} >> setup.env
for core_module in ${core_modules[@]}; do
core=${core_module%%:*}
core=$( echo $core | tr '[:lower:]' '[:upper:]')
core_name=${core_module##*:}
core_name=${core_name//-/_}
core_name=$( echo $core_name | tr '[:lower:]' '[:upper:]')
if [[ "$core_name" == "$name" ]]; then
echo $core=$name >> setup.env
fi
done
done
echo "Created module-address and core-module mappings in setup.env..."
modules_up=""
for core_module in ${core_modules[@]}; do
modules_up+=${core_module##*:}" "
done
if [[ -z "$1" ]] ; then
echo "Finished setting up!"
exit 0
fi
case $1 in
build)
if [[ -z "$2" ]] ; then
echo "Building core modules:"
echo $modules_up
docker compose -f docker-compose-base.yml ${str} build ${modules_up}
else
echo "Building specific modules: "+"${@:2}"
docker compose -f docker-compose-base.yml ${str} build "${@:2}"
fi
;;
start)
if [[ -z "$2" ]] ; then
echo "Starting system with core modules:"
echo $modules_up
docker compose -f docker-compose-base.yml ${str} build ${modules_up}
docker compose -f docker-compose-base.yml ${str} up ${modules_up}
else
echo "Starting specific modules: "+"${@:2}"
docker compose -f docker-compose-base.yml ${str} build "${@:2}"
docker compose -f docker-compose-base.yml ${str} up "${@:2}"
fi
;;
stop)
echo "Taking down full system..."
docker compose -f docker-compose-base.yml ${str} down
;;
clean)
echo "Taking down full system and removing volume data..."
docker compose -f docker-compose-base.yml ${str} down -v
;;
config)
echo "Showing the merged compose file that will be used..."
docker compose -f docker-compose-base.yml ${str} config
;;
list)
echo "Listing all available modules..."
for module in ${modules[@]}; do
echo - ${module%%:*}" "
done
;;
auto-completion)
the_source=$(readlink -f -- "${BASH_SOURCE[0]}")
the_dirname=$(dirname "${the_source}")
the_filename=$(basename "${the_source}")
echo $'\n'complete -W \"\$"(ls -C ${the_dirname}/modules/)"\" ./${the_filename} >> ~/.bashrc
. ~/.bashrc
echo "Added auto-completion to .bashrc"
;;
*)
echo "Please use either 'build', 'start', 'stop', 'clean', 'config', 'list', 'auto-completion', or call without args to generate the necessary configuration without doing anything else."
echo "Add space-separated module names afterwards to perform the operation for specific modules."
;;
esac