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.
69 lines
1.7 KiB
Bash
69 lines
1.7 KiB
Bash
#!/bin/bash
|
|
#Inputs
|
|
name=${1}
|
|
number=${2}
|
|
packages="bash-completion,htop,net-tools,ssmtp"
|
|
if [ ${3} ]; then
|
|
packages="${packages},${3}"
|
|
fi
|
|
enable=""
|
|
if [ ${4} ]; then
|
|
enable="-e ${4}"
|
|
fi
|
|
#Variables
|
|
hwaddr = "52:54:00:00:${number}:01"
|
|
ipv6 = "2a01:4f8:151:13cd::${number}/64"
|
|
|
|
# Create lxc Container
|
|
lxc-create -t archlinux -n ${name} -B overlayfs -- -P ${packages} ${enable}
|
|
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/archlinux.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 = 2G
|
|
lxc.cgroup.memory.memsw.limit_in_bytes = 4G
|
|
|
|
#lxc.mount.entry=/pathk path/in/container none bind,ro 0 0
|
|
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
|