Files
shell_sequencer/seqs/onlyoffice.sh

195 lines
5.6 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=
# Get script working directory
# (when called from a different directory)
WDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >>/dev/null 2>&1 && pwd)"
APTOPT=
CONFIG=0
SCRIPT_FILE=$(basename -- $0)
SCRIPT_NAME=${SCRIPT_FILE%%.*}
CONFIG_FILE_NAME="${SCRIPT_NAME}.cfg"
CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example"
step_config() {
## Called once before executing steps.
## e.g. to source a config file manually:
#. "$CONFIG_FILE"
## or to use sequencer api with global config file:
initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE"
## or to use sequencer api with profile config file support:
#initSeqConfig -p "$SCRIPT_NAME" "$CONFIG_FILE_TEMPLATE"
if [ $? -eq 0 ] ; then
CONFIG=1
else
# End if no configuration file exists
[ $DRY -eq 0 ] && return -1
fi
## Apt cmdline option to suppress user interaction
[ $QUIET -ne 0 ] && APTOPT="-y"
dockerDnsEntry="DOCKER_OPTS=\"--dns $dockerDns1 --dns $dockerDns2\""
## Return of non zero value will abort the sequence
return 0
}
step_1_info() { echo "Install Docker dependencies"; }
step_1_alias() { ALIAS="install"; }
step_1() {
exe apt update
exe apt install $dockerDeps $APTOPT
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() {
echoinfoArgs "[SECRET]"
echo "Install/start onlyoffice docker container"
echoinfo "If [SECRET] is empty, user input will be available if not run --quiet."
echoinfo "$toolName will be run unsecured if no secret was provied."
}
step_5_alias() { ALIAS="startoo"; }
step_5() {
local options=
local secret=
if [ ! -z "$2" ] ; then
secret="$2"
elif [ ! -z "$dockerSecret" ]; then
secret="$dockerSecret"
elif [ $QUIET -eq 0 ] ; then
exe read -s -p "JWT Secret: " secret
fi
# The correct expansion for missing SECRET or SECRET with spaces is not possible.
# Therefore docker without secret needs to be called separately
if [ ! -z "$secret" ] ; 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}"$secret" --restart=always \
-v /app/onlyoffice/DocumentServer/logs:/var/log/onlyoffice \
-v /app/onlyoffice/DocumentServer/data:/var/www/onlyoffice/Data \
-v /app/onlyoffice/DocumentServer/lib:/var/lib/onlyoffice \
-v /app/onlyoffice/DocumentServer/db:/var/lib/postgresql "${dockerImageName}"
else
echoerr " [W] Running $toolName without JWT (JSON Web Tokens)"
exe docker run -i -t -d -p ${onlyOfficePort}:80 --restart=always "${dockerImageName}"
fi
unset secret
}
step_7_info() { echo "Upgrade $toolName to latest version"; }
step_7_alias() { ALIAS="upgrade"; }
step_7() {
# get container ID
local containerId=$(docker ps -aqf ancestor="$dockerImageName")
if [ ! -z $containerId ] ; then
exe docker stop $containerId
exe docker rm $containerId
else
echoerr " [W] No $toolName Docker container found"
fi
exe docker pull $dockerImageName
endReturn -o $? "Error getting $toolName Docker update"
step startoo
}
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"
echoinfo "(unused containers, dangling images, networks, build cache and volumes)"
}
step_12_alias() { ALIAS="prune"; }
step_12() {
exe docker system df
exe docker system prune
exe docker volume 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 service docker stop
exe rm -rf /var/lib/docker
;;
*)
return 0
;;
esac
}
VERSION_SEQREV=15
. /usr/local/bin/sequencer.sh