create.sh
· 4.8 KiB · Bash
原始檔案
#!/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
| 1 | #!/bin/bash |
| 2 | |
| 3 | set -e |
| 4 | |
| 5 | REQUIREMENTS=( curl jq podman ) |
| 6 | for req in ${REQUIREMENTS[@]}; do |
| 7 | if ! command -v $req > /dev/null; then |
| 8 | echo "This script requires $req to run." |
| 9 | exit 1 |
| 10 | fi |
| 11 | done |
| 12 | |
| 13 | # NEXTCLOUD_DIGEST= # NOT USED YET |
| 14 | # MARIADB_DIGEST= # NOT USED YET |
| 15 | # |
| 16 | # MYSQL_ROOT_PASSWD='' |
| 17 | # MYSQL_PASSWD='' #Used for Postgres too |
| 18 | # |
| 19 | # POSTGRES_USER='' |
| 20 | # POSTGRES_DB='' |
| 21 | # |
| 22 | # |
| 23 | # ADMIN_USER='' |
| 24 | # ADMIN_PASSWD='' |
| 25 | # NEXTCLOUD_DATA_DIR='' |
| 26 | # NEXTCLOUD_DB_DIR='' |
| 27 | # TRUSTED_DOMAINS='' |
| 28 | # |
| 29 | # CLAMAV_DB_DIR='' |
| 30 | # CLAMAV_CONF_DIR='' |
| 31 | |
| 32 | ## Place the above configurations in a file called env in the same |
| 33 | ## directory as this script |
| 34 | ## |
| 35 | ## A template env file is included in the repo |
| 36 | [[ -f ./env ]] && . ./env || exit 1 |
| 37 | |
| 38 | ## Change this to 1 if you haven't enabled previews before |
| 39 | ## Or this is a fresh installation |
| 40 | APPEND_PREVIEW_CONFIG=0 |
| 41 | |
| 42 | ## Just in case to avoid file permission errors |
| 43 | #sudo chown "$USER": "$NEXTCLOUD_DB_DIR" |
| 44 | |
| 45 | ## Remove old log file |
| 46 | if [ "$UID" -ne 0 ]; then |
| 47 | podman unshare rm -f "$NEXTCLOUD_DATA_DIR"/data/nextcloud.log |
| 48 | else |
| 49 | rm -f "$NEXTCLOUD_DATA_DIR"/data/nextcloud.log |
| 50 | fi |
| 51 | |
| 52 | |
| 53 | ## |
| 54 | ## Create a pod for Nextcloud |
| 55 | ## |
| 56 | |
| 57 | podman pod create -p 8081:80 --hostname "$NEXTCLOUD_HOSTNAME" --name nextcloud |
| 58 | |
| 59 | ## |
| 60 | ## Mariadb |
| 61 | ## |
| 62 | # |
| 63 | # podman build -f ./mariadb-nextcloud.Containerfile -t localhost/mariadb:latest |
| 64 | # podman create --name nextcloud-db --pod nextcloud \ |
| 65 | # -e MYSQL_ROOT_PASSWORD="$MYSQL_ROOT_PASSWD" \ |
| 66 | # -e MYSQL_DATABASE='nextcloud' \ |
| 67 | # -e MYSQL_USER='nextcloud' \ |
| 68 | # -e MYSQL_PASSWORD="$MYSQL_PASSWD" \ |
| 69 | # -v "$NEXTCLOUD_DB_DIR":/var/lib/mysql:Z \ |
| 70 | # localhost/mariadb:latest |
| 71 | |
| 72 | ## |
| 73 | ## Postgres |
| 74 | ## |
| 75 | # |
| 76 | podman create --pod nextcloud --name nextcloud-postgres \ |
| 77 | -e POSTGRES_USER=nextcloud \ |
| 78 | -e POSTGRES_DB=nextcloud \ |
| 79 | -e POSTGRES_PASSWORD="$MYSQL_PASSWD" \ |
| 80 | -v "$NEXTCLOUD_DB_DIR":/var/lib/postgresql/data:Z \ |
| 81 | docker.io/postgres:alpine |
| 82 | |
| 83 | |
| 84 | ## |
| 85 | ## Redis |
| 86 | ## |
| 87 | |
| 88 | podman create --name nextcloud-redis --pod nextcloud docker.io/redis:alpine |
| 89 | |
| 90 | ## |
| 91 | ## ClamAV |
| 92 | ## |
| 93 | |
| 94 | ## No typos in the :z and :Z flags, NC data dir needs the small z |
| 95 | ## which means shared with another container |
| 96 | |
| 97 | podman create --name nextcloud-clamav --pod nextcloud \ |
| 98 | -v "$CLAMAV_DB_DIR":/var/lib/clamav:Z \ |
| 99 | -v "$CLAMAV_CONF_DIR":/etc/clamav:Z \ |
| 100 | clamav/clamav:latest |
| 101 | |
| 102 | ## Add the following: |
| 103 | ## -v $NEXTCLOUD_DATA_DIR/data:/scandir:z \ |
| 104 | ## to clamav to use ClamAV's clamd scanning as well |
| 105 | ## (not tested) |
| 106 | |
| 107 | |
| 108 | ## |
| 109 | ## Nextcloud |
| 110 | ## |
| 111 | |
| 112 | [ -n "$NEXTCLOUD_HOSTNAME" ] && sed -i "s|^ServerName.*$|ServerName $NEXTCLOUD_HOSTNAME|" apache2.conf |
| 113 | podman build -f ./nextcloud-app.Containerfile -t nextcloud:latest |
| 114 | podman create --name nextcloud-app --pod nextcloud \ |
| 115 | -e POSTGRES_DB='nextcloud' \ |
| 116 | -e POSTGRES_USER='nextcloud' \ |
| 117 | -e POSTGRES_PASSWORD="$MYSQL_PASSWD" \ |
| 118 | -e POSTGRES_HOST='127.0.0.1' \ |
| 119 | -e NEXTCLOUD_ADMIN_USER="$ADMIN_USER" \ |
| 120 | -e NEXTCLOUD_ADMIN_PASSWORD="$ADMIN_PASSWD" \ |
| 121 | -e NEXTCLOUD_TRUSTED_DOMAINS="$TRUSTED_DOMAINS" \ |
| 122 | -e PHP_MEMORY_LIMIT="$NEXTCLOUD_PHP_MEMORY_LIMIT" \ |
| 123 | -e PHP_UPLOAD_LIMIT='10G' \ |
| 124 | -e REDIS_HOST='127.0.0.1' \ |
| 125 | -e REDIS_PORT='6379' \ |
| 126 | -e APACHE_DISABLE_REWRITE_IP=1 \ |
| 127 | -e TRUSTED_PROXIES="$TRUSTED_PROXIES" \ |
| 128 | -v "$NEXTCLOUD_DATA_DIR":/var/www/html:z \ |
| 129 | localhost/nextcloud:latest |
| 130 | |
| 131 | # -e MYSQL_DATABASE='nextcloud' \ |
| 132 | # -e MYSQL_USER='nextcloud' \ |
| 133 | # -e MYSQL_PASSWORD="$MYSQL_PASSWD" \ |
| 134 | # -e MYSQL_HOST='127.0.0.1:3306' \ |
| 135 | |
| 136 | ## |
| 137 | ## Enable previews |
| 138 | ## |
| 139 | |
| 140 | if [[ "$APPEND_PREVIEW_CONFIG" -eq 1 ]]; then |
| 141 | sudo sed -i '/^);$/d' "$NEXTCLOUD_DATA_DIR"/config/config.php; cat previews.conf | sudo tee -a "$NEXTCLOUD_DATA_DIR"/config/config.php > /dev/null |
| 142 | podman restart nextcloud-app |
| 143 | fi |
| 144 | |
| 145 | ## |
| 146 | ## Generate systemd units |
| 147 | ## |
| 148 | |
| 149 | if [[ "$1" == "--generate-systemd" ]]; then |
| 150 | |
| 151 | ## Added UID check in case using rootful containers (under LXC guest, for example) |
| 152 | if [ "$UID" -ne 0 ]; then |
| 153 | [[ ! -d "$HOME"/.config/systemd/user ]] && mkdir -p "$HOME"/.config/systemd/user |
| 154 | cd "$HOME"/.config/systemd/user |
| 155 | if [[ "$2" == "--new" ]]; then |
| 156 | podman generate systemd --new -n -f nextcloud |
| 157 | else |
| 158 | podman generate systemd -n -f nextcloud |
| 159 | fi |
| 160 | systemctl --user daemon-reload |
| 161 | |
| 162 | systemctl --user enable --now pod-nextcloud |
| 163 | else |
| 164 | cd /etc/systemd/system |
| 165 | if [[ "$2" == "--new" ]]; then |
| 166 | podman generate systemd --new -n -f nextcloud |
| 167 | else |
| 168 | podman generate systemd -n -f nextcloud |
| 169 | fi |
| 170 | systemctl daemon-reload |
| 171 | |
| 172 | systemctl enable --now pod-nextcloud |
| 173 | fi |
| 174 | |
| 175 | else |
| 176 | echo "Not generating systemd units. Use --generate-systemd flag to do so automatically." |
| 177 | podman pod start nextcloud |
| 178 | fi |
| 179 | |
| 180 | echo "Waiting for nextcloud to initialize.." |
| 181 | while [[ "$(curl -s localhost:8081/status.php | jq '.installed')" != "true" ]]; do |
| 182 | sleep 1 |
| 183 | done |
| 184 | |
| 185 | ## Tag images |
| 186 | VERSION=$(curl -s localhost:8081/status.php | jq -r '.versionstring') |
| 187 | echo "Tagging current image..." |
| 188 | podman tag localhost/nextcloud:latest localhost/nextcloud:"$VERSION" |
| 189 | echo "localhost/nextcloud version $VERSION is up!" |
| 190 | exit 0 |
| 191 |