#!/bin/sh oci=$(which podman || which docker) test -n "$APPNAME" || APPNAME=xrforge db=/config/manyfold.sqlite3 # utility funcs error(){ echocolor "[error]" "$*"; exit 1; } echocolor(){ printf "\033[96m%s\033[0m \033[95m%s\033[0m %s\n" "$1" "$2" "$3"; } debug(){ set -x; "$@"; set +x; } create_config(){ test -d ./config || mkdir config test -d ./experiences || mkdir experiences } run(){ test -x ${oci} || { echo "warning: not running manyfold OCI container [install podman/docker/etc]"; exit; } echocolor "[$APPNAME]" "$(basename ${oci}) detected..starting OCI container" ${oci} rm -f xrforge debug ${oci} run "$@" -p 8790:3214 --name xrforge \ -e SECRET_KEY_BASE=lkjwljlkwejrlkjek34k234l \ -e DATABASE_ADAPTER=sqlite3 \ -e SUDO_RUN_UNSAFELY=enabled \ -e HTTPS_ONLY=disabled \ -e MULTIUSER=enabled \ -e FEDERATION=enabled \ -e THEME=vapor \ -e PUBLIC_HOSTNAME=localhost \ -e PUBLIC_PORT=80 \ --cap-add SYS_ADMIN --security-opt apparmor:unconfined --device /dev/fuse \ xrforge #ghcr.io/manyfold3d/manyfold-solo:latest } overlayfs(){ test -d /manyfold || return 0; # nothing to override echocolor "[$APPNAME]" "applying filesystem overlay" cd /manyfold rsync -ravuzi * /. } db(){ default(){ test -f /manyfold/manyfold.sql && ! test -f /config/manyfold.sql && { echocolor "[$APPNAME]" "copying default database" test -d /config || mkdir /config cat /manyfold/manyfold.sql | sqlite3 $db } } dump(){ sqlite3 source.db ".dump" > /manyfold/manyfold.sql } import(){ sqlite3 $db < "$1" #/manyfold/manyfold.sql } "$@" } rclone_mount(){ libraries(){ rclone listremotes | while read remote; do dir="${remote/:/}" test -d /mnt/$dir || mkdir /mnt/$dir echocolor "[$APPNAME]" "rclone: mounting $remote to /mnt/$dir" debug rclone mount --daemon $remote /mnt/$dir -vv debug sqlite3 $db "INSERT INTO libraries VALUES(NULL,'/mnt/$dir',DATE('NOW'),DATE('NOW'),'','','$dir',NULL,'','filesystem','','','','','','$dir',1);" done } library(){ echocolor "[$APPNAME]" "rclone: mounting $RCLONE_REMOTE to /mnt/models" test -d /mnt/models || mkdir /mnt/models debug rclone mount --daemon ${RCLONE_REMOTE}: /mnt/models -vv debug sqlite3 $db "INSERT INTO libraries VALUES(NULL,'/mnt/models',DATE('NOW'),DATE('NOW'),'','','$dir',NULL,'','filesystem','','','','','','models',1);" } test -n "$RCLONE_REMOTE" && library test -n "$RCLONE_REMOTE" || libraries } set_theme(){ test -z "$THEME" && return 0 # nothing to do echocolor "[$APPNAME]" "setting theme to '$THEME'" debug sqlite3 /config/manyfold.sqlite3 "UPDATE settings SET value = '"$THEME"' WHERE var == 'theme';" } rename_app(){ echocolor "[$APPNAME]" "renaming manyfold to $APPNAME" sed -i 's/title: Manyfold/title: '$APPNAME'/g' /usr/src/app/config/locales/*.yml sed -i 's|powered_by_html:.*|powered_by_html: Powered by Manyfold, XR Fragments and XR Forge|g' /usr/src/app/config/locales/*.yml } # The new entrypoint of the docker boot(){ echocolor "[$APPNAME]" "booting..." test -z "$NO_OVERLAYFS" && overlayfs test -z "$NO_DEFAULTDB" && db default rename_app set_theme rclone_mount exec "$@" # exec prevents error 's6-overlay-suexec: fatal: can only run as pid 1' } is_inside_container(){ test -d /package/admin && return 0 || return 1 } usage(){ echocolor "Usage:" manyfold.sh "" echocolor "Cmds:" echocolor " " "run [-d] " "# runs a OCI container (needs podman/docker)" exit 0 } test -n "$1" && "$@" test -n "$1" || usage