jualhosting commited on
Commit
8ed4d8b
·
verified ·
1 Parent(s): c2e48c2

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +42 -0
  2. README.md +21 -5
  3. entrypoint.sh +70 -0
Dockerfile ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:22.04
2
+
3
+ # Avoid interactive prompts during package installation
4
+ ENV DEBIAN_FRONTEND=noninteractive
5
+
6
+ # Update system and install required packages
7
+ RUN apt-get update && apt-get install -y \
8
+ curl \
9
+ git \
10
+ python3 \
11
+ rclone \
12
+ inotify-tools \
13
+ && rm -rf /var/lib/apt/lists/*
14
+
15
+ # Install File Browser using the official script
16
+ RUN curl -fsSL https://raw.githubusercontent.com/filebrowser/filebrowser/master/get.sh | bash
17
+
18
+ # Create a non-root user matching Hugging Face Space UID (1000)
19
+ RUN useradd -m -u 1000 user && \
20
+ mkdir -p /data && \
21
+ chown -R user:user /data
22
+
23
+ # Set user home and workspace
24
+ ENV HOME=/home/user
25
+ WORKDIR $HOME
26
+
27
+ # Switch to the non-root user
28
+ USER user
29
+
30
+ # Create directories for File Browser configuration and database
31
+ RUN mkdir -p $HOME/setup_guide
32
+
33
+ # Copy setup guide and entrypoint script
34
+ COPY --chown=user:user setup_guide/index.html $HOME/setup_guide/index.html
35
+ COPY --chown=user:user entrypoint.sh $HOME/entrypoint.sh
36
+ RUN chmod +x $HOME/entrypoint.sh
37
+
38
+ # Expose Hugging Face Space default port
39
+ EXPOSE 7860
40
+
41
+ # Set entrypoint
42
+ CMD ["/home/user/entrypoint.sh"]
README.md CHANGED
@@ -1,10 +1,26 @@
1
  ---
2
- title: FileBrowser
3
- emoji: 📈
4
- colorFrom: pink
5
- colorTo: purple
6
  sdk: docker
 
7
  pinned: false
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Cloud File Manager
3
+ emoji: 📁
4
+ colorFrom: green
5
+ colorTo: blue
6
  sdk: docker
7
+ app_port: 7860
8
  pinned: false
9
  ---
10
 
11
+ # Cloud File Manager (File Browser + Google Drive Sync)
12
+
13
+ A fully-featured web-based file manager that looks like Google Drive/Dropbox, hosted on **Hugging Face Spaces (Free Tier)**. It persistent-syncs all files and settings to your **Google Drive** using **Rclone**.
14
+
15
+ ## Features
16
+ * **Google Drive Integration**: Syncs files and database automatically back to your Drive.
17
+ * **Persistent Settings**: Saves user accounts, shares, and settings.
18
+ * **UI**: File Browser (clean, mobile-friendly Google Drive alternative).
19
+ * **Port**: 7860 (Hugging Face default).
20
+ * **Resource**: 16 GB RAM / 2 vCPUs.
21
+
22
+ ## How to Configure
23
+ 1. Create a new Space on Hugging Face using the **Docker** SDK (Blank template).
24
+ 2. Upload `Dockerfile`, `entrypoint.sh`, `README.md`, and the `setup_guide` folder to your Space.
25
+ 3. Configure `RCLONE_CONFIG_DATA` in your Space Settings -> **Repository secrets**. Refer to the on-screen setup guide for details.
26
+ 4. Restart your Space.
entrypoint.sh ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Define paths
4
+ CONFIG_PATH="/tmp/rclone.conf"
5
+ DB_PATH="/tmp/filebrowser.db"
6
+ DATA_DIR="/data"
7
+
8
+ # Check if RCLONE_CONFIG_DATA secret is set
9
+ if [ -z "$RCLONE_CONFIG_DATA" ]; then
10
+ echo "RCLONE_CONFIG_DATA is missing. Starting setup guide server on port 7860..."
11
+ # Start a simple python server to show the configuration guide
12
+ python3 -m http.server 7860 --directory /home/user/setup_guide
13
+ exit 0
14
+ fi
15
+
16
+ # Write the rclone config file
17
+ echo "$RCLONE_CONFIG_DATA" > "$CONFIG_PATH"
18
+ chmod 600 "$CONFIG_PATH"
19
+
20
+ # Extract the remote name from rclone.conf dynamically (the first section name)
21
+ REMOTE_NAME=$(grep -oE '^\[[^\]]+\]' "$CONFIG_PATH" | head -n 1 | tr -d '[]')
22
+
23
+ if [ -z "$REMOTE_NAME" ]; then
24
+ echo "Failed to parse remote name from rclone config. Using fallback 'gdrive'."
25
+ REMOTE_NAME="gdrive"
26
+ fi
27
+
28
+ echo "Detected remote name: $REMOTE_NAME"
29
+
30
+ # Ensure SQLite database file exists so inotifywait can monitor it
31
+ touch "$DB_PATH"
32
+
33
+ # 1. Download database from Google Drive if it exists
34
+ echo "Checking for persistent database on Google Drive..."
35
+ rclone copy "$REMOTE_NAME:.filebrowser.db" "/tmp/" --config "$CONFIG_PATH" || true
36
+
37
+ # 2. Download files from Google Drive to local /data directory
38
+ echo "Syncing files from Google Drive..."
39
+ rclone sync "$REMOTE_NAME:" "$DATA_DIR" --config "$CONFIG_PATH" || true
40
+
41
+ # 3. Start background sync loops
42
+ # Loop A: Sync files in /data to Google Drive when modified
43
+ (
44
+ echo "Starting file sync daemon..."
45
+ while true; do
46
+ # Monitor /data for write, create, delete, or move events
47
+ inotifywait -r -e modify,create,delete,move "$DATA_DIR"
48
+ sleep 5
49
+ echo "Changes detected in $DATA_DIR, syncing to Google Drive ($REMOTE_NAME)..."
50
+ rclone sync "$DATA_DIR" "$REMOTE_NAME:" --config "$CONFIG_PATH"
51
+ done
52
+ ) &
53
+
54
+ # Loop B: Sync database /tmp/filebrowser.db to Google Drive when modified
55
+ (
56
+ echo "Starting database sync daemon..."
57
+ while true; do
58
+ # Monitor SQLite database file for modification events
59
+ inotifywait -e modify "$DB_PATH"
60
+ sleep 2
61
+ echo "Database modified, uploading to Google Drive ($REMOTE_NAME)..."
62
+ rclone copyto "$DB_PATH" "$REMOTE_NAME:.filebrowser.db" --config "$CONFIG_PATH"
63
+ done
64
+ ) &
65
+
66
+ # 4. Start File Browser
67
+ echo "Starting File Browser on port 7860..."
68
+ # File Browser will run in the foreground. Default credentials are admin / admin.
69
+ # Make sure to change your password after logging in.
70
+ filebrowser --port 7860 --address 0.0.0.0 --database "$DB_PATH" --root "$DATA_DIR"