1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2025-04-04 00:17:06 +00:00

Add support for non-interactive install

Centralize all scripts into 'ehdd'
This commit is contained in:
downtownallday 2020-06-22 10:03:21 -04:00
parent 7137fb6556
commit 38d0bcff22
7 changed files with 27 additions and 29 deletions

View File

@ -1,6 +1,6 @@
#!/bin/bash
source "setup/ehdd/ehdd_funcs.sh" || exit 1
source "ehdd/ehdd_funcs.sh" || exit 1
if [ "$1" == "" ]; then
echo "usage: $0 <size-in-gb>"
@ -26,14 +26,14 @@ if [ ! -e "$EHDD_IMG" ]; then
dd if=/dev/zero of="$EHDD_IMG" bs=1M count=$count || exit 1
loop=$(find_unused_loop)
losetup $loop "$EHDD_IMG" || exit 1
if ! cryptsetup luksFormat -i 15000 $loop; then
if ! cryptsetup luksFormat $(keyfile_option) --batch-mode -i 15000 $loop; then
losetup -d $loop
rm -f "$EHDD_IMG"
exit 1
fi
echo ""
echo "NOTE: You will need to reenter your drive encryption password a number of times"
cryptsetup luksOpen $loop $EHDD_LUKS_NAME # map device to /dev/mapper/NAME
echo "NOTE: You will need to reenter your drive encryption password"
cryptsetup luksOpen $(keyfile_option) $loop $EHDD_LUKS_NAME # map device to /dev/mapper/NAME
mke2fs -j /dev/mapper/$EHDD_LUKS_NAME
cryptsetup luksClose $EHDD_LUKS_NAME
losetup -d $loop

View File

@ -18,3 +18,9 @@ find_unused_loop() {
find_inuse_loop() {
losetup -l | awk "\$6 == \"$EHDD_IMG\" { print \$1 }"
}
keyfile_option() {
if [ ! -z "$EHDD_KEYFILE" ]; then
echo "--key-file $EHDD_KEYFILE"
fi
}

View File

@ -1,6 +1,6 @@
#!/bin/bash
. "setup/ehdd/ehdd_funcs.sh" || exit 1
. "ehdd/ehdd_funcs.sh" || exit 1
if [ ! -e "$EHDD_IMG" ]; then
echo "Warning: ecrypted HDD not found at $EHDD_IMG, not mounting"
@ -15,7 +15,7 @@ fi
loop=$(find_unused_loop)
losetup $loop "$EHDD_IMG" || exit 1
# map device to /dev/mapper/NAME
cryptsetup luksOpen $loop $EHDD_LUKS_NAME
cryptsetup luksOpen $(keyfile_option) $loop $EHDD_LUKS_NAME
code=$?
if [ $code -ne 0 ]; then
echo "luksOpen failed ($code) - is $EHDD_IMG luks formatted?"

View File

@ -1,6 +1,6 @@
#!/bin/bash
. "setup/ehdd/ehdd_funcs.sh" || exit 1
. "ehdd/ehdd_funcs.sh" || exit 1
if [ -e "$EHDD_IMG" ]; then
@ -20,22 +20,10 @@ if [ -e "$EHDD_IMG" ]; then
echo ""
echo "IMPORTANT:"
echo " Services have been disabled at startup because the encrypted HDD will"
echo " be unavailable. Run tools/startup.sh after a reboot."
echo " be unavailable. Run ehdd/startup.sh after a reboot."
fi
fi
# run local modifications
h=$(hostname --fqdn 2>/dev/null || hostname)
count=0
for d in local/mods.sh local/mods-${h}.sh; do
if [ -e $d ]; then
let count+=1
if ! ./$d; then
echo "Local modification script $d failed"
exit 1
fi
fi
done

View File

@ -1,5 +1,5 @@
#!/bin/bash
EHDD_IMG="$(setup/ehdd/create_hdd.sh -location)"
EHDD_IMG="$(ehdd/create_hdd.sh -location)"
[ -e /etc/mailinabox.conf ] && . /etc/mailinabox.conf
@ -11,17 +11,21 @@ if [ ! -e "$EHDD_IMG" -a ! -z "$STORAGE_ROOT" -a \
elif [ ! -e "$EHDD_IMG" ]; then
echo "Creating a new encrypted HDD."
echo -n "How big should it be? Enter a number in gigabytes: "
read gb
setup/ehdd/create_hdd.sh "$gb" || exit 1
if [ -z "${NONINTERACTIVE:-}" ]; then
echo -n "How big should it be? Enter a number in gigabytes: "
read gb
else
gb="${EHDD_GB:-5}"
fi
ehdd/create_hdd.sh "$gb" || exit 1
fi
if setup/ehdd/mount.sh; then
if ehdd/mount.sh; then
setup/start.sh $@
if [ $? -eq 0 ]; then
setup/ehdd/postinstall.sh || exit 1
ehdd/postinstall.sh || exit 1
else
echo "setup/start.sh failed"
fi

View File

@ -1,5 +1,5 @@
#!/bin/bash
setup/ehdd/mount.sh || exit 1
ehdd/mount.sh || exit 1
if [ -s /etc/mailinabox.conf ]; then
[ -x /usr/sbin/slapd ] && systemctl start slapd
@ -9,7 +9,7 @@ if [ -s /etc/mailinabox.conf ]; then
systemctl start nginx
systemctl start cron
#systemctl start nsd
systemctl link -f $HOME/mailinabox/conf/mailinabox.service
systemctl link -f $(pwd)/conf/mailinabox.service
systemctl start mailinabox
systemctl start fail2ban
fi

View File

@ -1,6 +1,6 @@
#!/bin/bash
. "setup/ehdd/ehdd_funcs.sh" || exit 1
. "ehdd/ehdd_funcs.sh" || exit 1
if ! mount | grep "$EHDD_MOUNTPOINT" >/dev/null; then
# not mounted