#!/bin/bash set -e REQUIREMENTS=( curl jq podman ) for req in ${REQUIREMENTS[@]}; do if ! command -v $req > /dev/null; then echo "This script requires $req to run." exit 1 fi done # NEXTCLOUD_DIGEST= # NOT USED YET # MARIADB_DIGEST= # NOT USED YET # # MYSQL_ROOT_PASSWD='' # MYSQL_PASSWD='' #Used for Postgres too # # POSTGRES_USER='' # POSTGRES_DB='' # # # ADMIN_USER='' # ADMIN_PASSWD='' # NEXTCLOUD_DATA_DIR='' # NEXTCLOUD_DB_DIR='' # TRUSTED_DOMAINS='' # # CLAMAV_DB_DIR='' # CLAMAV_CONF_DIR='' ## Place the above configurations in a file called env in the same ## directory as this script ## ## A template env file is included in the repo [[ -f ./env ]] && . ./env || exit 1 ## Change this to 1 if you haven't enabled previews before ## Or this is a fresh installation APPEND_PREVIEW_CONFIG=0 ## Just in case to avoid file permission errors #sudo chown "$USER": "$NEXTCLOUD_DB_DIR" ## Remove old log file if [ "$UID" -ne 0 ]; then podman unshare rm -f "$NEXTCLOUD_DATA_DIR"/data/nextcloud.log else rm -f "$NEXTCLOUD_DATA_DIR"/data/nextcloud.log fi ## ## Create a pod for Nextcloud ## podman pod create -p 8081:80 --hostname "$NEXTCLOUD_HOSTNAME" --name nextcloud ## ## Mariadb ## # # podman build -f ./mariadb-nextcloud.Containerfile -t localhost/mariadb:latest # podman create --name nextcloud-db --pod nextcloud \ # -e MYSQL_ROOT_PASSWORD="$MYSQL_ROOT_PASSWD" \ # -e MYSQL_DATABASE='nextcloud' \ # -e MYSQL_USER='nextcloud' \ # -e MYSQL_PASSWORD="$MYSQL_PASSWD" \ # -v "$NEXTCLOUD_DB_DIR":/var/lib/mysql:Z \ # localhost/mariadb:latest ## ## Postgres ## # podman create --pod nextcloud --name nextcloud-postgres \ -e POSTGRES_USER=nextcloud \ -e POSTGRES_DB=nextcloud \ -e POSTGRES_PASSWORD="$MYSQL_PASSWD" \ -v "$NEXTCLOUD_DB_DIR":/var/lib/postgresql/data:Z \ docker.io/postgres:alpine ## ## Redis ## podman create --name nextcloud-redis --pod nextcloud docker.io/redis:alpine ## ## ClamAV ## ## No typos in the :z and :Z flags, NC data dir needs the small z ## which means shared with another container podman create --name nextcloud-clamav --pod nextcloud \ -v "$CLAMAV_DB_DIR":/var/lib/clamav:Z \ -v "$CLAMAV_CONF_DIR":/etc/clamav:Z \ clamav/clamav:latest ## Add the following: ## -v $NEXTCLOUD_DATA_DIR/data:/scandir:z \ ## to clamav to use ClamAV's clamd scanning as well ## (not tested) ## ## Nextcloud ## [ -n "$NEXTCLOUD_HOSTNAME" ] && sed -i "s|^ServerName.*$|ServerName $NEXTCLOUD_HOSTNAME|" apache2.conf podman build -f ./nextcloud-app.Containerfile -t nextcloud:latest podman create --name nextcloud-app --pod nextcloud \ -e POSTGRES_DB='nextcloud' \ -e POSTGRES_USER='nextcloud' \ -e POSTGRES_PASSWORD="$MYSQL_PASSWD" \ -e POSTGRES_HOST='127.0.0.1' \ -e NEXTCLOUD_ADMIN_USER="$ADMIN_USER" \ -e NEXTCLOUD_ADMIN_PASSWORD="$ADMIN_PASSWD" \ -e NEXTCLOUD_TRUSTED_DOMAINS="$TRUSTED_DOMAINS" \ -e PHP_MEMORY_LIMIT="$NEXTCLOUD_PHP_MEMORY_LIMIT" \ -e PHP_UPLOAD_LIMIT='10G' \ -e REDIS_HOST='127.0.0.1' \ -e REDIS_PORT='6379' \ -e APACHE_DISABLE_REWRITE_IP=1 \ -e TRUSTED_PROXIES="$TRUSTED_PROXIES" \ -v "$NEXTCLOUD_DATA_DIR":/var/www/html:z \ localhost/nextcloud:latest # -e MYSQL_DATABASE='nextcloud' \ # -e MYSQL_USER='nextcloud' \ # -e MYSQL_PASSWORD="$MYSQL_PASSWD" \ # -e MYSQL_HOST='127.0.0.1:3306' \ ## ## Enable previews ## if [[ "$APPEND_PREVIEW_CONFIG" -eq 1 ]]; then sudo sed -i '/^);$/d' "$NEXTCLOUD_DATA_DIR"/config/config.php; cat previews.conf | sudo tee -a "$NEXTCLOUD_DATA_DIR"/config/config.php > /dev/null podman restart nextcloud-app fi ## ## Generate systemd units ## if [[ "$1" == "--generate-systemd" ]]; then ## Added UID check in case using rootful containers (under LXC guest, for example) if [ "$UID" -ne 0 ]; then [[ ! -d "$HOME"/.config/systemd/user ]] && mkdir -p "$HOME"/.config/systemd/user cd "$HOME"/.config/systemd/user if [[ "$2" == "--new" ]]; then podman generate systemd --new -n -f nextcloud else podman generate systemd -n -f nextcloud fi systemctl --user daemon-reload systemctl --user enable --now pod-nextcloud else cd /etc/systemd/system if [[ "$2" == "--new" ]]; then podman generate systemd --new -n -f nextcloud else podman generate systemd -n -f nextcloud fi systemctl daemon-reload systemctl enable --now pod-nextcloud fi else echo "Not generating systemd units. Use --generate-systemd flag to do so automatically." podman pod start nextcloud fi echo "Waiting for nextcloud to initialize.." while [[ "$(curl -s localhost:8081/status.php | jq '.installed')" != "true" ]]; do sleep 1 done ## Tag images VERSION=$(curl -s localhost:8081/status.php | jq -r '.versionstring') echo "Tagging current image..." podman tag localhost/nextcloud:latest localhost/nextcloud:"$VERSION" echo "localhost/nextcloud version $VERSION is up!" exit 0