From 27e619a3cb772ba769a8d0809bba8a257e4eab0c Mon Sep 17 00:00:00 2001 From: nguyenpanda Date: Thu, 20 Aug 2026 22:46:10 +0700 Subject: [PATCH 1/2] Fix `bin/init::set_up_config_files` error on macOS due to `sed` implementation differences on BSD. **Error encountered on macOS:** `sed: 1: "...": extra characters at the end of n command` **Reference:** [StackOverflow: sed command with -i option in place editing works fine on Ubuntu but not Mac](https://stackoverflow.com/questions/16745988/sed-command-with-i-option-in-place-editing-works-fine-on-ubuntu-but-not-mac) ## Description This PR fixes a cross-platform scripting issue in `bin/init`. The `-i` (in-place) flag behaves differently between GNU `sed` (Linux) and BSD `sed` (macOS). On macOS, BSD `sed` requires a space between the `-i` flag and the backup extension (or empty string), whereas GNU `sed` requires no space. The previous implementation (`sed -i''`) caused the script to fail on macOS. This update implements a cross-platform approach so the configuration files generate successfully on both Linux and macOS environments. --- bin/init | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/init b/bin/init index 21ab7d90..d7897afb 100755 --- a/bin/init +++ b/bin/init @@ -44,8 +44,9 @@ function set_up_config_files() { cp "$TOOLKIT_ROOT/lib/config-seed/version" "$TOOLKIT_ROOT/config/" local invite_token_secret invite_token_secret="$(openssl rand -base64 32)" - sed -i'' "s|OVERLEAF_INVITE_TOKEN_SECRET=|OVERLEAF_INVITE_TOKEN_SECRET=${invite_token_secret}|" \ + sed -i.bak "s|OVERLEAF_INVITE_TOKEN_SECRET=|OVERLEAF_INVITE_TOKEN_SECRET=${invite_token_secret}|" \ "$TOOLKIT_ROOT/config/variables.env" + rm -f "$TOOLKIT_ROOT/config/variables.env.bak" } function set_up_tls_proxy() { From e26b06ca543abb7c2c52679c1e61c8cf0eb0d0e9 Mon Sep 17 00:00:00 2001 From: nguyenpanda Date: Thu, 20 Aug 2026 23:02:58 +0700 Subject: [PATCH 2/2] Customize for my personal self-hosted overleaf --- Dockerfile | 7 ++ NGUYEPANDA_README.md | 169 ++++++++++++++++++++++++++++++++++++ lib/config-seed/overleaf.rc | 2 +- lib/docker-compose.base.yml | 1 + lib/shared-functions.sh | 2 +- 5 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100644 NGUYEPANDA_README.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..38ae0253 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM sharelatex/sharelatex:6.2.2 + +# Upgrade and install full TeXLive scheme +RUN tlmgr update --self && \ + tlmgr install scheme-full && \ + tlmgr path add + \ No newline at end of file diff --git a/NGUYEPANDA_README.md b/NGUYEPANDA_README.md new file mode 100644 index 00000000..56216f85 --- /dev/null +++ b/NGUYEPANDA_README.md @@ -0,0 +1,169 @@ +# nguyenpanda Overleaf Deployment Guide + +This document captures the complete, step-by-step replication guide for the Overleaf Toolkit deployment tailored for the nguyenpanda environment. + +## 1. Prerequisites & Initialization + +Clone the Overleaf Toolkit and initialize the default configurations: + +```bash +git clone https://github.com/overleaf/toolkit.git overleaf-toolkit +cd overleaf-toolkit +./bin/init +``` + +## 2. Custom Image Build (TeXLive Full) + +To ensure persistence of the full LaTeX library across container restarts without re-downloading packages, a custom `Dockerfile` is used. + +**Create `Dockerfile` in the toolkit root:** + +```dockerfile +FROM sharelatex/sharelatex:6.2.2 + +# Upgrade and install full TeXLive scheme +RUN tlmgr update --self && \ + tlmgr install scheme-full && \ + tlmgr path add +``` + +**Patch Version Validation Script:** + +Modify `lib/shared-functions.sh` to allow the `-full` suffix. Edit the regex check around line 18: + +```bash +# In lib/shared-functions.sh in read_image_version() +if [[ ! "$IMAGE_VERSION" =~ ^([0-9]+)\.([0-9]+)\.([0-9])+(-RC[0-9]*)?(-with-texlive-full|-full)?$ ]]; then +``` + +**Update `config/version`:** + +Edit `config/version` to use the newly built custom tag: + +```text +6.2.2-full +``` + +**Build the custom image:** + +```bash +docker build -t sharelatex/sharelatex:6.2.2-full . +``` + +## 3. Environment Variables & Core Configuration + +### `config/overleaf.rc` + +Modify the core configuration to bind to `127.0.0.1:9999` (for Cloudflare Tunneling) and disable sibling containers for the Community Edition. + +```zsh +#### Overleaf RC #### + +PROJECT_NAME=overleaf + +OVERLEAF_DATA_PATH=data/overleaf +SERVER_PRO=false +OVERLEAF_LISTEN_IP=127.0.0.1 +OVERLEAF_PORT=9999 + +# Sibling Containers +SIBLING_CONTAINERS_ENABLED=false +DOCKER_SOCKET_PATH=/var/run/docker.sock + +# Mongo configuration +MONGO_ENABLED=true +MONGO_DATA_PATH=data/mongo +MONGO_IMAGE=mongo +MONGO_VERSION=8.0 + +# Redis configuration +REDIS_ENABLED=true +REDIS_DATA_PATH=data/redis +REDIS_IMAGE=redis:7.4 +REDIS_AOF_PERSISTENCE=true + +# Git-bridge configuration (Server Pro only) +GIT_BRIDGE_ENABLED=false +GIT_BRIDGE_DATA_PATH=data/git-bridge +NGINX_ENABLED=false +NGINX_CONFIG_PATH=config/nginx/nginx.conf +NGINX_HTTP_PORT=80 +NGINX_HTTP_LISTEN_IP=127.0.1.1 +NGINX_TLS_LISTEN_IP=127.0.1.1 +TLS_PRIVATE_KEY_PATH=config/nginx/certs/overleaf_key.pem +TLS_CERTIFICATE_PATH=config/nginx/certs/overleaf_certificate.pem +TLS_PORT=443 +``` + +*Note: `SIBLING_CONTAINERS_ENABLED` is explicitly set to `false` to disable sandboxing warnings for Community Edition.* + +### `config/variables.env` + +Apply the custom branding, proxy settings, and strictly formatted JSON footers. The header image URL includes a query parameter `?v=2` to bypass aggressive browser caching of redirects. + +```zsh +OVERLEAF_APP_NAME="Overleaf | nguyenpanda" + +ENABLED_LINKED_FILE_TYPES=project_file,project_output_file + +# Enables Thumbnail generation using an external converter (pdftocairo by default) +ENABLE_CONVERSIONS=true + +# Disables email confirmation requirement +EMAIL_CONFIRMATION_DISABLED=true +OVERLEAF_ALLOW_PUBLIC_REGISTRATION=false + +# Secret generated at bin/init time +# If you clone directly this branch, must run `openssl rand -base64 32` and pass to below +OVERLEAF_INVITE_TOKEN_SECRET= + +## Nginx +# NGINX_WORKER_PROCESSES=4 +# NGINX_WORKER_CONNECTIONS=768 + +## Set for TLS via nginx-proxy +OVERLEAF_BEHIND_PROXY=true +OVERLEAF_SECURE_COOKIE=true + +OVERLEAF_SITE_URL=https://overleaf.nguyenpanda.com +OVERLEAF_NAV_TITLE="Overleaf: nguyenpanda" +OVERLEAF_HEADER_IMAGE_URL="/header.png" +OVERLEAF_ADMIN_EMAIL="nguyenpanda@nguyenpanda.com" + +OVERLEAF_LEFT_FOOTER='[{"text": "Hosted locally by nguyenpanda.com", "url": "https://nguyenpanda.com"}]' +OVERLEAF_RIGHT_FOOTER='[{"text": "System Administrator: nguyenpanda", "url": "mailto:nguyenpanda@nguyenpanda.com"}]' + +################ +## Server Pro ## +################ + +EXTERNAL_AUTH=none +``` + +## 4. UI & Brand Customization (Docker Compose Mods) + +To serve the custom header image (`header.png`), an explicit read-only volume mount was added to `lib/docker-compose.base.yml`. + +**In `lib/docker-compose.base.yml` under `sharelatex.volumes`:** + +```yaml +services: + sharelatex: + volumes: + - "${OVERLEAF_DATA_PATH}:${OVERLEAF_IN_CONTAINER_DATA_PATH}" + - "${OVERLEAF_DATA_PATH}/header.png:/overleaf/services/web/public/header.png:ro" +``` + +Place your custom logo file at `data/overleaf/header.png`. Note that placing it directly inside `data/overleaf/` is required because `${OVERLEAF_DATA_PATH}` resolves to `data/overleaf`. + +## 5. Operation Commands + +To properly apply changes and start the server without data loss: + +```bash +# Stop and remove containers (preserves data in mounted volumes) +./bin/docker-compose down + +# Start containers in detached mode +./bin/up -d +``` diff --git a/lib/config-seed/overleaf.rc b/lib/config-seed/overleaf.rc index 3d08256e..ac960922 100644 --- a/lib/config-seed/overleaf.rc +++ b/lib/config-seed/overleaf.rc @@ -11,7 +11,7 @@ OVERLEAF_LISTEN_IP=127.0.0.1 OVERLEAF_PORT=80 # Sibling Containers -SIBLING_CONTAINERS_ENABLED=true +SIBLING_CONTAINERS_ENABLED=false DOCKER_SOCKET_PATH=/var/run/docker.sock # Mongo configuration diff --git a/lib/docker-compose.base.yml b/lib/docker-compose.base.yml index 4e061bc8..4a5400c5 100644 --- a/lib/docker-compose.base.yml +++ b/lib/docker-compose.base.yml @@ -7,6 +7,7 @@ services: container_name: sharelatex volumes: - "${OVERLEAF_DATA_PATH}:${OVERLEAF_IN_CONTAINER_DATA_PATH}" + - "${OVERLEAF_DATA_PATH}/header.png:/overleaf/services/web/public/header.png:ro" ports: - "${OVERLEAF_LISTEN_IP:-127.0.0.1}:${OVERLEAF_PORT:-80}:80" environment: diff --git a/lib/shared-functions.sh b/lib/shared-functions.sh index a35d17c7..356d0d54 100644 --- a/lib/shared-functions.sh +++ b/lib/shared-functions.sh @@ -15,7 +15,7 @@ function read_config() { function read_image_version() { IMAGE_VERSION="$(head -n 1 "$TOOLKIT_ROOT/config/version")" - if [[ ! "$IMAGE_VERSION" =~ ^([0-9]+)\.([0-9]+)\.([0-9])+(-RC[0-9]*)?(-with-texlive-full)?$ ]]; then + if [[ ! "$IMAGE_VERSION" =~ ^([0-9]+)\.([0-9]+)\.([0-9])+(-RC[0-9]*)?(-with-texlive-full|-full)?$ ]]; then echo "ERROR: invalid version '${IMAGE_VERSION}'" exit 1 fi