#!/bin/bash
#================
# FILE          : linuxrc
#----------------
# PROJECT       : OpenSuSE KIWI Image System
# COPYRIGHT     : (c) 2006 SUSE LINUX Products GmbH. All rights reserved
#               :
# AUTHOR        : Marcus Schaefer <ms@suse.de>
#               :
# BELONGS TO    : Operating System images
#               :
# DESCRIPTION   : OEM repartition code functions. This file is used
#               : to setup the partition table according to the OEM
#               : specifications
#               :
# STATUS        : BETA
#----------------
#======================================
# OEMRepartInit 
#--------------------------------------
function OEMRepartInit {
	# /.../
	# calculate memory based swapsize amount and initialize
	# size of recovery archive
	# ----
	mem_size=`grep MemTotal: /proc/meminfo | tr -dc '[0-9]'`
	swapsize=$(( $mem_size *2 / 1024 ))
	recoMByte=0
	if [ ! -z "$OEM_SWAPSIZE" ];then
		swapsize=$OEM_SWAPSIZE
	fi
	if [ ! -z "$OEM_WITHOUTSWAP" ];then
		swapsize=0
	fi
	if [ ! -z "$OEM_RECOVERY" ];then
		mkdir -p /reco-root
		if ! mount $imageRootDevice /reco-root >/dev/null;then
			systemException "Failed to mount root device" "reboot"
		fi
		if [ ! -f /reco-root/recovery.partition.size ];then
			systemException "Can't find recovery part size info" "reboot"
		fi
		recoMByte=$(cat /reco-root/recovery.partition.size)
		recoID=83
		if [ ! -z "$OEM_RECOVERY_ID" ];then
			recoID=$OEM_RECOVERY_ID
		fi
		umount /reco-root && rmdir /reco-root
	fi
	export input=/part.input
	rm -f $input
}

#======================================
# OEMRepartStandard
#--------------------------------------
function OEMRepartStandard {
	# /.../
	# repartition disk with read/write root filesystem
	# Initial partition table layout is:
	# =====================================
	# p1: ( root )  +luks
	# p2: [ boot ]
	# -------------------------------------
	#======================================
	# check for boot partition
	#--------------------------------------
	createBootDeviceData 2
	#======================================
	# deactivate features if required
	#--------------------------------------
	if [ "$haveBootPartition" = "yes" ];then
		export OEM_WITHOUTHOME=1
	fi
	#======================================
	# setup initial boot device ID
	#--------------------------------------
	export bootid=1
	if [ "$haveBootPartition" = "yes" ];then
		bootid=2
	fi
	#======================================
	# calculate partition sizes
	#--------------------------------------
	minhome=0
	if [ -z "$OEM_WITHOUTHOME" ];then
		minhome=500
	fi
	diskXMBytes=$(($(partitionSize $imageDiskDevice) / 1024))
	diskP1MByte=$(($(partitionSize $(ddn $imageDiskDevice 1)) / 1024))
	diskRMBytes=$((
		diskXMBytes - diskP1MByte - swapsize - recoMByte - bootXMBytes - minhome
	))
	disk1MBytes=$((diskP1MByte + diskRMBytes))
	if [ ! -z "$OEM_SYSTEMSIZE" ];then
		if [ $OEM_SYSTEMSIZE -le $disk1MBytes ];then
			disk1MBytes=$OEM_SYSTEMSIZE
		fi
	fi
	#======================================
	# check repart operation
	#--------------------------------------
	if [ $disk1MBytes -lt $diskP1MByte ];then
		# /.../
		# Requested system partition size is smaller than
		# existing partition, will not re-partition
		# ----
		Echo "Current system partition is bigger than requested size"
		Echo "Disk won't be re-partitioned"
		disableOEMParameters
		disableRepart
	fi
	#======================================
	# write new partition table
	#--------------------------------------
	if [ -z "$DONT_PARTITION" ];then
		pID=1
		bootParam=1
		recoParam=no
		swapParam=no
		homeParam=no
		#======================================
		# clean/backup boot partition
		#--------------------------------------
		if [ "$haveBootPartition" = "yes" ];then
			createPartitionerInput \
				d 2
		fi
		#======================================
		# repart root partition
		#--------------------------------------
		createPartitionerInput \
			d n p $pID . +"$disk1MBytes"M
		#======================================
		# add swap partition
		#--------------------------------------
		if [ -z "$OEM_WITHOUTSWAP" ];then
			pID=$((pID + 1))
			createPartitionerInput \
				n p $pID . +"$swapsize"M t 2 82
			swapParam=$pID
		fi
		#======================================
		# add recovery partition
		#--------------------------------------
		if [ ! -z "$OEM_RECOVERY" ];then
			pID=$((pID + 1))
			createPartitionerInput \
				n p $pID . +"$recoMByte"M t $pID $recoID
			recoParam=$pID
		fi
		#======================================
		# add boot partition
		#--------------------------------------
		if [ ! -z "$bootXMBytes" ];then
			pID=$((pID + 1))
			createPartitionerInput \
				n p $pID . +"$bootXMBytes"M t $pID $bootpartID
			bootParam=$pID
		fi
		#======================================
		# add home partition
		#--------------------------------------
		if [ -z "$OEM_WITHOUTHOME" ];then
			pID=$((pID + 1))
			createPartitionerInput \
				n p $pID . .
			homeParam=$pID
		fi
		#======================================
		# setup new device names
		#--------------------------------------
		setupDeviceNames \
			1 $swapParam $homeParam $recoParam $bootParam no
		callPartitioner $input
	fi
	#======================================
	# post repart actions
	#--------------------------------------
	if [ -z "$DONT_PARTITION" ];then
		#======================================
		# Activate boot partition
		#--------------------------------------
		activateBootPartition
		#======================================
		# Create boot filesystem if required
		#--------------------------------------
		createBootDeviceFilesystem
	fi
}

#======================================
# OEMRepartSplit
#--------------------------------------
function OEMRepartSplit {
	# /.../
	# repartition disk for overlay systems with aufs, clicfs
	# and friends and also systems of image type split.
	# Initial partition table layout is:
	# =====================================
	# p1: ( compressed )
	# p2: ( write area ) +luks
	# p3: [ boot ]
	# -------------------------------------
	#====================================== 
	# no recovery support in union mode
	#--------------------------------------
	unset OEM_RECOVERY
	#====================================== 
	# no homepart support for union mode
	#--------------------------------------
	export OEM_WITHOUTHOME=1
	#======================================
	# check for boot partition
	#--------------------------------------
	createBootDeviceData 3
	#======================================
	# setup initial boot device ID
	#--------------------------------------
	export bootid=2
	if [ "$haveBootPartition" = "yes" ];then
		bootid=3
	fi
	#====================================== 
	# check for read-write partition
	#--------------------------------------
	if ! partitionSize $(ddn $imageDiskDevice 2) &>/dev/null;then
		Echo "No read-write partition in this split/overlay image"
		disableOEMParameters
		disableRepart
	fi
	if [ -z "$DONT_PARTITION" ];then
		#======================================
		# calculate partition sizes
		#--------------------------------------
		diskXMBytes=$(($(partitionSize $imageDiskDevice) / 1024))
		diskP1MByte=$(($(partitionSize $(ddn $imageDiskDevice 1)) / 1024))
		diskP2MByte=$(($(partitionSize $(ddn $imageDiskDevice 2)) / 1024))
		diskRMBytes=$((
			diskXMBytes - diskP1MByte - diskP2MByte - swapsize - bootXMBytes
		))
		disk2MBytes=$((diskP2MByte + diskRMBytes))
		if [ ! -z "$OEM_SYSTEMSIZE" ];then
			if [ $OEM_SYSTEMSIZE -le $disk2MBytes ];then
				disk2MBytes=$OEM_SYSTEMSIZE
			fi
		fi
		#======================================
		# check repart operation
		#--------------------------------------
		if [ $disk2MBytes -lt $diskP2MByte ];then
			# /.../
			# Requested read/write partition size is smaller than
			# existing partition, will not re-partition
			# ----
			Echo "Current read/write partition is bigger than requested size"
			Echo "Disk won't be re-partitioned"
			disableOEMParameters
			disableRepart
		fi
	fi
	#======================================
	# write new partition table
	#--------------------------------------
	if [ -z "$DONT_PARTITION" ];then
		pID=2
		bootParam=2
		recoParam=no
		swapParam=no
		homeParam=no
		#======================================
		# clean/backup boot partition
		#--------------------------------------
		if [ "$haveBootPartition" = "yes" ];then
			createPartitionerInput \
				d 3
		fi
		#======================================
		# repart cow partition
		#--------------------------------------
		createPartitionerInput \
			d $pID n p $pID . +"$disk2MBytes"M
		#======================================
		# add swap partition
		#--------------------------------------
		if [ ! $swapsize = 0 ];then
			pID=$((pID + 1))
			createPartitionerInput \
				n p $pID . +"$swapsize"M t $pID 82
			swapParam=$pID
		fi
		#======================================
		# add boot partition
		#--------------------------------------
		if [ "$haveBootPartition" = "yes" ];then
			pID=$((pID + 1))
			createPartitionerInput \
				n p $pID . +"$bootXMBytes"M t $pID $bootpartID
			bootParam=$pID
		fi
		#======================================
		# setup new device names
		#--------------------------------------
		setupDeviceNames \
			1 $swapParam $homeParam $recoParam $bootParam 2
		callPartitioner $input
	fi
	#======================================
	# post repart actions
	#--------------------------------------
	if [ -z "$DONT_PARTITION" ];then
		#======================================
		# Activate boot partition
		#--------------------------------------
		activateBootPartition
		#======================================
		# Create boot filesystem if required
		#--------------------------------------
		createBootDeviceFilesystem
	fi
}

#======================================
# OEMRepartLVM
#--------------------------------------
function OEMRepartLVM {
	# /.../
	# repartition disk if LVM partition plus boot partition
	# is used. Initial partition table layout is:
	# =====================================
	# p1: ( LVM  )  +luks
	# p2: ( boot )
	# -------------------------------------
	#======================================
	# setup initial boot device ID
	#--------------------------------------
	export bootid=2
	#======================================
	# calculate partition sizes
	#--------------------------------------
	local extendID
	local VOverHeadMB=300
	local diskXMBytes=$(($(partitionSize $imageDiskDevice) / 1024))
	local disk1MBytes=$(($(partitionSize $(ddn $imageDiskDevice 1)) / 1024))
	local disk2MBytes=$(($(partitionSize $(ddn $imageDiskDevice 2)) / 1024))
	if [ ! -z "$OEM_SYSTEMSIZE" ];then
		disk1MBytes=$OEM_SYSTEMSIZE
	fi
	local diskRMBytes=$((
		recoMByte + disk1MBytes + disk2MBytes + swapsize + VOverHeadMB
	))
	#======================================
	# check repart operation
	#--------------------------------------
	if [ $diskRMBytes -gt $diskXMBytes ];then
		Echo "Disk is too small, will not re-partition it"
		disableOEMParameters
		disableRepart
	fi
	#======================================
	# write new partition table
	#--------------------------------------
	if [ -z "$DONT_PARTITION" ];then
		pID=3
		bootParam=2
		recoParam=no
		swapParam=no
		homeParam=no
		#======================================
		# close open device mappings
		#--------------------------------------
		if [ "$haveLuks" = "yes" ];then
			luksClose
		fi
		vgchange -an
		#======================================
		# add recovery partition
		#--------------------------------------
		if [ ! -z "$OEM_RECOVERY" ];then
			createPartitionerInput \
				n p $pID . +"$recoMByte"M t $pID $recoID
			recoParam=$pID
			pID=$((pID + 1))
		fi
		#======================================
		# add rest space LVM partition
		#--------------------------------------
		createPartitionerInput \
			n p $pID . . t $pID 8e
		extendID=$pID
		#======================================
		# setup new device names
		#--------------------------------------
		setupDeviceNames \
			1 $swapParam $homeParam $recoParam $bootParam yes $VGROUP
		callPartitioner $input
		waitForStorageDevice $(ddn $imageDiskDevice $extendID)
		dd if=/dev/zero of=$(ddn $imageDiskDevice $extendID) bs=1024 count=5
		vgchange -an
		activateBootPartition
		#======================================
		# extend volume group with rest space
		#--------------------------------------
		vgchange -a y $VGROUP
		pvcreate $(ddn $imageDiskDevice $extendID)
		vgextend $VGROUP $(ddn $imageDiskDevice $extendID)
		#======================================
		# Extend LVRoot to requested size
		#--------------------------------------
		lvextend --size $disk1MBytes"M" /dev/$VGROUP/LVRoot
		#======================================
		# Add LVSwap if requested.
		#--------------------------------------
		if [ -z "$OEM_WITHOUTSWAP" ];then
			lvcreate --size $swapsize"M" -n LVSwap $VGROUP
			swapParam=yes
		fi
		#======================================
		# Add LVHome if requested
		#--------------------------------------
		if [ -z "$OEM_WITHOUTHOME" ];then
			lvcreate -l 100%FREE -n LVHome $VGROUP
			homeParam=yes
		elif [ -z "$OEM_SYSTEMSIZE" ];then
			lvextend -l 100%FREE /dev/$VGROUP/LVRoot
		fi
		#======================================
		# setup new device names
		#--------------------------------------
		setupDeviceNames \
			1 $swapParam $homeParam $recoParam $bootParam yes $VGROUP
	fi
}

#======================================
# OEMPartitionInstall
#--------------------------------------
function OEMPartitionInstall {
	# /.../
	# don't repart the disk but prepare it for use with
	# the existing partition table
	# ----
	#======================================
	# no recovery support for part install
	#--------------------------------------
	unset OEM_RECOVERY
	#======================================
	# no homepart support for part install
	#--------------------------------------
	export OEM_WITHOUTHOME=1
	#======================================
	# check for LVM, resize to full space
	#--------------------------------------
	if searchVolumeGroup;then
		#======================================
		# resize PV's
		#--------------------------------------
		pvresize $(ddn $imageDiskDevice $rID)
		#======================================
		# resize LV's
		#--------------------------------------
		lvresize -l 100%FREE $imageRootDevice
	fi
	#======================================
	# resize boot filesystem if needed
	#--------------------------------------
	if [ ! $imageBootDevice = $imageRootDevice ];then
		resizeFilesystem $imageBootDevice
	fi
	#======================================
	# cleanup temporary flags
	#--------------------------------------
	unset DONT_PARTITION
}

#======================================
# OEMRepart
#--------------------------------------
function OEMRepart {
	# /.../
	# call the appropriate repartition functions
	# ----
	if [ ! $LOCAL_BOOT = "no" ];then
		return
	fi
	#======================================
	# check for luks extension
	#--------------------------------------
	if [ "$haveLuks" = "yes" ];then
		unset  OEM_RECOVERY
		export OEM_WITHOUTHOME=1
	fi
	#======================================
	# Initialize
	#--------------------------------------
	OEMRepartInit
	#======================================
	# Do the repartitioning
	#--------------------------------------
	if [ ! -z "$OEM_PARTITION_INSTALL" ];then
		OEMPartitionInstall
	elif [ ! -z "$haveLVM" ];then
		OEMRepartLVM
	elif isFSTypeReadOnly;then
		OEMRepartSplit
	else
		OEMRepartStandard
	fi
	sleep 1
	#======================================
	# setup luks maps
	#--------------------------------------
	if [ "$haveLuks" = "yes" ];then
		createLuksMaps
	fi
	#======================================
	# find fstype for root partition
	#--------------------------------------
	probeFileSystem $imageRootDevice
	#======================================
	# Activate swap space
	#--------------------------------------
	if [ -z "$DONT_PARTITION" ] && [ $swapsize -gt 0 ]; then
		if partitionSize $imageSwapDevice &>/dev/null;then
			Echo "Activating swap space on $imageSwapDevice"
			if ! mkswap $imageSwapDevice 1>&2;then
				systemException "Failed to create swap signature" "reboot"
			fi
		fi
	fi
	#======================================
	# Create home file system
	#--------------------------------------
	if [ -z "$DONT_PARTITION" ] && [ -z "$OEM_WITHOUTHOME" ];then
		Echo "Creating Home filesystem on $imageHomeDevice"
		createFilesystem $imageHomeDevice
	fi
	#======================================
	# Create recovery file system
	#--------------------------------------
	if [ -z "$DONT_PARTITION" ] && [ ! -z "$OEM_RECOVERY" ];then
		Echo "Creating Recovery filesystem on $imageRecoveryDevice"
		if ! mke2fs -T ext2 -q -L recovery $imageRecoveryDevice 1>&2;then
			systemException "Failed to create Recovery fs" "reboot"
		fi
	fi
	#======================================
	# Setup recovery contents
	#--------------------------------------
	if [ -z "$DONT_PARTITION" ] && [ ! -z "$OEM_RECOVERY" ];then
		Echo "Setting up recovery archive..."
		mkdir -p /reco-root
		if ! mount $imageRootDevice /reco-root >/dev/null;then
			systemException "Failed to mount root device" "reboot"
		fi
		if [ ! -z "$haveLVM" ];then
			mkdir -p /recoboot && mount $imageBootDevice /recoboot
			mount --bind /recoboot/boot /reco-root/boot
		fi
		mkdir -p /reco-save
		if ! mount $imageRecoveryDevice /reco-save >/dev/null;then
			systemException "Failed to mount recovery device" "reboot"
		fi
		if ! mv /reco-root/recovery.tar.files /reco-save >/dev/null;then
			systemException "Failed to move recovery file count" "reboot"
		fi
		if ! mv /reco-root/recovery.tar.filesystem /reco-save >/dev/null;then
			systemException "Failed to move recovery filesystem info" "reboot"
		fi
		if ! mv /reco-root/recovery.tar.size /reco-save >/dev/null;then
			systemException "Failed to move recovery size info" "reboot"
		fi
		if ! mv /reco-root/recovery.partition.size /reco-save >/dev/null;then
			systemException "Failed to move recovery part size info" "reboot"
		fi
		if [ -f /reco-root/recovery.tar.gz ];then
			if ! mv /reco-root/recovery.tar.gz /reco-save >/dev/null;then
				systemException "Failed to move recovery archive" "reboot"
			fi
		else
			pushd /reco-root
			Echo "Creating recovery root tarball..."
			tar --numeric-owner -czpf /reco-save/recovery.tar.gz . \
				--exclude "./dev" \
				--exclude "./proc" \
				--exclude "./sys" \
				--exclude "./recovery.*"
			popd
		fi
		mkdir /reco-save/boot
		if [ "$loader" = "grub" ];then
			if ! cp /reco-root/boot/initrd.vmx /reco-save/boot/initrd;then
				systemException "Failed to copy recovery initrd" "reboot"
			fi
			if ! cp /reco-root/boot/linux.vmx /reco-save/boot/vmlinuz;then
				systemException "Failed to copy recovery kernel" "reboot"
			fi
			if ! cp /reco-root/boot/message /reco-save/boot/message;then
				systemException "Failed to copy recovery gfx message" "reboot"
			fi
		fi
		if [ -f /boot.tgz ];then
			if ! tar -xf /boot.tgz -C /reco-save;then
				systemException "Failed to extract recovery boot files" "reboot"
			fi
		fi
		if ! dd if=$imageDiskDevice of=/reco-save/mbr bs=1 count=512;then
			systemException "Failed to store MBR" "reboot"
		fi
		if [ ! -z "$haveLVM" ];then
			if ! vgcfgbackup -f /reco-save/lvm $VGROUP;then
				systemException "Failed to store LVM metadata" "reboot"
			fi
		fi
		if [ ! -z "$haveLVM" ];then
			umount /reco-root/boot
			umount /recoboot && rmdir /recoboot
		fi
		umount /reco-save && rmdir /reco-save
		umount /reco-root && rmdir /reco-root
	fi
}

#======================================
# activateBootPartition
#--------------------------------------
function activateBootPartition {
	# /.../
	# set boot flag to current value of $bootid
	# ----
	Echo "Set boot flag to partition ID: $bootid [ $imageDiskDevice ]"
	parted $imageDiskDevice set $bootid boot on
	if test $? != 0; then
		systemException "Failed to set boot flag" "reboot"
	fi
	blockdev --rereadpt $imageDiskDevice
	local deviceTest=$(ddn $imageDiskDevice 1)
	if ! waitForStorageDevice $deviceTest;then
		systemException \
			"Partition $deviceTest doesn't appear... fatal !" \
		"reboot"
	fi
}

#======================================
# setupDeviceNames
#--------------------------------------
function setupDeviceNames {
	local rootID=$1
	local swapID=$2
	local homeID=$3
	local recoID=$4
	local bootID=$5
	local iorwID=$6
	local vgroup=$7
	if [ -z "$vgroup" ];then
		#======================================
		# set root device name
		#--------------------------------------
		export imageRootDevice=$(ddn $imageDiskDevice $rootID)
		#======================================
		# set swap device name
		#--------------------------------------
		if [ ! $swapID = "no" ];then
			export imageSwapDevice=$(ddn $imageDiskDevice $swapID)
		fi
		#======================================
		# set home device name
		#--------------------------------------
		if [ ! $homeID = "no" ];then
			export imageHomeDevice=$(ddn $imageDiskDevice $homeID)
		fi
		#======================================
		# set recovery device name
		#--------------------------------------
		if [ ! $recoID = "no" ];then
			export imageRecoveryDevice=$(ddn $imageDiskDevice $recoID)
			export recoid=$recoID
		fi
		#======================================
		# set read-write device name
		#--------------------------------------
		if [ ! $iorwID = "no" ];then
			export imageIOWRDevice=$(ddn $imageDiskDevice $iorwID)
			export imageRWDevice=$imageIOWRDevice
			export imageRODevice=$imageRootDevice
		fi
		#======================================
		# set boot device name
		#--------------------------------------
		export imageBootDevice=$(ddn $imageDiskDevice $bootID)
		#======================================
		# set boot partition id
		#--------------------------------------
		export bootid=$bootID
	else
		#======================================
		# set LVM root device name
		#--------------------------------------
		export imageRootDevice=/dev/$vgroup/LVRoot
		#======================================
		# set LVM swap device name
		#--------------------------------------
		if [ ! $swapID = "no" ];then
			export imageSwapDevice=/dev/$vgroup/LVSwap
		fi
		#======================================
		# set LVM home device name
		#--------------------------------------
		if [ ! $homeID = "no" ];then
			export imageHomeDevice=/dev/$vgroup/LVHome
		fi
		#======================================
		# set LVM recovery device name
		#--------------------------------------
		if [ ! $recoID = "no" ];then
			export imageRecoveryDevice=$(ddn $imageDiskDevice $recoID)
			export recoid=$recoID
		fi
		#======================================
		# set LVM read-write device name
		#--------------------------------------
		if [ ! $iorwID = "no" ];then
			if [ -e /dev/$vgroup/LVComp ];then
				export imageRootDevice=/dev/$vgroup/LVComp
			fi
			export imageIOWRDevice=/dev/$vgroup/LVRoot
			export imageRWDevice=$imageIOWRDevice
			export imageRODevice=/dev/$vgroup/LVComp
		fi
		#======================================
		# set LVM boot device name
		#--------------------------------------
		export imageBootDevice=$(ddn $imageDiskDevice $bootID)
		#======================================
		# set LVM boot partition id
		#--------------------------------------
		export bootid=$bootID
	fi
}

#======================================
# createBootDeviceData
#--------------------------------------
function createBootDeviceData {
	local bootPart=$1
	if partitionSize $(ddn $imageDiskDevice $bootPart) &>/dev/null;then
		#======================================
		# Variable setup
		#--------------------------------------
		export haveBootPartition=yes
		export bootXMBytes=60
		export bootpartID=83
		if [ "$loader" = "syslinux" ];then
			bootpartID=6
		fi
		#======================================
		# Store contents in RAM
		#--------------------------------------
		mount $(ddn $imageDiskDevice $bootPart) /mnt
		tar -czf /boot.tgz -C /mnt .
		umount /mnt
	fi
	#====================================== 
	# check for overlay type
	#--------------------------------------
	local unionFST=`echo $UNIONFS_CONFIG | cut -d , -f 3`
	if [ "$unionFST" = "clicfs" ];then
		export haveClicFS=yes
	fi
	sleep 1
}

#======================================
# createBootDeviceFilesystem
#--------------------------------------
function createBootDeviceFilesystem {
	if [ ! "$haveBootPartition" = "yes" ];then
		return
	fi
	if [ "$loader" = "syslinux" ];then
		mkdosfs $imageBootDevice >/dev/null 2>&1
	else
		mke2fs -q $imageBootDevice >/dev/null 2>&1
	fi
	if [ ! $? = 0 ];then
		systemException \
			"Failed to create Boot filesystem" \
		"reboot"
	fi
}

#======================================
# createLuksMaps
#--------------------------------------
function createLuksMaps {
	export imageRootDevice=$(luksOpen $imageRootDevice)
	if isFSTypeReadOnly;then
		export imageIOWRDevice=$(luksOpen $imageIOWRDevice luksReadWrite)
		export imageRWDevice=$imageIOWRDevice
		export imageRODevice=$imageRootDevice
	fi
}

#======================================
# disableOEMParameters
#--------------------------------------
function disableOEMParameters {
	export OEM_WITHOUTHOME=1
	export OEM_WITHOUTSWAP=1
	unset OEM_RECOVERY
	unset OEM_SYSTEMSIZE
}

#======================================
# disableRepart
#--------------------------------------
function disableRepart {
	DONT_PARTITION=1
}

