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

[BUG] rename doesn't consider custom MOUNT #659

Open
gahr opened this issue Jan 6, 2024 · 1 comment · May be fixed by #666
Open

[BUG] rename doesn't consider custom MOUNT #659

gahr opened this issue Jan 6, 2024 · 1 comment · May be fixed by #666
Labels
bug Something isn't working

Comments

@gahr
Copy link

gahr commented Jan 6, 2024

[MANDATORY] Describe the bug [MANDATORY]
The rename command contains a update_fstab routine to update the fstab file of the jail to the new name. However, this is not applied to custom mounts, e.g., those initiated by a MOUNT command in a template.

[MANDATORY] Bastille and FreeBSD version (paste bastille -v && freebsd-version -kru output)
0.10.20231125
14.0-RELEASE-p3
14.0-RELEASE-p3
14.0-RELEASE-p4

[MANDATORY] How did you install bastille? (port/pkg/git)
pkg

[optional] Steps to reproduce?

  1. create a jail named foo
  2. apply a template that contains a MOUNT command, e.g., MOUNT /root/bastille/data data nullfs rw 0 0
  3. rename the jail: bastille rename foo bar
  4. see how the custom entry in the jail fstab file still points to the old path: /root/bastille/data /usr/local/bastille/jails/foo/root/data nullfs rw 0 0

[optional] Expected behavior
The rename command takes care of updating all entries in fstab, so my entry would be updated to /root/bastille/data /usr/local/bastille/jails/bar/root/data nullfs rw 0 0

@gahr gahr added the bug Something isn't working label Jan 6, 2024
@gahr
Copy link
Author

gahr commented Jan 6, 2024

This might be simplistic but works for me :)

From 0be4428682c272d4bff2fcf23f3a1898b86b0483 Mon Sep 17 00:00:00 2001
From: Pietro Cerutti <[email protected]>
Date: Sat, 6 Jan 2024 13:28:02 +0000
Subject: [PATCH] rename: adjust all mount points

---
 usr/local/share/bastille/rename.sh | 19 +------------------
 1 file changed, 1 insertion(+), 18 deletions(-)

diff --git a/usr/local/share/bastille/rename.sh b/usr/local/share/bastille/rename.sh
index 08ebe10..9caf7e8 100644
--- a/usr/local/share/bastille/rename.sh
+++ b/usr/local/share/bastille/rename.sh
@@ -81,24 +81,7 @@ update_fstab() {
     # Update fstab to use the new name
     FSTAB_CONFIG="${bastille_jailsdir}/${NEWNAME}/fstab"
     if [ -f "${FSTAB_CONFIG}" ]; then
-        # Skip if fstab is empty, e.g newly created thick or clone jails
-        if [ -s "${FSTAB_CONFIG}" ]; then
-            FSTAB_RELEASE=$(grep -owE '([1-9]{2,2})\.[0-9](-RELEASE|-RC[1-9])|([0-9]{1,2}-stable-build-[0-9]{1,3})|(current-build)-([0-9]{1,3})|(current-BUILD-LATEST)|([0-9]{1,2}-stable-BUILD-LATEST)|(current-BUILD-LATEST)' "${FSTAB_CONFIG}")
-            FSTAB_CURRENT=$(grep -w ".*/releases/.*/jails/${TARGET}/root/.bastille" "${FSTAB_CONFIG}")
-            FSTAB_NEWCONF="${bastille_releasesdir}/${FSTAB_RELEASE} ${bastille_jailsdir}/${NEWNAME}/root/.bastille nullfs ro 0 0"
-            if [ -n "${FSTAB_CURRENT}" ] && [ -n "${FSTAB_NEWCONF}" ]; then
-                # If both variables are set, update as needed
-                if ! grep -qw "${bastille_releasesdir}/${FSTAB_RELEASE}.*${bastille_jailsdir}/${NEWNAME}/root/.bastille" "${FSTAB_CONFIG}"; then
-                    sed -i '' "s|${FSTAB_CURRENT}|${FSTAB_NEWCONF}|" "${FSTAB_CONFIG}"
-                fi
-            fi
-
-            # Update linuxjail fstab name entries
-            # Search for either linprocfs/linsysfs, if true assume is a linux jail
-            if grep -qwE "linprocfs|linsysfs" "${FSTAB_CONFIG}"; then
-                sed -i '' "s|.${bastille_jailsdir}/${TARGET}/|${bastille_jailsdir}/${NEWNAME}/|" "${FSTAB_CONFIG}"
-            fi
-        fi
+        sed -i '' "s|${bastille_jailsdir}/${TARGET}|${bastille_jailsdir}/${NEWNAME}|g" "${FSTAB_CONFIG}"
     fi
 }
 
-- 
2.43.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant