Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ease of setup script, shell function for ratarmount #149

Open
shodanx2 opened this issue Feb 24, 2025 · 0 comments
Open

Ease of setup script, shell function for ratarmount #149

shodanx2 opened this issue Feb 24, 2025 · 0 comments

Comments

@shodanx2
Copy link

Hello,

I wanted to make it easier on myself to setup ratarmount in the future on my debian system.

So I created this shell function, which for now appears to work
It creates a mount service using the venv and it also runs daily commit of the files.

first installing ratarmount on debian (not 100% on this, my notes are poor)

apt install python3 python3-pip python3-venv fuse sqlite3
python3 -m venv /opt/ratarmount
source /opt/ratarmount/bin/activate
 pip install ratarmount[full]
apt install liblzo2-dev
/opt/ratarmount/bin/ratarmount --help

the shell function in oneliner format ready to paste

create_ratarmount_service() { [[ -f "$2" && -d "$1" && -x "$1/bin/ratarmount" && -d "$3" ]] || { echo "Error: Check paths (venv, tar file, mount point)"; return 1; }; OVERLAY="${2%.*}-overlay"; MOUNT_SERVICE="/etc/systemd/system/ratarmount.service"; COMMIT_SERVICE="/etc/systemd/system/ratarmount-commit.service"; COMMIT_TIMER="/etc/systemd/system/ratarmount-commit.timer"; echo '🔄 Stopping and removing any existing ratarmount services...'; systemctl stop ratarmount ratarmount-commit 2>/dev/null; systemctl disable ratarmount ratarmount-commit 2>/dev/null; rm -f "$MOUNT_SERVICE" "$COMMIT_SERVICE" "$COMMIT_TIMER"; echo '📌 Creating new systemd service files...'; echo -e "[Unit]\nDescription=Ratarmount Service for $2\[nAfter=network.target](http://nafter=network.target/) [local-fs.target](http://local-fs.target/)\n[Service]\nType=simple\nExecStart=/bin/bash -c 'source $1/bin/activate && ratarmount --write-overlay $OVERLAY $2 $3'\nExecStop=/bin/bash -c 'fusermount -u $3'\nRestart=always\nUser=root\n[Install]\[nWantedBy=multi-user.target](http://nwantedby=multi-user.target/)" > "$MOUNT_SERVICE"; echo -e "[Unit]\nDescription=Commit Ratarmount overlay changes to TAR\nAfter=ratarmount.service\n[Service]\nType=oneshot\nExecStart=/bin/bash -c '[[ -n \"\$(ls -A $OVERLAY 2>/dev/null)\" ]] && ratarmount --commit-overlay --write-overlay $OVERLAY $2 $3 || echo No changes detected'\n[Install]\[nWantedBy=multi-user.target](http://nwantedby=multi-user.target/)" > "$COMMIT_SERVICE"; echo -e "[Unit]\nDescription=Daily commit of Ratarmount overlay changes\n[Timer]\nOnCalendar=daily\nPersistent=true\n[Install]\[nWantedBy=timers.target](http://nwantedby=timers.target/)" > "$COMMIT_TIMER"; echo '🔄 Reloading systemd and enabling services...'; systemctl daemon-reload; systemctl enable ratarmount ratarmount-commit ratarmount-commit.timer; systemctl start ratarmount; systemctl start ratarmount-commit.timer; systemctl status ratarmount --no-pager; systemctl status ratarmount-commit.timer --no-pager; ls -la "$3"; echo -e "✅ Ratarmount setup complete\n📂 TAR File: $2\n📍 Mount Point: $3\n🗂️ Overlay Folder: $OVERLAY\n🛠️ Services:\n   - Mount: $MOUNT_SERVICE\n   - Commit: $COMMIT_SERVICE\n   - Timer: $COMMIT_TIMER (runs daily)\n📌 Changes in the overlay will be committed automatically once a day.\n🔄 Manually trigger commit anytime with: systemctl start ratarmount-commit"; }

Example command

create_ratarmount_service "/opt/ratarmount" "/mnt/winiso/template/windows.iso.repository.tar.zst" "/mnt/winiso/template/iso"

Usage information

create_ratarmount_service --help
Usage: create_ratarmount_service <VENV_PATH> <TAR_FILE> <MOUNT_POINT>

Automatically sets up and configures a systemd service to mount a TAR file using Ratarmount.
Also configures an automatic daily commit of overlay changes.

Arguments:
  VENV_PATH    Path to the Ratarmount virtual environment (e.g., /opt/ratarmount)
  TAR_FILE     Path to the TAR archive to be mounted (e.g., /mnt/winiso/template/windows.iso.repository.tar.zst)
  MOUNT_POINT  Path to the folder where the TAR should be mounted (e.g., /mnt/winiso/template/iso)

Example:
  create_ratarmount_service /opt/ratarmount /mnt/winiso/template/windows.iso.repository.tar.zst /mnt/winiso/template/iso

Description:
  - Creates systemd services for mounting and committing overlay changes.
  - Uses an overlay folder stored alongside the TAR file (e.g., windows.iso.repository-overlay).
  - Commits overlay changes to the TAR file once per day via a systemd timer.
  - Provides detailed status and file listing after setup.

Generated Systemd Services:
  - /etc/systemd/system/ratarmount.service            (Mounts the TAR file)
  - /etc/systemd/system/ratarmount-commit.service    (Commits changes from the overlay to the TAR)
  - /etc/systemd/system/ratarmount-commit.timer      (Schedules commit daily)

Additional Commands:
  - Manually trigger a commit: systemctl start ratarmount-commit
  - Check mount status:         systemctl status ratarmount
  - Check commit timer:         systemctl list-timers --all | grep ratarmount-commit
  - Unmount manually:           fusermount -u <MOUNT_POINT>
  - Remove all services:        systemctl stop ratarmount ratarmount-commit && systemctl disable ratarmount ratarmount-commit ratarmount-commit.timer && rm -f /etc/systemd/system/ratarmount*

Notes:
  - The TAR file must exist before running this function.
  - The Ratarmount virtual environment must be set up with the necessary dependencies.
  - The mount point directory must exist.

Sample console output

root@proxmox:~# create_ratarmount_service "/opt/ratarmount" "/mnt/winiso/template/windows.iso.repository.tar.zst" "/mnt/winiso/template/iso"
🔄 Stopping and removing any existing ratarmount services...
📌 Creating new systemd service files...
🔄 Reloading systemd and enabling services...
Created symlink /etc/systemd/system/multi-user.target.wants/ratarmount.service → /etc/systemd/system/ratarmount.service.
Created symlink /etc/systemd/system/multi-user.target.wants/ratarmount-commit.service → /etc/systemd/system/ratarmount-commit.service.
Created symlink /etc/systemd/system/timers.target.wants/ratarmount-commit.timer → /etc/systemd/system/ratarmount-commit.timer.
● ratarmount.service - Ratarmount Service for /mnt/winiso/template/windows.iso.repository.tar.zst
     Loaded: loaded (/etc/systemd/system/ratarmount.service; enabled; preset: enabled)
     Active: active (running) since Mon 2025-02-24 07:31:31 EST; 11ms ago
   Main PID: 2862928 (ratarmount)
      Tasks: 1 (limit: 76956)
     Memory: 3.1M
        CPU: 9ms
     CGroup: /system.slice/ratarmount.service
             └─2862928 /opt/ratarmount/bin/python3 /opt/ratarmount/bin/ratarmount --write-overlay /mnt/winiso/template/windows.iso.repository.tar-overlay /mnt/winiso/template/windows.iso.repository.tar.zst /mnt/winiso/template/iso

Feb 24 07:31:31 proxmox systemd[1]: Started ratarmount.service - Ratarmount Service for /mnt/winiso/template/windows.iso.repository.tar.zst.
● ratarmount-commit.timer - Daily commit of Ratarmount overlay changes
     Loaded: loaded (/etc/systemd/system/ratarmount-commit.timer; enabled; preset: enabled)
     Active: active (waiting) since Mon 2025-02-24 07:31:31 EST; 11ms ago
    Trigger: Tue 2025-02-25 00:00:00 EST; 16h left
   Triggers: ● ratarmount-commit.service

Feb 24 07:31:31 proxmox systemd[1]: Started ratarmount-commit.timer - Daily commit of Ratarmount overlay changes.
total 8
drwxr-xr-x 2 root root 4096 Feb 24 05:08 .
drwxr-xr-x 3 root root 4096 Feb 24 06:14 ..
✅ Ratarmount setup complete
📂 TAR File: /mnt/winiso/template/windows.iso.repository.tar.zst
📍 Mount Point: /mnt/winiso/template/iso
🗂️ Overlay Folder: /mnt/winiso/template/windows.iso.repository.tar-overlay
🛠️ Services:
   - Mount: /etc/systemd/system/ratarmount.service
   - Commit: /etc/systemd/system/ratarmount-commit.service
   - Timer: /etc/systemd/system/ratarmount-commit.timer (runs daily)
📌 Changes in the overlay will be committed automatically once a day.
🔄 Manually trigger commit anytime with: systemctl start ratarmount-commit
root@proxmox:~# 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant