Thomas Vachuska | 0fdf7c9 | 2016-05-05 17:01:39 -0700 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # Creates a new node from the base image. |
| 3 | |
| 4 | base="$1" |
| 5 | ip="$2" |
| 6 | name="$3" |
| 7 | key="$4" |
| 8 | |
| 9 | sudo lxc-clone -o $base -n $name |
| 10 | |
| 11 | sudo chmod 777 /var/lib/lxc |
| 12 | sudo chmod 777 /var/lib/lxc/$name |
| 13 | sudo chmod 666 /var/lib/lxc/$name/config |
| 14 | |
| 15 | sudo cat >>/var/lib/lxc/$name/config <<EOF |
| 16 | lxc.network.ipv4 = ${ip}/16 |
| 17 | lxc.network.ipv4.gateway = 10.128.0.1 |
| 18 | EOF |
| 19 | |
| 20 | sudo chmod 644 /var/lib/lxc/$name/config |
| 21 | sudo chmod 750 /var/lib/lxc/$name |
| 22 | sudo chmod 700 /var/lib/lxc |
| 23 | |
| 24 | sudo lxc-start -d -n $name |
| 25 | sudo lxc-attach -n $name -- ping -c1 8.8.8.8 |
| 26 | sudo lxc-attach -n $name -- bash -c "echo $key >> /home/sdn/.ssh/authorized_keys" |
| 27 | sudo lxc-ls --fancy |