Anaconda/PreScript

From FedoraProject

Jump to: navigation, search

Example Pre Script Kickstart Section

#



%pre --interpreter /usr/bin/python
import commands
import os
import string
import sys
import re

script_name = sys.argv[0] 

output = commands.getoutput('fdisk -l')

pattern = "sda"
matchobj = re.search(pattern, output)
if matchobj:
scsi = "yes"
else:
scsi = "no"

pattern = "sdb"
matchobj = re.search(pattern, output)
if matchobj:
scsi2 = "yes"
else:
scsi2 = "no"

pattern = "hda"
matchobj = re.search(pattern, output)
if matchobj:
ide = "yes"
else:
ide = "no"

pattern = "hdb"
matchobj = re.search(pattern, output)
if matchobj:
ide2 = "yes"
else:
ide2 = "no"

if scsi == "yes":
drive1 = "sda"
drive1_size = commands.getoutput('fdisk -l').strip()
pattern = "sda: (\d+)"
matchobj = re.search(pattern, drive1_size)
if matchobj:
drive1_size = matchobj.group(1)
if scsi2 == "yes":
drive2 = "sdb"
elif ide == "yes":
drive2 = "hda"

if scsi == "no":
if ide == "yes":
drive1 = "hda"
drive1_size = commands.getoutput('fdisk -l').strip()
pattern = "hda: (\d+)"
matchobj = re.search(pattern, drive1_size)
if matchobj:
drive1_size = matchobj.group(1)

if ide2 == "yes":
drive2 = "hdb"

drive1_size = float(drive1_size)

drive_size_m = int(drive1_size) * 1024

boot_size = 100;
var_size = int(drive_size_m)/15
usr_size = int(drive_size_m)/15
root_size = 1024
tmp_size = 1024

f = open('/tmp/part-include', 'w')

f.write("""# Drive partitioning information determined from %s
clearpart --all --initlabel
part /boot --fstype ext3 --size=%s --ondisk=%s --asprimary
part /var --fstype ext3 --size=%s --ondisk=%s
part /usr --fstype ext3 --size=%s --ondisk=%s --asprimary
part / --fstype ext3 --size=%s --ondisk=%s
part swap --recommended --ondisk=%s --asprimary
part /tmp --fstype ext3 --size=%s --ondisk=%s
part /home --fstype ext3 --size=1 --grow --ondisk=%s
""" %(script_name, boot_size, drive1, var_size, drive1, usr_size, drive1, root_size, drive1, drive1, tmp_size, drive1, drive1) )

try: drive2
except NameError:
f.write('# no backup selected\n')
else:
f.write('part /backup --fstype ext3 --size=1 --grow --ondisk=%s' % drive2)

f.close()