Skip to content

Instantly share code, notes, and snippets.

@vijinho
Created January 8, 2025 01:27
Show Gist options
  • Save vijinho/2e66ded83cd236c2f29cc9dc1c4b349f to your computer and use it in GitHub Desktop.
Save vijinho/2e66ded83cd236c2f29cc9dc1c4b349f to your computer and use it in GitHub Desktop.
Folder mounting tool for Internet Archive archive.org items using rclone, making access to IA items transparent to the filesystem
#!/bin/bash
# Internet Archive File Mounting Tool
usage() {
echo "Usage:"
echo "1. Create a file with the archive.org ID (e.g., 'test.ia' for https://archive.org/details/test)."
echo "2. Run this script."
echo "It will mount each '.ia' file, list its contents, and append directory information to the corresponding file."
}
# Check if rclone command exists
if ! command -v rclone &> /dev/null; then
echo "ERROR: rclone command not found."
echo "Please download and install rclone from: https://rclone.org/"
exit 1
fi
# Check if there are any .ia files present
if [ ! -f *.ia ]; then
usage
exit 1
fi
# Loop through all '.ia' files
for item in *.ia; do
archive_id=$(basename "$item" .ia)
# Check if archive ID exists on archive.org using curl and grep
curl -s "https://archive.org/details/$archive_id" | grep -q "<title>" && echo "$archive_id exists on archive.org" || {
echo "ERROR: $archive_id does not exist on archive.org"
continue 2 # Skip to the next iteration if the ID doesn't exist
}
mkdir -p $archive_id
rclone mount ia://"$archive_id"/ "$archive_id" --daemon --read-only \
--attr-timeout=48h --dir-cache-time=48h \
--vfs-cache-mode full --vfs-fast-fingerprint \
--write-back-cache --vfs-case-insensitive \
--vfs-cache-max-age 48h --vfs-read-chunk-size 1M \
--vfs-read-ahead 1M --no-modtime --cache-dir "$TEMP" --volname "$archive_id"
# Generate directory tree and disk usage information, displaying it
#sleep 3 # give a few seconds for the mount to happen
tree $archive_id > "$item"
cat $item
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment