Use this code, populate the variables and run the script.
#!/bin/bash
#
# A Shell script to add grommunio files after initial system installation
#
# Copyright 2023 Walter Hofstaedtler
# SPDX-License-Identifier: AGPL-3.0-or-later
# Authors: Walter Hofstaedtler <walter@hofstaedtler.com>
#
# Credits:
# Most parts are stolen from grommunio-setup script
# Mike Williams added some code
#
# Notice:
# This script will destroy a current grommunio files installation!
#
# Variables to be set by the user of this script
#
# the domain for this server
DOMAIN=<DOMAIN>
#
# The FQDN for this server, if you uses mail.$DOAMIN no need to touch this variable
FQDN="mail.${DOMAIN}"
#
# Password for files admin
FILES_ADMIN_PASS="<PASSWORD>"
#
# Password for MariaDB connection
FILES_MYSQL_PASS="<PASSWORD>"
#
# The log file
LOGFILE="/root/grofiles_wh_setup.log"
#
# MariaDB hostname, in most cases "localhost" is sufficient
FILES_MYSQL_HOST="localhost"
#
# MariaDB user for grommunio files, leave as "grofiles"
FILES_MYSQL_USER="grofiles"
#
# MariaDB database for grommunio files, leave as "grofiles"
FILES_MYSQL_DB="grofiles"
# From here on, no code or variables need changing by the user of this script.
#
# Declare an error handler
# shellcheck disable=SC2317 # Don't warn about unreachable commands in this function
trapERR() {
ss=$? bc="$BASH_COMMAND" ln="$BASH_LINENO"
echo ">> Failing command is '$bc' on line $ln and status is $ss <<" >&2
exit "$ss"
}
# Write to log and screen
Write-MLog () {
LEVEL="???"
# prepare color and severity level
case $2 in
"red")
LEVEL="FAIL"
COL=1
;;
"green")
LEVEL="INFO"
COL=2
;;
"yellow")
LEVEL="WARN"
COL=3
;;
"cyan")
LEVEL="INFO"
COL=6
;;
"white")
LEVEL=" "
COL=7
;;
"none")
LEVEL=""
COL=7
;;
*)
LEVEL="UNKN"
COL=5
esac
[[ $2 != "none" ]] && echo "$(tput setaf $COL)$1 $(tput sgr 0)"
echo "$(date +"%d.%m.%Y %H:%M:%S") $LEVEL $1">>$LOGFILE
}
# Main starts here
# Arrange to call trapERR when an error is raised
trap trapERR ERR
# migration / sync code
Write-MLog "" white
Write-MLog "" white
Write-MLog "===========================================================================" none
Write-MLog "" white
Write-MLog "" white
Write-MLog "WARNING: " red
Write-MLog " Running this script will add grommunuio files to an existing grommunio server." yellow
Write-MLog " Please note, an existing grommunio files installation will be silently removed!" red
Write-MLog " If there is an existing grommunio files installation on this machine, all of this data will be lost!" red
Write-MLog "" white
#
# Ask the Admin - continue Y/N?
while true; do
# shellcheck disable=SC2162
read -p "Do you want to proceed? (y/n) " yn
case $yn in
[yYjJ1] ) Write-MLog "Continue script" white; break;;
[nN0] ) Write-MLog "Exiting script" white; exit "1";;
* ) echo "invalid response";;
esac
done
#
#
Write-MLog "Grommunio files installation start" cyan
Write-MLog "" white
Write-MLog "0. parameter grofiles, Passwd: ${FILES_ADMIN_PASS}, FQDN: ${FQDN}, Logfile: $LOGFILE" white
#
Write-MLog "1. install current grommunio-files packages" white
zypper ref >>"${LOGFILE}" 2>&1
zypper in grommunio-files >>"${LOGFILE}" 2>&1
#
#
FT_FILES="true"
if [ "$FT_FILES" == "true" ] ; then
# set_files_mysql_param
if [ "${FILES_MYSQL_HOST}" == "localhost" ] ; then
Write-MLog "2. drop database if exists ${FILES_MYSQL_DB}; on localhost." white
#
echo "drop database if exists ${FILES_MYSQL_DB}; \
create database ${FILES_MYSQL_DB}; \
grant all on ${FILES_MYSQL_DB}.* to '${FILES_MYSQL_USER}'@'${FILES_MYSQL_HOST}' identified by '${FILES_MYSQL_PASS}';" | mysql >>"${LOGFILE}" 2>&1
else
Write-MLog "2. drop database if exists ${FILES_MYSQL_DB}; on remote host: ${FILES_MYSQL_HOST}." white
#
echo "drop database if exists ${FILES_MYSQL_DB}; \
create database ${FILES_MYSQL_DB};" | mysql -h"${FILES_MYSQL_HOST}" -u"${FILES_MYSQL_USER}" -p"${FILES_MYSQL_PASS}" "${FILES_MYSQL_DB}" >>"${LOGFILE}" 2>&1
fi
# nuke default admin data, since it wont install if the admin user that is created already has files
Write-MLog "3. nuke default admin data, since it wont install if the admin user that is created already has files." white
rm -rf /var/lib/grommunio-files/data/admin
#make a clean config.php
Write-MLog "4. make a clean config.php." white
cat > /usr/share/grommunio-files/config/config.php <<'EOF'
<?php
$CONFIG = array (
'overwritewebroot' => '/files',
'datadirectory' => '/var/lib/grommunio-files/data',
'logfile' => '/var/log/grommunio-files/files.log',
'theme' => 'theme-grommunio',
'logtimezone' => 'UTC',
'apps_paths' =>
array (
0 =>
array (
'path' => '/usr/share/grommunio-files/apps',
'url' => '/apps',
'writable' => false,
),
1 =>
array (
'path' => '/var/lib/grommunio-files/apps-external',
'url' => '/apps-external',
'writable' => true,
),
),
'memcache.local' => '\\OC\\Memcache\\Redis',
'filelocking.enabled' => true,
'memcache.locking' => '\\OC\\Memcache\\Redis',
'upgrade.disable-web' => true,
'upgrade.automatic-app-update' => true,
'updater.server.url' => '127.0.0.1',
'integrity.check.disabled' => false,
);
EOF
# dialog_files_adminpass
Write-MLog "5. configure grofiles, Passwd: ${FILES_ADMIN_PASS}, FQDN: ${FQDN}" white
pushd /usr/share/grommunio-files
Write-MLog "*** sudo -u grofiles ./occ -q -n maintenance:install --database=mysql --database-name=${FILES_MYSQL_DB} --database-user=${FILES_MYSQL_USER} --database-pass=${FILES_MYSQL_PASS} --admin-user=admin --admin-pass="${FILES_ADMIN_PASS}" --data-dir=/var/lib/grommunio-files/data" white
sudo -u grofiles ./occ -q -n maintenance:install --database=mysql --database-name=${FILES_MYSQL_DB} --database-user=${FILES_MYSQL_USER} --database-pass=${FILES_MYSQL_PASS} --admin-user=admin --admin-pass="${FILES_ADMIN_PASS}" --data-dir=/var/lib/grommunio-files/data >>"${LOGFILE}" 2>&1
sudo -u grofiles ./occ -q -n config:system:set trusted_domains 1 --value="${FQDN}" >>"${LOGFILE}" 2>&1
sudo -u grofiles ./occ -q -n config:system:set trusted_domains 2 --value="${DOMAIN}" >>"${LOGFILE}" 2>&1
sudo -u grofiles ./occ -q -n config:system:set trusted_domains 3 --value="mail.${DOMAIN}" >>"${LOGFILE}" 2>&1
sudo -u grofiles ./occ -q -n app:enable user_external >>"${LOGFILE}" 2>&1
sudo -u grofiles ./occ -q -n config:system:set user_backends 0 arguments 0 --value="https://${FQDN}/dav" >>"${LOGFILE}" 2>&1
sudo -u grofiles ./occ -q -n config:system:set user_backends 0 class --value='\OCA\UserExternal\BasicAuth' >>"${LOGFILE}" 2>&1
sudo -u grofiles ./occ -q -n app:enable onlyoffice >>"${LOGFILE}" 2>&1
sudo -u grofiles ./occ -q -n config:system:set integrity.check.disabled --type boolean --value true >>"${LOGFILE}" 2>&1
sudo -u grofiles ./occ -q -n theming:config name 'grommunio Files' >>"${LOGFILE}" 2>&1
sudo -u grofiles ./occ -q -n theming:config logo /usr/share/grommunio-files/logo.png >>"${LOGFILE}" 2>&1
sudo -u grofiles ./occ -q -n theming:config logoheader /usr/share/grommunio-files/logo.png >>"${LOGFILE}" 2>&1
sudo -u grofiles ./occ -q -n theming:config favicon /usr/share/grommunio-files/favicon.svg >>"${LOGFILE}" 2>&1
sudo -u grofiles ./occ -q -n theming:config background /usr/share/grommunio-files/background.jpg >>"${LOGFILE}" 2>&1
sudo -u grofiles ./occ -q -n theming:config disable-user-theming true >>"${LOGFILE}" 2>&1
sudo -u grofiles ./occ -q -n theming:config slogan 'filesync & sharing' >>"${LOGFILE}" 2>&1
sudo -u grofiles ./occ -q -n theming:config url 'https://grommunio.com' >>"${LOGFILE}" 2>&1
sudo -u grofiles ./occ -q -n theming:config color '#0072B0' >>"${LOGFILE}" 2>&1
sudo -u grofiles ./occ -q -n config:system:set mail_from_address --value='admin' >>"${LOGFILE}" 2>&1
sudo -u grofiles ./occ -q -n config:system:set mail_smtpmode --value='sendmail' >>"${LOGFILE}" 2>&1
sudo -u grofiles ./occ -q -n config:system:set mail_sendmailmode --value='smtp' >>"${LOGFILE}" 2>&1
sudo -u grofiles ./occ -q -n config:system:set mail_domain --value="${DOMAIN}" >>"${LOGFILE}" 2>&1
sudo -u grofiles ./occ -q -n config:system:set mail_smtphost --value='localhost' >>"${LOGFILE}" 2>&1
sudo -u grofiles ./occ -q -n config:system:set mail_smtpport --value='25' >>"${LOGFILE}" 2>&1
popd || return
Write-MLog "6. Enable services" white
systemctl enable grommunio-files-cron.service >>"${LOGFILE}" 2>&1
systemctl enable grommunio-files-cron.timer >>"${LOGFILE}" 2>&1
systemctl start grommunio-files-cron.timer >>"${LOGFILE}" 2>&1
# what is this ????
#jq '.fileWebAddress |= "https://'${FQDN}'/files"' /tmp/config.json > /tmp/config-new.json
#mv /tmp/config-new.json /tmp/config.json
Write-MLog "7. done." cyan
fi