blob: 14d0678c624b944662e93e8a28e544cec316405d [file] [log] [blame]
Thomas Vachuska0fdf7c92016-05-05 17:01:39 -07001#!/bin/bash
2# Creates a new node from the base image.
3
4base="$1"
5ip="$2"
6name="$3"
Thomas Vachuskae91541f2016-05-05 23:15:41 -07007shift 3
8key="$@"
Thomas Vachuska0fdf7c92016-05-05 17:01:39 -07009
10sudo lxc-clone -o $base -n $name
11
12sudo chmod 777 /var/lib/lxc
13sudo chmod 777 /var/lib/lxc/$name
14sudo chmod 666 /var/lib/lxc/$name/config
15
16sudo cat >>/var/lib/lxc/$name/config <<EOF
17lxc.network.ipv4 = ${ip}/16
18lxc.network.ipv4.gateway = 10.128.0.1
19EOF
20
21sudo chmod 644 /var/lib/lxc/$name/config
22sudo chmod 750 /var/lib/lxc/$name
23sudo chmod 700 /var/lib/lxc
24
25sudo lxc-start -d -n $name
26sudo lxc-attach -n $name -- ping -c1 8.8.8.8
27sudo lxc-attach -n $name -- bash -c "echo $key >> /home/sdn/.ssh/authorized_keys"
Thomas Vachuska6cda04b2016-05-06 12:46:08 -070028sudo lxc-attach -n $name -- bash -c "sed -i \"s/127.0.1.1.*/127.0.1.1 $name/\" /etc/hosts"