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>
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.
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.
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.
21 # Read command-line arguments
27 # Set configuration for required folders, programs and scripts
30 meshlinksrclibpath="${meshlinkrootpath}/src/${ltlibfolder}"
31 cattasrclibpath="${meshlinkrootpath}/catta/src/${ltlibfolder}"
32 blackboxpath="${meshlinkrootpath}/test/blackbox"
33 blackboxlibpath="${meshlinkrootpath}/test/blackbox/${ltlibfolder}"
34 blackboxutilpath="${blackboxpath}/util"
35 testcasepath="${blackboxpath}/${testcase}"
36 testcaselibpath="${blackboxpath}/${testcase}/${ltlibfolder}"
38 mirrorfolderpath="${testcasepath}/${mirrorfolder}"
39 mirrorfolderlibpath="${mirrorfolderpath}/${ltlibfolder}"
40 containerdstpath="/home/ubuntu/${mirrorfolder}"
41 containerconfbase="/testconf"
43 # Program/Script Names
45 nodestepscript="node_step.sh"
46 nodesimpgm="node_sim_${nodename}"
47 nodesimltscript="${ltprefix}${nodesimpgm}"
48 geninvitepgm="gen_invite"
49 geninviteltscript="${ltprefix}${geninvitepgm}"
50 lxccopydirscript="lxc_copy_dir.sh"
51 lxccopyfilescript="lxc_copy_file.sh"
52 lxcrunscript="lxc_run.sh"
54 containername="${testcase}_${nodename}"
56 # Run Libtool Wrapper Scripts once in their built paths in order to generate lt-<program> script inside .libs directory
57 ${blackboxpath}/${geninvitepgm} >/dev/null 2>/dev/null
58 ${testcasepath}/${nodesimpgm} >/dev/null 2>/dev/null
62 # Create Meshlink Container Mirror Folder (Delete any existing folder before creating new folder)
63 rm -rf ${mirrorfolderpath} >/dev/null 2>/dev/null
64 mkdir ${mirrorfolderpath}
66 # Populate Mirror Folder
67 # Copy Wrapper Scripts for Utility Programs
68 cp ${blackboxpath}/${geninvitepgm} ${mirrorfolderpath}
69 cp ${testcasepath}/${nodesimpgm} ${mirrorfolderpath}
70 # Copy Utility Scripts
71 cp ${blackboxutilpath}/${nodestepscript} ${mirrorfolderpath}
72 # Set Script Permissions
73 chmod 755 ${mirrorfolderpath}/*
74 # Copy Binaries, lt- Scripts and Required Libraries
75 mkdir ${mirrorfolderlibpath}
76 cp ${blackboxlibpath}/* ${mirrorfolderlibpath}
77 cp ${testcaselibpath}/*${nodesimpgm}* ${mirrorfolderlibpath}
78 cp ${meshlinksrclibpath}/* ${mirrorfolderlibpath}
79 cp ${cattasrclibpath}/* ${mirrorfolderlibpath}
81 # Copy mirror folder into LXC Container
82 # Delete Destination Folder
83 ${blackboxutilpath}/${lxcrunscript} "rm -rf ${containerdstpath}" ${containername}
84 # Delete Meshlink confbase folder and logs from Container - every new test case starts on a clean slate
85 ${blackboxutilpath}/${lxcrunscript} "rm -rf ${containerconfbase}" ${containername}
86 ${blackboxutilpath}/${lxcrunscript} "rm ${containerlogpath}/*.log" ${containername}
87 # Create Destination Folder and Copy Files
88 ${blackboxutilpath}/${lxccopydirscript} ${mirrorfolderpath} ${containername} ${containerdstpath}
89 # Kill any running instances of the Node Simulation Program
90 ${blackboxutilpath}/${lxcrunscript} "${containerdstpath}/${nodestepscript} ${ltprefix}${nodesimpgm} SIGTERM 2>/dev/null" ${containername}
91 # Restore the 'interfaces' file in the Container
92 echo "auto lo" > interfaces
93 echo "iface lo inet loopback" >> interfaces
95 echo "auto eth0" >> interfaces
96 echo "iface eth0 inet dhcp" >> interfaces
97 ${blackboxutilpath}/${lxccopyfilescript} interfaces ${containername} /etc/network/interfaces