diff --git a/settings.conf b/settings.conf index c8d163974..d2c41ec24 100644 --- a/settings.conf +++ b/settings.conf @@ -34,6 +34,7 @@ install: - locale - keyboard #- users +- umount # Phase 3 - postinstall. # View modules are shown as UI pages, jobs from job modules are executed immediately in diff --git a/src/modules/umount/main.py b/src/modules/umount/main.py new file mode 100644 index 000000000..8c51a2d2c --- /dev/null +++ b/src/modules/umount/main.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +# encoding: utf-8 +# === This file is part of Calamares - === +# +# Copyright 2014, Aurélien Gâteau +# +# Calamares is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Calamares is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Calamares. If not, see . + +import os +import subprocess + +import libcalamares + + +def listMounts( rootMountPoint ): + lst = [] + for line in open( "/etc/mtab" ).readlines(): + device, mountPoint, _ = line.split( " ", 2 ) + if mountPoint.startswith( rootMountPoint ): + lst.append( ( device, mountPoint ) ) + return lst + + +def calamares_main(): + rootMountPoint = libcalamares.global_storage.value( "rootMountPoint" ) + if not rootMountPoint: + return "GlobalStorage does not contain a \"rootMountPoint\" key, doing nothing" + if not os.path.exists( rootMountPoint ): + return "GlobalStorage[\"rootMountPoint\"] is \"{}\", which does not exist, doing nothing".format( rootMountPoint ) + + lst = listMounts( rootMountPoint ) + # Sort the list by mount point in decreasing order. This way we can be sure + # we unmount deeper dirs first. + lst.sort( key = lambda x: x[ 1 ], reverse = True ) + + for device, mountPoint in lst: + subprocess.check_call( [ "umount", mountPoint ] ) + + os.rmdir( rootMountPoint ) + return "All done" diff --git a/src/modules/umount/module.conf b/src/modules/umount/module.conf new file mode 100644 index 000000000..64168b3e6 --- /dev/null +++ b/src/modules/umount/module.conf @@ -0,0 +1,6 @@ +type: "job" +name: "umount" +interface: "python" +requires: [] +script: "main.py" +configuration: