#!/bin/sh # _ _ ___ __ _ (R) # | | (_)_ _____ / __|___ _ _ / _(_)__ _ # | |__| \ V / -_) (__/ _ \ ' \| _| / _` | # |____|_|\_/\___|\___\___/_||_|_| |_\__, |___________________________________ # |___/ # LiveConfig automated install script # # Source: https://install.liveconfig.com/lc3 # Documentation: https://www.liveconfig.com/install # ____________________________________________________________________________ INST_VERSION="1.22" TERM_RED=`tput setaf 1 2>/dev/null || echo ""` TERM_NORMAL=`tput sgr0 2>/dev/null || echo ""` TERM_CLEAR=`tput clear 2>/dev/null || echo ""` TERM_BOLD=`tput bold 2>/dev/null || echo ""` RAM=`grep "MemTotal" /proc/meminfo | awk '{ print $2 }'` export NEWT_MONO=1 # monochrome setting for whiptail selected= for o in $@; do case $o in web) selected="${selected} WEB" ;; mail) selected="${selected} MAIL" ;; db) selected="${selected} DB" ;; dns) selected="${selected} DNS" ;; *) echo "Unknown option: '$o'" exit 1; ;; esac done askYesNo() { text=$1 title="" if [ $# -ge 2 ]; then title=$2; fi height=7 if [ $# -ge 3 ]; then height=$3; fi width=50; if [ $# -ge 4 ]; then width=$4; fi if [ "$title" != "" ]; then whiptail --yesno "$text" $height $width --title "$title"; else whiptail --yesno "$text" $height $width; fi return $? } checklist() { SELECTED="$(whiptail --checklist "$@" 3>&1 1>&2 2>&3)" status=$? # "return" selected results echo "$SELECTED" # return status return $status } msgBox() { text=$1 title="" if [ $# -ge 2 ]; then title=$2; fi height=7 if [ $# -ge 3 ]; then height=$3; fi width=50; if [ $# -ge 4 ]; then width=$4; fi if [ "$title" != "" ]; then whiptail --msgbox "$text" $height $width --title "$title"; else whiptail --msgbox "$text" $height $width; fi return $? } check_requirements() { if [ "$(whoami)" != "root" ]; then print_header print_bold "This script needs to be run as root." print_footer exit 1 fi wget=$(which wget 2> /dev/null) if [ $? -eq 0 ]; then dltool_file="${wget} -nv" dltool_stdout="${wget} -nv -O -" return fi curl=$(which curl 2> /dev/null) if [ $? -eq 0 ]; then dltool_file="${curl} -OsS" dltool_stdout="${curl} -sS" return fi print_header print_bold "Neither 'wget' nor 'curl' are installed on this system. Please install at least one of them." print_footer exit 1; } download() { ${dltool_file} "$@" } download_stdout() { ${dltool_stdout} "$@" } print_header() { echo "${TERM_CLEAR}${TERM_RED} _ _ ___ __ _ (R)" echo "| | (_)_ _____ / __|___ _ _ / _(_)__ _" echo "| |__| \\ V / -_) (__/ _ \\ ' \\| _| / _\` | ${TERM_NORMAL}LiveConfig Installer v${INST_VERSION}${TERM_RED}" echo "|____|_|\\_/\\___|\\___\\___/_||_|_| |_\\__, |_____________________________________" echo " |___/${TERM_NORMAL}\n" } print_footer() { echo "${TERM_RED}______________________________________________________________________________${TERM_NORMAL}\n" } print_bold() { echo ${TERM_BOLD}$( translate "$1" )${TERM_NORMAL} } print_translated() { echo $( translate "$1" ) } distro_unknown() { print_header print_bold "Unfortunately, your operating system distribution is not supported by this script." echo print_bold "Please contact support@liveconfig.com for any further questions." print_footer exit 1 } detect_distro() { if [ -f /etc/debian_version ]; then distro="deb" elif [ -f /etc/redhat-release ]; then distro="rpm" fi } translate() { key="$1" case $LANG in de_DE*) case $key in "([y]es or [N]o):") retval="([j]a/[y]es oder [N]ein):" ;; "Adding LiveConfig repository...") retval="Füge LiveConfig-Repository hinzu..." ;; "Failed to install required packages") retval="Installation der benötigten Pakete fehlgeschlagen" ;; "Import of apt key failed!") retval="Import des APT-Keys fehlgeschlagen!" ;; "Installation of LiveConfig failed!") retval="Installation von LiveConfig fehlgeschlagen!" ;; "Installing LiveConfig 3...") retval="Installiere LiveConfig..." ;; "Installing on CentOS system") retval="Installiere auf CentOS System" ;; "Installing on Debian/Ubuntu system") retval="Installiere auf Debian/Ubuntu System" ;; "Installing on openSUSE system") retval="Installiere auf openSUSE System" ;; "LiveConfig 3 already installed!") retval="LiveConfig ist bereits installiert!" ;; "LiveConfig 3 successfully installed.") retval="LiveConfig erfolgreich installiert." ;; "Neither 'wget' nor 'curl' are installed on this system. Please install at least one of them.") retval="Weder 'wget' noch 'curl' sind auf diesem System installiert. Bitte installieren Sie zumindest eines davon." ;; "Please contact support@liveconfig.com for any further questions.") retval="Bei Fragen wenden Sie sich bitte an support@liveconfig.com" ;; "This script needs to be run as root.") retval="Dieses Script muss mit dem root-Benutzer ausgeführt werden." ;; "Unfortunately, your operating system distribution is not supported by this script.") retval="Leider wird Ihre Betriebssystem-Distribution nicht von diesem Script unterstützt." ;; "Please select the services to be installed:") retval="Bitte wählen Sie die zu installierenden Services aus:" ;; "Install Web Server") retval="Installiere Webserver" ;; "Install Mail Server") retval="Installiere Mailserver" ;; "Install Database Server") retval="Installiere Datenbank-Server" ;; "Install DNS Server") retval="Installiere DNS-Server" ;; "Service selection") retval="Service Auswahl" ;; "No service selected for installation") retval="Keine Services zur installation ausgewählt" ;; "It looks like /sbin and /usr/sbin are not in your PATH.") retval="Scheinbar sind /sbin und /usr/sbin nicht in Ihrem PATH." ;; "Please use 'sudo' or start your root shell with 'su -'.") retval="Bitte verwenden Sie 'sudo' oder starten Sie die root-Shell mit 'su -'." ;; *) retval=$key;; esac ;; *) retval=$key;; esac echo "$retval" } ## # Deb ## deb_enable_http2() { if [ ! -f /usr/lib/apache2/modules/mod_http2.so ] || [ -f /etc/apache2/mods-enabled/http2.load ]; then # mod_http2 not available or already enabled return 0 fi # switch MPM from prefork to event: if [ -f /etc/apache2/mods-enabled/mpm_prefork.load ] || [ -f /etc/apache2/mods-enabled/mpm_worker.load ]; then [ -f /etc/apache2/mods-enabled/mpm_prefork.load ] && /usr/sbin/a2dismod mpm_prefork [ -f /etc/apache2/mods-enabled/mpm_worker.load ] && /usr/sbin/a2dismod mpm_worker /usr/sbin/a2enmod mpm_event fi # enable HTTP/2 /usr/sbin/a2enmod http2 } install_deb_web() { print_bold "Installing web server packages..." PKG_LIST="quota bzip2 unzip zip apache2 apache2-suexec-pristine libapache2-mod-fcgid \ php-cgi php-cli php-fpm php-curl php-gd php-imagick php-mbstring php-mysql php-sqlite3 php-xml \ imagemagick proftpd-basic" DEB_VERSION=$(lsb_release -cs) if [ "${DEB_VERSION}" = "trixie" ]; then PKG_LIST="${PKG_LIST} awstats" else PKG_LIST="${PKG_LIST} webalizer php-imap" fi LANG=C DEBIAN_FRONTEND=noninteractive apt -qy -o APT::Install-Recommends=no install ${PKG_LIST} if [ $? -ne 0 ]; then print_bold "Installation of web server packages failed!" print_footer exit 7 fi # now do configure some apache settings # enable some apache modules after installation: if [ -x /usr/sbin/a2enmod ]; then /usr/sbin/a2enmod actions cgid include proxy_http rewrite ssl suexec [ -f /usr/lib/apache2/modules/mod_proxy_fcgi.so ] && /usr/sbin/a2enmod proxy_fcgi deb_enable_http2 /usr/sbin/a2dismod status fi # set "ServerTokens" and "TraceEnable" to safer values if [ -f /etc/apache2/conf.d/security ]; then sed -i -e "s/^ServerTokens .*/ServerTokens Prod/" \ -e "s/^TraceEnable On/TraceEnable Off/i" \ /etc/apache2/conf.d/security fi if [ -f /etc/apache2/conf-available/security.conf ]; then sed -i -e "s/^ServerTokens .*/ServerTokens Prod/" \ -e "s/^TraceEnable On/TraceEnable Off/i" \ /etc/apache2/conf-available/security.conf fi # restart Apache service apache2 restart print_bold "Web server packages successfully installed and configured!" } install_deb_mail() { print_bold "Installing mail server packages..." LANG=C DEBIAN_FRONTEND=noninteractive apt -qy -o APT::Install-Recommends=no install \ postfix dovecot-imapd dovecot-pop3d dovecot-sieve opendkim postgrey \ lc-postsrsd if [ $? -ne 0 ]; then print_bold "Installation of mail server packages failed!" print_footer exit 7 fi # try to install spamd (Debian >= 12) LANG=C DEBIAN_FRONTEND=noninteractive apt show -q spamd 1>/dev/null 2>&1 && \ apt -qy -o APT::Install-Recommends=no install spamd # only if at least 3.5 GB RAM is available: install ClamAV if [ -n "${RAM}" -a ${RAM} -ge 3670016 ]; then LANG=C DEBIAN_FRONTEND=noninteractive apt -qy -o APT::Install-Recommends=no install \ clamav-daemon clamav-freshclam clamav-milter if [ $? -ne 0 ]; then print_bold "Installation of ClamAV packages failed!" fi else print_bold "Skipped installation of ClamAV packages due to low memory (<3.5GB)." fi print_bold "Mail server packages successfully installed and configured!" } install_deb_db() { print_bold "Installing database server packages..." LANG=C DEBIAN_FRONTEND=noninteractive apt -qy -o APT::Install-Recommends=no install \ mariadb-server if [ $? -ne 0 ]; then print_bold "Installation of database server packages failed!" print_footer exit 7 fi print_bold "Database server packages successfully installed and configured!" } install_deb_dns() { print_bold "Installing DNS server packages..." LANG=C DEBIAN_FRONTEND=noninteractive apt -qy -o APT::Install-Recommends=no install \ bind9 if [ $? -ne 0 ]; then print_bold "Installation of DNS server packages failed!" print_footer exit 7 fi print_bold "DNS server packages successfully installed and configured!" } install_deb() { if [ -z "`which ldconfig`" ]; then print_bold "It looks like /sbin and /usr/sbin are not in your PATH." print_bold "Please use 'sudo' or start your root shell with 'su -'." exit 1 fi print_header print_bold "Installing on Debian/Ubuntu system" # install required packages apt update && apt-get install -qy ca-certificates gnupg 1>/dev/null 2>&1 if [ $? -ne 0 ]; then print_bold "Failed to install required packages" print_footer exit 2 fi dpkg -s liveconfig-keyring > /dev/null 2>&1 if [ $? -ne 0 ]; then print_translated "Adding LiveConfig repository..." cd /root download https://www.liveconfig.com/liveconfig-keyring.deb dpkg -i liveconfig-keyring.deb if [ $? -ne 0 ]; then print_bold "Installation of package 'liveconfig-keyring' failed!" print_footer exit 3 fi echo "Patching liveconfig.sources to use LiveConfig 3 from test repository" sed -i -e 's/repo.liveconfig.com\/debian\//repo.liveconfig.com\/debian-test\//' /etc/apt/sources.list.d/liveconfig.sources if [ $? -ne 0 ]; then print_bold "Patching of 'liveconfig.sources' failed, please check manually." print_footer exit 4 fi rm liveconfig-keyring.deb fi apt update if [ $? -ne 0 ]; then print_bold "apt update failed!" print_footer exit 5 fi if [ "$selected" = "" ]; then selected=$(checklist "$(translate "Please select the services to be installed:")" 12 60 4 \ "WEB" "$(translate "Install Web Server")" OFF \ "MAIL" "$(translate "Install Mail Server")" OFF \ "DB" "$(translate "Install Database Server")" OFF \ "DNS" "$(translate "Install DNS Server")" OFF \ "--title" "$(translate "Service selection")") fi for s in $selected; do case "$(echo $s | sed -e 's/^"//' -e 's/"$//')" in WEB) install_deb_web ;; MAIL) install_deb_mail ;; DB) install_deb_db ;; DNS) install_deb_dns ;; *) echo "Unknown service selected!" ;; esac done dpkg -s liveconfig3 > /dev/null 2>&1 if [ $? -ne 0 ]; then # Install LiveConfig print_bold "Installing LiveConfig 3..." apt-get install -qy liveconfig3 if [ $? -ne 0 ]; then print_bold "Installation of LiveConfig 3 failed!" print_footer exit 6 fi print_bold "LiveConfig 3 successfully installed." else print_bold "LiveConfig 3 already installed." fi } ## # /Deb ## ## # RPM ## install_rpm_web() { print_bold "Installing web server packages..." dnf install -y quota bzip2 unzip httpd mod_ssl mod_fcgid \ php php-cli php-fpm php-gd php-mbstring php-mysqlnd php-pear php-pdo php-soap php-xml \ vsftpd libdb-utils \ awstats if [ $? -ne 0 ]; then print_bold "Installation of web server packages failed!" print_footer exit 7 fi # enable services systemctl enable httpd.service systemctl enable vsftpd.service print_bold "Web server packages successfully installed and configured!" } install_rpm_mail() { print_bold "Installing mail server packages..." dnf install -y postfix dovecot dovecot-pigeonhole spamassassin \ opendkim postgrey # ToDo: PostSRSd 2.x ! if [ $? -ne 0 ]; then print_bold "Installation of mail server packages failed!" print_footer exit 7 fi # only if at least 3.5 GB RAM is available: install ClamAV if [ -n "${RAM}" -a ${RAM} -ge 3670016 ]; then dnf install -y clamd clamav-freshclam clamav-milter if [ $? -ne 0 ]; then print_bold "Installation of ClamAV packages failed!" else # do some basic configuration for ClamAV sed -i -e "s/#LocalSocket /LocalSocket /" /etc/clamd.d/scan.conf # run freshclam to fetch initial signatures freshclam # enable services systemctl enable clamd@scan.service systemctl enable clamav-freshclam.service systemctl enable clamav-milter.service systemctl start clamd@scan.service systemctl start clamav-freshclam.service fi else print_bold "Skipped installation of ClamAV packages due to low memory (<3.5GB)." fi # enable services systemctl enable postfix.service systemctl enable dovecot.service systemctl enable spamassassin.service print_bold "Mail server packages successfully installed and configured!" } install_rpm_db() { print_bold "Installing database server packages..." dnf install -y mariadb mariadb-server if [ $? -ne 0 ]; then print_bold "Installation of database server packages failed!" print_footer exit 7 fi # patch [client] section in MariaDB config: if ! grep -q '^socket=' /etc/my.cnf.d/client.cnf; then sed -i -e 's/^\(\[client\]\)/\1\nsocket=\/var\/lib\/mysql\/mysql.sock/i' \ /etc/my.cnf.d/client.cnf fi # enable services systemctl enable mariadb.service systemctl start mariadb.service print_bold "Database server packages successfully installed and configured!" } install_rpm_dns() { print_bold "Installing DNS server packages..." dnf install -y bind if [ $? -ne 0 ]; then print_bold "Installation of DNS server packages failed!" print_footer exit 7 fi # enable services systemctl enable named.service systemctl start named.service print_bold "DNS server packages successfully installed and configured!" } install_rpm() { print_header print_bold "Installing on RPM-based system" dnf check 1>/dev/null 2>/dev/null if [ $? -ne 0 ]; then askYesNo "dnf check failed - try to reinstall missing/broken packages?" if [ $? -eq 1 ]; then PKGLIST=`LANG=C dnf check 2>/dev/null | grep 'has missing requires' | cut -d ' ' -f 1 | sort | uniq | tr '\n' ' '` if [ -n "$PKGLIST" ]; then print_translated "Reinstalling packages: " echo $PKGLIST dnf -y reinstall $PKGLIST else print_translated "No missing packages found. Please run 'dnf check'." exit 1 fi else print_translated "aborting." exit 1 fi fi print_translated "Checking/installing required packages..." dnf install -y ca-certificates epel-release # install_yum nss-pem if [ ! -f /etc/yum.repos.d/liveconfig.repo ]; then dnf config-manager --add-repo http://repo.liveconfig.com/rpm-test/liveconfig.repo if [ $? -ne 0 ]; then print_translated "Import of LiveConfig RPM repository failed!" print_footer exit 2 fi fi # enable CRB dnf config-manager --set-enabled crb if [ $? -ne 0 ]; then print_translated "enabling CRB failed!" print_footer exit 3 fi print_translated "Updating repository & packages" dnf -y update if [ $? -ne 0 ]; then print_translated "dnf update failed!" print_footer exit 4 fi if [ "$selected" = "" ]; then selected=$(checklist "$(translate "Please select the services to be installed:")" 12 60 4 \ "WEB" "$(translate "Install Web Server")" OFF \ "MAIL" "$(translate "Install Mail Server")" OFF \ "DB" "$(translate "Install Database Server")" OFF \ "DNS" "$(translate "Install DNS Server")" OFF \ "--title" "$(translate "Service selection")") fi for s in $selected; do case "$(echo $s | sed -e 's/^"//' -e 's/"$//')" in WEB) install_rpm_web ;; MAIL) install_rpm_mail ;; DB) install_rpm_db ;; DNS) install_rpm_dns ;; *) echo "Unknown service selected!" ;; esac done dnf list installed liveconfig3 > /dev/null 2>&1 if [ $? -ne 0 ]; then # Install LiveConfig print_bold "Installing LiveConfig 3..." dnf -y -q install liveconfig3 if [ $? -ne 0 ]; then print_bold "Installation of LiveConfig 3 failed!" print_footer exit 5 fi print_bold "LiveConfig 3 successfully installed." else print_bold "LiveConfig 3 already installed." fi } ## # /RPM ## check_requirements detect_distro case ${distro} in deb) install_deb ;; rpm) install_rpm ;; *) distro_unknown ;; esac