From 391aa25f5903aba3a3f40220e6d1d6ef34bb32c5 Mon Sep 17 00:00:00 2001
From: David Beniamine <david.beniamine@tetras-libre.fr>
Date: Wed, 5 Feb 2025 13:46:43 +0100
Subject: [PATCH] Build our own to fix umask limitations

---
 .env.sample          |  3 ++-
 Readme.md            |  5 +++--
 docker/Dockerfile    | 14 ++++++++++++++
 docker/entrypoint.sh |  1 -
 4 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/.env.sample b/.env.sample
index 5ba3054..557c921 100644
--- a/.env.sample
+++ b/.env.sample
@@ -3,7 +3,8 @@ COMPOSE_FILE=docker-compose.yml:dev.yml
 # For prod
 #COMPOSE_FILE=docker-compose.yml:traefik.yml
 NAME=filebrowser
-VERSION=v2
+# Must be full version number
+VERSION=v2.32.0
 # Hostname for prod `FQDN` ex HOSTS=`files.example.org`
 HOSTS=
 DEV_PORT=8080
diff --git a/Readme.md b/Readme.md
index 5a51f5b..73ca616 100644
--- a/Readme.md
+++ b/Readme.md
@@ -9,6 +9,8 @@ docker-compose up -d
 
 The initial credentials are admin / admin please change them as soon as your are logged in.
 
+We build our own version of filebrowser to fix issue [3399](https://github.com/filebrowser/filebrowser/issues/3399#issuecomment-2326120447).
+
 ## Customisation
 
 ### Run a command upon file creation
@@ -25,11 +27,10 @@ It will be called each time a new file/directory is created with the file path a
 
 ### Set default permissions
 
-It is possible to set a [umask](https://www.liquidweb.com/blog/what-is-umask-and-how-to-use-it-effectively/) on all files created but this is only compatible with filebrowser versions up to 2.27, so you must set in your `.env`
+It is possible to set a [umask](https://www.liquidweb.com/blog/what-is-umask-and-how-to-use-it-effectively/) on all files created.
 
 ```
 UMASK=007
-VERSION=v2.27.9
 ```
 
 If you which that all new directories have permissions `770`  and files `660`
diff --git a/docker/Dockerfile b/docker/Dockerfile
index 8cd3890..98e7b1e 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -1,5 +1,19 @@
+ARG VERSION=v2
+FROM node:22 as frontbuilder
+RUN git clone https://github.com/filebrowser/filebrowser; cd filebrowser; git switch -d ${VERSION}
+RUN cd filebrowser/frontend; npm install; npm install -g pnpm; npm run build
+RUN ls -lstrh /filebrowser
+
+FROM golang:1.23 AS builder
+COPY --from=frontbuilder /filebrowser /go/filebrowser
+# See https://github.com/filebrowser/filebrowser/issues/3399#issuecomment-2573494806
+RUN cd filebrowser; sed -i 's/755/777/' files/file.go; sed -i 's/644/666/' files/file.go; go mod download; CGO_ENABLED=0 go build -ldflags="-s -w"
+RUN ls -lstrh /go/filebrowser
+
 ARG VERSION=v2
 FROM filebrowser/filebrowser:${VERSION}
+COPY --from=builder /go/filebrowser/filebrowser /filebrowser
+RUN ls -lstrh /
 COPY entrypoint.sh /
 RUN apk add inotify-tools shadow
 ENTRYPOINT '/entrypoint.sh'
diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh
index 30eeae3..ff4cd59 100755
--- a/docker/entrypoint.sh
+++ b/docker/entrypoint.sh
@@ -15,4 +15,3 @@ if [ ! -z "$UMASK" ]; then
 fi
 callback_daemon &
 exec /filebrowser
-
-- 
GitLab