File loolwsd-setup.in of Package libreoffice-online

#!/bin/bash
# Name: Libreoffice Online Configuration Tool
# Version: 1.1.0
# Description:Configure Libreoffice Online automatically on openSUSE.
# Author: Hillwood Yang <hillwood@opensuse.org>
# License: WTFPL-2.0

#----------------------------------------------------------------
# force root
if [ "$(id -u)" != "0" ]; then
    echo "error: You must be root to use this program!"
    exit 1
fi

echo "Libreoffice Online is the TDF release, when used in what would be likely 
to imply an enterprise situation - more than 10 concurrent documents and/or more\
 than 20 connections - LibreOffice Online will display a prominent "not \
supported" warning, while continuing to function.
The program will configure libreoffice online automatically. Press any key\
 to continue ... "
read -n1


#----------------------------------------------------------------
# Check ip address
while :
do
    ANSWER1=y
    echo "Do you have a public ip address? [y/n]y"
    read ANSWER1
    case $ANSWER1 in
        Y | y | yes)
            break;;
        N | n | no)
            break;;
        *)
            echo "Unknown response, please reinput";;
    esac
done

if [ "$ANSWER1" = "n" ] || [ "$ANSWER1" = "N" ] || [ "$ANSWER1" = "no" ]; then
    echo "This program doesn't support LAN ip, please configure libreoffice online manually."
    exit 1
fi

#----------------------------------------------------------------
# Check domain
while :
do
    ANSWER2=y
    echo "Are you the admin of a domain [y/n]y"
    read ANSWER2
    case $ANSWER2 in
        Y | y | yes)
            break;;
        N | n | no)
            break;;
        *)
            echo "Unknown response, please reinput";;
    esac
done

if [ "$ANSWER2" = "n" ] || [ "$ANSWER2" = "N" ] || [ "$ANSWER2" = "no" ]; then
    echo "You can not control a domain, please configure libreoffice online manually."
    exit 1
fi

#----------------------------------------------------------------
# Configure libreoffice online domain.
echo "Please input the domain which libreoffice online will install"
read LO_SITE
sed -i "s/office.example.net/$LO_SITE/g" /etc/loolwsd/loolwsd.xml

while :
do
    ANSWER3=y
    echo "Is the 80 port allowed by ISP and have the libreoffice online domain \
been installed in this server with apache or nigix? If you can not sure, please \
choose 'n'. [y/n]n"
    read ANSWER3
    case $ANSWER3 in
        Y | y | yes)
            break;;
        N | n | no)
            break;;
        *)
            echo "Unknown response, please reinput";;
    esac
done

echo "Creating Let's Encrypt key for Libreoffice Online..."
if [ "$ANSWER3" = "y" ] || [ "$ANSWER3" = "Y" ] || [ "$ANSWER3" = "yes" ]; then
    certbot -d "$LO_SITE"
elif  [ "$ANSWER3" = "n" ] || [ "$ANSWER3" = "N" ] || [ "$ANSWER3" = "no" ]; then
    certbot certonly --manual --preferred-challenge dns -d "$LO_SITE"
fi
# Fix letsencrypt permissions, make sure loolwsd can read the Let's Encrypt key.
chmod 750 /etc/letsencrypt/live -R
chmod 750 /etc/letsencrypt/archive -R

#----------------------------------------------------------------
# Configure wopi domain.
echo "which site do you want to allow call the libreoffice online? Please \
input its domain: "
read WOPI_SITE
sed -i "s/wopi.example.net/$WOPI_SITE/g" /etc/loolwsd/loolwsd.xml

#----------------------------------------------------------------
# Configure admin user and password.
while :
do
    ANSWER4=y
    echo "Do you want to set the admin user name and password ? [y/n]y"
    read ANSWER4
    case $ANSWER4 in
        Y | y | yes)
            break;;
        N | n | no)
            break;;
        *)
            echo "Unknown response, please reinput";;
    esac
done

if [ "$ANSWER4" = "y" ] || [ "$ANSWER4" = "Y" ] || [ "$ANSWER4" = "yes" ]; then
    echo "Please input the admin user name:"
    read ADMIN
    sed -i "s/opensuse/$ADMIN/g" /etc/loolwsd/loolwsd.xml
    echo "Please input the admin password:"
    read PASSWORD
    sed -i "s/gecko2020/$PASSWORD/g" /etc/loolwsd/loolwsd.xml
elif [ "$ANSWER4" = "n" ] || [ "$ANSWER4" = "N" ] || [ "$ANSWER4" = "no" ]; then
    echo "The default admin user is opensuse, the password is gecko2020."
fi

#----------------------------------------------------------------
# Configure firewall

echo "configuring firewalld."
firewall-cmd --add-port=9980/tcp --permanent
systemctl restart firewalld

#----------------------------------------------------------------
# Finish configuration
echo "configuration is succeed, Please run 'systemctl start loolwsd' with root to \
launch. The Libreoffice Online server url is 'https://$LO_SITE:9980'. If you \
need a reverse proxy, please refer \
https://www.collaboraoffice.com/code/apache-reverse-proxy and \
https://www.collaboraoffice.com/code/nginx-reverse-proxy. Change more settings \
to edit /etc/loolwsd/loolwsd.xml"

openSUSE Build Service is sponsored by