Created
April 29, 2025 18:43
-
-
Save KiralyCraft/7d600b5e6c5662e58b80451f5cb6f46b to your computer and use it in GitHub Desktop.
S3Hub - Local Mount
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CRED_FILE="${HOME}/.passwd-s3fs" | |
BUCKET_FILE="${HOME}/.s3fs_bucket_name" | |
MOUNT_POINT="${HOME}/s3bucket" | |
S3_URL="http://s3hub-intern.cs.ubbcluj.ro:9000" | |
# Check for existing credentials | |
if [[ -f "${CRED_FILE}" ]]; then | |
echo "Credentials file found at ${CRED_FILE}." | |
read -p "Do you want to reset the credentials? (y/n): " RESET | |
if [[ "${RESET}" =~ ^[Yy]$ ]]; then | |
rm -f "${CRED_FILE}" | |
fi | |
fi | |
# Prompt for new credentials if needed | |
if [[ ! -f "${CRED_FILE}" ]]; then | |
read -p "Enter your Access Key ID: " ACCESS_KEY | |
read -s -p "Enter your Secret Access Key: " SECRET_KEY | |
echo | |
echo "${ACCESS_KEY}:${SECRET_KEY}" > "${CRED_FILE}" | |
chmod 600 "${CRED_FILE}" | |
echo "Credentials saved to ${CRED_FILE}." | |
fi | |
# Check or ask for bucket name | |
if [[ -f "${BUCKET_FILE}" ]]; then | |
BUCKET=$(<"${BUCKET_FILE}") | |
echo "Previously used bucket: ${BUCKET}" | |
read -p "Do you want to use this bucket? (y/n): " USE_OLD | |
if [[ ! "${USE_OLD}" =~ ^[Yy]$ ]]; then | |
read -p "Enter the S3 bucket name: " BUCKET | |
echo "${BUCKET}" > "${BUCKET_FILE}" | |
fi | |
else | |
read -p "Enter the S3 bucket name: " BUCKET | |
echo "${BUCKET}" > "${BUCKET_FILE}" | |
fi | |
# Create mount point | |
mkdir -p "${MOUNT_POINT}" | |
# Mount the S3 bucket | |
s3fs "${BUCKET}" "${MOUNT_POINT}" \ | |
-o passwd_file="${CRED_FILE}" \ | |
-o url="${S3_URL}" \ | |
-o use_path_request_style | |
# Confirm mount status | |
if mountpoint -q "${MOUNT_POINT}"; then | |
echo "Bucket '${BUCKET}' successfully mounted at ${MOUNT_POINT}" | |
else | |
echo "Failed to mount the bucket. Please verify your settings." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment