diff --git a/docker-run.sh b/docker-run.sh deleted file mode 100755 index decf9a6..0000000 --- a/docker-run.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -set -euo pipefail -IFS=$'\n\t' - -DIR="${0%/*}" -docker rm -f nextcloud -docker run -d --name=nextcloud -p 8080:80 -v "${PWD}:/var/www/html/custom_apps/upschooling" docker.io/nextcloud -docker exec nextcloud chown -R 33 /var/www/html/custom_apps -docker exec nextcloud chmod -R ug+rw /var/www/html/custom_apps -docker exec --user 33 nextcloud bash -c 'cd /var/www/html/custom_apps/upschooling && make composer' -docker exec --user 33 nextcloud php occ maintenance:install --database "sqlite" --admin-user "admin" --admin-pass "admin" -docker exec --user 33 nextcloud php occ config:system:set --value=true --type=boolean debug -docker exec --user 33 nextcloud php occ app:enable --force upschooling - - diff --git a/podman-reown.sh b/podman-reown.sh deleted file mode 100755 index c81773c..0000000 --- a/podman-reown.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -set -euo pipefail -IFS=$'\n\t' - -DIR="${0%/*}" - -if [ $(id -u) -eq 0 ];then - podman exec nextcloud chown -R 33 /var/www/html/custom_apps - podman exec nextcloud chmod -R ug+rw /var/www/html/custom_apps -else - podman unshare -- chown -R 33 "$DIR" - podman unshare -- chgrp -R 0 "$DIR" - podman unshare -- chmod -R ug+rw "$DIR" -fi diff --git a/podman-run.sh b/podman-run.sh deleted file mode 100755 index a57412d..0000000 --- a/podman-run.sh +++ /dev/null @@ -1,85 +0,0 @@ -#!/bin/bash - -set -euo pipefail -IFS=$'\n\t' - -DIR="${0%/*}" - -# replace containers -podman rm -if synapse -podman rm -if nextcloud - -if [[ ! -d vendor ]]; then - make composer -fi - -podman run -d --name=nextcloud -p 8080:80 -p 8008:8008 -v "$DIR:/var/www/html/custom_apps/upschooling" \ - --add-host "synapse:127.0.0.1" docker.io/nextcloud -podman exec nextcloud bash -c 'apt-get update && apt-get install -y git' -podman exec nextcloud chown -R 33 /var/www/html/custom_apps -"$DIR/podman-reown.sh" -podman exec --user 33 nextcloud bash -c 'cd /var/www/html/custom_apps/upschooling && make composer' -podman exec --user 33 nextcloud php occ maintenance:install --database sqlite --admin-user admin --admin-pass admin -podman exec --user 33 nextcloud php occ config:system:set --value=true --type=boolean debug -podman exec --user 33 nextcloud php occ app:enable --force upschooling - -if podman volume exists synapse-data; then - echo "Found existing synapse-data volume" -else - podman 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="$(podman volume inspect --format "{{.Mountpoint}}" synapse-data)" -if [ $(id -u) -eq 0 ];then - sed -i 's|macaroon_secret_key: .*|macaroon_secret_key: "~d9fJpPKDZIV67A7=tPCvok:=fTBLV;MFf=9FRxtAazW@-GwSo"|' "$LOCAL_SYNAPSE_DATA_PATH/homeserver.yaml" -else - podman unshare -- sed -i 's|macaroon_secret_key: .*|macaroon_secret_key: "~d9fJpPKDZIV67A7=tPCvok:=fTBLV;MFf=9FRxtAazW@-GwSo"|' "$LOCAL_SYNAPSE_DATA_PATH/homeserver.yaml" -fi - -podman run -d \ - --log-driver "k8s-file" \ - --name=synapse \ - "--mount=type=volume,src=synapse-data,dst=/data" \ - "--network=container:$(podman 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 podman 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 \`podman logs synapse\` to investigate" - exit 1 -fi - -set +e -REGISTER_USER_OUTPUT="$(podman 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 diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..0dffd5e --- /dev/null +++ b/run.sh @@ -0,0 +1,115 @@ +#!/bin/bash + +set -xeuo pipefail +IFS=$'\n\t' + +DIR="${0%/*}" +RUNTIME_IS_PODMAN="false" +if [[ -x "$(which podman)" ]]; then + CONTAINER_RUNTIME="$(which podman)" + RUNTIME_IS_PODMAN="true" +elif [[ -x "$(which docker)" ]]; then + CONTAINER_RUNTIME="$(which docker)" +else + echo "Container runtime (docker/podman) not found!" + exit 1 +fi + +# replace containers +if $CONTAINER_RUNTIME inspect --type container synapse; then + $CONTAINER_RUNTIME rm -f synapse +fi +if $CONTAINER_RUNTIME inspect --type container nextcloud; then + $CONTAINER_RUNTIME rm -f nextcloud +fi + +if [[ ! -d vendor ]]; then + make composer +fi + +$CONTAINER_RUNTIME run -d \ + --name=nextcloud \ + -p 8080:80 \ + -p 8008:8008 \ + -v "$DIR:/var/www/html/custom_apps/upschooling" \ + --add-host "synapse:127.0.0.1" \ + docker.io/nextcloud + +$CONTAINER_RUNTIME exec nextcloud bash -c 'apt-get update && apt-get install -y git' +$CONTAINER_RUNTIME exec nextcloud chown -R 33 /var/www/html/custom_apps + +if [[ $(id -u) -eq 0 || $RUNTIME_IS_PODMAN != "true" ]]; then + $CONTAINER_RUNTIME exec nextcloud chown -R 33 /var/www/html/custom_apps + $CONTAINER_RUNTIME exec nextcloud chmod -R ug+rw /var/www/html/custom_apps +else + $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 +$CONTAINER_RUNTIME exec --user 33 nextcloud php occ app:enable --force upschooling + +if $CONTAINER_RUNTIME volume exists synapse-data; then + echo "Found existing synapse-data volume" +else + $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)" +SED_ARGS=(-i 's|macaroon_secret_key: .*|macaroon_secret_key: "~d9fJpPKDZIV67A7=tPCvok:=fTBLV;MFf=9FRxtAazW@-GwSo"|' "$LOCAL_SYNAPSE_DATA_PATH/homeserver.yaml") +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