mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2026-03-04 15:54:48 +01:00
Move system-setup directory to tests
Set the hosts FQDN instead of adding hosts entry for private ip
This commit is contained in:
@@ -1,234 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# setup MiaB-LDAP with a remote Nextcloud running on the same
|
||||
# host under Docker exposed as localhost:8000
|
||||
#
|
||||
# to use:
|
||||
# on a fresh Ubuntu:
|
||||
# 1. checkout or copy the MiaB-LDAP code to ~/mailinabox
|
||||
# 2. cd ~/mailinabox
|
||||
# 3. sudo tests/assets/system-setup/remote-nextcloud-docker.sh
|
||||
#
|
||||
# when complete you should have a working MiaB-LDAP and Nextcloud
|
||||
#
|
||||
# You can access MiaB-LDAP using your browser to the Ubuntu system in
|
||||
# the normal way, (eg: https://<ubuntu-box>/admin).
|
||||
#
|
||||
# Nextcloud is running under Docker on the ubuntu box, so to access it
|
||||
# you'll first need to ssh into the ubuntu box with port-forrwarding
|
||||
# enabled.
|
||||
#
|
||||
# eg: ssh -L 8000:localhost:8000 user@<ubuntu-box>
|
||||
#
|
||||
# Then, in your browser visit http://localhost:8000/.
|
||||
#
|
||||
# See setup-defaults.sh for usernames and passwords.
|
||||
#
|
||||
|
||||
|
||||
usage() {
|
||||
echo "Usage: $(basename "$0") [\"before-miab-install\"|\"miab-install\"|\"after-miab-install\"]"
|
||||
echo "Install MiaB-LDAP and a remote Nextcloud running under docker exposed as localhost:8000"
|
||||
echo "With no arguments, all three stages are run."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# ensure working directory
|
||||
if [ ! -d "tests/assets/system-setup" ]; then
|
||||
echo "This script must be run from the MiaB root directory"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# load helper scripts
|
||||
. "tests/assets/system-setup/setup-defaults.sh" \
|
||||
|| die "Could not load setup-defaults"
|
||||
. "tests/assets/system-setup/setup-funcs.sh" \
|
||||
|| die "Could not load setup-funcs"
|
||||
|
||||
# ensure running as root
|
||||
if [ "$EUID" != "0" ]; then
|
||||
die "This script must be run as root (sudo)"
|
||||
fi
|
||||
|
||||
|
||||
|
||||
before_miab_install() {
|
||||
H1 "BEFORE MIAB-LDAP INSTALL"
|
||||
|
||||
# create /etc/hosts entry for PRIVATE_IP
|
||||
H2 "Update /etc/hosts"
|
||||
update_hosts_for_private_ip || die "Could not update /etc/hosts"
|
||||
|
||||
# update package lists before installing anything
|
||||
H2 "apt-get update"
|
||||
apt-get update -qq || die "apt-get update failed!"
|
||||
|
||||
# install prerequisites
|
||||
H2 "QA prerequisites"
|
||||
install_qa_prerequisites || die "Error installing QA prerequisites"
|
||||
|
||||
# update system time (ignore errors)
|
||||
H2 "Set system time"
|
||||
update_system_time
|
||||
|
||||
# copy in pre-built MiaB-LDAP ssl files
|
||||
# 1. avoid the lengthy generation of DH params
|
||||
H2 "Install QA pre-built"
|
||||
mkdir -p $STORAGE_ROOT/ssl || die "Unable to create $STORAGE_ROOT/ssl"
|
||||
cp tests/assets/ssl/dh2048.pem $STORAGE_ROOT/ssl \
|
||||
|| die "Copy dhparams failed"
|
||||
|
||||
# create miab_ldap.conf to specify what the Nextcloud LDAP service
|
||||
# account password will be to avoid a random one created by start.sh
|
||||
mkdir -p $STORAGE_ROOT/ldap
|
||||
[ -e $STORAGE_ROOT/ldap/miab_ldap.conf ] && \
|
||||
echo "Warning: exists: $STORAGE_ROOT/ldap/miab_ldap.conf" 1>&2
|
||||
echo "LDAP_NEXTCLOUD_PASSWORD=\"$LDAP_NEXTCLOUD_PASSWORD\"" >> $STORAGE_ROOT/ldap/miab_ldap.conf
|
||||
|
||||
# enable the remote Nextcloud setup mod, which tells MiaB-LDAP to use
|
||||
# the remote Nextcloud for calendar and contacts instead of the
|
||||
# MiaB-installed one
|
||||
H2 "Create setup/mods.d/remote-nextcloud.sh symbolic link"
|
||||
if [ ! -e "setup/mods.d/remote-nextcloud.sh" ]; then
|
||||
ln -s "../mods.available/remote-nextcloud.sh" "setup/mods.d/remote-nextcloud.sh" || die "Could not create remote-nextcloud.sh symlink"
|
||||
fi
|
||||
|
||||
# install Docker
|
||||
H2 "Install Docker"
|
||||
install_docker || die "Could not install Docker! ($?)"
|
||||
}
|
||||
|
||||
|
||||
miab_install() {
|
||||
H1 "MIAB-LDAP INSTALL"
|
||||
if ! setup/start.sh; then
|
||||
H1 "OUTPUT OF SELECT FILES"
|
||||
dump_log "/var/log/syslog" 100
|
||||
dump_conf_files "$TRAVIS"
|
||||
H2; H2 "End"; H2
|
||||
die "setup/start.sh failed!"
|
||||
fi
|
||||
H1 "OUTPUT OF SELECT FILES"
|
||||
dump_conf_files "$TRAVIS"
|
||||
H2; H2 "End"; H2
|
||||
}
|
||||
|
||||
|
||||
after_miab_install() {
|
||||
H1 "AFTER MIAB-LDAP INSTALL"
|
||||
|
||||
. /etc/mailinabox.conf || die "Could not load /etc/mailinabox.conf"
|
||||
|
||||
# TRAVIS: fix nsd startup problem
|
||||
#H2 "Apply Travis-CI nsd fix"
|
||||
#travis_fix_nsd || die "Could not fix NSD startup issue for TRAVIS-CI"
|
||||
|
||||
# run Nextcloud docker image
|
||||
H2 "Start Nextcloud docker container"
|
||||
docker run -d --name NC -p 8000:80 \
|
||||
--env SQLITE_DATABASE=nextclouddb.sqlite \
|
||||
--env NEXTCLOUD_ADMIN_USER="$NC_ADMIN_USER" \
|
||||
--env NEXTCLOUD_ADMIN_PASSWORD="$NC_ADMIN_PASSWORD" \
|
||||
--env NEXTCLOUD_TRUSTED_DOMAINS="127.0.0.1 ::1" \
|
||||
--env NEXTCLOUD_UPDATE=1 \
|
||||
--env SMTP_HOST="$PRIMARY_HOSTNAME" \
|
||||
--env SMTP_SECURE="tls" \
|
||||
--env SMTP_PORT=587 \
|
||||
--env SMTP_AUTHTYPE="LOGIN" \
|
||||
--env SMTP_NAME="$EMAIL_ADDR" \
|
||||
--env SMTP_PASSWORD="$EMAIL_PW" \
|
||||
--env SMTP_FROM_ADDRESS="$(awk -F@ '{print $1}' <<< "$EMAIL_ADDR")" \
|
||||
--env MAIL_DOMAIN="$(awk -F@ '{print $2}' <<< "$EMAIL_ADDR")" \
|
||||
nextcloud:latest \
|
||||
|| die "Docker run failed!"
|
||||
|
||||
H2 "docker: Update /etc/hosts so it can find MiaB-LDAP by name"
|
||||
echo "$PRIVATE_IP $PRIMARY_HOSTNAME" | \
|
||||
docker exec -i NC bash -c 'cat >>/etc/hosts' \
|
||||
|| die "docker: could not update /etc/hosts"
|
||||
|
||||
# apt-get update
|
||||
H2 "docker: apt-get update"
|
||||
docker exec NC apt-get update || die "docker: apt-get update failed"
|
||||
|
||||
# allow LDAP access from docker image
|
||||
H2 "Allow ldaps through firewall so Nextcloud can perform LDAP searches"
|
||||
ufw allow ldaps || die "Unable to modify firewall to permit ldaps"
|
||||
|
||||
# add MiaB-LDAP's ca_certificate.pem to docker's trusted cert list
|
||||
H2 "docker: update trusted CA list"
|
||||
docker cp \
|
||||
$STORAGE_ROOT/ssl/ca_certificate.pem \
|
||||
NC:/usr/local/share/ca-certificates/mailinabox.crt \
|
||||
|| die "docker: copy ca_certificate.pem failed"
|
||||
docker exec NC update-ca-certificates \
|
||||
|| die "docker: update-ca-certificates failed"
|
||||
|
||||
# wait for Nextcloud installation to complete
|
||||
H2 "Wait for Nextcloud installation to complete"
|
||||
echo -n "Waiting ..."
|
||||
local count=0
|
||||
while true; do
|
||||
if [ $count -ge 10 ]; then
|
||||
echo "FAILED"
|
||||
die "Giving up"
|
||||
fi
|
||||
sleep 6
|
||||
let count+=1
|
||||
if [ $(docker exec NC php -n -r "include 'config/config.php'; print \$CONFIG['installed']?'true':'false';") == "true" ]; then
|
||||
echo "ok"
|
||||
break
|
||||
fi
|
||||
echo -n "${count}..."
|
||||
done
|
||||
|
||||
# install and enable Nextcloud and apps
|
||||
H2 "docker: install Nextcloud calendar app"
|
||||
docker exec -u www-data NC ./occ app:install calendar \
|
||||
|| die "docker: installing calendar app failed"
|
||||
H2 "docker: install Nextcloud contacts app"
|
||||
docker exec -u www-data NC ./occ app:install contacts \
|
||||
|| die "docker: installing contacts app failed"
|
||||
H2 "docker: enable user_ldap"
|
||||
docker exec -u www-data NC ./occ app:enable user_ldap \
|
||||
|| die "docker: enabling user_ldap failed"
|
||||
|
||||
# integrate Nextcloud with MiaB-LDAP
|
||||
H2 "docker: integrate Nextcloud with MiaB-LDAP"
|
||||
docker cp setup/mods.available/remote-nextcloud-use-miab.sh NC:/tmp \
|
||||
|| die "docker: cp remote-nextcloud-use-miab.sh failed"
|
||||
docker exec NC /tmp/remote-nextcloud-use-miab.sh \
|
||||
. \
|
||||
"$NC_ADMIN_USER" \
|
||||
"$NC_ADMIN_PASSWORD" \
|
||||
"$PRIMARY_HOSTNAME" \
|
||||
"$LDAP_NEXTCLOUD_PASSWORD" \
|
||||
|| die "docker: error running remote-nextcloud-use-miab.sh"
|
||||
}
|
||||
|
||||
|
||||
|
||||
#
|
||||
# process command line
|
||||
#
|
||||
|
||||
case "$1" in
|
||||
before-miab-install )
|
||||
before_miab_install
|
||||
;;
|
||||
after-miab-install )
|
||||
after_miab_install
|
||||
;;
|
||||
miab-install )
|
||||
miab_install
|
||||
;;
|
||||
"" )
|
||||
before_miab_install
|
||||
miab_install
|
||||
after_miab_install
|
||||
;;
|
||||
* )
|
||||
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
@@ -1,33 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Used by MiaB-LDAP setup/start.sh
|
||||
export NONINTERACTIVE=${NONINTERACTIVE:-1}
|
||||
export SKIP_NETWORK_CHECKS=${SKIP_NETWORK_CHECKS:-1}
|
||||
export STORAGE_USER="${STORAGE_USER:-user-data}"
|
||||
export STORAGE_ROOT="${STORAGE_ROOT:-/home/$STORAGE_USER}"
|
||||
export EMAIL_ADDR="${EMAIL_ADDR:-qa@abc.com}"
|
||||
export EMAIL_PW="${EMAIL_PW:-Test_1234}"
|
||||
export PUBLIC_IP="${PUBLIC_IP:-$(source setup/functions.sh; get_default_privateip 4)}"
|
||||
|
||||
if [ "$TRAVIS" == "true" ]; then
|
||||
export PRIMARY_HOSTNAME=${PRIMARY_HOSTNAME:-box.abc.com}
|
||||
elif [ -z "$PRIMARY_HOSTNAME" ]; then
|
||||
export PRIMARY_HOSTNAME=${PRIMARY_HOSTNAME:-$(hostname --fqdn || hostname)}
|
||||
fi
|
||||
|
||||
|
||||
# Placing this var in STORAGE_ROOT/ldap/miab_ldap.conf before running
|
||||
# setup/start.sh will avoid a random password from being used for the
|
||||
# Nextcloud LDAP service account
|
||||
export LDAP_NEXTCLOUD_PASSWORD=${LDAP_NEXTCLOUD_PASSWORD:-Test_LDAP_1234}
|
||||
|
||||
# Used by setup/mods.available/remote-nextcloud.sh. These define to
|
||||
# MiaB-LDAP the remote Nextcloud that serves calendar and contacts
|
||||
export NC_PROTO=${NC_PROTO:-http}
|
||||
export NC_HOST=${NC_HOST:-127.0.0.1}
|
||||
export NC_PORT=${NC_PORT:-8000}
|
||||
export NC_PREFIX=${NC_PREFIX:-/}
|
||||
|
||||
# For setup scripts that are installing a remote Nextcloud
|
||||
export NC_ADMIN_USER="${NC_ADMIN_USER:-admin}"
|
||||
export NC_ADMIN_PASSWORD="${NC_ADMIN_PASSWORD:-Test_1234}"
|
||||
@@ -1,169 +0,0 @@
|
||||
|
||||
|
||||
die() {
|
||||
local msg="$1"
|
||||
echo "$msg" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
H1() {
|
||||
local msg="$1"
|
||||
echo "----------------------------------------------"
|
||||
if [ ! -z "$msg" ]; then
|
||||
echo " $msg"
|
||||
echo "----------------------------------------------"
|
||||
fi
|
||||
}
|
||||
|
||||
H2() {
|
||||
local msg="$1"
|
||||
if [ -z "$msg" ]; then
|
||||
echo "***"
|
||||
else
|
||||
echo "*** $msg ***"
|
||||
fi
|
||||
}
|
||||
|
||||
dump_log() {
|
||||
local log_file="$1"
|
||||
local lines="$2"
|
||||
local title="DUMP OF $log_file"
|
||||
echo ""
|
||||
echo "--------"
|
||||
echo -n "-------- $log_file"
|
||||
if [ ! -z "$lines" ]; then
|
||||
echo " (last $line lines)"
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
echo "--------"
|
||||
|
||||
if [ ! -z "$lines" ]; then
|
||||
tail -$lines "$log_file"
|
||||
else
|
||||
cat "$log_file"
|
||||
fi
|
||||
}
|
||||
|
||||
is_true() {
|
||||
if [ "$1" == "true" \
|
||||
-o "$1" == "TRUE" \
|
||||
-o "$1" == "True" \
|
||||
-o "$1" == "yes" \
|
||||
-o "$1" == "YES" \
|
||||
-o "$1" == "Yes" \
|
||||
-o "$1" == "1" ]
|
||||
then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
dump_conf_files() {
|
||||
local skip
|
||||
if [ $# -eq 0 ]; then
|
||||
skip="false"
|
||||
else
|
||||
skip="true"
|
||||
for item; do
|
||||
if is_true "$item"; then
|
||||
skip="false"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
if [ "$skip" == "false" ]; then
|
||||
dump_log "/etc/mailinabox.conf"
|
||||
dump_log "/etc/hosts"
|
||||
dump_log "/etc/nsd/nsd.conf"
|
||||
dump_log "/etc/postfix/main.cf"
|
||||
fi
|
||||
}
|
||||
|
||||
install_qa_prerequisites() {
|
||||
# python3-dnspython: is used by the python scripts in 'tests' and is
|
||||
# not installed by setup
|
||||
# ntpdate: is used by this script
|
||||
apt-get install -y \
|
||||
ntpdate \
|
||||
python3-dnspython
|
||||
}
|
||||
|
||||
update_system_time() {
|
||||
ntpdate -s ntp.ubuntu.com && echo "System time updated"
|
||||
}
|
||||
|
||||
update_hosts() {
|
||||
local host="$1"
|
||||
shift
|
||||
local ip
|
||||
for ip; do
|
||||
if [ ! -z "$ip" ]; then
|
||||
local line="$ip $host"
|
||||
if ! grep -F "$line" /etc/hosts 1>/dev/null; then
|
||||
echo "$line" >>/etc/hosts
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
update_hosts_for_private_ip() {
|
||||
# create /etc/hosts entry for PRIVATE_IP and PRIVATE_IPV6
|
||||
# PRIMARY_HOSTNAME must already be set
|
||||
local ip4=$(source setup/functions.sh; get_default_privateip 4)
|
||||
local ip6=$(source setup/functions.sh; get_default_privateip 6)
|
||||
[ -z "$ip4" -a -z "$ip6" ] && return 1
|
||||
[ -z "$ip6" ] && ip6="::1"
|
||||
update_hosts "$PRIMARY_HOSTNAME" "$ip4" "$ip6" || return 1
|
||||
}
|
||||
|
||||
install_docker() {
|
||||
if [ -x /usr/bin/docker ]; then
|
||||
echo "Docker already installed"
|
||||
return 0
|
||||
fi
|
||||
|
||||
apt-get install -y \
|
||||
apt-transport-https \
|
||||
ca-certificates \
|
||||
curl \
|
||||
gnupg-agent \
|
||||
software-properties-common \
|
||||
|| return 1
|
||||
|
||||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - \
|
||||
|| return 2
|
||||
|
||||
apt-key fingerprint 0EBFCD88 || return 3
|
||||
|
||||
add-apt-repository -y --update "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" || return 4
|
||||
|
||||
apt-get install -y \
|
||||
docker-ce \
|
||||
docker-ce-cli \
|
||||
containerd.io \
|
||||
|| return 5
|
||||
}
|
||||
|
||||
|
||||
travis_fix_nsd() {
|
||||
if [ "$TRAVIS" != "true" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
# nsd won't start on Travis-CI without the changes below: ip6 off and
|
||||
# control-enable set to no. Even though the nsd docs say the
|
||||
# default value for control-enable is no, running "nsd-checkconf -o
|
||||
# control-enable /etc/nsd/nsd.conf" returns "yes", so we explicitly
|
||||
# set it here.
|
||||
#
|
||||
# we're assuming that the "ip-address" line is the last line in the
|
||||
# "server" section of nsd.conf. if this generated file output
|
||||
# changes, the sed command below may need to be adjusted.
|
||||
sed -i 's/ip-address\(.\)\(.*\)/ip-address\1\2\n do-ip4\1 yes\n do-ip6\1 no\n verbosity\1 3\nremote-control\1\n control-enable\1 no/' /etc/nsd/nsd.conf || return 1
|
||||
cat /etc/nsd/nsd.conf
|
||||
systemctl reset-failed nsd.service || return 2
|
||||
systemctl restart nsd.service || return 3
|
||||
}
|
||||
Reference in New Issue
Block a user