Add support of configuration file for installation scripts.

This commit is contained in:
2020-04-29 15:12:23 +02:00
parent 42e52f1cb1
commit 23fcca1527
6 changed files with 406 additions and 35 deletions

View File

@@ -3,14 +3,12 @@
script_name="$(basename $(realpath $0))"
working_dir="$(dirname $(realpath $0))"
conf_file="${working_dir}/conf/${script_name%%.*}.conf"
#conf_file="${working_dir}/conf/${script_name%%.*}.conf"
conf_file="${working_dir}/conf/bbb.conf"
LOCK_DIR="/tmp/$(basename $0).$$.LOCK"
log_file="${LOCK_DIR}/${script_name%%.*}.log"
DIST="ubuntu"
DIST_RELEASE="xenial"
# ----------
# Base Function(s)
@@ -96,6 +94,35 @@ blank_line() {
fi
}
detect_os () {
if $(which lsb_release > /dev/null 2>&1) ; then
DIST="$(lsb_release -i | awk '{print tolower($3)}')"
DIST_VERSION="$(lsb_release -r | awk '{print tolower($2)}')"
DIST_CODENAME="$(lsb_release -c | awk '{print tolower($2)}')"
if [[ "$DIST" = "debian" ]]; then
if $(echo "$DIST_VERSION" | grep -q '\.') ; then
DIST_VERSION=$(echo "$DIST_VERSION" | cut --delimiter='.' -f1)
fi
fi
elif [[ -e "/etc/os-release" ]]; then
. /etc/os-release
DIST=$ID
DIST_VERSION=${VERSION_ID}
fi
# remove whitespace from DIST and DIST_VERSION
DIST="${DIST// /}"
DIST_VERSION="${DIST_VERSION// /}"
}
# ----------
@@ -139,18 +166,55 @@ if $terminal ; then
echo -e "\033[1m----------\033[m"
fi
# ----------
# Read Configurations from $conf_file
# ----------
# - Give your default values here
# -
DEFAULT_FQDN_HOSTNAME="$(hostname -f)"
if [[ -f "$conf_file" ]]; then
source "$conf_file"
else
warn "No configuration file '$conf_file' present.\n
Loading default values.."
fi
[[ -n "$FQDN_HOSTNAME" ]] && DEFAULT_FQDN_HOSTNAME="$FQDN_HOSTNAME"
blank_line
echononl "Detect distribution/release of running OS.."
detect_os > "$log_file" 2>&1
if [[ $? -ne 0 ]]; then
echo_failed
error "$(cat "$log_file")"
else
echo_ok
fi
FQDN_HOSTNAME=
echo ""
echo -e "\033[32m--\033[m"
echo ""
echo "Insert full qualified hostname for BigBlueButton Service"
echo ""
if [[ -n "$_FQDN_HOSTNAME" ]]; then
echononl "Full qualified hostname [${_FQDN_HOSTNAME}]: "
read FQDN_HOSTNAME
if [[ "X${FQDN_HOSTNAME}" = "X" ]]; then
FQDN_HOSTNAME=$_FQDN_HOSTNAME
fi
if [[ -n "$DEFAULT_FQDN_HOSTNAME" ]]; then
while [[ "X${FQDN_HOSTNAME}" = "X" ]]; do
echononl "Full qualified hostname [${DEFAULT_FQDN_HOSTNAME}]: "
read FQDN_HOSTNAME
if [[ "X${FQDN_HOSTNAME}" = "X" ]]; then
FQDN_HOSTNAME=$DEFAULT_FQDN_HOSTNAME
fi
if [[ ! $FQDN_HOSTNAME =~ \. ]]; then
echo -e "\n\tGiven Host \033[33m\033[1m$FQDN_HOSTNAME\033[m seems not to be a full qualified hostname.\n"
FQDN_HOSTNAME=""
fi
done
else
while [[ "X${FQDN_HOSTNAME}" = "X" ]]; do
echononl "Full qualified hostname: "
@@ -158,9 +222,12 @@ else
if [[ "X${FQDN_HOSTNAME}" = "X" ]]; then
echo -e "\n\t\033[33m\033[1mFull qualified hostname is reqired\033[m\n"
fi
if [[ ! $FQDN_HOSTNAME =~ \. ]]; then
echo -e "\n\tGiven Host \033[33m\033[1m$FQDN_HOSTNAME\033[m seems not to be a full qualified hostname.\n"
FQDN_HOSTNAME=""
fi
done
fi
HOSTNAME="${FQDN_HOSTNAME%%.*}"
echo ""
@@ -170,6 +237,9 @@ echo ""
echo -e "\tFull qualified Hostname..: $FQDN_HOSTNAME"
echo -e "\tHostname.................: $HOSTNAME"
echo ""
echo -e "\tOS Distribution..........: $DIST"
echo -e "\tDistribution's codename..: $DIST_CODENAME"
echo ""
echononl "einverstanden (yes/no): "
read OK
OK=${OK,,}
@@ -231,14 +301,14 @@ fi
blank_line
echononl "Create sources.list for '$DIST $DIST_RELEASE'.."
echononl "Create sources.list for '$DIST $DIST_CODENAME'.."
cat <<EOF > /etc/apt/sources.list 2> "$log_file"
deb http://archive.ubuntu.com/ubuntu ${DIST_RELEASE} main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu ${DIST_RELEASE}-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu ${DIST_CODENAME} main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu ${DIST_CODENAME}-updates main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu ${DIST_RELEASE}-security main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu ${DIST_CODENAME}-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu ${DIST_RELEASE}-backports main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu ${DIST_CODENAME}-backports main restricted universe multiverse
EOF
if [[ $? -ne 0 ]]; then
echo_failed
@@ -380,7 +450,7 @@ fi
echononl "Add repository for 'mongodb'.."
cat <<EOF > /etc/apt/sources.list.d/mongodb-org-3.4.list 2> "$log_file"
deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu ${DIST_RELEASE}/mongodb-org/3.4 multiverse
deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu ${DIST_CODENAME}/mongodb-org/3.4 multiverse
EOF
if [[ $? -ne 0 ]]; then
echo_failed
@@ -447,7 +517,7 @@ fi
#
echononl "Add repository for BigBlueButton 2.2 packages.."
cat <<EOF > /etc/apt/sources.list.d/bigbluebutton.list 2> "$log_file"
deb https://ubuntu.bigbluebutton.org/${DIST_RELEASE}-220/ bigbluebutton-${DIST_RELEASE} main
deb https://ubuntu.bigbluebutton.org/${DIST_CODENAME}-220/ bigbluebutton-${DIST_CODENAME} main
EOF
if [[ $? -ne 0 ]]; then
echo_failed