]> git.meshlink.io Git - meshlink/blob - test/blackbox/util/build_container.sh
Don't link with Catta anymore.
[meshlink] / test / blackbox / util / build_container.sh
1 #!/bin/sh
2 #    build_container.sh -- Script to populate an LXC Container with the files
3 #                          required to run a Meshlink Node Simulation.
4 #                          Designed to run on unprivileged Containers.
5 #    Copyright (C) 2018  Guus Sliepen <guus@meshlink.io>
6 #
7 #    This program is free software; you can redistribute it and/or modify
8 #    it under the terms of the GNU General Public License as published by
9 #    the Free Software Foundation; either version 2 of the License, or
10 #    (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU General Public License for more details.
16 #
17 #    You should have received a copy of the GNU General Public License along
18 #    with this program; if not, write to the Free Software Foundation, Inc.,
19 #    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 # Read command-line arguments
22 testcase=$1
23 nodename=$2
24 meshlinkrootpath=$3
25 setx=$4
26
27 # Set configuration for required folders, programs and scripts
28 #   Folder Paths
29 ltlibfolder=".libs"
30 meshlinksrclibpath="${meshlinkrootpath}/src/${ltlibfolder}"
31 blackboxpath="${meshlinkrootpath}/test/blackbox"
32 blackboxlibpath="${meshlinkrootpath}/test/blackbox/${ltlibfolder}"
33 blackboxutilpath="${blackboxpath}/util"
34 testcasepath="${blackboxpath}/${testcase}"
35 testcaselibpath="${blackboxpath}/${testcase}/${ltlibfolder}"
36 mirrorfolder="test"
37 mirrorfolderpath="${testcasepath}/${mirrorfolder}"
38 mirrorfolderlibpath="${mirrorfolderpath}/${ltlibfolder}"
39 containerdstpath="/home/ubuntu/${mirrorfolder}"
40 containerconfbase="/testconf"
41 containerlogpath=""
42 #   Program/Script Names
43 ltprefix="lt-"
44 nodestepscript="node_step.sh"
45 nodesimpgm="node_sim_${nodename}"
46 nodesimltscript="${ltprefix}${nodesimpgm}"
47 geninvitepgm="gen_invite"
48 geninviteltscript="${ltprefix}${geninvitepgm}"
49 lxccopydirscript="lxc_copy_dir.sh"
50 lxccopyfilescript="lxc_copy_file.sh"
51 lxcrunscript="lxc_run.sh"
52 #   Container Name
53 containername="${testcase}_${nodename}"
54
55 # Run Libtool Wrapper Scripts once in their built paths in order to generate lt-<program> script inside .libs directory
56 ${blackboxpath}/${geninvitepgm} >/dev/null 2>/dev/null
57 ${testcasepath}/${nodesimpgm} >/dev/null 2>/dev/null
58
59 set ${setx}
60
61 # Create Meshlink Container Mirror Folder (Delete any existing folder before creating new folder)
62 rm -rf ${mirrorfolderpath} >/dev/null 2>/dev/null
63 mkdir ${mirrorfolderpath}
64
65 # Populate Mirror Folder
66 #   Copy Wrapper Scripts for Utility Programs
67 cp ${blackboxpath}/${geninvitepgm} ${mirrorfolderpath}
68 cp ${testcasepath}/${nodesimpgm} ${mirrorfolderpath}
69 #   Copy Utility Scripts
70 cp ${blackboxutilpath}/${nodestepscript} ${mirrorfolderpath}
71 #    Set Script Permissions
72 chmod 755 ${mirrorfolderpath}/*
73 #   Copy Binaries, lt- Scripts and Required Libraries
74 mkdir ${mirrorfolderlibpath}
75 cp ${blackboxlibpath}/* ${mirrorfolderlibpath}
76 cp ${testcaselibpath}/*${nodesimpgm}* ${mirrorfolderlibpath}
77 cp ${meshlinksrclibpath}/* ${mirrorfolderlibpath}
78
79 # Copy mirror folder into LXC Container
80 #   Delete Destination Folder
81 ${blackboxutilpath}/${lxcrunscript} "rm -rf ${containerdstpath}" ${containername}
82 #   Delete Meshlink confbase folder and logs from Container - every new test case starts on a clean slate
83 ${blackboxutilpath}/${lxcrunscript} "rm -rf ${containerconfbase}" ${containername}
84 ${blackboxutilpath}/${lxcrunscript} "rm ${containerlogpath}/*.log" ${containername}
85 #   Create Destination Folder and Copy Files
86 ${blackboxutilpath}/${lxccopydirscript} ${mirrorfolderpath} ${containername} ${containerdstpath}
87 #   Kill any running instances of the Node Simulation Program
88 ${blackboxutilpath}/${lxcrunscript} "${containerdstpath}/${nodestepscript} ${ltprefix}${nodesimpgm} SIGTERM 2>/dev/null" ${containername}
89 #   Restore the 'interfaces' file in the Container
90 echo "auto lo" > interfaces
91 echo "iface lo inet loopback" >> interfaces
92 echo "" >> interfaces
93 echo "auto eth0" >> interfaces
94 echo "iface eth0 inet dhcp" >> interfaces
95 ${blackboxutilpath}/${lxccopyfilescript} interfaces ${containername} /etc/network/interfaces
96
97 set +x