You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.2 KiB
Bash

7 years ago
#!/bin/bash
#Inputs
name=${1}
number=${2}
distro="alpine"
#if [ ${#} < 3 ]; then
# cat << EOF
#
#Usage: lxc-create-avc <container-name> <container number> [<packages>]
#
#EOF
#fi
packages="htop,ssmtp,vim"
if [ ${4} ]; then
packages="${packages},${3}"
fi
enable=""
if [ ${4} ]; then
nable="-e ${4}"
fi
#Variables
hwaddr="52:54:00:00:${number}:01"
ipv6="2a01:4f8:151:13cd::${number}/64"
# Create lxc Container
#lxc-create -B btrfs -t ${distro} -n ${name} -- --release latest-stable # -P ${packages} ${enable}
lxc-create -t download -n ${name}
cat > /var/lib/lxc/${name}/config << EOF
# Template used to create this container: /usr/share/lxc/templates/lxc-archlinux
# Parameters passed to the template:
# For additional config options, please look at lxc.container.conf(5)
lxc.rootfs = /var/lib/lxc/${name}/rootfs
lxc.utsname = ${name}
lxc.arch = x86_64
lxc.include = /usr/share/lxc/config/${distro}.common.conf
# Network configuration
lxc.network.type = veth
lxc.network.link = br0
lxc.network.flags = up
lxc.network.hwaddr = ${hwaddr}
lxc.network.name = eth0
lxc.network.veth.pair = veth.${number}.0
lxc.network.ipv6 = ${ipv6}
lxc.network.ipv6.gateway = fe80::1
lxc.network.type = veth
lxc.network.link = br1
lxc.network.flags = up
lxc.network.hwaddr = 52:54:00:00:${number}:02
lxc.network.name = eth1
lxc.network.veth.pair = veth.${number}.1
lxc.network.ipv4 = 10.0.1.${number}/24
lxc.network.ipv4.gateway = 10.0.1.1
lxc.start.auto=1
lxc.cgroup.memory.limit_in_bytes = 1536M
lxc.cgroup.memory.memsw.limit_in_bytes = 2G
#lxc.mount.entry=/pathk path/in/container none bind,ro 0 0
EOF
# Inner etwork settings
cat > /var/lib/lxc/${name}/rootfs/etc/network/interfaces << EOF
auto eth0
iface eth0 inet6 manual
auto eth1
iface eth1 inet manual
EOF
cat > /var/lib/lxc/${name}/rootfs/etc/resolv.conf << EOF
nameserver 2a01:4f8:0:a0a1::add:1010
nameserver 2a01:4f8:0:a102::add:9999
nameserver 2001:470:20::2
nameserver 213.73.91.35
nameserver 213.133.98.98
nameserver 5.9.49.12
EOF
# SSMPT Settings
#cat > /var/lib/lxc/${name}/rootfs/etc/ssmtp/ssmtp.conf << EOF
#root=test@mein.com
#mailhub=smtp.mein.com:587
#rewriteDomain=mein.com
#hostname=${name}
#FromLineOverride=YES
#UseTLS=YES
#UseSTARTTLS=Yes
#AuthUser=test@mein.com
#AutPass=
#FromLineOverride=yes
#
#EOF