#!/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 )" 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 dockerDnsEntry="DOCKER_OPTS=\"--dns $dockerDns1 --dns $dockerDns2\"" } 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 ." echoinfo "If 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 [ $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 onlyoffice/documentserver else echoerr " [W] Running $toolName without JWT (JSON Web Tokens)" exe docker run -i -t -d -p ${onlyOfficePort}:80 --restart=always onlyoffice/documentserver 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=8 . sequencer.sh