Skip to content

πŸ—‚οΈ Collection of automation scripts for Hetzner services. One-command Storage Box mounting for Ubuntu (ARM64/x86_64).

License

Notifications You must be signed in to change notification settings

Automations-Project/Hetzner-Shells

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

22 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ—‚οΈ Hetzner Storage Box Auto-Mount

Shell Script Multi-Distro Hetzner License: MIT

ARM64 x86_64 Production Ready alt text

One-command solution to automatically mount Hetzner Storage Box on Linux systems with zero manual configuration. Now supports multiple distributions, non-interactive mode, and enhanced security.

πŸš€ Quick Start

One-Line Install (Recommended)

curl -fsSL https://raw.githubusercontent.com/Automations-Project/Hetzner-Shells/main/Storage/Mount-Storage-Box.sh | sudo bash -s

Download & Review (Safer)

wget https://raw.githubusercontent.com/Automations-Project/Hetzner-Shells/main/Storage/Mount-Storage-Box.sh
chmod +x Mount-Storage-Box.sh
sudo ./Mount-Storage-Box.sh

One-Liners (Examples)

# Simply run:
curl -fsSL https://raw.githubusercontent.com/Automations-Project/Hetzner-Shells/main/Storage/Mount-Storage-Box.sh | sudo bash -s

# Just for testing (Dry Run):
curl -fsSL https://raw.githubusercontent.com/Automations-Project/Hetzner-Shells/main/Storage/Mount-Storage-Box.sh | sudo bash -s -- --dry-run

# Non-interactive:
curl -fsSL https://raw.githubusercontent.com/Automations-Project/Hetzner-Shells/main/Storage/Mount-Storage-Box.sh | sudo bash -s -- --non-interactive --username u123456 --password-file /secure/pass.txt --mount-point /mnt/hetzner-storage --mount-method systemd

✨ Features

Feature Description
πŸ” Auto-Detection Detects distribution (Ubuntu, Debian, RHEL), version, architecture (ARM64/x86_64), package/service managers, and system compatibility
πŸ”§ Repository Fixes Automatically fixes ARM64 repository configuration for ports.ubuntu.com (Ubuntu-specific)
πŸ“¦ Package Management Installs cifs-utils, keyutils, and required kernel modules using apt/yum/dnf/zypper
πŸ” Security First Creates secure credentials file with 0600 permissions; supports password files for non-interactive use; validates mount points; signal handling (INT/TERM) for graceful cleanup; warnings for insecure CLI passwords
πŸ—‚οΈ Smart Mounting Tests SMB versions (3.1.1 to 1.0), validates write access, handles existing mounts; centralized command building for efficiency
βš™οΈ Persistent Setup Optional /etc/fstab or systemd mount unit integration with automount support
πŸŽ›οΈ Non-Interactive Mode Run without prompts using flags (e.g., --username, --password-file, --mount-point); dry-run (--dry-run) and verbose (--verbose) options
πŸ“Š Comprehensive Logging Full operation logging with timestamps, colored output, and ANSI stripping for clean logs
πŸ›‘οΈ Error Handling Strict mode (set -eEuo pipefail), traps for errors/signals, retries (up to 3), automatic backups, rollback capabilities, specific failure diagnostics
⚑ Optimizations Performance tuning (rsize/wsize for Hetzner network); conditional skips for existing setups; spinner for non-blocking operations

πŸ’» Supported Systems

  • βœ… Ubuntu 20.04+ LTS (ARM64/x86_64)
  • βœ… Debian 10+ (x86_64/ARM64 where supported)
  • βœ… RHEL/CentOS 7+ (x86_64)
  • βœ… Fedora (via DNF)
  • βœ… openSUSE (via Zypper)
  • βœ… Hetzner Cloud VPS (all architectures)
  • βœ… Other Linux systems with compatible package managers

🎯 Problem Solved

Before (Manual Process):

# Multiple commands, distro/arch-specific issues
sudo nano /etc/apt/sources.list  # Fix ARM64 repositories
sudo apt update                   # Often fails with 404s
sudo apt install cifs-utils      # "Package not found" errors
sudo nano /etc/cifs-credentials.txt  # Manual credential creation
sudo chmod 0600 /etc/cifs-credentials.txt
sudo mkdir /mnt/hetzner-storage
sudo mount.cifs //server/path /mnt/...  # Complex mount options
sudo nano /etc/fstab             # Manual fstab editing

After (This Script):

# Single command - everything automated
curl -fsSL https://raw.githubusercontent.com/Automations-Project/Hetzner-Shells/main/Storage/Mount-Storage-Box.sh | sudo bash

Non-interactive example:

sudo ./Mount-Storage-Box.sh --non-interactive --username u123456 --password-file /secure/pass.txt --mount-point /data/storage --mount-method systemd

πŸ”§ How It Works

  1. Argument Parsing & Welcome - Handles flags, shows banner
  2. System Analysis - Detects distro, arch, managers, network/DNS
  3. Preparation - Fixes repos (ARM64), updates packages, installs dependencies
  4. Configuration - Gets credentials (interactive or args), mount options with validation
  5. Mount Testing - Negotiates SMB, mounts with retries, verifies access
  6. Persistence - Configures fstab/systemd based on choice/method
  7. Verification & Tips - Shows stats, commands, performance advice

πŸ“‹ Usage Examples

Interactive:

sudo ./Mount-Storage-Box.sh

Non-Interactive with Password File:

sudo ./Mount-Storage-Box.sh --non-interactive --username u123456-sub1 --password-file /secure/pass.txt --verbose

Dry-Run (Preview Changes):

sudo ./Mount-Storage-Box.sh --dry-run --username u123456 --password-file /secure/pass.txt

Custom Options:

sudo ./Mount-Storage-Box.sh --non-interactive --username u123456 --password-file /secure/pass.txt --mount-point /mnt/custom --uid 1000 --gid 1000 --no-tuning --mount-method fstab

Full Help:

sudo ./Mount-Storage-Box.sh --help

πŸ—οΈ Project Structure

Hetzner-Shells/
β”œβ”€β”€ Storage/
β”‚   └── Mount-Storage-Box.sh    # Main auto-mount script (v1.0.2)
β”œβ”€β”€ README.md                   # This file
β”œβ”€β”€ LICENSE                     # MIT License
β”œβ”€β”€ TESTING.md                  # Testing & deployment guide
└── test-logs.txt               # Example test output

πŸ”’ Security Considerations

  • Credentials: Stored in /etc/cifs-credentials.txt with root:0600 ownership. Use --password-file for automation to avoid CLI exposure.
  • Validation: Mount points sanitized against dangerous paths (e.g., /etc, /boot); username regex-checked.
  • Signals: Handles Ctrl+C (INT) and TERM for cleanup (unmount, temp file removal).
  • Recommendations: On production, consider encrypting credentials (e.g., via gpg) or using secrets managers. Run in isolated environments.
  • Audits: Script passes ShellCheck; no known vulnerabilities.

⚑ Optimizations & Best Practices

  • Performance: Hetzner-specific options (seal, rsize=130048, cache=loose) for 300-800 MB/s throughput.
  • Efficiency: Skips redundant steps (e.g., existing packages); non-blocking spinners; conditional network checks in dry-run.
  • Maintainability: Modular functions, readonly globals, centralized logging/error handling.
  • Testing: Use --dry-run for safe previews; full tests in TESTING.md.

🀝 Contributing

Contributions welcome! Submit PRs for new distros, features, or fixes. Run shellcheck Mount-Storage-Box.sh before submitting.

πŸ“„ License

MIT License - see LICENSE for details.

πŸ†˜ Support

  • πŸ“– Documentation: TESTING.md for tests; Hetzner Docs
  • πŸ› Issues: GitHub Issues
  • πŸ’‘ Features: Suggest via Issues
  • πŸ“§ Contact: Open an issue

⭐ Show Your Support

Star this repo if it helps! Contributions and feedback drive improvements.


Made with ❀️ for the Linux & Hetzner community
Get Started β€’ Features β€’ Security β€’ Hetzner Docs

About

πŸ—‚οΈ Collection of automation scripts for Hetzner services. One-command Storage Box mounting for Ubuntu (ARM64/x86_64).

Topics

Resources

License

Stars

Watchers

Forks

Languages