1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2026-03-04 15:54:48 +01:00

Improve formatting of setup output

This commit is contained in:
downtownallday
2022-03-06 10:53:00 -05:00
parent b7c7187fa5
commit a6c819eea0
3 changed files with 62 additions and 13 deletions

View File

@@ -49,11 +49,18 @@ dump_file_if_exists() {
}
update_system_time() {
if [ ! -x /usr/sbin/ntpdate ]; then
wait_for_apt
apt-get install -y -qq ntpdate || return 1
if systemctl is-active --quiet ntp; then
# ntpd is running and running ntpdate will fail with "the NTP
# socket is in use"
echo "ntpd is already running, not updating time"
return 0
fi
ntpdate -s ntp.ubuntu.com && echo "System time updated"
if [ ! -x /usr/sbin/ntpdate ]; then
echo "Installing ntpdate"
wait_for_apt
exec_no_output apt-get install -y ntpdate || return 1
fi
ntpdate ntp.ubuntu.com
}
set_system_hostname() {
@@ -110,3 +117,26 @@ install_docker() {
|| return 5
}
exec_no_output() {
# This function hides the output of a command unless the command
# fails
local of=$(mktemp)
"$@" &> "$of"
local code=$?
if [ $code -ne 0 ]; then
echo "" 1>&2
echo "FAILED: $@" 1>&2
echo "-----------------------------------------" 1>&2
echo "Return code: $code" 1>&2
echo "Output:" 1>&2
cat "$of" 1>&2
echo "-----------------------------------------" 1>&2
fi
# Remove temporary file.
rm -f "$of"
[ $code -ne 0 ] && return 1
return 0
}