summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/libs/lib-blockdevices-filesystems.sh97
-rw-r--r--src/core/libs/lib-ui-interactive.sh86
-rwxr-xr-xsrc/fifa.sh2
3 files changed, 101 insertions, 84 deletions
diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh
index d17a769..5397c42 100644
--- a/src/core/libs/lib-blockdevices-filesystems.sh
+++ b/src/core/libs/lib-blockdevices-filesystems.sh
@@ -285,3 +285,100 @@ target_configure_fstab()
sort $TMP_FSTAB >>$var_TARGET_DIR/etc/fstab
fi
}
+
+
+# partitions a disk , creates filesystems and mounts them
+# $1 device to partition
+# $2 a string of the form: <mountpoint>:<partsize>:<fstype>[:+] (the + is bootable flag)
+partition ()
+{
+ debug "Partition called like: partition '$1' '$2'"
+ [ -z "$1" ] && die_error "partition() requires a device file and a partition string"
+ [ -z "$2" ] && die_error "partition() requires a partition string"
+
+ DEVICE=$1
+ STRING=$2
+
+ # validate DEVICE
+ if [ ! -b "$DEVICE" ]; then
+ notify "Device '$DEVICE' is not valid"
+ return 1
+ fi
+
+ # validate DEST
+ if [ ! -d "$var_TARGET_DIR" ]; then
+ notify "Destination directory '$var_TARGET_DIR' is not valid"
+ return 1
+ fi
+
+ # / required
+ if [ $(grep -c '/:' <<< $STRING) -ne 1 ]; then
+ notify "Need exactly one root partition"
+ return 1
+ fi
+
+ rm -f $TMP_FSTAB
+
+ target_umountall
+ # setup input var for sfdisk
+ for fsspec in $STRING; do
+ fssize=$(echo $fsspec | tr -d ' ' | cut -f2 -d:)
+ if [ "$fssize" = "*" ]; then
+ fssize_spec=';'
+ else
+ fssize_spec=",$fssize"
+ fi
+ fstype=$(echo $fsspec | tr -d ' ' | cut -f3 -d:)
+ if [ "$fstype" = "swap" ]; then
+ fstype_spec=",S"
+ else
+ fstype_spec=","
+ fi
+ bootflag=$(echo $fsspec | tr -d ' ' | cut -f4 -d:)
+ if [ "$bootflag" = "+" ]; then
+ bootflag_spec=",*"
+ else
+ bootflag_spec=""
+ fi
+ sfdisk_input="${sfdisk_input}${fssize_spec}${fstype_spec}${bootflag_spec}\n"
+ done
+ sfdisk_input=$(printf "$sfdisk_input")
+
+ # invoke sfdisk
+ printk off
+ infofy "Partitioning $DEVICE"
+ sfdisk $DEVICE -uM >$LOG 2>&1 <<EOF
+$sfdisk_input
+EOF
+ if [ $? -gt 0 ]; then
+ notify "Error partitioning $DEVICE (see $LOG for details)"
+ printk on
+ return 1
+ fi
+ printk on
+
+ # need to mount root first, then do it again for the others
+ part=1
+ for fsspec in $STRING; do
+ mountpoint=$(echo $fsspec | tr -d ' ' | cut -f1 -d:)
+ fstype=$(echo $fsspec | tr -d ' ' | cut -f3 -d:)
+ if echo $mountpoint | tr -d ' ' | grep '^/$' 2>&1 > /dev/null; then
+ _mkfs yes ${DEVICE}${part} "$fstype" "$var_TARGET_DIR" "$mountpoint" || return 1
+ fi
+ part=$(($part + 1))
+ done
+
+ # make other filesystems
+ part=1
+ for fsspec in $STRING; do
+ mountpoint=$(echo $fsspec | tr -d ' ' | cut -f1 -d:)
+ fstype=$(echo $fsspec | tr -d ' ' | cut -f3 -d:)
+ if [ $(echo $mountpoint | tr -d ' ' | grep '^/$' | wc -l) -eq 0 ]; then
+ _mkfs yes ${DEVICE}${part} "$fstype" "$var_TARGET_DIR" "$mountpoint" || return 1
+ fi
+ part=$(($part + 1))
+ done
+
+ return 0
+}
+
diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh
index a639214..032f57e 100644
--- a/src/core/libs/lib-ui-interactive.sh
+++ b/src/core/libs/lib-ui-interactive.sh
@@ -209,95 +209,15 @@ interactive_autoprepare()
|| return 1
DEVICE=$DISC
+ # TODO: why do we define a $DEFAULTFS variable someplace else if we hardcode it's attributes here to be able to replace them with custom values? Can't we just construct the custom thing?
FSSPECS=$(echo $DEFAULTFS | sed -e "s|/:7500:ext3|/:$ROOT_PART_SIZE:$FSTYPE|g" -e "s|/home:\*:ext3|/home:\*:$FSTYPE|g" -e "s|swap:256|swap:$SWAP_PART_SIZE|g" -e "s|/boot:32|/boot:$BOOT_PART_SIZE|g")
sfdisk_input=""
# we assume a /dev/hdX format (or /dev/sdX)
PART_ROOT="${DEVICE}3"
- # validate DEVICE
- if [ ! -b "$DEVICE" ]; then
- notify "Device '$DEVICE' is not valid"
- return 1
- fi
-
- # validate DEST
- if [ ! -d "$var_TARGET_DIR" ]; then
- notify "Destination directory '$var_TARGET_DIR' is not valid"
- return 1
- fi
-
- # / required
- if [ $(echo $FSSPECS | grep '/:' | wc -l) -ne 1 ]; then
- notify "Need exactly one root partition"
- return 1
- fi
-
- rm -f $TMP_FSTAB
-
- target_umountall
-
- # setup input var for sfdisk
- for fsspec in $FSSPECS; do
- fssize=$(echo $fsspec | tr -d ' ' | cut -f2 -d:)
- if [ "$fssize" = "*" ]; then
- fssize_spec=';'
- else
- fssize_spec=",$fssize"
- fi
- fstype=$(echo $fsspec | tr -d ' ' | cut -f3 -d:)
- if [ "$fstype" = "swap" ]; then
- fstype_spec=",S"
- else
- fstype_spec=","
- fi
- bootflag=$(echo $fsspec | tr -d ' ' | cut -f4 -d:)
- if [ "$bootflag" = "+" ]; then
- bootflag_spec=",*"
- else
- bootflag_spec=""
- fi
- sfdisk_input="${sfdisk_input}${fssize_spec}${fstype_spec}${bootflag_spec}\n"
- done
- sfdisk_input=$(printf "$sfdisk_input")
-
- # invoke sfdisk
- printk off
- infofy "Partitioning $DEVICE"
- sfdisk $DEVICE -uM >$LOG 2>&1 <<EOF
-$sfdisk_input
-EOF
- if [ $? -gt 0 ]; then
- notify "Error partitioning $DEVICE (see $LOG for details)"
- printk on
- return 1
- fi
- printk on
-
- # need to mount root first, then do it again for the others
- part=1
- for fsspec in $FSSPECS; do
- mountpoint=$(echo $fsspec | tr -d ' ' | cut -f1 -d:)
- fstype=$(echo $fsspec | tr -d ' ' | cut -f3 -d:)
- if echo $mountpoint | tr -d ' ' | grep '^/$' 2>&1 > /dev/null; then
- _mkfs yes ${DEVICE}${part} "$fstype" "$var_TARGET_DIR" "$mountpoint" || return 1
- fi
- part=$(($part + 1))
- done
-
- # make other filesystems
- part=1
- for fsspec in $FSSPECS; do
- mountpoint=$(echo $fsspec | tr -d ' ' | cut -f1 -d:)
- fstype=$(echo $fsspec | tr -d ' ' | cut -f3 -d:)
- if [ $(echo $mountpoint | tr -d ' ' | grep '^/$' | wc -l) -eq 0 ]; then
- _mkfs yes ${DEVICE}${part} "$fstype" "$var_TARGET_DIR" "$mountpoint" || return 1
- fi
- part=$(($part + 1))
- done
-
- notify "Auto-prepare was successful"
- return 0
+ partition "$FSSPECS" && notify "Auto-prepare was successful" && return 0
+ return 1
}
diff --git a/src/fifa.sh b/src/fifa.sh
index ba10a73..0dc3900 100755
--- a/src/fifa.sh
+++ b/src/fifa.sh
@@ -154,7 +154,7 @@ execute ()
ret=${!exit_var}
fi
- debug "$1 $2 exit state was $ret"
+ debug "$1 $2 exit state was $ret" #TODO: why are $1 and $2 empty here? Something to do with the recursion maybe? Also, exit codes for phases are not shown :/
cd $PWD_BACKUP
return $ret
}