Skip to content
Snippets Groups Projects
Verified Commit 3f210b4a authored by David Beniamine's avatar David Beniamine
Browse files

Umask and callbacks

parent 8f7748d1
No related branches found
No related tags found
No related merge requests found
...@@ -10,5 +10,5 @@ DEV_PORT=8080 ...@@ -10,5 +10,5 @@ DEV_PORT=8080
DATA_PATH=./data/files DATA_PATH=./data/files
UID=1000 UID=1000
GID=1000 GID=1000
DEFAULT_PERMS_DIR=755 UMASK=
DEFAULT_PERMS_FILE=644 FILE_CREATION_SCRIPT=
...@@ -8,3 +8,28 @@ docker-compose up -d ...@@ -8,3 +8,28 @@ docker-compose up -d
The initial credentials are admin / admin please change them as soon as your are logged in. The initial credentials are admin / admin please change them as soon as your are logged in.
## Customisation
### Run a command upon file creation
If you which to run a commande upon file creation (or upload), you can add a custom script in `data/scripts/new_file.sh`, this script **must** be executable, and **must** start with `/bin/sh` not `/bin/bash`.
Then add to your `.env` :
```
FILE_CREATION_SCRIPT=/scripts/new_file.sh
```
It will be called each time a new file/directory is created with the file path as the first argument
### 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`
```
UMASK=007
VERSION=v2.27.9
```
If you which that all new directories have permissions `770` and files `660`
...@@ -9,7 +9,8 @@ services: ...@@ -9,7 +9,8 @@ services:
user: "${UID}:${GID}" user: "${UID}:${GID}"
volumes: volumes:
- ./data/database.db:/database.db - ./data/database.db:/database.db
- ./data/scripts:/scripts
- ${DATA_PATH}:/srv - ${DATA_PATH}:/srv
environment: environment:
DEFAULT_PERMS_DIR: FILE_CREATION_SCRIPT:
DEFAULT_PERMS_FILE: UMASK:
ARG VERSION=v2 ARG VERSION=v2
FROM filebrowser/filebrowser:${VERSION} FROM filebrowser/filebrowser:${VERSION}
COPY entrypoint.sh / COPY entrypoint.sh /
RUN apk add inotify-tools RUN apk add inotify-tools shadow
ENTRYPOINT '/entrypoint.sh' ENTRYPOINT '/entrypoint.sh'
#!/bin/sh #!/bin/sh
set_perms() { callback_daemon() {
if [ -z "$FILE_CREATION_SCRIPT" ]; then
return
fi
inotifywait --monitor --recursive --quiet --event create /srv --format "%w%f" | \ inotifywait --monitor --recursive --quiet --event create /srv --format "%w%f" | \
while read f;do while read f;do
if [ -d "$f" ]; then $FILE_CREATION_SCRIPT "$f"
chmod -R $DEFAULT_PERMS_DIR "$f"
else
chmod $DEFAULT_PERMS_FILE "$f"
fi
done done
} }
set_perms & if [ ! -z "$UMASK" ]; then
echo "Setting umask to $UMASK"
umask $UMASK
fi
callback_daemon &
exec /filebrowser exec /filebrowser
...@@ -2,5 +2,6 @@ ...@@ -2,5 +2,6 @@
DIR=$(dirname $0) DIR=$(dirname $0)
mkdir -p $DIR/data/files mkdir -p $DIR/data/files
mkdir -p $DIR/data/scripts
touch $DIR/data/database.db touch $DIR/data/database.db
cp $DIR/.env.sample .env cp $DIR/.env.sample .env
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment