2021-10-09 14:45:31 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -xeuo pipefail
|
|
|
|
IFS=$'\n\t'
|
|
|
|
|
2021-10-09 15:24:04 +00:00
|
|
|
DIR="$(realpath ${0%/*})"
|
2021-10-09 14:45:31 +00:00
|
|
|
RUNTIME_IS_PODMAN="false"
|
2023-07-19 12:12:31 +00:00
|
|
|
if [[ -x "$(command -v podman)" ]]; then
|
|
|
|
CONTAINER_RUNTIME="$(command -v podman 2> /dev/null)"
|
2021-10-09 14:45:31 +00:00
|
|
|
RUNTIME_IS_PODMAN="true"
|
2023-07-19 12:12:31 +00:00
|
|
|
elif [[ -x "$(command -v docker)" ]]; then
|
|
|
|
CONTAINER_RUNTIME="$(command -v docker 2> /dev/null)"
|
2021-10-09 14:45:31 +00:00
|
|
|
else
|
|
|
|
echo "Container runtime (docker/podman) not found!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# replace containers
|
2021-10-09 15:24:04 +00:00
|
|
|
if $CONTAINER_RUNTIME inspect --type container synapse 1> /dev/null; then
|
2021-10-09 14:45:31 +00:00
|
|
|
$CONTAINER_RUNTIME rm -f synapse
|
2022-02-26 18:40:02 +00:00
|
|
|
sleep 0.5
|
2021-10-09 14:45:31 +00:00
|
|
|
fi
|
2022-02-26 16:27:19 +00:00
|
|
|
if $CONTAINER_RUNTIME inspect --type container elementweb 1> /dev/null; then
|
|
|
|
$CONTAINER_RUNTIME rm -f elementweb
|
|
|
|
sleep 0.5
|
|
|
|
fi
|
2021-10-09 15:24:04 +00:00
|
|
|
if $CONTAINER_RUNTIME inspect --type container nextcloud 1> /dev/null; then
|
2021-10-09 14:45:31 +00:00
|
|
|
$CONTAINER_RUNTIME rm -f nextcloud
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -d vendor ]]; then
|
|
|
|
make composer
|
|
|
|
fi
|
|
|
|
|
|
|
|
$CONTAINER_RUNTIME run -d \
|
|
|
|
--name=nextcloud \
|
2022-02-26 16:27:19 +00:00
|
|
|
-p 8080:8080 \
|
|
|
|
-p 8081:80 \
|
|
|
|
-p 8082:8082 \
|
2021-10-09 14:45:31 +00:00
|
|
|
-p 8008:8008 \
|
2023-07-19 12:13:09 +00:00
|
|
|
-p 2280:22 \
|
|
|
|
-e PHP_MEMORY_LIMIT=512M \
|
2021-10-09 14:45:31 +00:00
|
|
|
-v "$DIR:/var/www/html/custom_apps/upschooling" \
|
|
|
|
--add-host "synapse:127.0.0.1" \
|
|
|
|
docker.io/nextcloud
|
|
|
|
|
2022-02-26 18:40:02 +00:00
|
|
|
echo -e "Nextcloud has started. \e[1;38;5;2mOK\033[0m"
|
|
|
|
|
2023-07-19 12:13:09 +00:00
|
|
|
$CONTAINER_RUNTIME exec nextcloud bash -c 'apt-get update && apt-get upgrade -y && apt-get install --no-install-recommends -y git openssh-server'
|
|
|
|
# sets www-data password to extrasecret
|
|
|
|
$CONTAINER_RUNTIME exec nextcloud usermod \
|
|
|
|
--password '$6$bpNXAZwf$Xt.BzPV.mNTx5qVJQLK9Lut4VqMcrotgDHdcSZ0SwMxz2k9KVMSpAU7QmCv5vqj87ykIErYGpj9.Hb0A/XpX81' \
|
|
|
|
--shell '/bin/bash' \
|
|
|
|
www-data
|
|
|
|
$CONTAINER_RUNTIME exec nextcloud /etc/init.d/ssh start
|
2021-10-09 14:45:31 +00:00
|
|
|
$CONTAINER_RUNTIME exec nextcloud chown -R 33 /var/www/html/custom_apps
|
|
|
|
|
2021-10-09 15:24:04 +00:00
|
|
|
if [[ $(id -u) -ne 0 && $RUNTIME_IS_PODMAN == "true" ]]; then
|
2021-10-09 14:45:31 +00:00
|
|
|
$CONTAINER_RUNTIME unshare -- chown -R 33 "$DIR"
|
|
|
|
$CONTAINER_RUNTIME unshare -- chgrp -R 0 "$DIR"
|
|
|
|
$CONTAINER_RUNTIME unshare -- chmod -R ug+rw "$DIR"
|
|
|
|
fi
|
|
|
|
|
|
|
|
$CONTAINER_RUNTIME exec --user 33 nextcloud bash -c 'cd /var/www/html/custom_apps/upschooling && make composer'
|
|
|
|
$CONTAINER_RUNTIME exec --user 33 nextcloud php occ maintenance:install --database sqlite --admin-user admin --admin-pass admin
|
|
|
|
$CONTAINER_RUNTIME exec --user 33 nextcloud php occ config:system:set --value=true --type=boolean debug
|
2022-02-26 18:40:02 +00:00
|
|
|
$CONTAINER_RUNTIME exec --user 33 nextcloud php occ log:manage --level=debug
|
2021-10-09 14:45:31 +00:00
|
|
|
$CONTAINER_RUNTIME exec --user 33 nextcloud php occ app:enable --force upschooling
|
|
|
|
|
2022-02-26 18:40:02 +00:00
|
|
|
echo -e "Nextcloud and app was configured. \e[1;38;5;2mOK\033[0m"
|
|
|
|
|
2021-10-09 15:24:04 +00:00
|
|
|
SYNAPSE_DATA_VOLUME_EXISTS="false"
|
|
|
|
if [[ $RUNTIME_IS_PODMAN == "true" ]]; then
|
|
|
|
if $CONTAINER_RUNTIME volume exists synapse-data; then
|
|
|
|
echo "Found existing synapse-data volume (via volume exists)"
|
|
|
|
SYNAPSE_DATA_VOLUME_EXISTS="true"
|
|
|
|
fi
|
2021-10-09 14:45:31 +00:00
|
|
|
else
|
2021-10-09 15:24:04 +00:00
|
|
|
if $CONTAINER_RUNTIME volume inspect synapse-data 1> /dev/null; then
|
|
|
|
echo "Found existing synapse-data volume (via volume inspect)"
|
|
|
|
SYNAPSE_DATA_VOLUME_EXISTS="true"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-10-09 17:04:23 +00:00
|
|
|
if [[ $SYNAPSE_DATA_VOLUME_EXISTS == "false" ]]; then
|
2021-10-09 14:45:31 +00:00
|
|
|
$CONTAINER_RUNTIME run --rm \
|
|
|
|
--name=synapse \
|
|
|
|
--hostname synapse \
|
|
|
|
"--mount=type=volume,src=synapse-data,dst=/data" \
|
|
|
|
-e SYNAPSE_SERVER_NAME=synapse \
|
|
|
|
-e SYNAPSE_REPORT_STATS=no \
|
|
|
|
docker.io/matrixdotorg/synapse \
|
|
|
|
generate
|
|
|
|
echo "Generated fresh synapse-data volume"
|
|
|
|
fi
|
|
|
|
|
|
|
|
LOCAL_SYNAPSE_DATA_PATH="$($CONTAINER_RUNTIME volume inspect --format "{{.Mountpoint}}" synapse-data)"
|
2021-10-09 17:04:23 +00:00
|
|
|
SED_ARGS=(-i 's|registration_shared_secret: .*|registration_shared_secret: "oyYh_iEJ7Aim.iB+ye.Xk;Gl3iHFab5*8K,zv~IulT85P=c-38"|' "$LOCAL_SYNAPSE_DATA_PATH/homeserver.yaml")
|
2021-10-09 14:45:31 +00:00
|
|
|
if [[ $(id -u) -eq 0 || $RUNTIME_IS_PODMAN != "true" ]]; then
|
|
|
|
sed ${SED_ARGS[@]}
|
|
|
|
else
|
|
|
|
podman unshare -- sed ${SED_ARGS[@]}
|
|
|
|
fi
|
|
|
|
|
|
|
|
$CONTAINER_RUNTIME run -d \
|
|
|
|
--log-driver "k8s-file" \
|
|
|
|
--name=synapse \
|
|
|
|
"--mount=type=volume,src=synapse-data,dst=/data" \
|
|
|
|
"--network=container:$($CONTAINER_RUNTIME inspect --format "{{.Id}}" nextcloud)" \
|
|
|
|
--hostname synapse \
|
|
|
|
docker.io/matrixdotorg/synapse
|
|
|
|
|
|
|
|
# wait for synapse to start
|
|
|
|
MAX_TRIES=15
|
|
|
|
for ((i = 0 ; i < $MAX_TRIES ; i++)); do
|
|
|
|
if $CONTAINER_RUNTIME logs synapse 2>&1 | grep -q "Synapse now listening on TCP port 8008"; then
|
|
|
|
echo -e "Synapse has started. \e[1;38;5;2mOK\033[0m"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ $i -ge $MAX_TRIES ]]; then
|
|
|
|
echo "Synapse did not start in time! Use \`$CONTAINER_RUNTIME logs synapse\` to investigate"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
set +e
|
|
|
|
REGISTER_USER_OUTPUT="$($CONTAINER_RUNTIME exec synapse register_new_matrix_user -u upschooling -p secret -a -c /data/homeserver.yaml http://localhost:8008)"
|
|
|
|
REGISTER_USER_SUCCESS=$?
|
|
|
|
set -e
|
|
|
|
|
|
|
|
if [[ "$REGISTER_USER_SUCCESS" != "0" ]]; then
|
|
|
|
if echo $REGISTER_USER_OUTPUT | grep -q "User ID already taken."; then
|
|
|
|
echo -e "User @upschooling:synapse already exists. \e[1;38;5;2mOK\033[0m"
|
|
|
|
else
|
|
|
|
echo "Could not create user @upschooling:synapse"
|
|
|
|
echo $REGISTER_USER_OUTPUT
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo -e "Matrix user @upschooling:synapse created. \e[1;38;5;2mOK\033[0m"
|
|
|
|
fi
|
2022-02-26 18:40:02 +00:00
|
|
|
|
2022-02-26 16:27:19 +00:00
|
|
|
$CONTAINER_RUNTIME run -d \
|
|
|
|
--log-driver "k8s-file" \
|
|
|
|
--name=elementweb \
|
|
|
|
"--network=container:$($CONTAINER_RUNTIME inspect --format "{{.Id}}" nextcloud)" \
|
|
|
|
-v "$DIR/extra/element-web-nginx.conf:/etc/nginx/conf.d/default.conf" \
|
2022-02-26 18:40:21 +00:00
|
|
|
-v "$DIR/extra/element-config.json:/app/config.json" \
|
2022-02-26 16:27:19 +00:00
|
|
|
--hostname elementweb \
|
|
|
|
docker.io/vectorim/element-web
|
|
|
|
|
|
|
|
echo -e "Element Web has started. \e[1;38;5;2mOK\033[0m"
|
|
|
|
|
2022-02-26 18:40:02 +00:00
|
|
|
# for nextcloud logs use $CONTAINER_RUNTIME exec --user 33 -it nextcloud ./occ log:watch
|
|
|
|
# for webserver logs use $CONTAINER_RUNTIME logs -f elementweb
|