PEPify fstab

This commit is contained in:
Teo Mrnjavac 2014-07-29 14:26:19 +02:00
parent 906560ffee
commit 98b62808de

View File

@ -18,9 +18,6 @@
# along with Calamares. If not, see <http://www.gnu.org/licenses/>. # along with Calamares. If not, see <http://www.gnu.org/licenses/>.
import os import os
import subprocess
import sys
import tempfile
import libcalamares import libcalamares
@ -39,64 +36,54 @@ FS_MAP = {
} }
def mkdir_p( path ): def mkdir_p(path):
if not os.path.exists( path ): if not os.path.exists(path):
os.makedirs( path ) os.makedirs(path)
def listUuids(): def generate_fstab_line(partition):
dct = {} fs = partition["fs"]
uuidDir = "/dev/disk/by-uuid" mount_point = partition["mountPoint"]
for uuid in os.listdir( uuidDir ):
devicePath = os.readlink( os.path.join( uuidDir, uuid ) )
devicePath = os.path.join( "/dev", os.path.basename( devicePath ) )
dct[ devicePath ] = uuid
return dct
fs = FS_MAP.get(fs, fs)
def generateFstabLine( partition ): if not mount_point and not fs == "swap":
fs = partition[ "fs" ]
mountPoint = partition[ "mountPoint" ]
fs = FS_MAP.get( fs, fs )
if not mountPoint and not fs == "swap":
return return
options = "defaults" options = "defaults"
if mountPoint == "/": if mount_point == "/":
check = 1 check = 1
elif mountPoint: elif mount_point:
check = 2 check = 2
else: else:
check = 0 check = 0
return "UUID={} {:<14} {:<7} {:<10} 0 {}".format( return "UUID={} {:<14} {:<7} {:<10} 0 {}".format(
partition[ "uuid" ], partition["uuid"],
mountPoint or "none", mount_point or "none",
fs, fs,
options, options,
check) check)
def run(): def run():
partitions = libcalamares.globalStorage.value( "partitions" ) partitions = libcalamares.globalstorage.value("partitions")
rootMountPoint = libcalamares.globalStorage.value( "rootMountPoint" ) root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
# Create fstab # Create fstab
mkdir_p( os.path.join( rootMountPoint, "etc" ) ) mkdir_p(os.path.join(root_mount_point, "etc"))
fstabPath = os.path.join( rootMountPoint, "etc", "fstab" ) fstab_path = os.path.join(root_mount_point, "etc", "fstab")
with open( fstabPath, "w" ) as fl: with open(fstab_path, "w") as fl:
print( HEADER, file = fl ) print(HEADER, file=fl)
for partition in partitions: for partition in partitions:
line = generateFstabLine( partition ) line = generate_fstab_line(partition)
if line: if line:
print( line, file = fl ) print(line, file=fl)
# Create mount points # Create mount points
for partition in partitions: for partition in partitions:
if partition[ "mountPoint" ]: if partition["mountPoint"]:
mkdir_p( rootMountPoint + partition[ "mountPoint" ] ) mkdir_p(root_mount_point + partition["mountPoint"])
return "All done" return None