Files
shell_sequencer/seqs/onlyoffice.sh

141 lines
4.2 KiB
Bash
Executable File

#!/bin/bash
# Source
# Docker - Install using the repository
# https://docs.docker.com/install/linux/docker-ce/ubuntu/
#
# Onlyoffice - Docker
# https://helpcenter.onlyoffice.com/server/docker/document/docker-installation.aspx
toolName="onlyoffice"
dockerDeps="apt-transport-https ca-certificates curl gnupg-agent software-properties-common"
dockerGpgKeyUrl="https://download.docker.com/linux/ubuntu/gpg"
dockerRepoUrl="https://download.docker.com/linux/ubuntu"
dockerPackages="docker-ce docker-ce-cli containerd.io"
# Entry in config value $dockerDefaultConf
dockerDnsEntry="DOCKER_OPTS=\"--dns $dockerDns1 --dns $dockerDns2\""
# Get script working directory
# (when called from a different directory)
WDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )"
CONFIG_FILE="$WDIR/${toolName}.cfg"
CONFIG_FILE_DEFAULT="${CONFIG_FILE}.example"
step_config() {
if [ ! -s "$CONFIG_FILE" ] && [ ! -s "$CONFIG_FILE_DEFAULT" ] ; then
echoerr " [E] No configuration \"$CONFIG_FILE_DEFAULT\" or \"$CONFIG_FILE\" found"
exit 1;
fi
if [ -s "$CONFIG_FILE" ] ; then
. "$CONFIG_FILE"
else
echoerr " [W] User configuration \"$CONFIG_FILE\" not found. Using \"$CONFIG_FILE_DEFAULT\""
. "$CONFIG_FILE_DEFAULT"
fi
}
step_1_info() { echo "Install docker dependencies"; }
step_1_alias() { ALIAS="install"; }
step_1() {
local aptOption=
exe apt update
if [ $QUIET -ne 0 ] ; then
aptOption="-y"
else
aptOption=""
fi
exe apt install $dockerDeps $aptOption
endReturn -o $? "Docker dependencies installation failed"
}
step_2_info() { echo "Install docker repository"; }
step_2() {
# Add official docker GPG key
exep "curl -fsSL ${dockerGpgKeyUrl} | sudo apt-key add -"
# Add stable repository
exe add-apt-repository "deb [arch=amd64] ${dockerRepoUrl} $(lsb_release -cs) stable"
endReturn -o $? "Failed to add Docker repository"
exe apt update
endReturn -o $? "Docker repository not available"
}
step_3_info() { echo "Install latest docker version"; }
step_3() {
# Install the latest version
if [ $QUIET -ne 0 ] ; then
aptOption="-y"
else
aptOption=""
fi
exe apt install $dockerPackages $aptOption
echo " [I] You may test the installation by running:"
echo " sudo docker run hello-world"
}
step_4_info() { echo "Replace Docker DNS entry"; }
step_4() {
exe sed -i "s/\(^#DOCKER_OPTS=.*\)$/#\1\n${dockerDnsEntry}/" "$dockerDefaultConf"
exep "grep \"${dockerDns1}\" \"$dockerDefaultConf\" >>/dev/null"
if [ $? -ne 0 ] ; then
echoerr " [W] Docker dns entry could not be changed"
fi
}
step_5_info() { echo "Install/start onlyoffice docker container <SECRET>"; }
step_5_alias() { ALIAS="startoo"; }
step_5() {
local options=
# The correct expansion for missing SECRET or SECRET with spaces is not possible.
# Therefore docker without secret needs to be called separately
if [ ! -z "$2" ] && [ "$2" != "" ] ; then
options="-e JWT_ENABLED=true -e JWT_SECRET="
# This is the only way to provide SECRET($2) to docker command line which handles all types of characters.
exe docker run -i -t -d -p ${onlyOfficePort}:80 ${options}"$2" --restart=always onlyoffice/documentserver
else
echo " [I] Running $toolName without JWT (JSON Web Tokens)"
exe docker run -i -t -d -p ${onlyOfficePort}:80 --restart=always onlyoffice/documentserver
fi
}
step_10_info() { echo "List running Docker container"; }
step_10_alias() { ALIAS="ls"; }
step_10() {
exe docker container ls
echo
echo " [I] To stop a container run:"
echo " docker stop [CONTAINER ID]"
echo " e.g.: docker stop 70f1c5c81be2"
}
step_12_info() { echo "Clean unused Docker data (unused containers, dangling images, networks and build cache)"; }
step_12_alias() { ALIAS="prune"; }
step_12() {
exe docker system df
exe docker system prune
}
step_100_info() { echo "Uninstall docker"; }
step_100_alias() { ALIAS="uninstall"; }
step_100() {
exe apt-get purge docker-ce
}
step_102_info() { echo "Purge images, containers, volumes, or customized configuration files"; }
step_102_alias() { ALIAS="purge"; }
step_102() {
exe read -p "Are you sure y/[n]? " answer
case $answer in
yY)
exe rm -rf /var/lib/docker
;;
*)
return 0
;;
esac
}
VERSION_SEQREV=8
. sequencer.sh