-
Notifications
You must be signed in to change notification settings - Fork 8
/
initial_data_cont.sh
executable file
·74 lines (61 loc) · 2.5 KB
/
initial_data_cont.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
#!/usr/bin/env bash
# Run server image (New mailman server) and copy what we get inside the
# /var/lib/mailman/{data,lists,archives} directories.
# We will use this dir skeleton as the basic image of data_image.
# Abort on failure.
set -e
# Check if mailman_server_cont is running. If it does,
# we will abort. We don't want to initialize the data while the server
# container is running.
nlines_server=`docker ps | grep mailman_server_cont | wc -l`
if [ "$nlines_server" -gt "0" ]
then echo "mailman_server_cont is still running! Aborting data initialization." && \
exit
fi
# Count the amount of lines with "mailman_data_cont" inside the
# output of "docker ps -a". This tells us if the mailman_data_cont container is there.
# If it is there, we backup it first. If it is not there, there is nothing
# to backup.
nlines_data=`docker ps -a | grep mailman_data_cont | wc -l`
if [ "$nlines_data" -gt "0" ]
then echo "There might be important data inside mailman_data_cont.
Creating a backup first..." && \
./backup_data.sh ; fi
# Generate directories:
mkdir -p ./var_files/data
mkdir -p ./var_files/lists
mkdir -p ./var_files/archives
# Get the directories contents by running a new mailman_server:
docker run --name gen_skeleton_cont \
-v $(readlink -f ./var_files/data):/mm_vfiles/data \
-v $(readlink -f ./var_files/lists):/mm_vfiles/lists \
-v $(readlink -f ./var_files/archives):/mm_vfiles/archives \
-v $(readlink -f ./server_image/assets):/raw_assets \
-v $(readlink -f ./server.conf):/raw_assets/server.conf \
mailman_server sh -c "chmod +x /raw_assets/*.sh && \
/raw_assets/conf_server.sh && \
/assets/server_first_usage.sh && \
/assets/run_server.sh && \
cp -R /var/lib/mailman/data /mm_vfiles && \
cp -R /var/lib/mailman/lists /mm_vfiles && \
cp -R /var/lib/mailman/archives /mm_vfiles"
# Cleanup the gen_skeleton_cont:
docker rm -f gen_skeleton_cont
# Remove the mailman_data_cont (If it is in the list of "docker ps -a"
if [ "$nlines_data" -gt "0" ]
then docker rm -f mailman_data_cont
fi
# Build a new mailman_data_cont:
docker run --name mailman_data_cont \
-v $(readlink -f ./var_files):/mm_vfiles \
mailman_data \
sh -c "\
cp -R /mm_vfiles/data /var/lib/mailman && \
cp -R /mm_vfiles/lists /var/lib/mailman && \
cp -R /mm_vfiles/archives /var/lib/mailman && \
rm -R /mm_vfiles/data && \
rm -R /mm_vfiles/lists && \
rm -R /mm_vfiles/archives"
rm -rf ./var_files
# Unset abort on failure.
set +e