@@ -100,13 +100,14 @@ def get_atomic_snap(snapper_root_config):
100100def cleanup ():
101101 logging .info ("Cleaning up..." )
102102 umount_command = f"""
103- LC_ALL=C mount -l | grep '{ TMP_DIR } ' | awk '{{print $3}}' | awk '{{print length, $0}}' | sort -rn | awk '{{print $2}}' | awk '{{system("umount " $0)}}';
103+ LC_ALL=C mount -l | grep '{ TMP_MOUNT_DIR } ' | awk '{{print $3}}' | awk '{{print length, $0}}' | sort -rn | awk '{{print $2}}' | awk '{{system("umount " $0)}}';
104104"""
105105 while True :
106106 out , ret = shell_exec (umount_command )
107107 if out == "" and ret == 0 :
108108 break
109109 time .sleep (0.01 )
110+ shell_exec (f"rmdir { quote (TMP_MOUNT_DIR )} " )
110111 shell_exec (f"rmdir { quote (TMP_DIR )} " )
111112
112113def sigint_handler (signum , frame ):
@@ -257,6 +258,8 @@ def sigint_handler(signum, frame):
257258
258259# Create secure temp dir
259260TMP_DIR = tempfile .mkdtemp (dir = "/tmp" , prefix = "atomic-update_" )
261+ TMP_MOUNT_DIR = f"{ TMP_DIR } /rootfs"
262+ os .makedirs (TMP_MOUNT_DIR , mode = 0o700 , exist_ok = True )
260263
261264# Handle commands: dup, run
262265if COMMAND in ["dup" , "run" ]:
@@ -310,15 +313,15 @@ def sigint_handler(signum, frame):
310313 # populate temp dir with atomic snapshot mounts
311314 logging .info ("Setting up temp mounts..." )
312315 commands = f"""
313- mount -o subvol={ snap_subvol } { rootfs_device } { TMP_DIR } ;
314- for i in dev proc run sys; do mount --rbind --make-rslave /$i { TMP_DIR } /$i; done;
315- chroot { TMP_DIR } mount -a;
316+ mount -o subvol={ snap_subvol } { rootfs_device } { TMP_MOUNT_DIR } ;
317+ for i in dev proc run sys; do mount --rbind --make-rslave /$i { TMP_MOUNT_DIR } /$i; done;
318+ chroot { TMP_MOUNT_DIR } mount -a;
316319"""
317320 shell_exec (commands )
318321 if COMMAND == "dup" :
319322 # check if dup has anything to do
320323 logging .info ("Checking for packages to upgrade" )
321- xml_output , ret = shell_exec (f"LC_ALL=C zypper --root { TMP_DIR } --non-interactive --no-cd --xmlout dist-upgrade --dry-run" )
324+ xml_output , ret = shell_exec (f"LC_ALL=C zypper --root { TMP_MOUNT_DIR } --non-interactive --no-cd --xmlout dist-upgrade --dry-run" )
322325 docroot = ET .fromstring (xml_output )
323326 for item in docroot .iter ('install-summary' ):
324327 num_pkgs = int (item .attrib ["packages-to-change" ])
@@ -327,7 +330,7 @@ def sigint_handler(signum, frame):
327330 cleanup ()
328331 sys .exit ()
329332 logging .info ("Performing distribution upgrade within chroot..." )
330- ret = os .system (f"zypper --root { TMP_DIR } { '' if CONFIRM else '--non-interactive' } --no-cd dist-upgrade" )
333+ ret = os .system (f"zypper --root { TMP_MOUNT_DIR } { '' if CONFIRM else '--non-interactive' } --no-cd dist-upgrade" )
331334 if ret != 0 :
332335 logging .error (f"Zypper returned exit code { ret } . Discarding snapshot { atomic_snap } " )
333336 shell_exec (f"snapper -c { snapper_root_config } delete { atomic_snap } " )
@@ -337,7 +340,7 @@ def sigint_handler(signum, frame):
337340 elif COMMAND == "run" :
338341 exec_cmd = ' ' .join (ARG )
339342 logging .info (f"Running command { exec_cmd !r} within chroot..." )
340- ret = os .system (f"chroot { snap_dir } { exec_cmd } " )
343+ ret = os .system (f"chroot { TMP_MOUNT_DIR } { exec_cmd } " )
341344 if ret != 0 :
342345 logging .error (f"Command returned exit code { ret } . Discarding snapshot { atomic_snap } " )
343346 shell_exec (f"snapper -c { snapper_root_config } delete { atomic_snap } " )
@@ -347,7 +350,7 @@ def sigint_handler(signum, frame):
347350 if SHELL :
348351 logging .info (f"Opening bash shell within chroot of snapshot { atomic_snap } " )
349352 logging .info ("Continue with 'exit' or discard with 'exit 1'" )
350- ret = os .system (f"chroot { snap_dir } env PS1='atomic-update:${{PWD}} # ' bash --noprofile --norc" )
353+ ret = os .system (f"chroot { TMP_MOUNT_DIR } env PS1='atomic-update:${{PWD}} # ' bash --noprofile --norc" )
351354 if ret != 0 :
352355 logging .error (f"Shell returned exit code { ret } . Discarding snapshot { atomic_snap } " )
353356 shell_exec (f"snapper -c { snapper_root_config } delete { atomic_snap } " )
0 commit comments