summaryrefslogtreecommitdiffstats
path: root/scripts/anaconda-cleanup
diff options
context:
space:
mode:
authorDavid Lehman <dlehman@redhat.com>2010-12-15 14:48:05 -0600
committerDavid Lehman <dlehman@redhat.com>2010-12-17 10:26:03 -0600
commit06f0f376e3297eba60e5c2a278eb223a16af305a (patch)
tree4fd59ae040a8b1e49b0ed81d705db839504a9567 /scripts/anaconda-cleanup
parent518fb847919d3b4d0ad2e57fb94d889150dd0166 (diff)
downloadanaconda-06f0f376e3297eba60e5c2a278eb223a16af305a.tar.gz
anaconda-06f0f376e3297eba60e5c2a278eb223a16af305a.tar.xz
anaconda-06f0f376e3297eba60e5c2a278eb223a16af305a.zip
Rename anaconda-image-cleanup and use it for all cleanup in liveinst.
New name is anaconda-cleanup.
Diffstat (limited to 'scripts/anaconda-cleanup')
-rwxr-xr-xscripts/anaconda-cleanup98
1 files changed, 98 insertions, 0 deletions
diff --git a/scripts/anaconda-cleanup b/scripts/anaconda-cleanup
new file mode 100755
index 000000000..5107bfc2b
--- /dev/null
+++ b/scripts/anaconda-cleanup
@@ -0,0 +1,98 @@
+#!/usr/bin/python
+"""
+ image install:
+
+ - unmount everything under /mnt/sysimage
+ - populate a devicetree with only the image "disks"
+
+ live install:
+
+ - unmount everything under /mnt/sysimage
+ - unmount everything under /media
+ - populate a devicetree and tear everything down
+
+"""
+import os
+import sys
+
+live_install = "--liveinst" in sys.argv
+image_install = False
+
+# see if there are disk images to take down
+sys_class_block = "/sys/class/block"
+for dev in os.listdir(sys_class_block):
+ if not dev.startswith("dm-"):
+ continue
+
+ uuid = open("%s/%s/dm/uuid" % (sys_class_block, dev)).read().strip()
+ if uuid.startswith("ANACONDA-"):
+ image_install = True
+ break
+
+# set the imageInstall flag so the logger won't log to the syslog
+from pyanaconda.flags import flags
+flags.imageInstall = True
+
+import pyanaconda.anaconda_log
+pyanaconda.anaconda_log.init()
+
+from pyanaconda import iutil
+
+from pyanaconda.cmdline import InstallInterface
+from pyanaconda.storage import StorageDiscoveryConfig
+from pyanaconda.storage.devicetree import DeviceTree
+from pyanaconda.storage import devicelibs
+
+intf = InstallInterface()
+storage_config = StorageDiscoveryConfig()
+
+# find devices representing disk images
+sys_class_block = "/sys/class/block"
+for dev in os.listdir(sys_class_block):
+ if not dev.startswith("dm-"):
+ continue
+
+ name = open("%s/%s/dm/name" % (sys_class_block, dev)).read().strip()
+ uuid = open("%s/%s/dm/uuid" % (sys_class_block, dev)).read().strip()
+ if not name or not uuid.startswith("ANACONDA-"):
+ continue
+
+ loop = os.listdir("%s/%s/slaves" % (sys_class_block, dev))[0].strip()
+ path = devicelibs.loop.get_device_path(loop)
+ storage_config.diskImages[name] = path
+
+if not image_install and not live_install:
+ print >> sys.stderr, "not a live install or an image install -- exiting"
+ sys.exit(1)
+
+# unmount filesystems
+for mounted in reversed(open("/proc/mounts").readlines()):
+ (device, mountpoint, rest) = mounted.split(" ", 2)
+ if mountpoint.startswith("/mnt/anactest"):
+ continue
+
+ # If this is for an image install, only unmount all filesystems under
+ # /mnt/sysimage
+ if image_install and not mountpoint.startswith("/mnt/sysimage"):
+ continue
+
+ # If this is for a live install, unmount any non-nodev filesystem that
+ # isn't related to the live image.
+ if (not mountpoint.startswith("/media") and
+ not device.startswith("/dev") or
+ "live" in mounted):
+ continue
+
+ os.system("umount %s" % mountpoint)
+
+os.system("udevadm control --env=ANACONDA=1")
+os.system("udevadm trigger --subsystem-match block")
+os.system("udevadm settle")
+devicetree = DeviceTree(intf=intf, conf=storage_config)
+devicetree.populate(cleanupOnly=True)
+devicetree.teardownAll()
+for name in devicetree.diskImages.keys():
+ device = devicetree.getDeviceByName(name)
+ device.deactivate(recursive=True)
+os.system("udevadm control --env=ANACONDA=0")
+