jualhosting commited on
Commit
9f8a082
·
verified ·
1 Parent(s): 274c0f4

Upload 4 files

Browse files
Files changed (1) hide show
  1. entrypoint.sh +23 -7
entrypoint.sh CHANGED
@@ -37,18 +37,34 @@ if [ -z "$REMOTE_NAME" ]; then
37
  REMOTE_NAME="gdrive"
38
  fi
39
 
40
- echo "Detected remote name: '$REMOTE_NAME'"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  # Ensure SQLite database file exists so inotifywait can monitor it
43
  touch "$DB_PATH"
44
 
45
  # 1. Download database from Google Drive if it exists
46
  echo "Checking for persistent database on Google Drive..."
47
- rclone copyto "$REMOTE_NAME:.filebrowser.db" "$DB_PATH" --config "$CONFIG_PATH" --drive-skip-shortcuts --drive-acknowledge-abuse || true
48
 
49
  # 2. Download files from Google Drive to local /data directory
50
  echo "Syncing files from Google Drive..."
51
- rclone copy "$REMOTE_NAME:" "$DATA_DIR" --config "$CONFIG_PATH" --drive-skip-shortcuts --drive-acknowledge-abuse || true
52
 
53
  # 3. Start background sync loops
54
  # Loop A: Sync files in /data to Google Drive when modified
@@ -58,8 +74,8 @@ rclone copy "$REMOTE_NAME:" "$DATA_DIR" --config "$CONFIG_PATH" --drive-skip-sho
58
  # Monitor /data for write, create, delete, or move events
59
  inotifywait -r -e modify,create,delete,move "$DATA_DIR"
60
  sleep 5
61
- echo "Changes detected in $DATA_DIR, copying to Google Drive ($REMOTE_NAME)..."
62
- rclone copy "$DATA_DIR" "$REMOTE_NAME:" --config "$CONFIG_PATH" --drive-skip-shortcuts --drive-acknowledge-abuse
63
  done
64
  ) &
65
 
@@ -70,8 +86,8 @@ rclone copy "$REMOTE_NAME:" "$DATA_DIR" --config "$CONFIG_PATH" --drive-skip-sho
70
  # Monitor SQLite database file for modification events
71
  inotifywait -e modify "$DB_PATH"
72
  sleep 2
73
- echo "Database modified, uploading to Google Drive ($REMOTE_NAME)..."
74
- rclone copyto "$DB_PATH" "$REMOTE_NAME:.filebrowser.db" --config "$CONFIG_PATH"
75
  done
76
  ) &
77
 
 
37
  REMOTE_NAME="gdrive"
38
  fi
39
 
40
+ # Determine the remote path (root or subfolder) to prevent exceeding Hugging Face's 50GB limit
41
+ if [ -n "$RCLONE_REMOTE_PATH" ]; then
42
+ # Trim leading/trailing slashes
43
+ CLEAN_PATH=$(echo "$RCLONE_REMOTE_PATH" | sed -e 's/^\///' -e 's/\/$//')
44
+ REMOTE_PATH="$REMOTE_NAME:$CLEAN_PATH"
45
+ echo "Using subfolder path: $REMOTE_PATH"
46
+ else
47
+ REMOTE_PATH="$REMOTE_NAME:"
48
+ echo "Using root path: $REMOTE_PATH"
49
+ fi
50
+
51
+ # Set shared-with-me flag if requested
52
+ SHARED_FLAG=""
53
+ if [ "$RCLONE_SHARED_WITH_ME" = "true" ]; then
54
+ SHARED_FLAG="--drive-shared-with-me"
55
+ echo "Rclone will access 'Shared with me' files/folders."
56
+ fi
57
 
58
  # Ensure SQLite database file exists so inotifywait can monitor it
59
  touch "$DB_PATH"
60
 
61
  # 1. Download database from Google Drive if it exists
62
  echo "Checking for persistent database on Google Drive..."
63
+ rclone copyto "$REMOTE_PATH/.filebrowser.db" "$DB_PATH" --config "$CONFIG_PATH" --drive-skip-shortcuts --drive-acknowledge-abuse $SHARED_FLAG || true
64
 
65
  # 2. Download files from Google Drive to local /data directory
66
  echo "Syncing files from Google Drive..."
67
+ rclone copy "$REMOTE_PATH" "$DATA_DIR" --config "$CONFIG_PATH" --drive-skip-shortcuts --drive-acknowledge-abuse $SHARED_FLAG || true
68
 
69
  # 3. Start background sync loops
70
  # Loop A: Sync files in /data to Google Drive when modified
 
74
  # Monitor /data for write, create, delete, or move events
75
  inotifywait -r -e modify,create,delete,move "$DATA_DIR"
76
  sleep 5
77
+ echo "Changes detected in $DATA_DIR, copying to Google Drive ($REMOTE_PATH)..."
78
+ rclone copy "$DATA_DIR" "$REMOTE_PATH" --config "$CONFIG_PATH" --drive-skip-shortcuts --drive-acknowledge-abuse $SHARED_FLAG
79
  done
80
  ) &
81
 
 
86
  # Monitor SQLite database file for modification events
87
  inotifywait -e modify "$DB_PATH"
88
  sleep 2
89
+ echo "Database modified, uploading to Google Drive ($REMOTE_PATH)..."
90
+ rclone copyto "$DB_PATH" "$REMOTE_PATH/.filebrowser.db" --config "$CONFIG_PATH" $SHARED_FLAG
91
  done
92
  ) &
93