create-lx-container.sh: among other things, fix support for ubuntu distribution.

This commit is contained in:
Christoph 2025-01-21 12:36:58 +01:00
parent 6bb73a755d
commit 0fb729fa2f

View File

@ -311,6 +311,10 @@ echo ""
echo " # Insert the Code name of the Linux Distribution."
echo " #"
echo " # Type <return> to accept the default '$DEFAULT_CODENAME'."
echo " #"
echo " # In case of Ubuntu type in the Short Code Name:"
echo " # Noble Numbat -> Noble"
echo " #"
echo ""
echononl "\033[1mCode name [${DEFAULT_CODENAME}]:\033[m "
read LXC_RELEASE
@ -549,50 +553,6 @@ if ! $NETWORK_CONFIGURATION_DHCP ; then
IPV6_PREFIX_2=$DEFAULT_IPV6_PREFIX
fi
else # if [[ "$LXC_DIST" = "debian" ]]; then
echo ""
echo -e "\033[32m--\033[m"
echo ""
echo " # Insert Nameserver for the first IPv4 Address."
echo " #"
echo " # Type <return> to accept the default one"
echo ""
echononl "\033[1mNameserver (IPv4 Address) [$DEFAULT_IPV4_NAME_SERVER_1]:\033[m "
read IPV4_NAME_SERVER_1
while ! $(is_valid_ipv4 $IPV4_NAME_SERVER_1) ; do
if [[ -z "$(trim $IPV4_NAME_SERVER_1)" ]]; then
IPV4_NAME_SERVER_1="$DEFAULT_IPV4_NAME_SERVER_1"
break
else
warn "'$IPV4_NAME_SERVER_1' is not a valid IPv4 address. Try again.."
fi
echononl "\033[1mNameserver (IPv4 Address) [$DEFAULT_IPV4_NAME_SERVER_1]:\033[m "
read IPV4_NAME_SERVER_1
done
echo ""
echo -e "\033[32m--\033[m"
echo ""
echo " # Insert Search Domain for the new LX Containers."
echo " #"
echo -e " # Type \033[33mNone\033[m if no search domain should be assigned"
echo " #"
echo ""
echononl "\033[1mSearch Domain:\033[m "
read SEARCH_DOMAIN
while [[ -z "$(trim $SEARCH_DOMAIN)" ]]; do
warn "Parameter is needed. Try again.."
echononl "\033[1mSEARCH_DOMAIN:\033[m "
read SEARCH_DOMAIN
done
if [[ "${SEARCH_DOMAIN,,}" = 'none' ]] ; then
IPV6_ADDRESS_1=""
fi
fi # if [[ "$LXC_DIST" = "debian" ]]; then
echo ""
@ -633,6 +593,58 @@ if ! $NETWORK_CONFIGURATION_DHCP ; then
done
fi
echo ""
echo -e "\033[32m--\033[m"
echo ""
echo " # Insert (list of) Nameserver(s)."
echo " #"
echo " # Note:"
echo " # if the LX container supports IPv6 Adresses also IPv6 nameserver(s) are possible."
echo " #"
echo " #"
echo " # Example:"
echo " # 185.12.64.1 2a01:4ff:ff00::add:2 185.12.64.2 2a01:4ff:ff00::add:1"
echo " #"
echo " # Give a blank separated list of ip addresses"
echo " #"
echo " #"
echo " #"
echo " # Type <return> to accept the default one"
echo ""
echononl "\033[1mNameserver (IPv4 Address) [$DEFAULT_IPV4_NAME_SERVER_1]:\033[m "
read NAME_SERVER_IPS
if [[ -z "$(trim $NAME_SERVER_IPS)" ]]; then
NAME_SERVER_IPS="$DEFAULT_IPV4_NAME_SERVER_1"
fi
declare -a nameserver_ip_arr=()
for _ip in ${NAME_SERVER_IPS} ; do
nameserver_ip_arr+=("$_ip")
done
echo ""
echo -e "\033[32m--\033[m"
echo ""
echo " # Insert Search Domain for the new LX Containers."
echo " #"
echo -e " # Type \033[33mNone\033[m if no search domain should be assigned"
echo " #"
echo ""
echononl "\033[1mSearch Domain:\033[m "
read SEARCH_DOMAIN
while [[ -z "$(trim $SEARCH_DOMAIN)" ]]; do
warn "Parameter is needed. Try again.."
echononl "\033[1mSEARCH_DOMAIN:\033[m "
read SEARCH_DOMAIN
done
if [[ "${SEARCH_DOMAIN,,}" = 'none' ]] ; then
SEARCH_DOMAIN=""
fi
fi # if ! $NETWORK_CONFIGURATION_DHCP ; then
@ -681,8 +693,20 @@ if $NETWORK_CONFIGURATION_DHCP ; then
echo -e " Network Configuration....................: \033[33mvia DHCP\033[m"
else
echo " IPv4 Address (first).....................: $IPV4_ADDRESS_1"
echo " IPv4 Gateway Address (first).............: $IPV4_GATEWAY_1"
echo " Netmask first IPv4 Address...............: $IPV4_NETMASK_1"
echo " IPv4 Gateway Address (first).............: $IPV4_GATEWAY_1"
declare -i _index=0
for _ip in "${nameserver_ip_arr[@]}" ; do
if [[ ${_index} -lt 1 ]] ; then
echo " Nameserver(s)............................: ${_ip}"
else
echo " ${_ip}"
fi
(( _index++ ))
done
if [[ -n "${SEARCH_DOMAIN}" ]] ; then
echo " Search Domain............................: ${SEARCH_DOMAIN}"
fi
echo " CIDR (IPv4 Prefix) of netmask............: $IPV4_PREFIX_1"
echo ""
if [[ -n "$IPV6_ADDRESS_1" ]] ; then
@ -830,8 +854,10 @@ length_msg=${#msg}
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
if [[ "$LXC_DIST" = "ubuntu" ]] ; then
lxc-create -n $LXC_NAME -t download -P "$(dirname "$LXC_CONTAINER_DIR")" -- \
--no-validate -d $LXC_DIST --release $LXC_RELEASE --arch amd64 > /dev/null 2> $err_msg
-d $LXC_DIST --release $LXC_RELEASE --arch amd64 > /dev/null 2> $err_msg
elif [[ "$LXC_DIST" = "debian" ]]; then
lxc-create -n $LXC_NAME -t $LXC_DIST -P "$(dirname "$LXC_CONTAINER_DIR")" -- \
--release $LXC_RELEASE --arch amd64 > /dev/null 2> $err_msg
@ -1322,29 +1348,73 @@ EOF
fi
else # if [[ "$LXC_DIST" = "debian" ]];
msg="Adjust Container configuration file '${LXC_CONTAINER_DIR}/config' .."
# - Create the Container configuration file
# -
msg="Create Container Configuration '${LXC_CONTAINER_DIR}/config (LXC Version $LXC_VERSION)' .."
echo -en "\033[1G \033[1;30m[ \033[5m\033[1m...\033[m ] \033[32m$msg\033[m"
length_msg=${#msg}
_failed=false
echo -en "\033[1G \033[1;30m[ \033[5m\033[1m...\033[m ] \033[32m$msg\033[m"
sed -i '/\s*lxc.net.0.type\s*=/d' ${LXC_CONTAINER_DIR}/config > /dev/null 2>$err_msg
if [[ $? -ne 0 ]]; then
_failed=true
fi
cat << EOF > ${LXC_CONTAINER_DIR}/config 2> $err_msg
# Template used to create this container: /usr/share/lxc/templates/lxc-download
# Parameters passed to the template: -d ubuntu --release noble --arch amd64
# For additional config options, please look at lxc.container.conf(5)
# Uncomment the following line to support nesting containers:
#lxc.include = /usr/share/lxc/config/nesting.conf
# (Be aware this has security implications)
# Distribution configuration
lxc.include = /usr/share/lxc/config/common.conf
#lxc.include = /usr/share/lxc/config/${LXC_DIST}.common.conf
lxc.arch = linux64
# Container specific configuration
#lxc.apparmor.profile = generated
#lxc.apparmor.allow_nesting = 1
lxc.rootfs.path = dir:${LXC_CONTAINER_DIR}/rootfs
lxc.uts.name = $LXC_NAME
#lxc.mount.fstab = ${LXC_CONTAINER_DIR}/fstab
# Network configuration
cat <<EOF >> ${LXC_CONTAINER_DIR}/config 2>>$err_msg
### Device 1
lxc.net.0.type = veth
lxc.net.0.flags = up
lxc.net.0.link = br0
lxc.net.0.name = eth0
lxc.net.0.hwaddr = $MAC_ADDRESS_1
# IPv4
lxc.net.0.ipv4.address = ${IPV4_ADDRESS_1}/$IPV4_PREFIX_1
lxc.net.0.ipv4.gateway = ${IPV4_GATEWAY_1}
# IPv6
EOF
if [[ $? -ne 0 ]]; then
_failed=true
fi
if [[ -n "${IPV6_ADDRESS_1}" ]] ; then
cat << EOF >> ${LXC_CONTAINER_DIR}/config 2>> $err_msg
lxc.net.0.ipv6.address = ${IPV6_ADDRESS_1}/$IPV6_PREFIX_1
lxc.net.0.ipv6.gateway = $IPV6_GATEWAY_1
EOF
else
cat << EOF >> ${LXC_CONTAINER_DIR}/config 2>> $err_msg
#lxc.net.0.ipv6.address = ${IPV6_ADDRESS_1}/$IPV6_PREFIX_1
#lxc.net.0.ipv6.gateway = $IPV6_GATEWAY_1
EOF
fi
if [[ $? -ne 0 ]]; then
_failed=true
fi
if [[ -n "$IPV4_ADDRESS_2" ]]; then
cat << EOF >> ${LXC_CONTAINER_DIR}/config 2>> $err_msg
@ -1354,44 +1424,36 @@ lxc.net.1.flags = up
lxc.net.1.link = br0
lxc.net.1.name = eth1
lxc.net.1.hwaddr = $MAC_ADDRESS_2
# IPv4
lxc.net.1.ipv4.address = ${IPV4_ADDRESS_2}/$IPV4_PREFIX_2
lxc.net.1.ipv4.gateway = ${IPV4_GATEWAY_2}
# IPv6
EOF
if [[ $? -ne 0 ]]; then
_failed=true
fi
fi
if [[ $LXC_MAJOR_VERSION -lt 3 ]]; then
if [[ -n "${IPV6_ADDRESS_2}" ]] ; then
cat << EOF >> ${LXC_CONTAINER_DIR}/config 2>> $err_msg
# Mount iso file inside LX Container
#lxc.aa_profile = unconfined
#lxc.cgroup.devices.allow = b 7:* rwm
#lxc.cgroup.devices.allow = c 10:237 rwm
# Autostart
lxc.start.auto = 1
lxc.start.delay = 5
lxc.start.order = 100
# Limt memory to 1GB less than full Memory of the server
# -
lxc.cgroup.memory.limit_in_bytes = $(( $(free -b | grep -oP '\d+' | head -n 1)-1000000000 ))
# Exposing a directory on the host machine to an LXC container
#
# - lxc.mount.entry = /path/to/folder/on/host /path/to/mount/point none bind 0 0
#
#lxc.mount.entry = /path/to/folder/on/host /path/to/mount/point none bind 0 0
lxc.net.0.ipv6.address = ${IPV6_ADDRESS_2}/$IPV6_PREFIX_2
lxc.net.0.ipv6.gateway = $IPV6_GATEWAY_2
EOF
if [[ $? -ne 0 ]]; then
_failed=true
fi
else
cat << EOF >> ${LXC_CONTAINER_DIR}/config 2>> $err_msg
#lxc.net.0.ipv6.address =
#lxc.net.0.ipv6.gateway =
EOF
fi
if [[ $? -ne 0 ]]; then
_failed=true
fi
cat << EOF >> ${LXC_CONTAINER_DIR}/config 2>> $err_msg
# Mount iso file inside LX Container
#lxc.apparmor.profile = unconfined
@ -1441,7 +1503,7 @@ EOF
# lxc.apparmor.profile = generated
# lxc.apparmor.allow_nesting = 1
#
#lxc.apparmor.profile = unconfined
lxc.apparmor.profile = unconfined
# support fuse (filesystem in userspace)
@ -1468,9 +1530,8 @@ lxc.cgroup.memory.limit_in_bytes = $(( $(free -b | grep -oP '\d+' | head -n 1)-1
#
#lxc.mount.entry = /path/to/folder/on/host /path/to/mount/point none bind 0 0
EOF
if [[ $? -ne 0 ]]; then
_failed=true
fi
if [[ $? -ne 0 ]]; then
_failed=true
fi
if $_failed ; then
@ -1523,7 +1584,7 @@ if [[ "$LXC_DIST" = "debian" ]]; then
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
cp ${LXC_CONTAINER_DIR}/rootfs/etc/network/interfaces \
${LXC_CONTAINER_DIR}/rootfs/etc/network/interfaces.ORIG
${LXC_CONTAINER_DIR}/rootfs/etc/network/interfaces.ORIG 2> ${err_msg}
if [[ $? -eq 0 ]] ; then
msg_ok="File '${LXC_CONTAINER_DIR}/rootfs/etc/network/interfaces.ORIG' saved."
@ -1646,44 +1707,207 @@ EOF
echo -e "\033[1G [ \033[32m\033[1mok\033[m ] ${msg_ok}${blank_signs}"
fi
elif [[ "$LXC_DIST" = "ubuntu" ]]; then
msg="Backup file '${LXC_CONTAINER_DIR}/rootfs/etc/netplan/10-lxc.yaml"
# - Backup Containers file '/etc/resolv.conf'
# -
echo ""
msg="Backup file '${LXC_CONTAINER_DIR}/rootfs/etc/resolv.conf' .."
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
cp ${LXC_CONTAINER_DIR}/rootfs/etc/netplan/10-lxc.yaml \
${LXC_CONTAINER_DIR}/rootfs/etc/netplan/10-lxc.yaml.ORIG
if [[ -f "${LXC_CONTAINER_DIR}/rootfs/etc/resolv.conf" ]] ; then
if [[ $? -eq 0 ]] ; then
msg_ok="File '${LXC_CONTAINER_DIR}/rootfs/etc/netplan/10-lxc.yaml.ORIG' saved."
length_msg_ok=${#msg_ok}
blank_signs=""
if [[ $length_msg -gt $length_msg_ok ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_ok)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
cp "${LXC_CONTAINER_DIR}/rootfs/etc/resolv.conf" \
"${LXC_CONTAINER_DIR}/rootfs/etc/resolv.conf.ORIG" > $err_msg 2>&1
if [[ $? -eq 0 ]] ; then
msg_ok="File '${LXC_CONTAINER_DIR}/rootfs/etc/resolv.conf.ORIG' saved."
length_msg_ok=${#msg_ok}
blank_signs=""
if [[ $length_msg -gt $length_msg_ok ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_ok)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
done
fi
echo -e "\033[1G [ \033[32m\033[1mok\033[m ] ${msg_ok}${blank_signs}"
# - Create new containers file '/etc/resolv.conf'
# -
_failed=false
msg="Create a new file '${LXC_CONTAINER_DIR}/rootfs/etc/resolv.conf' .."
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
: > "${LXC_CONTAINER_DIR}/rootfs/etc/resolv.conf"
for _ip in "${nameserver_ip_arr[@]}" ; do
echo "nameserver ${_ip}" >> "${LXC_CONTAINER_DIR}/rootfs/etc/resolv.conf"
if [[ $? -ne 0 ]]; then
_failed=true
fi
done
if [[ -n "${SEARCH_DOMAIN}" ]] ; then
echo "search ${SEARCH_DOMAIN}" >> "${LXC_CONTAINER_DIR}/rootfs/etc/resolv.conf"
if [[ $? -ne 0 ]]; then
_failed=true
fi
fi
if ${_failed} ; then
msg_failed="Failed to create file '${LXC_CONTAINER_DIR}/rootfs/etc/resolv.conf'!"
length_msg_failed=${#msg_failed}
blank_signs=""
if [[ $length_msg -gt $length_msg_failed ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_failed)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
done
fi
echo -e "\033[1G [ \033[31m\033[1mfailed\033[m ] ${msg_failed}${blank_signs}"
error "$(cat $err_msg)"
else
msg_ok="New file '${LXC_CONTAINER_DIR}/rootfs/etc/resolv.conf' created."
length_msg_ok=${#msg_ok}
blank_signs=""
if [[ $length_msg -gt $length_msg_ok ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_ok)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
done
fi
echo -e "\033[1G [ \033[32m\033[1mok\033[m ] ${msg_ok}${blank_signs}"
fi
else
msg_failed="Could not backup file '${LXC_CONTAINER_DIR}/rootfs/etc/resolv.conf'!"
length_msg_failed=${#msg_failed}
blank_signs=""
if [[ $length_msg -gt $length_msg_failed ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_failed)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
done
fi
echo -e "\033[1G [ \033[31m\033[1mfailed\033[m ] ${msg_failed}${blank_signs}"
error "$(cat $err_msg)"
fi
echo -e "\033[1G [ \033[32m\033[1mok\033[m ] ${msg_ok}${blank_signs}"
else
msg_failed="Could not backup file '${LXC_CONTAINER_DIR}/rootfs/etc/netplan/10-lxc.yaml'!"
length_msg_failed=${#msg_failed}
msg_skipped="File '${LXC_CONTAINER_DIR}/rootfs/etc/resolv.conf not present."
length_msg_skipped=${#msg_skipped}
blank_signs=""
if [[ $length_msg -gt $length_msg_failed ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_failed)
if [[ $length_msg -gt $length_msg_skipped ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_skipped)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
done
fi
echo -e "\033[1G [ \033[31m\033[1mfailed\033[m ] ${msg_failed}${blank_signs}"
error "$(cat $err_msg)"
echo -e "\033[1G [ \033[30m\033[1mskip\033[m ] ${msg_skipped}${blank_signs}"
fi
elif [[ "$LXC_DIST" = "ubuntu" ]]; then
if [[ -f "${LXC_CONTAINER_DIR}/rootfs/etc/netplan/10-lxc.yaml" ]] ; then
msg="Backup file '${LXC_CONTAINER_DIR}/rootfs/etc/netplan/10-lxc.yaml"
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
cp ${LXC_CONTAINER_DIR}/rootfs/etc/netplan/10-lxc.yaml \
${LXC_CONTAINER_DIR}/rootfs/etc/netplan/10-lxc.yaml.ORIG 2> ${err_msg}
if [[ $? -eq 0 ]] ; then
msg_ok="File '${LXC_CONTAINER_DIR}/rootfs/etc/netplan/10-lxc.yaml.ORIG' saved."
length_msg_ok=${#msg_ok}
blank_signs=""
if [[ $length_msg -gt $length_msg_ok ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_ok)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
done
fi
echo -e "\033[1G [ \033[32m\033[1mok\033[m ] ${msg_ok}${blank_signs}"
else
msg_failed="Could not backup file '${LXC_CONTAINER_DIR}/rootfs/etc/netplan/10-lxc.yaml'!"
length_msg_failed=${#msg_failed}
blank_signs=""
if [[ $length_msg -gt $length_msg_failed ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_failed)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
done
fi
echo -e "\033[1G [ \033[31m\033[1mfailed\033[m ] ${msg_failed}${blank_signs}"
error "$(cat $err_msg)"
fi
elif [ -e /etc/netplan/*.yaml ] ; then
for _file in $(ls ${LXC_CONTAINER_DIR}/root/netplan/*.yml) ; do
msg="Backup file '${_file}'"
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
mv "${_file}" "${_file}.ORIG" 2> ${err_msg}
if [[ $? -eq 0 ]] ; then
msg_ok="File '${_file}.ORIG' saved."
length_msg_ok=${#msg_ok}
blank_signs=""
if [[ $length_msg -gt $length_msg_ok ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_ok)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
done
fi
echo -e "\033[1G [ \033[32m\033[1mok\033[m ] ${msg_ok}${blank_signs}"
else
msg_failed="Could not backup file '${_file}'!"
length_msg_failed=${#msg_failed}
blank_signs=""
if [[ $length_msg -gt $length_msg_failed ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_failed)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
done
fi
echo -e "\033[1G [ \033[31m\033[1mfailed\033[m ] ${msg_failed}${blank_signs}"
error "$(cat $err_msg)"
fi
done
fi
# - Create Containers network configuration
# -
msg="Create a new file '${LXC_CONTAINER_DIR}/rootfs/etc/netplan/10-lxc.yaml' .."
@ -1700,10 +1924,33 @@ network:
dhcp4: true
dhcp-identifier: mac
EOF
if [[ $? -ne 0 ]]; then
_failed=true
fi
else
cat << EOF > ${LXC_CONTAINER_DIR}/rootfs/etc/netplan/10-lxc.yaml
if [[ -n ${IPV6_ADDRESS_1} ]] ; then
cat << EOF > ${LXC_CONTAINER_DIR}/rootfs/etc/netplan/10-lxc.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
dhcp6: no
addresses:
- ${IPV4_ADDRESS_1}/${IPV4_PREFIX_1}
- ${IPV6_ADDRESS_1}/${IPV6_PREFIX_1}
gateway4: ${IPV4_GATEWAY_1}
gateway6: ${IPV6_GATEWAY_1}
EOF
if [[ $? -ne 0 ]]; then
_failed=true
fi
else
cat << EOF > ${LXC_CONTAINER_DIR}/rootfs/etc/netplan/10-lxc.yaml
network:
version: 2
renderer: networkd
@ -1711,22 +1958,45 @@ network:
eth0:
dhcp4: no
addresses:
- ${IPV4_ADDRESS_1}/24
- ${IPV4_ADDRESS_1}/${IPV4_PREFIX_1}
gateway4: ${IPV4_GATEWAY_1}
EOF
if [[ $? -ne 0 ]]; then
_failed=true
fi
fi
if [[ ${#nameserver_ip_arr[@]} -gt 0 ]] ; then
cat << EOF >> ${LXC_CONTAINER_DIR}/rootfs/etc/netplan/10-lxc.yaml
nameservers:
addresses:
- ${IPV4_NAME_SERVER_1}
search:
- ${SEARCH_DOMAIN}
EOF
for _nameserver in ${nameserver_ip_arr[@]} ; do
cat << EOF >> ${LXC_CONTAINER_DIR}/rootfs/etc/netplan/10-lxc.yaml
- ${_nameserver}
EOF
if [[ $? -ne 0 ]]; then
_failed=true
fi
done
fi
if [[ ${#search_ip_arr[@]} -gt 0 ]] ; then
cat << EOF >> ${LXC_CONTAINER_DIR}/rootfs/etc/netplan/10-lxc.yaml
search:
EOF
for _search_domain in ${search_ip_arr[@]} ; do
cat << EOF >> ${LXC_CONTAINER_DIR}/rootfs/etc/netplan/10-lxc.yaml
- ${SEARCH_DOMAIN}
EOF
if [[ $? -ne 0 ]]; then
_failed=true
fi
done
fi
fi # if $NETWORK_CONFIGURATION_DHCP
if [[ $? -ne 0 ]]; then
_failed=true
fi
if $_failed ; then
msg_failed="Failed to create file '${LXC_CONTAINER_DIR}/rootfs/etc/netplan/10-lxc.yaml'!"
length_msg_failed=${#msg_failed}
@ -1851,12 +2121,11 @@ else
cat << EOF > ${LXC_CONTAINER_DIR}/rootfs/etc/apt/sources.list 2>> $err_msg
# Generated by distrobuilder
deb http://archive.ubuntu.com/ubuntu $LXC_RELEASE main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu $LXC_RELEASE-updates main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu $LXC_RELEASE-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu ${LXC_RELEASE} main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu ${LXC_RELEASE}-updates main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu ${LXC_RELEASE}-security main restricted universe multiverse
deb http://de.archive.ubuntu.com/ubuntu/ $LXC_RELEASE-backports main restricted universe multiverse
deb http://archive.canonical.com/ubuntu $LXC_RELEASE partner
deb http://archive.ubuntu.com/ubuntu ${LXC_RELEASE}-backports main restricted universe multiverse
EOF
@ -2081,7 +2350,7 @@ else
fi
if [[ "$LXC_DIST" = "debian" ]]; then
if [[ "$LXC_DIST" = "debian" ]] || [[ "${LXC_DIST}" = "ubuntu" ]] ; then
# - Install 'figlet' from debian package system
# -
@ -2131,128 +2400,12 @@ if [[ "$LXC_DIST" = "debian" ]]; then
msg="Backup file '${LXC_CONTAINER_DIR}/rootfs/etc/motd' .."
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
mv "${LXC_CONTAINER_DIR}/rootfs/etc/motd" "${LXC_CONTAINER_DIR}/rootfs/etc/motd.ORIG" > $err_msg 2>&1
if [[ -f "${LXC_CONTAINER_DIR}/rootfs/etc/motd" ]] ; then
if [[ $? -eq 0 ]] ; then
msg_ok="File '${LXC_CONTAINER_DIR}/rootfs/etc/motd.ORIG' saved."
length_msg_ok=${#msg_ok}
blank_signs=""
if [[ $length_msg -gt $length_msg_ok ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_ok)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
done
fi
echo -e "\033[1G [ \033[32m\033[1mok\033[m ] ${msg_ok}${blank_signs}"
else
msg_failed="Could not backup file '${LXC_CONTAINER_DIR}/rootfs/etc/motd'!"
length_msg_failed=${#msg_failed}
blank_signs=""
if [[ $length_msg -gt $length_msg_failed ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_failed)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
done
fi
echo -e "\033[1G [ \033[31m\033[1mfailed\033[m ] ${msg_failed}${blank_signs}"
error "$(cat $err_msg)"
fi
# - Create new containers file '/etc/motd'
# -
msg="Create a new file '${LXC_CONTAINER_DIR}/rootfs/etc/motd' .."
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
figlet $HOSTNAME > "${LXC_CONTAINER_DIR}/rootfs/etc/motd"
if [[ $? -eq 0 ]] ; then
msg_ok="New file '${LXC_CONTAINER_DIR}/rootfs/etc/motd' created."
length_msg_ok=${#msg_ok}
blank_signs=""
if [[ $length_msg -gt $length_msg_ok ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_ok)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
done
fi
echo -e "\033[1G [ \033[32m\033[1mok\033[m ] ${msg_ok}${blank_signs}"
else
msg_failed="Failed to create file '${LXC_CONTAINER_DIR}/rootfs/etc/motd'!"
length_msg_failed=${#msg_failed}
blank_signs=""
if [[ $length_msg -gt $length_msg_failed ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_failed)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
done
fi
echo -e "\033[1G [ \033[31m\033[1mfailed\033[m ] ${msg_failed}${blank_signs}"
error "$(cat $err_msg)"
fi
fi # if [[ "$LXC_DIST" = "debian" ]]
if [[ "$LXC_DIST" = "debian" ]]; then
# - Backup Containers file '/etc/ssh/sshd_config'
# -
echo ""
msg="Backup file '${LXC_CONTAINER_DIR}/rootfs/etc/ssh/sshd_config' .."
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
mv "${LXC_CONTAINER_DIR}/rootfs/etc/ssh/sshd_config" "${LXC_CONTAINER_DIR}/rootfs/etc/ssh/sshd_config.ORIG" > $err_msg 2>&1
if [[ $? -eq 0 ]] ; then
msg_ok="File '${LXC_CONTAINER_DIR}/rootfs/etc/ssh/sshd_config.ORIG' saved."
length_msg_ok=${#msg_ok}
blank_signs=""
if [[ $length_msg -gt $length_msg_ok ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_ok)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
done
fi
echo -e "\033[1G [ \033[32m\033[1mok\033[m ] ${msg_ok}${blank_signs}"
else
msg_failed="Could not backup file '${LXC_CONTAINER_DIR}/rootfs/etc/ssh/sshd_config'!"
length_msg_failed=${#msg_failed}
blank_signs=""
if [[ $length_msg -gt $length_msg_failed ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_failed)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
done
fi
echo -e "\033[1G [ \033[31m\033[1mfailed\033[m ] ${msg_failed}${blank_signs}"
error "$(cat $err_msg)"
fi
# - Create new containers file '/etc/ssh/sshd_config'
# -
msg="Create a new file '${LXC_CONTAINER_DIR}/rootfs/etc/ssh/sshd_config' .."
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
if [[ -f "${working_dir}/supported-files/sshd_config" ]]; then
cp -a "${working_dir}/supported-files/sshd_config" \
"${LXC_CONTAINER_DIR}/rootfs/etc/ssh/sshd_config" 2>$err_msg
cp "${LXC_CONTAINER_DIR}/rootfs/etc/motd" "${LXC_CONTAINER_DIR}/rootfs/etc/motd.ORIG" > $err_msg 2>&1
if [[ $? -eq 0 ]] ; then
msg_ok="New file '${LXC_CONTAINER_DIR}/rootfs/etc/ssh/sshd_config' created."
msg_ok="File '${LXC_CONTAINER_DIR}/rootfs/etc/motd.ORIG' saved."
length_msg_ok=${#msg_ok}
blank_signs=""
if [[ $length_msg -gt $length_msg_ok ]]; then
@ -2264,8 +2417,47 @@ if [[ "$LXC_DIST" = "debian" ]]; then
done
fi
echo -e "\033[1G [ \033[32m\033[1mok\033[m ] ${msg_ok}${blank_signs}"
# - Create new containers file '/etc/motd'
# -
msg="Create a new file '${LXC_CONTAINER_DIR}/rootfs/etc/motd' .."
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
figlet $HOSTNAME > "${LXC_CONTAINER_DIR}/rootfs/etc/motd"
if [[ $? -eq 0 ]] ; then
msg_ok="New file '${LXC_CONTAINER_DIR}/rootfs/etc/motd' created."
length_msg_ok=${#msg_ok}
blank_signs=""
if [[ $length_msg -gt $length_msg_ok ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_ok)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
done
fi
echo -e "\033[1G [ \033[32m\033[1mok\033[m ] ${msg_ok}${blank_signs}"
else
msg_failed="Failed to create file '${LXC_CONTAINER_DIR}/rootfs/etc/motd'!"
length_msg_failed=${#msg_failed}
blank_signs=""
if [[ $length_msg -gt $length_msg_failed ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_failed)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
done
fi
echo -e "\033[1G [ \033[31m\033[1mfailed\033[m ] ${msg_failed}${blank_signs}"
error "$(cat $err_msg)"
fi
else
msg_failed="Failed to create file '${LXC_CONTAINER_DIR}/rootfs/etc/ssh/sshd_config'!"
msg_failed="Could not backup file '${LXC_CONTAINER_DIR}/rootfs/etc/motd'!"
length_msg_failed=${#msg_failed}
blank_signs=""
if [[ $length_msg -gt $length_msg_failed ]]; then
@ -2279,10 +2471,131 @@ if [[ "$LXC_DIST" = "debian" ]]; then
echo -e "\033[1G [ \033[31m\033[1mfailed\033[m ] ${msg_failed}${blank_signs}"
error "$(cat $err_msg)"
fi
else
echo -e "\033[1G [ \033[30m\033[1mskip\033[m ] $msg"
msg_skipped="File '${LXC_CONTAINER_DIR}/rootfs/etc/motd not present."
length_msg_skipped=${#msg_skipped}
blank_signs=""
if [[ $length_msg -gt $length_msg_skipped ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_skipped)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
done
fi
echo -e "\033[1G [ \033[30m\033[1mskip\033[m ] ${msg_skipped}${blank_signs}"
fi
fi # if [[ "$LXC_DIST" = "debian" ]]
if [[ "$LXC_DIST" = "debian" ]] || [[ "${LXC_DIST}" = "ubuntu" ]]; then
# - Backup Containers file '/etc/ssh/sshd_config'
# -
echo ""
msg="Backup file '${LXC_CONTAINER_DIR}/rootfs/etc/ssh/sshd_config' .."
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
if [[ -f "${LXC_CONTAINER_DIR}/rootfs/etc/sshd_config" ]] ; then
cp "${LXC_CONTAINER_DIR}/rootfs/etc/ssh/sshd_config" \
"${LXC_CONTAINER_DIR}/rootfs/etc/ssh/sshd_config.ORIG" > $err_msg 2>&1
if [[ $? -eq 0 ]] ; then
msg_ok="File '${LXC_CONTAINER_DIR}/rootfs/etc/ssh/sshd_config.ORIG' saved."
length_msg_ok=${#msg_ok}
blank_signs=""
if [[ $length_msg -gt $length_msg_ok ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_ok)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
done
fi
echo -e "\033[1G [ \033[32m\033[1mok\033[m ] ${msg_ok}${blank_signs}"
# - Create new containers file '/etc/ssh/sshd_config'
# -
msg="Create a new file '${LXC_CONTAINER_DIR}/rootfs/etc/ssh/sshd_config' .."
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
if [[ -f "${working_dir}/supported-files/sshd_config" ]]; then
cp -a "${working_dir}/supported-files/sshd_config" \
"${LXC_CONTAINER_DIR}/rootfs/etc/ssh/sshd_config" 2>$err_msg
if [[ $? -eq 0 ]] ; then
msg_ok="New file '${LXC_CONTAINER_DIR}/rootfs/etc/ssh/sshd_config' created."
length_msg_ok=${#msg_ok}
blank_signs=""
if [[ $length_msg -gt $length_msg_ok ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_ok)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
done
fi
echo -e "\033[1G [ \033[32m\033[1mok\033[m ] ${msg_ok}${blank_signs}"
else
msg_failed="Failed to create file '${LXC_CONTAINER_DIR}/rootfs/etc/ssh/sshd_config'!"
length_msg_failed=${#msg_failed}
blank_signs=""
if [[ $length_msg -gt $length_msg_failed ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_failed)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
done
fi
echo -e "\033[1G [ \033[31m\033[1mfailed\033[m ] ${msg_failed}${blank_signs}"
error "$(cat $err_msg)"
fi
else
echo -e "\033[1G [ \033[30m\033[1mskip\033[m ] $msg"
fi
else
msg_failed="Could not backup file '${LXC_CONTAINER_DIR}/rootfs/etc/ssh/sshd_config'!"
length_msg_failed=${#msg_failed}
blank_signs=""
if [[ $length_msg -gt $length_msg_failed ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_failed)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
done
fi
echo -e "\033[1G [ \033[31m\033[1mfailed\033[m ] ${msg_failed}${blank_signs}"
error "$(cat $err_msg)"
fi
else
msg_skipped="File '${LXC_CONTAINER_DIR}/rootfs/etc/ssh/sshd_config not present."
length_msg_skipped=${#msg_skipped}
blank_signs=""
if [[ $length_msg -gt $length_msg_skipped ]]; then
number_blank_sign=$(expr $length_msg - $length_msg_skipped)
index_i=0
while [[ $index_i -lt $number_blank_sign ]] ; do
blank_signs="$blank_signs "
(( index_i++ ))
done
fi
echo -e "\033[1G [ \033[30m\033[1mskip\033[m ] ${msg_skipped}${blank_signs}"
fi
fi # if [[ "$LXC_DIST" = "debian" ]]
@ -2811,6 +3124,7 @@ if [[ "$LXC_DIST" = "ubuntu" ]]; then
fi
info " Inside the new Contaimer, run the following commands to create/adjust users:
\033[1madd_new_user.sh root
apt update
apt install sudo vim git mc
add_new_user.sh chris
add_new_user.sh sysadm