2313 lines
68 KiB
Bash
Executable File
2313 lines
68 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
|
|
working_dir="$(dirname $(realpath $0))"
|
|
conf_file="${working_dir}/conf/create-lx-container.conf"
|
|
|
|
LOCK_DIR="/tmp/create-lx-container.LOCK"
|
|
err_msg="$LOCK_DIR/error.log"
|
|
|
|
|
|
# -------------
|
|
# - Some functions
|
|
# -------------
|
|
|
|
clean_up() {
|
|
|
|
# Perform program exit housekeeping
|
|
rm -rf "$LOCK_DIR"
|
|
exit $1
|
|
}
|
|
|
|
echononl(){
|
|
if $terminal ; then
|
|
echo X\\c > /tmp/shprompt$$
|
|
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
|
|
echo -e -n "$*\\c" 1>&2
|
|
else
|
|
echo -e -n "$*" 1>&2
|
|
fi
|
|
rm /tmp/shprompt$$
|
|
fi
|
|
}
|
|
|
|
fatal(){
|
|
echo ""
|
|
if $terminal ; then
|
|
echo -e " [ \033[31m\033[1mFatal\033[m ]: $*"
|
|
echo ""
|
|
echo -e " \033[31m\033[1mScript was terminated\033[m!"
|
|
else
|
|
echo " [ Fatal ]: $*"
|
|
echo ""
|
|
echo " Script was terminated...."
|
|
fi
|
|
echo ""
|
|
clean_up 1
|
|
}
|
|
|
|
error (){
|
|
echo ""
|
|
if $terminal ; then
|
|
echo -e " [ \033[31m\033[1mError\033[m ]: $*"
|
|
else
|
|
echo "[ Error ]: $*"
|
|
fi
|
|
echo ""
|
|
}
|
|
|
|
warn (){
|
|
echo ""
|
|
if $terminal ; then
|
|
echo -e " [ \033[33m\033[1mWarning\033[m ]: $*"
|
|
else
|
|
echo "[ Warning ]: $*"
|
|
fi
|
|
echo ""
|
|
}
|
|
info (){
|
|
|
|
if $terminal ; then
|
|
echo ""
|
|
echo -e " [ \033[32m\033[1mInfo\033[m ]: $*"
|
|
echo ""
|
|
fi
|
|
}
|
|
|
|
echo_done() {
|
|
if $terminal ; then
|
|
echo -e "\033[75G[ \033[32mdone\033[m ]"
|
|
fi
|
|
}
|
|
echo_failed(){
|
|
if $terminal && $LOGGING ; then
|
|
echo -e "\033[75G[ \033[1;31mfailed\033[m ]"
|
|
fi
|
|
}
|
|
echo_skipped() {
|
|
if $terminal && $LOGGING ; then
|
|
echo -e "\033[75G[ \033[33m\033[1mskipped\033[m ]"
|
|
fi
|
|
}
|
|
|
|
trim() {
|
|
local var="$*"
|
|
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
|
|
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters
|
|
echo -n "$var"
|
|
}
|
|
is_valid_ipv4() {
|
|
local -a octets=( ${1//\./ } )
|
|
local RETURNVALUE=0
|
|
|
|
# return an error if the IP doesn't have exactly 4 octets
|
|
[[ ${#octets[@]} -ne 4 ]] && return 1
|
|
|
|
for octet in ${octets[@]}
|
|
do
|
|
if [[ ${octet} =~ ^[0-9]{1,3}$ ]]
|
|
then # shift number by 8 bits, anything larger than 255 will be > 0
|
|
((RETURNVALUE += octet>>8 ))
|
|
else # octet wasn't numeric, return error
|
|
return 1
|
|
fi
|
|
done
|
|
return ${RETURNVALUE}
|
|
}
|
|
is_valid_mac_address() {
|
|
[[ "$1" =~ ^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$ ]] && return 0 || return 1
|
|
}
|
|
netmask2cidr() {
|
|
case $1 in
|
|
0x*)
|
|
local hex=${1#0x*} quad=
|
|
while [ -n "${hex}" ]; do
|
|
local lastbut2=${hex#??*}
|
|
quad=${quad}${quad:+.}0x${hex%${lastbut2}*}
|
|
hex=${lastbut2}
|
|
done
|
|
set -- ${quad}
|
|
;;
|
|
esac
|
|
|
|
local i= len=
|
|
local IFS=.
|
|
for i in $1; do
|
|
while [ ${i} != "0" ]; do
|
|
len=$((${len} + ${i} % 2))
|
|
i=$((${i} >> 1))
|
|
done
|
|
done
|
|
|
|
echo "${len}"
|
|
}
|
|
|
|
detect_os_1 () {
|
|
|
|
if $(which lsb_release > /dev/null 2>&1) ; then
|
|
|
|
os_dist="$(lsb_release -i | awk '{print tolower($3)}')"
|
|
os_version="$(lsb_release -r | awk '{print tolower($2)}')"
|
|
os_codename="$(lsb_release -c | awk '{print tolower($2)}')"
|
|
|
|
if [[ "$os_dist" = "debian" ]]; then
|
|
if $(echo "$os_version" | grep -q '\.') ; then
|
|
os_version=$(echo "$os_version" | cut --delimiter='.' -f1)
|
|
fi
|
|
fi
|
|
|
|
elif [[ -e "/etc/os-release" ]]; then
|
|
|
|
. /etc/os-release
|
|
|
|
os_dist=$ID
|
|
os_version=${VERSION_ID}
|
|
|
|
fi
|
|
|
|
# remove whitespace from os_dist and os_version
|
|
os_dist="${os_dist// /}"
|
|
os_version="${os_version// /}"
|
|
|
|
}
|
|
|
|
|
|
# -------------
|
|
# - Running in a terminal?
|
|
# -------------
|
|
|
|
if [[ -t 1 ]] ; then
|
|
terminal=true
|
|
else
|
|
terminal=false
|
|
fi
|
|
|
|
|
|
# -------------
|
|
# - Read Configurations from $conf_file
|
|
# -------------
|
|
|
|
DEFAULT_LXC_ROOT_DIR="/var/lib/lxc"
|
|
DEFAULT_LXC_DIST="debian"
|
|
DEFAULT_MAC_ADDRESS_1="$(echo -n 00 ; dd bs=1 count=5 if=/dev/random 2>/dev/null | hexdump -v -e '/1 ":%02X"')"
|
|
|
|
DEFAULT_IPV4_NETMASK_1="255.255.255.0"
|
|
|
|
DEFAULT_IPV6_PREFIX=64
|
|
|
|
DEFAULT_CODENAME="$(lsb_release -c | awk '{print tolower($2)}')"
|
|
|
|
if [[ -f "$conf_file" ]]; then
|
|
source "$conf_file"
|
|
else
|
|
warn "No Configuration file '$(basename ${conf_file})'. Using default values.."
|
|
fi
|
|
|
|
[[ -z "$LXC_ROOT_DIR" ]] || DEFAULT_LXC_ROOT_DIR="$LXC_ROOT_DIR"
|
|
[[ -z "$LXC_DIST" ]] || DEFAULT_LXC_DIST="$LXC_DIST"
|
|
|
|
|
|
|
|
# -------------
|
|
# - Job is already running?
|
|
# -------------
|
|
|
|
# - If job already runs, stop execution..
|
|
# -
|
|
if mkdir "$LOCK_DIR" 2> /dev/null ; then
|
|
|
|
# - Remove lockdir when the script finishes, or when it receives a signal
|
|
# -
|
|
trap clean_up SIGHUP SIGINT SIGTERM
|
|
|
|
else
|
|
|
|
datum="$(date +"%d.%m.%Y %H:%M")"
|
|
|
|
msg=" [ Error ]: A previos instance of '$(basename $0)' seems already be running.\n\n Exiting now.."
|
|
|
|
error "A previos instance of the script '$(basename $0)' seems already be running."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
clear
|
|
|
|
#echo -e " \033[32m---\033[m"
|
|
#echo -e " \033[32m\033[1mInsert parameter for the new LX Container\033[m"
|
|
#echo -e " \033[32m---\033[m"
|
|
#echo
|
|
#
|
|
#echo " # Insert base directory for LX Containers."
|
|
#echo " #"
|
|
#echo " # Type <return> to accept the default '$DEFAULT_LXC_ROOT_DIR'."
|
|
#echo ""
|
|
#echononl "\033[1mRoot directory for LX Containers [$DEFAULT_LXC_ROOT_DIR]:\033[m "
|
|
#read LXC_ROOT_DIR
|
|
#if [[ -z "$(trim $LXC_ROOT_DIR)" ]] ; then
|
|
# LXC_ROOT_DIR="$DEFAULT_LXC_ROOT_DIR"
|
|
#fi
|
|
|
|
# - We won't change the default. Realise different container directories
|
|
# - by using symlinks.
|
|
# -
|
|
LXC_ROOT_DIR="$DEFAULT_LXC_ROOT_DIR"
|
|
|
|
echo ""
|
|
echo -e "\033[32m--\033[m"
|
|
echo ""
|
|
|
|
echo " # Insert the name new LX Containers."
|
|
echo " #"
|
|
echo " # Note: It's NOT the hostname, its only the name of the inew LX Container."
|
|
echo " #"
|
|
echo ""
|
|
echononl "\033[1mName of the Container:\033[m "
|
|
read LXC_NAME
|
|
|
|
while [[ -z "$(trim $LXC_NAME)" ]]; do
|
|
warn "Parameter is needed. Try again.."
|
|
echononl "\033[1mName of the Container:\033[m "
|
|
read LXC_NAME
|
|
done
|
|
|
|
echo ""
|
|
echo -e "\033[32m--\033[m"
|
|
echo ""
|
|
|
|
DEFAULT_LXC_CONTAINER_DIR="${DEFAULT_LXC_ROOT_DIR}/$LXC_NAME"
|
|
|
|
echo -e " # Insert root directory for the new LX Container \033[1m$LXC_NAME\\033[m."
|
|
echo " #"
|
|
echo " # Type <return> to accept the default '$DEFAULT_LXC_CONTAINER_DIR'."
|
|
echo ""
|
|
echononl "\033[1mRoot directory for LX Containers [$DEFAULT_LXC_CONTAINER_DIR]:\033[m "
|
|
read LXC_CONTAINER_DIR
|
|
if [[ -z "$(trim $LXC_CONTAINER_DIR)" ]] ; then
|
|
LXC_CONTAINER_DIR="$DEFAULT_LXC_CONTAINER_DIR"
|
|
fi
|
|
|
|
echo ""
|
|
echo -e "\033[32m--\033[m"
|
|
echo ""
|
|
|
|
echo " # Insert linux distribution for the new LX Containers."
|
|
echo " #"
|
|
echo " # Type <return> to accept the default '$DEFAULT_LXC_DIST'."
|
|
echo ""
|
|
echononl "\033[1mLinux Distribution [$DEFAULT_LXC_DIST]:\033[m "
|
|
read LXC_DIST
|
|
if [[ -z "$(trim $LXC_DIST)" ]] ; then
|
|
LXC_DIST="$DEFAULT_LXC_DIST"
|
|
fi
|
|
|
|
echo ""
|
|
echo -e "\033[32m--\033[m"
|
|
echo ""
|
|
|
|
echo " # Insert the Code name of the Linux Distribution."
|
|
echo " #"
|
|
echo " # Type <return> to accept the default '$DEFAULT_CODENAME'."
|
|
echo ""
|
|
echononl "\033[1mCode name [${DEFAULT_CODENAME}]:\033[m "
|
|
read LXC_RELEASE
|
|
if [[ -z "$(trim $LXC_RELEASE)" ]] ; then
|
|
LXC_RELEASE="$DEFAULT_CODENAME"
|
|
fi
|
|
|
|
#while [[ -z "$(trim $LXC_RELEASE)" ]]; do
|
|
# warn "Parameter is needed. Try again.."
|
|
# echononl "\033[1mCode name:\033[m "
|
|
# read LXC_RELEASE
|
|
#done
|
|
|
|
echo ""
|
|
echo -e "\033[32m--\033[m"
|
|
echo ""
|
|
|
|
echo " # Insert MAC Address for the first network device of the new LX Containers."
|
|
echo " #"
|
|
echo " # Type <return> to accept the randomised created one '$DEFAULT_MAC_ADDRESS_1'."
|
|
echo ""
|
|
echononl "\033[1mMAC Address of the firts network device [$DEFAULT_MAC_ADDRESS_1]:\033[m "
|
|
read MAC_ADDRESS_1
|
|
|
|
while ! $(is_valid_mac_address $MAC_ADDRESS_1) ; do
|
|
if [[ -z "$(trim $MAC_ADDRESS_1)" ]] ; then
|
|
MAC_ADDRESS_1="$DEFAULT_MAC_ADDRESS_1"
|
|
break
|
|
fi
|
|
warn "'$MAC_ADDRESS_1' isn't a valid MAC Address."
|
|
echononl "\033[1mMAC Address of the firts network device [$DEFAULT_MAC_ADDRESS_1]:\033[m "
|
|
read MAC_ADDRESS_1
|
|
done
|
|
|
|
echo ""
|
|
echo -e "\033[32m--\033[m"
|
|
echo ""
|
|
|
|
echo " # Insert first IPv4 Address for the new LX Containers."
|
|
echo " #"
|
|
echo ""
|
|
echononl "\033[1mFirst IPv4 Address:\033[m "
|
|
read IPV4_ADDRESS_1
|
|
|
|
while ! $(is_valid_ipv4 $IPV4_ADDRESS_1); do
|
|
if [[ -z "$(trim $IPV4_ADDRESS_1)" ]]; then
|
|
warn "Parameter is needed. Try again.."
|
|
else
|
|
warn "'$IPV4_ADDRESS_1' is not a valid IPv4 Address. Try again.."
|
|
fi
|
|
echononl "\033[1mFirst IPv4 Address:\033[m "
|
|
read IPV4_ADDRESS_1
|
|
done
|
|
_octets=( ${IPV4_ADDRESS_1//\./ } )
|
|
DEFAULT_IPV4_GATEWAY_1="${_octets[0]}.${_octets[1]}.${_octets[2]}.1"
|
|
|
|
echo ""
|
|
echo -e "\033[32m--\033[m"
|
|
echo ""
|
|
|
|
echo " # Insert IPv4 Address for the gateway."
|
|
echo " #"
|
|
echo " # Type <return> to accept the default '$DEFAULT_IPV4_GATEWAY_1'."
|
|
echo ""
|
|
echononl "\033[1mIPv4 (first) Gateway Address [$DEFAULT_IPV4_GATEWAY_1]:\033[m "
|
|
read IPV4_GATEWAY_1
|
|
|
|
while ! $(is_valid_ipv4 $IPV4_GATEWAY_1) ; do
|
|
if [[ -z "$(trim $IPV4_GATEWAY_1)" ]]; then
|
|
IPV4_GATEWAY_1="$DEFAULT_IPV4_GATEWAY_1"
|
|
break
|
|
else
|
|
warn "'$IPV4_GATEWAY_1' is not a valid IPv4 Address. Try again.."
|
|
fi
|
|
echononl "\033[1mIPv4 (first) Gateway Address [$DEFAULT_IPV4_GATEWAY_1]:\033[m "
|
|
read IPV4_GATEWAY_1
|
|
done
|
|
|
|
echo ""
|
|
echo -e "\033[32m--\033[m"
|
|
echo ""
|
|
|
|
echo " # Insert Netmask for the first IPv4 Address."
|
|
echo " #"
|
|
echo " # Type <return> to accept the default '$DEFAULT_IPV4_NETMASK_1'."
|
|
echo ""
|
|
echononl "\033[1mNetmask (first) IPv4 Address [$DEFAULT_IPV4_NETMASK_1]:\033[m "
|
|
read IPV4_NETMASK_1
|
|
|
|
while ! $(is_valid_ipv4 $IPV4_NETMASK_1) ; do
|
|
if [[ -z "$(trim $IPV4_NETMASK_1)" ]]; then
|
|
IPV4_NETMASK_1="$DEFAULT_IPV4_NETMASK_1"
|
|
break
|
|
else
|
|
warn "'$IPV4_NETMASK_1' is not a valid netmask. Try again.."
|
|
fi
|
|
echononl "\033[1mNetmask (first) IPv4 Address [$DEFAULT_IPV4_NETMASK_1]:\033[m "
|
|
read IPV4_NETMASK_1
|
|
done
|
|
IPV4_PREFIX_1="$(netmask2cidr $IPV4_NETMASK_1)"
|
|
IPV6_PREFIX_1=$DEFAULT_IPV6_PREFIX
|
|
|
|
|
|
echo ""
|
|
echo -e "\033[32m--\033[m"
|
|
echo ""
|
|
echononl "\033[1mDo you want to apply a second IPv4 Address? [yes/no]: "
|
|
read OK
|
|
[[ "$(trim ${OK,,})" = "yes" ]] && _second_ipv4=true || _second_ipv4=false
|
|
|
|
if $_second_ipv4 ; then
|
|
|
|
_last_octet=${MAC_ADDRESS_1: -2}
|
|
_new_last_octet="$(printf "%X\n" $((0x$_last_octet + 1)))"
|
|
if [[ ${#_new_last_octet} -eq 1 ]]; then
|
|
_new_last_octet="0$_new_last_octet"
|
|
elif [[ ${#_new_last_octet} -eq 3 ]]; then
|
|
_new_last_octet="00"
|
|
fi
|
|
DEFAULT_MAC_ADDRESS_2="${MAC_ADDRESS_1:0:14}:$_new_last_octet"
|
|
|
|
echo ""
|
|
echo -e "\033[32m--\033[m"
|
|
echo ""
|
|
|
|
echo " # Insert MAC Address for the second network device of the new LX Containers."
|
|
echo " #"
|
|
echo " # Type <return> to accept the randomised created one '$DEFAULT_MAC_ADDRESS_2'."
|
|
echo ""
|
|
echononl "\033[1mMAC Address of the second network device [$DEFAULT_MAC_ADDRESS_2]:\033[m "
|
|
read MAC_ADDRESS_2
|
|
|
|
while ! $(is_valid_mac_address $MAC_ADDRESS_2) ; do
|
|
if [[ -z "$(trim $MAC_ADDRESS_2)" ]] ; then
|
|
MAC_ADDRESS_2="$DEFAULT_MAC_ADDRESS_2"
|
|
break
|
|
fi
|
|
warn "'$MAC_ADDRESS_2' isn't a valid MAC Address."
|
|
echononl "\033[1mMAC Address of the second network device [$DEFAULT_MAC_ADDRESS_2]:\033[m "
|
|
read MAC_ADDRESS_2
|
|
done
|
|
|
|
echo ""
|
|
echo -e "\033[32m--\033[m"
|
|
echo ""
|
|
|
|
echo " # Insert second IPv4 Address for the new LX Containers."
|
|
echo " #"
|
|
echo ""
|
|
echononl "\033[1mSecond IPv4 Address:\033[m "
|
|
read IPV4_ADDRESS_2
|
|
|
|
while ! $(is_valid_ipv4 $IPV4_ADDRESS_2); do
|
|
if [[ -z "$(trim $IPV4_ADDRESS_2)" ]]; then
|
|
warn "Parameter is needed. Try again.."
|
|
else
|
|
warn "'$IPV4_ADDRESS_2' is not a valid IPv4 Address. Try again.."
|
|
fi
|
|
echononl "\033[1mSecond IPv4 Address:\033[m "
|
|
read IPV4_ADDRESS_2
|
|
done
|
|
|
|
echo ""
|
|
echo -e "\033[32m--\033[m"
|
|
echo ""
|
|
|
|
echo " # Insert IPv4 Address for the gateway (second)."
|
|
echo " #"
|
|
echo " # Normally, the second gateway is the same as the first one. Change if you"
|
|
echo " # know what you are doing."
|
|
echo " #"
|
|
echo " # Type <return> to accept the default one"
|
|
echo ""
|
|
echononl "\033[1mIPv4 (second) Gateway Address [$IPV4_GATEWAY_1]:\033[m "
|
|
read IPV4_GATEWAY_2
|
|
|
|
while ! $(is_valid_ipv4 $IPV4_GATEWAY_2) ; do
|
|
if [[ -z "$(trim $IPV4_GATEWAY_2)" ]]; then
|
|
IPV4_GATEWAY_2="$IPV4_GATEWAY_1"
|
|
break
|
|
else
|
|
warn "'$IPV4_GATEWAY_2' is not a valid IPv4 Address. Try again.."
|
|
fi
|
|
echononl "\033[1mIPv4 (second) Gateway Address:\033[m "
|
|
read IPV4_GATEWAY_2
|
|
done
|
|
|
|
echo ""
|
|
echo -e "\033[32m--\033[m"
|
|
echo ""
|
|
|
|
echo " # Insert Netmask for the first IPv4 Address."
|
|
echo " #"
|
|
echo " # Type <return> to accept the default one"
|
|
echo ""
|
|
echononl "\033[1mNetmask (second) IPv4 Address [$IPV4_NETMASK_1]:\033[m "
|
|
read IPV4_NETMASK_2
|
|
|
|
while ! $(is_valid_ipv4 $IPV4_NETMASK_2) ; do
|
|
if [[ -z "$(trim $IPV4_NETMASK_2)" ]]; then
|
|
IPV4_NETMASK_2="$IPV4_NETMASK_1"
|
|
break
|
|
else
|
|
warn "'$IPV4_NETMASK_2' is not a valid netmask. Try again.."
|
|
fi
|
|
echononl "\033[1mNetmask (second) IPv4 Address:\033[m "
|
|
read IPV4_NETMASK_2
|
|
done
|
|
IPV4_PREFIX_2="$(netmask2cidr $IPV4_NETMASK_2)"
|
|
IPV6_PREFIX_2=$DEFAULT_IPV6_PREFIX
|
|
fi
|
|
|
|
echo " # Insert first IPv6 Address for the new LX Containers."
|
|
echo " #"
|
|
echo -e " # Type \033[33mNone\033[m if no ipv6-address should be assigned"
|
|
echo " #"
|
|
echo ""
|
|
echononl "\033[1mFirst IPv6 Address:\033[m "
|
|
read IPV6_ADDRESS_1
|
|
|
|
while [[ -z "$(trim $IPV6_ADDRESS_1)" ]]; do
|
|
warn "Parameter is needed. Try again.."
|
|
echononl "\033[1mFirst IPv6 Address:\033[m "
|
|
read IPV6_ADDRESS_1
|
|
done
|
|
if [[ "${IPV6_ADDRESS_1,,}" = 'none' ]] ; then
|
|
IPV6_ADDRESS_1=""
|
|
fi
|
|
|
|
if [[ -n "$IPV6_ADDRESS_1" ]] ; then
|
|
echo ""
|
|
echo -e "\033[32m--\033[m"
|
|
echo ""
|
|
|
|
echo " # Insert IPv6 Address for the gateway."
|
|
echo " #"
|
|
echo ""
|
|
echononl "\033[1mIPv6 (first) Gateway Address:\033[m "
|
|
read IPV6_GATEWAY_1
|
|
|
|
while [[ -z "$(trim $IPV6_GATEWAY_1)" ]]; do
|
|
warn "Parameter is needed. Try again.."
|
|
echononl "\033[1mFirst IPv6 i(first) Gateway Address:\033[m "
|
|
read IPV6_GATEWAY_1
|
|
done
|
|
fi
|
|
|
|
|
|
echo ""
|
|
echo -e "\033[32m--\033[m"
|
|
echo ""
|
|
|
|
echo " # Insert full quallified hostname for the new LX Container."
|
|
echo " #"
|
|
echo ""
|
|
echononl "\033[1mFull qualified hostname:\033[m "
|
|
read FQ_HOSTNAME
|
|
|
|
while [[ -z "$(trim $IPV4_NETMASK_1)" ]]; do
|
|
warn "Parameter is needed. Try again"
|
|
echononl "\033[1mFull qualified hostname::\033[m "
|
|
read FQ_HOSTNAME
|
|
done
|
|
HOSTNAME="$(echo "$FQ_HOSTNAME" | cut -f1 -d'.')"
|
|
|
|
# - Determin LXC Version
|
|
# -
|
|
LXC_VERSION="$(lxc-info --version)"
|
|
declare -i LXC_MAJOR_VERSION=$(echo $LXC_VERSION | cut -d '.' -f1)
|
|
|
|
|
|
echo ""
|
|
echo ""
|
|
echo -e " \033[32m---\033[m"
|
|
echo -e " \033[32m\033[1mParameter Summary - create new LX Container \033[m\033[1m$LXC_NAME\033[m"
|
|
echo -e " \033[32m---\033[m"
|
|
echo ""
|
|
echo " LXC Version..............................: $LXC_VERSION"
|
|
echo " LXC Major Version........................: $LXC_MAJOR_VERSION"
|
|
echo ""
|
|
echo " Base directory LX Containers.............: $LXC_ROOT_DIR"
|
|
echo " Root directory new LX Container..........: $LXC_CONTAINER_DIR"
|
|
echo ""
|
|
echo " Name of the new LX Container.............: $LXC_NAME"
|
|
echo " Linux distribution.......................: $LXC_DIST"
|
|
echo " Code name (or release number)............: $LXC_RELEASE"
|
|
echo ""
|
|
echo " MAC Address (first) network device.......: $MAC_ADDRESS_1"
|
|
echo ""
|
|
echo " IPv4 Address (first).....................: $IPV4_ADDRESS_1"
|
|
echo " IPv4 Gateway Address (first).............: $IPV4_GATEWAY_1"
|
|
echo " Netmask first IPv4 Address...............: $IPV4_NETMASK_1"
|
|
echo " CIDR (IPv4 Prefix) of netmask............: $IPV4_PREFIX_1"
|
|
echo ""
|
|
if [[ -n "$IPV6_ADDRESS_1" ]] ; then
|
|
echo " IPv6 Address (first).....................: $IPV6_ADDRESS_1"
|
|
echo " IPv6 Gateway Address (first).............: $IPV6_GATEWAY_1"
|
|
else
|
|
echo -e " IPv6 Address (first).....................: - \033[33mNot set\033[m - "
|
|
fi
|
|
if $_second_ipv4 ; then
|
|
echo ""
|
|
echo " MAC Address (second) network device......: $MAC_ADDRESS_2"
|
|
echo " IPv4 Address (second)....................: $IPV4_ADDRESS_2"
|
|
echo " IPv4 Gateway Address (second)............: $IPV4_GATEWAY_2"
|
|
echo " Netmask second IPv4 Address..............: $IPV4_NETMASK_2"
|
|
echo " CIDR (IPv4 Prefix) of netmask............: $IPV4_PREFIX_2"
|
|
fi
|
|
echo ""
|
|
echo " Hostname.................................: $HOSTNAME"
|
|
echo " Full qualified hostname..................: $FQ_HOSTNAME"
|
|
echo ""
|
|
|
|
echononl "\033[1mStart creation script with this parameters [yes/no]:\033[m "
|
|
read OK
|
|
[[ "$(trim ${OK,,})" = "yes" ]] || fatal "Start script with different parameters."
|
|
|
|
|
|
echo ""
|
|
|
|
|
|
# ---
|
|
# - Create the base container
|
|
# ---
|
|
|
|
echo ""
|
|
echo ""
|
|
echo -e " \033[37m\033[1mPreinstallation task....\033[m"
|
|
echo ""
|
|
|
|
if [[ "$(dirname "$LXC_CONTAINER_DIR")" != "$LXC_ROOT_DIR" ]]; then
|
|
|
|
msg="Create directory '$(dirname "$LXC_CONTAINER_DIR")'.."
|
|
_dir="$(dirname "$LXC_CONTAINER_DIR")"
|
|
if [[ ! -d "$_dir" ]] ; then
|
|
mkdir "$_dir" > /dev/null 2>$err_msg
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="Directory '${_dir}' 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="Creation of directory '$_dir' failed!"
|
|
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}"
|
|
fatal "$(cat $err_msg)"
|
|
fi
|
|
else
|
|
msg_skipped="Directory '$_dir' already exists."
|
|
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[33m\033[1mskip\033[m ] ${msg_skipped}${blank_signs}"
|
|
|
|
if [[ -d "$LXC_CONTAINER_DIR" ]] ; then
|
|
|
|
if [[ "$(ls -A $LXC_CONTAINER_DIR)" ]]; then
|
|
fatal "Container directory "$LXC_CONTAINER_DIR" exists but is not empty.."
|
|
else
|
|
msg="Remove empty directory '${LXC_CONTAINER_DIR}'.."
|
|
rmdir "${LXC_CONTAINER_DIR}" > /dev/null 2>$err_msg
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="(Empty) directory '${LXC_CONTAINER_DIR}' removed.."
|
|
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="Removing directory '${LXC_CONTAINER_DIR}' failed!"
|
|
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}"
|
|
fatal "$(cat $err_msg)"
|
|
fi
|
|
fi # if [[ "$(ls -A $LXC_CONTAINER_DIR)" ]]; then
|
|
|
|
fi # if [[ -d "$LXC_CONTAINER_DIR" ]]
|
|
|
|
fi # if [[ ! -d "$_dir" ]] ; then
|
|
|
|
fi # if [[ "$(dirname "$LXC_CONTAINER_DIR")" != "$LXC_ROOT_DIR" ]]; then
|
|
|
|
|
|
# - Prevent script from installing into an existing Container dir.
|
|
# -
|
|
if [[ -d "${LXC_CONTAINER_DIR}" ]] ; then
|
|
fatal "Container directory '$LXC_CONTAINER_DIR' already exists."
|
|
fi
|
|
|
|
echo ""
|
|
echo ""
|
|
echo -e " \033[37m\033[1mCreate the base container..\033[m"
|
|
echo ""
|
|
|
|
msg="Create Lx Container '$LXC_NAME' .."
|
|
length_msg=${#msg}
|
|
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
|
|
|
|
lxc-create -n $LXC_NAME -t $LXC_DIST -P "$(dirname "$LXC_CONTAINER_DIR")" -- \
|
|
--release $LXC_RELEASE --arch amd64 > /dev/null 2> $err_msg
|
|
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="Lx Container 'LXC_NAME' 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="Creation of Lx Container '$LXC_NAME' failed!"
|
|
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}"
|
|
fatal "$(cat $err_msg)"
|
|
fi
|
|
|
|
|
|
# ---
|
|
# - Configure the new LX Container
|
|
# ---
|
|
|
|
echo ""
|
|
echo ""
|
|
echo -e " \033[37m\033[1mConfigure the new LX Container..\033[m"
|
|
echo ""
|
|
|
|
|
|
if [[ "$(dirname "$LXC_CONTAINER_DIR")" != "$LXC_ROOT_DIR" ]]; then
|
|
|
|
|
|
msg="Create a symlink '${LXC_ROOT_DIR}/${LXC_NAME}' --> '${LXC_CONTAINER_DIR}' .."
|
|
length_msg=${#msg}
|
|
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
|
|
ln -s ${LXC_CONTAINER_DIR} ${LXC_ROOT_DIR}/${LXC_NAME} > /dev/null 2>$err_msg
|
|
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="Symlink '${LXC_ROOT_DIR}/${LXC_NAME}' --> '${LXC_CONTAINER_DIR}' 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="Creation of symlink '${LXC_ROOT_DIR}/${LXC_NAME}' --> '${LXC_CONTAINER_DIR}' failed!"
|
|
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}"
|
|
fatal "$(cat $err_msg)"
|
|
fi
|
|
fi
|
|
|
|
|
|
# - Create an empty fstab '${LXC_CONTAINER_DIR}/fstab'
|
|
# -
|
|
msg="Create an empty file '${LXC_CONTAINER_DIR}/fstab' .."
|
|
length_msg=${#msg}
|
|
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
|
|
|
|
touch ${LXC_CONTAINER_DIR}/fstab > /dev/null 2>$err_msg
|
|
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="Empty file '${LXC_CONTAINER_DIR}' 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="Creation of (empty) file '${LXC_CONTAINER_DIR}/fstab' failed!"
|
|
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
|
|
|
|
# - Backup original configuration file
|
|
# -
|
|
msg="Backup original Container configuration file '${LXC_CONTAINER_DIR}/config' .."
|
|
length_msg=${#msg}
|
|
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
|
|
|
|
cp ${LXC_CONTAINER_DIR}/config ${LXC_CONTAINER_DIR}/config.ORIG
|
|
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="File '${LXC_CONTAINER_DIR}/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}/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 the Container configuration file
|
|
# -
|
|
msg="Create Container Configuration '${LXC_CONTAINER_DIR}/config (LXC Version $LXC_VERSION)' .."
|
|
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
|
|
|
|
_failed=false
|
|
if [[ $LXC_MAJOR_VERSION -lt 3 ]]; then
|
|
cat << EOF > ${LXC_CONTAINER_DIR}/config 2> $err_msg
|
|
lxc.rootfs = ${LXC_CONTAINER_DIR}/rootfs
|
|
|
|
# Common configuration
|
|
lxc.include = /usr/share/lxc/config/${LXC_DIST}.common.conf
|
|
|
|
|
|
# Container specific configuration
|
|
lxc.mount = ${LXC_CONTAINER_DIR}/fstab
|
|
lxc.utsname = $LXC_NAME
|
|
lxc.arch = amd64
|
|
lxc.autodev = 1
|
|
lxc.kmsg = 0
|
|
|
|
|
|
# Network configuration
|
|
|
|
### Device 1
|
|
lxc.network.type = veth
|
|
lxc.network.flags = up
|
|
lxc.network.link = br0
|
|
lxc.network.name = eth0
|
|
lxc.network.hwaddr = $MAC_ADDRESS_1
|
|
# IPv4
|
|
lxc.network.ipv4 = ${IPV4_ADDRESS_1}/$IPV4_PREFIX_1
|
|
lxc.network.ipv4.gateway = ${IPV4_GATEWAY_1}
|
|
# IPv6
|
|
EOF
|
|
if [[ -n "${IPV6_ADDRESS_1}" ]] ; then
|
|
cat << EOF >> ${LXC_CONTAINER_DIR}/config 2>> $err_msg
|
|
lxc.network.ipv6 = ${IPV6_ADDRESS_1}/$IPV6_PREFIX_1
|
|
lxc.network.ipv6.gateway = $IPV6_GATEWAY_1
|
|
EOF
|
|
else
|
|
cat << EOF >> ${LXC_CONTAINER_DIR}/config 2>> $err_msg
|
|
#lxc.network.ipv6 = ${IPV6_ADDRESS_1}/$IPV6_PREFIX_1
|
|
#lxc.network.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
|
|
### Device 2
|
|
lxc.network.type = veth
|
|
lxc.network.flags = up
|
|
lxc.network.link = br0
|
|
lxc.network.name = eth1
|
|
lxc.network.hwaddr = $MAC_ADDRESS_2
|
|
## IPv4
|
|
lxc.network.ipv4 = ${IPV4_ADDRESS_2}/$IPV4_PREFIX_2
|
|
## IPv6
|
|
EOF
|
|
if [[ -n "$IPV6_ADDRESS_2" ]]; then
|
|
cat << EOF >> ${LXC_CONTAINER_DIR}/config 2>> $err_msg
|
|
lxc.network.ipv6 = ${IPV6_ADDRESS_2}/$IPV6_PREFIX_2
|
|
EOF
|
|
else
|
|
cat << EOF >> ${LXC_CONTAINER_DIR}/config 2>> $err_msg
|
|
#lxc.network.ipv6 = ${IPV6_ADDRESS_2}/$IPV6_PREFIX_2
|
|
|
|
EOF
|
|
fi
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
_failed=true
|
|
fi
|
|
fi
|
|
else
|
|
|
|
|
|
|
|
cat << EOF > ${LXC_CONTAINER_DIR}/config 2> $err_msg
|
|
lxc.rootfs.path = ${LXC_CONTAINER_DIR}/rootfs
|
|
|
|
# Common configuration
|
|
lxc.include = /usr/share/lxc/config/${LXC_DIST}.common.conf
|
|
|
|
|
|
# Container specific configuration
|
|
lxc.mount.fstab = ${LXC_CONTAINER_DIR}/fstab
|
|
lxc.uts.name = $LXC_NAME
|
|
lxc.arch = amd64
|
|
lxc.autodev = 1
|
|
|
|
|
|
# Network configuration
|
|
|
|
### 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 [[ -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
|
|
### Device 2
|
|
lxc.net.1.type = veth
|
|
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
|
|
## IPv6
|
|
EOF
|
|
if [[ -n "$IPV6_ADDRESS_2" ]]; then
|
|
cat << EOF >> ${LXC_CONTAINER_DIR}/config 2>> $err_msg
|
|
lxc.net.1.ipv6.address = ${IPV6_ADDRESS_2}/$IPV6_PREFIX_2
|
|
EOF
|
|
else
|
|
cat << EOF >> ${LXC_CONTAINER_DIR}/config 2>> $err_msg
|
|
#lxc.net.1.ipv6.address = ${IPV6_ADDRESS_2}/$IPV6_PREFIX_2
|
|
|
|
EOF
|
|
fi
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
_failed=true
|
|
fi
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
if [[ $LXC_MAJOR_VERSION -lt 3 ]]; 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 ))
|
|
EOF
|
|
if [[ $? -ne 0 ]]; then
|
|
_failed=true
|
|
fi
|
|
else
|
|
cat << EOF >> ${LXC_CONTAINER_DIR}/config 2>> $err_msg
|
|
|
|
# Mount iso file inside LX Container
|
|
#lxc.apparmor.profile = unconfined
|
|
#lxc.cgroup.devices.allow = b 7:* rwm
|
|
#lxc.cgroup.devices.allow = c 10:237 rwm
|
|
|
|
|
|
# Specify the apparmor profile under which the container should be run.
|
|
#
|
|
# To specify that the container should be unconfined, use
|
|
# lxc.apparmor.profile = unconfined
|
|
#
|
|
# If the apparmor profile should remain unchanged (i.e. if you are nesting
|
|
# containers and are already confined), then use
|
|
# lxc.apparmor.profile = unchanged
|
|
#
|
|
# If you instruct LXC to generate the apparmor profile, then use
|
|
# lxc.apparmor.profile = generated
|
|
#
|
|
#
|
|
# MariaDB (and maybe others) does not start
|
|
# =========================================
|
|
#
|
|
# see also: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=920643
|
|
#
|
|
# AppArmor support in Debian has increased, thus preventing some systemd
|
|
# isolation features to work in LXC 3.0.X. Debian has backported some
|
|
# patches from LXC 3.1 that, along with some configurations in a
|
|
# container, will allow systemd isolation features to work.
|
|
#
|
|
# This may entirely be a an apparmor/systemd issue and nothing to do
|
|
# with mariadb.
|
|
#
|
|
# A workaround is to remove the the following lines from
|
|
# systemd service file:
|
|
# ProtectSystem=full
|
|
# PrivateDevices=true
|
|
# ProtectHome=true
|
|
#
|
|
# Another workarround is to diasble apparmor here:
|
|
# lxc.apparmor.profile = unconfined
|
|
#
|
|
lxc.apparmor.profile = unconfined
|
|
|
|
|
|
# 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 ))
|
|
EOF
|
|
if [[ $? -ne 0 ]]; then
|
|
_failed=true
|
|
fi
|
|
fi
|
|
|
|
if $_failed ; then
|
|
msg_failed="Creation of '${LXC_CONTAINER_DIR}/config' failed!"
|
|
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="Container Configuration '${LXC_CONTAINER_DIR}/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}"
|
|
fi
|
|
|
|
|
|
|
|
# ---
|
|
# - Adjust network configuration
|
|
# ---
|
|
|
|
echo ""
|
|
echo ""
|
|
echo -e " \033[37m\033[1mAdjust network configuration inside the new LX Container ..\033[m"
|
|
echo ""
|
|
|
|
|
|
# - Backup file '/etc/network/interfaces' inside the Container
|
|
# -
|
|
msg="Backup file '${LXC_CONTAINER_DIR}/rootfs/etc/network/interfaces' .."
|
|
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
|
|
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="File '${LXC_CONTAINER_DIR}/rootfs/etc/network/interfaces.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/network/interfaces'!"
|
|
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 Containers network configuration
|
|
# -
|
|
msg="Create a new file '${LXC_CONTAINER_DIR}/rootfs/etc/network/interfaces' .."
|
|
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
|
|
|
|
_failed=false
|
|
if [[ -z "$IPV4_ADDRESS_2" ]] ; then
|
|
cat << EOF > ${LXC_CONTAINER_DIR}/rootfs/etc/network/interfaces
|
|
|
|
#-----------------------------
|
|
# lo: loopback
|
|
#-----------------------------
|
|
auto lo
|
|
iface lo inet loopback
|
|
|
|
|
|
#-----------------------------
|
|
# eth0
|
|
#-----------------------------
|
|
auto eth0
|
|
iface eth0 inet manual
|
|
iface eth0 inet6 manual
|
|
|
|
EOF
|
|
if [[ $? -ne 0 ]]; then
|
|
_failed=true
|
|
fi
|
|
|
|
else
|
|
cat << EOF > ${LXC_CONTAINER_DIR}/rootfs/etc/network/interfaces 2> $err_msg
|
|
|
|
#-----------------------------
|
|
# lo: loopback
|
|
#-----------------------------
|
|
auto lo
|
|
iface lo inet loopback
|
|
|
|
|
|
#-----------------------------
|
|
# eth0
|
|
#-----------------------------
|
|
auto eth0
|
|
iface eth0 inet manual
|
|
up ip route add default via ${IPV4_GATEWAY_1} dev eth0 table 100
|
|
up ip rule add from ${IPV4_ADDRESS_1} table 100 prio 100
|
|
|
|
|
|
|
|
#-----------------------------
|
|
# eth1
|
|
#-----------------------------
|
|
|
|
auto eth1
|
|
iface eth1 inet manual
|
|
up ip route add default via ${IPV4_GATEWAY_2} dev eth1 table 200
|
|
up ip rule add from ${IPV4_ADDRESS_2} table 200 prio 120
|
|
EOF
|
|
if [[ $? -ne 0 ]]; then
|
|
_failed=true
|
|
fi
|
|
fi
|
|
|
|
if $_failed ; then
|
|
msg_failed="Failed to create file '${LXC_CONTAINER_DIR}/rootfs/etc/network/interfaces'!"
|
|
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/network/interfaces' 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
|
|
|
|
|
|
|
|
# ---
|
|
# - Some post-installation tasks on the new LX Container
|
|
# ---
|
|
|
|
echo ""
|
|
echo ""
|
|
echo -e " \033[37m\033[1mSome post-installation tasks inside the new LX Container '${LXC_NAME}' ..\033[m"
|
|
echo ""
|
|
|
|
msg="Backup file '${LXC_CONTAINER_DIR}/rootfs/etc/apt/sources.list' .."
|
|
mv "${LXC_CONTAINER_DIR}/rootfs/etc/apt/sources.list" "${LXC_CONTAINER_DIR}/rootfs/etc/apt/sources.list.ORIG" > $err_msg 2>&1
|
|
|
|
|
|
# - Backup 'sources.list'-file.
|
|
# -
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="File '${LXC_CONTAINER_DIR}/rootfs/etc/apt/sources.list.ORIG' 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="Backup of file '${LXC_CONTAINER_DIR}/rootfs/etc/apt/sources.list' failed!"
|
|
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 'sources.list'-file.
|
|
# -
|
|
msg="Create file '${LXC_CONTAINER_DIR}/rootfs/etc/apt/sources.list' .."
|
|
cat << EOF > ${LXC_CONTAINER_DIR}/rootfs/etc/apt/sources.list 2> $err_msg
|
|
|
|
deb http://ftp.de.debian.org/debian/ $LXC_RELEASE main non-free contrib
|
|
deb-src http://ftp.de.debian.org/debian/ $LXC_RELEASE main non-free contrib
|
|
|
|
deb http://security.debian.org/ $LXC_RELEASE/updates main contrib non-free
|
|
deb-src http://security.debian.org/ $LXC_RELEASE/updates main contrib non-free
|
|
|
|
# $LXC_RELEASE-updates, previously known as 'volatile'
|
|
deb http://ftp.de.debian.org/debian/ $LXC_RELEASE-updates main contrib non-free
|
|
deb-src http://ftp.de.debian.org/debian/ $LXC_RELEASE-updates main contrib non-free
|
|
|
|
# $LXC_RELEASE-backports, previously on backports.debian.org
|
|
deb http://ftp.de.debian.org/debian/ $LXC_RELEASE-backports main contrib non-free
|
|
deb-src http://ftp.de.debian.org/debian/ $LXC_RELEASE-backports main contrib non-free
|
|
|
|
EOF
|
|
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="New file '${LXC_CONTAINER_DIR}/rootfs/etc/apt/sources.list' 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="Creation of file '${LXC_CONTAINER_DIR}/rootfs/etc/apt/sources.list' failed!"
|
|
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
|
|
|
|
|
|
# - Backup symlink '/bin/sh'. Move to '/bin/sh.ORIG'.
|
|
# -
|
|
echo ""
|
|
msg="Move Symlink '/bin/sh' to '/bin/sh.ORIG' .."
|
|
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
|
|
|
|
mv "${LXC_CONTAINER_DIR}/rootfs/bin/sh" "${LXC_CONTAINER_DIR}/rootfs/bin/sh.ORIG" > $err_msg 2>&1
|
|
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="Symlink '${LXC_CONTAINER_DIR}/rootfs/bin/sh.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="Saving Symlink '${LXC_CONTAINER_DIR}/rootfs/etc/bin/sh' failed!"
|
|
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 symlink '/bin/sh'
|
|
# -
|
|
msg="Create new Symlink '/bin/sh' pointing to 'bash' .."
|
|
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
|
|
|
|
ln -s bash ${LXC_CONTAINER_DIR}/rootfs/bin/sh > $err_msg 2>&1
|
|
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="New Symlink '${LXC_CONTAINER_DIR}/rootfs/bin/sh' 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="Creation of new Symlink '${LXC_CONTAINER_DIR}/rootfs/etc/bin/sh' failed!"
|
|
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
|
|
|
|
|
|
# - Add entry for hostname in /etc/hosts
|
|
# -
|
|
echo ""
|
|
msg="Add entry for hostname '$FQ_HOSTNAME' to file '${LXC_CONTAINER_DIR}/rootfs/etc/hosts' .."
|
|
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
|
|
|
|
perl -i.ORIG -n -p -e "s/^(\s*127\.0\.0\.1.*)/\1\n127.0.1.1 $FQ_HOSTNAME $HOSTNAME\n/" ${LXC_CONTAINER_DIR}/rootfs/etc/hosts > $err_msg 2>&1
|
|
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="Entry '127.0.1.1 $FQ_HOSTNAME $HOSTNAME' added to '${LXC_CONTAINER_DIR}/rootfs/etc/hosts'."
|
|
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="Adding entry '127.0.1.1 $FQ_HOSTNAME $HOSTNAME' to '${LXC_CONTAINER_DIR}/rootfs/etc/hosts' failed!"
|
|
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
|
|
|
|
|
|
# - Backup Containers file '/etc/hostname'
|
|
# -
|
|
echo ""
|
|
msg="Backup file '${LXC_CONTAINER_DIR}/rootfs/etc/hostname' .."
|
|
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
|
|
|
|
mv "${LXC_CONTAINER_DIR}/rootfs/etc/hostname" "${LXC_CONTAINER_DIR}/rootfs/etc/hostname.ORIG" > $err_msg 2>&1
|
|
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="File '${LXC_CONTAINER_DIR}/rootfs/etc/hostname.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/hostname'!"
|
|
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
|
|
|
|
|
|
# - Write new Containers file /etc/hostname
|
|
# -
|
|
msg="Create a new file '${LXC_CONTAINER_DIR}/rootfs/etc/hostname' .."
|
|
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
|
|
|
|
echo "$HOSTNAME" > "${LXC_CONTAINER_DIR}/rootfs/etc/hostname" 2>$err_msg
|
|
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="New file '${LXC_CONTAINER_DIR}/rootfs/etc/hostname' 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/hostname'!"
|
|
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
|
|
|
|
|
|
|
|
# - Install 'figlet' from debian package system
|
|
# -
|
|
echo ""
|
|
_pkg="figlet"
|
|
msg="Install '$_pkg' from debian package system .."
|
|
if ! $(aptitude search "$_pkg" | grep " $_pkg " | grep -e "^i" > /dev/null 2>&1) ; then
|
|
|
|
DEBIAN_FRONTEND=noninteractive apt-get -y install $_pkg > /dev/null 2> "$err_msg"
|
|
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="Debian package '$_pkg' successfully installed."
|
|
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="Installation of debiab package '$_pkg' failed!"
|
|
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
|
|
|
|
|
|
# - Backup Containers file '/etc/motd'
|
|
# -
|
|
echo ""
|
|
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 [[ $? -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
|
|
|
|
|
|
|
|
# - 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
|
|
|
|
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
|
|
|
|
|
|
# - Backup Containers file '/root/.bashrc'
|
|
# -
|
|
echo ""
|
|
msg="Backup file '${LXC_CONTAINER_DIR}/rootfs//root/.bashrc' .."
|
|
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
|
|
|
|
mv "${LXC_CONTAINER_DIR}/rootfs/root/.bashrc" "${LXC_CONTAINER_DIR}/rootfs/root/.bashrc.ORIG" > $err_msg 2>&1
|
|
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="File '${LXC_CONTAINER_DIR}/rootfs/root/.bashrc.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/root/.bashrc'!"
|
|
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 '/root/.bashrc'
|
|
# -
|
|
msg="Create a new file '${LXC_CONTAINER_DIR}/rootfs/root/.bashrc' .."
|
|
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
|
|
|
|
if [[ -f "${working_dir}/supported-files/templates_root/.bashrc" ]]; then
|
|
cp -a "${working_dir}/supported-files/templates_root/.bashrc" \
|
|
"${LXC_CONTAINER_DIR}/rootfs/root/.bashrc" 2>$err_msg
|
|
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="New file '${LXC_CONTAINER_DIR}/rootfs/root/.bashrc' 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/root/.bashrc'!"
|
|
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
|
|
|
|
|
|
# - Backup Containers file '/root/.profile'
|
|
# -
|
|
msg="Backup file '${LXC_CONTAINER_DIR}/rootfs//root/.profile' .."
|
|
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
|
|
|
|
mv "${LXC_CONTAINER_DIR}/rootfs/root/.profile" "${LXC_CONTAINER_DIR}/rootfs/root/.profile.ORIG" > $err_msg 2>&1
|
|
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="File '${LXC_CONTAINER_DIR}/rootfs/root/.profile.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/root/.profile'!"
|
|
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 '/root/.profile'
|
|
# -
|
|
msg="Create a new file '${LXC_CONTAINER_DIR}/rootfs/root/.profile' .."
|
|
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
|
|
|
|
if [[ -f "${working_dir}/supported-files/templates_root/.profile" ]]; then
|
|
cp -a "${working_dir}/supported-files/templates_root/.profile" \
|
|
"${LXC_CONTAINER_DIR}/rootfs/root/.profile" 2>$err_msg
|
|
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="New file '${LXC_CONTAINER_DIR}/rootfs/root/.profile' 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/root/.profile'!"
|
|
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
|
|
|
|
|
|
# - Create new containers file '/root/.vimrc'
|
|
# -
|
|
msg="Create a new file '${LXC_CONTAINER_DIR}/rootfs/root/.vimrc' .."
|
|
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
|
|
|
|
if [[ -f "${working_dir}/supported-files/templates_root/.vimrc" ]]; then
|
|
cp -a "${working_dir}/supported-files/templates_root/.vimrc" \
|
|
"${LXC_CONTAINER_DIR}/rootfs/root/.vimrc" 2>$err_msg
|
|
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="New file '${LXC_CONTAINER_DIR}/rootfs/root/.vimrc' 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/root/.vimrc'!"
|
|
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
|
|
|
|
|
|
|
|
# - Create new container directory '/root/bin'
|
|
# -
|
|
echo ""
|
|
msg="Create a new directory '${LXC_CONTAINER_DIR}/rootfs/root/bin' .."
|
|
|
|
mkdir "${LXC_CONTAINER_DIR}/rootfs/root/bin" > $err_msg 2>&1
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="New directory '${LXC_CONTAINER_DIR}/rootfs/root/bin' 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 directory '${LXC_CONTAINER_DIR}/rootfs/root/bin'!"
|
|
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
|
|
|
|
|
|
# - Add git repository 'admin-stuff'
|
|
# -
|
|
msg="Clone git repository 'admin-stuff' to '${LXC_CONTAINER_DIR}/rootfs/root/bin/admin-stuff'"
|
|
git clone https://git.oopen.de/script/admin-stuff ${LXC_CONTAINER_DIR}/rootfs/root/bin/admin-stuff 2> /dev/null
|
|
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="Git repository '${LXC_CONTAINER_DIR}/rootfs/root/bin/admin-stuff' 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 clone git repository 'admin-stuff'!"
|
|
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 directory '/root/.ssh'
|
|
# -
|
|
echo ""
|
|
msg="Create a new directory '${LXC_CONTAINER_DIR}/rootfs/root/.ssh' .."
|
|
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
|
|
|
|
if [[ -f "${working_dir}/supported-files/templates_root/.ssh/authorized_keys2" ]] ||
|
|
[[ -f "${working_dir}/supported-files/templates_root/.ssh/authorized_keys" ]]; then
|
|
|
|
mkdir "${LXC_CONTAINER_DIR}/rootfs/root/.ssh" > $err_msg 2>&1
|
|
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="New directory '${LXC_CONTAINER_DIR}/rootfs/root/.ssh' 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}"
|
|
|
|
msg="Copy supported files to '${LXC_CONTAINER_DIR}/rootfs/root/.ssh/' .."
|
|
cp -a "${working_dir}/supported-files/templates_root/.ssh" \
|
|
"${LXC_CONTAINER_DIR}/rootfs/root/" > $err_msg 2>&1
|
|
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="Supported files copied to new directory '${LXC_CONTAINER_DIR}/rootfs/root/.ssh'."
|
|
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 copy supported files to '${LXC_CONTAINER_DIR}/rootfs/root/.ssh'!"
|
|
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 directory '${LXC_CONTAINER_DIR}/rootfs/root/.ssh'!"
|
|
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
|
|
|
|
|
|
|
|
# ---
|
|
# - Start the new LX Container
|
|
# ---
|
|
|
|
echo ""
|
|
echo ""
|
|
echo -e " \033[37m\033[1mStart the new LX Container '${LXC_NAME}' ..\033[m"
|
|
echo ""
|
|
|
|
msg="Start Container '${LXC_NAME}' as a background process .."
|
|
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
|
|
|
|
lxc-start -d -n $LXC_NAME > /dev/null 2> $err_msg
|
|
|
|
if [[ $? -eq 0 ]] ; then
|
|
msg_ok="LX Container '${LXC_NAME}' started successfully."
|
|
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="Starting Container '${LXC_NAME}' failed!"
|
|
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 ""
|
|
# - Write summary for LX Container
|
|
# -
|
|
msg="Write summary for LX Container '${LXC_NAME}' to file '${working_dir}/conf/${LXC_NAME}.conf' .."
|
|
echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m"
|
|
|
|
_failed=false
|
|
cat << EOF > ${working_dir}/conf/${LXC_NAME}.conf 2> $err_msg
|
|
LXC_ROOT_DIR=$LXC_ROOT_DIR
|
|
LXC_CONTAINER_DIR=$LXC_CONTAINER_DIR
|
|
|
|
LXC_NAME=$LXC_NAME
|
|
|
|
LXC_DIST=$LXC_DIST
|
|
LXC_RELEASE=$LXC_RELEASE
|
|
|
|
MAC_ADDRESS_1=$MAC_ADDRESS_1
|
|
IPV4_ADDRESS_1=$IPV4_ADDRESS_1
|
|
IPV4_NETMASK_1=$IPV4_NETMASK_1
|
|
IPV4_GATEWAY_1=$IPV4_GATEWAY_1
|
|
IPV4_PREFIX_1=$IPV4_PREFIX_1
|
|
|
|
EOF
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
_failed=true
|
|
fi
|
|
|
|
if [[ "$IPV6_ADDRESS_1" ]]; then
|
|
cat << EOF >> ${working_dir}/conf/${LXC_NAME}.conf 2>> $err_msg
|
|
IPV6_ADDRESS_1=$IPV6_ADDRESS_1/$IPV6_PREFIX_1
|
|
IPV6_GATEWAY_1=$IPV6_GATEWAY_1
|
|
EOF
|
|
if [[ $? -ne 0 ]]; then
|
|
_failed=true
|
|
fi
|
|
fi
|
|
|
|
if $_second_ipv4 ; then
|
|
cat << EOF >> ${working_dir}/conf/${LXC_NAME}.conf 2>> $err_msg
|
|
|
|
MAC_ADDRESS_2=$MAC_ADDRESS_2
|
|
IPV4_ADDRESS_2=$IPV4_ADDRESS_2
|
|
IPV4_NETMASK_2=$IPV4_NETMASK_2
|
|
IPV4_GATEWAY_2=$IPV4_GATEWAY_2
|
|
IPV4_PREFIX_2=$IPV4_PREFIX_2
|
|
EOF
|
|
if [[ $? -ne 0 ]]; then
|
|
_failed=true
|
|
fi
|
|
fi
|
|
|
|
if [[ "$IPV6_ADDRESS_2" ]]; then
|
|
cat << EOF >> ${working_dir}/conf/${LXC_NAME}.conf 2>> $err_msg
|
|
IPV6_ADDRESS_2=$IPV6_ADDRESS_2/$IPV6_PREFIX_2
|
|
EOF
|
|
if [[ $? -ne 0 ]]; then
|
|
_failed=true
|
|
fi
|
|
fi
|
|
|
|
cat << EOF >> ${working_dir}/conf/${LXC_NAME}.conf 2>> $err_msg
|
|
|
|
HOSTNAME=$HOSTNAME
|
|
FQ_HOSTNAME=$FQ_HOSTNAME
|
|
EOF
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
_failed=true
|
|
fi
|
|
|
|
if $_failed ; then
|
|
msg_failed="Failed to create summary file '${working_dir}/conf/${LXC_NAME}.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="Summary file '${working_dir}/conf/${LXC_NAME}.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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo ""
|
|
info " Direct access to the new container with command:
|
|
\033[1mlxc-attach -n $LXC_NAME\033[m"
|
|
info " Inside the new Contaimer, run the following commands to create/adjust users:
|
|
\033[1madd_new_user.sh root
|
|
add_new_user.sh chris
|
|
add_new_user.sh sysadm
|
|
add_new_user.sh back\033[m"
|
|
echo ""
|
|
clean_up 0
|