From aeb33ecabcfdb2d0df20537a2ac97602c4d89905 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 21 Nov 2008 17:02:42 +0100 Subject: basics of new block device method --- src/core/libs/lib-blockdevices-filesystems.sh | 54 ++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index 9f88db2..3bea3cc 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -2,6 +2,8 @@ TMP_DEV_MAP=/home/arch/aif/runtime/dev.map TMP_FSTAB=/home/arch/aif/runtime/.fstab +TMP_PARTITIONS=/home/arch/aif/runtime/.partitions +TMP_FILESYSTEMS=/home/arch/aif/runtime/.filesystems # procedural code from quickinst functionized and fixed. # there were functions like this in the setup script too, with some subtle differences. see below @@ -294,7 +296,7 @@ target_configure_fstab() # partitions a disk , creates filesystems and mounts them # $1 device to partition # $2 a string of the form: ::[:+] (the + is bootable flag) -partition () +partition_deprecated () { debug "Partition called like: partition '$1' '$2'" [ -z "$1" ] && die_error "partition() requires a device file and a partition string" @@ -390,7 +392,7 @@ EOF # makes and mounts filesystems #TODO: don't use files but pass variables, integrate this with other functions # $1 file with setup -fix_filesystems () +fix_filesystems_deprecated () { [ -z "$1" -o ! -f "$1" ] && die_error "Fix_filesystems needs a file with the setup structure in it" @@ -426,3 +428,51 @@ fix_filesystems () return 0 } + + +# file layout: +TMP_PARTITIONS +# disk something-sfdisk-compliant + + +TMP_FILESYSTEMS +#blockdevice:filesystem:mountpoint(can be null for lvm/dm_crypt stuff):recreate FS? (yes/no)[:extra options for specific filesystem] + + +# go over each disk in $TMP_PARTITIONS and partition it +process_partitions () +{ +} + + +# go over each filesystem in $TMP_FILESYSTEMS, reorder them so that each entry has it's correspondent block device available (eg if you need /dev/mapper/foo which only becomes available after some other entry is processed) and process them +process_filesystems () +{ + debug "process_filesystems Called. checking all entries in $TMP_FILESYSTEMS" + devs_avail=1 + while [ $devs_avail = 1 ] + do + devs_avail=0 + for part in `findpartitions` + do + if entry=`grep ^$part $TMP_FILESYSTEMS` + then + process_filesystem "$entry" && sed -i "/^$part/d" $TMP_FILESYSTEMS && debug "$part processed and removed from $TMP_FILESYSTEMS" + devs_avail=1 + fi + done + done + entries=`wc -l $TMP_FILESYSTEMS` + if [ $entries -gt 0 ] + then + die_error "Could not process all entries because not all available blockdevices became available. Unprocessed:`awk '{print \$1}' $TMP_FILESYSTEMS`" + else + debug "All entries processed..." + fi +} + + +process_filesystem () +{ + debug "process_filesystem $1" +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf From b6ba983aef7f84174085b34716b7fb3b685c3bea Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 21 Nov 2008 18:18:33 +0100 Subject: more refactoring/cleaning/fixing --- src/core/libs/lib-blockdevices-filesystems.sh | 149 +++++++++++++++----------- 1 file changed, 85 insertions(+), 64 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index 3bea3cc..c191347 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -1,5 +1,11 @@ #!/bin/sh +#TODO: this should be fixed on the installcd. +modprobe dm-crypt || show_warning modprobe 'Could not modprobe dm-crypt. no support for disk encryption' +modprobe aes-i586 || show_warning modprobe 'Could not modprobe aes-i586. no support for disk encryption' + + + TMP_DEV_MAP=/home/arch/aif/runtime/dev.map TMP_FSTAB=/home/arch/aif/runtime/.fstab TMP_PARTITIONS=/home/arch/aif/runtime/.partitions @@ -205,74 +211,42 @@ mapdev() { } -# _mkfs() taken from setup code and slightly improved. +# _mkfs() taken from setup code and altered. # Create and mount filesystems in our destination system directory. # # args: -# $1 domk: Whether to make the filesystem or use what is already there (yes/no) -# $2 device: Device filesystem is on +# $2 device: target block device # $3 fstype: type of filesystem located at the device (or what to create) -# $4 dest: Mounting location for the destination system -# $5 mountpoint: Mount point inside the destination system, e.g. '/boot' +# $3 opts: extra opts for the mkfs program (optional) + # returns: 1 on failure _mkfs() { - local _domk=$1 - local _device=$2 - local _fstype=$3 - local _dest=$4 - local _mountpoint=$5 - - debug "_mkfs: domk: $1, _device: $2, fstype: $3, dest: $4, mountpoint: $5" - # we have two main cases: "swap" and everything else. - if [ "${_fstype}" = "swap" ]; then - swapoff ${_device} >/dev/null 2>&1 - if [ "${_domk}" = "yes" ]; then - mkswap ${_device} >$LOG 2>&1 || ( show_warning "Error creating swap: mkswap ${_device}" ; return 1 ) - fi - swapon ${_device} >$LOG 2>&1 || ( show_warning "Error activating swap: swapon ${_device}" ; return 1 ) - else - # make sure the fstype is one we can handle - local knownfs=0 - for fs in xfs jfs reiserfs ext2 ext3 vfat; do - [ "${_fstype}" = "${fs}" ] && knownfs=1 && break - done - - [ $knownfs -eq 0 ] && ( show_warning "unknown fstype ${_fstype} for ${_device}" ; return 1 ) - # if we were tasked to create the filesystem, do so - if [ "${_domk}" = "yes" ]; then - local ret - case ${_fstype} in - xfs) mkfs.xfs -f ${_device} >$LOG 2>&1; ret=$? ;; - jfs) yes | mkfs.jfs ${_device} >$LOG 2>&1; ret=$? ;; - reiserfs) yes | mkreiserfs ${_device} >$LOG 2>&1; ret=$? ;; - ext2) mke2fs "${_device}" >$LOG 2>&1; ret=$? ;; - ext3) mke2fs -j ${_device} >$LOG 2>&1; ret=$? ;; - vfat) mkfs.vfat ${_device} >$LOG 2>&1; ret=$? ;; - # don't handle anything else here, we will error later - esac - [ $ret != 0 ] && ( show_warning "Error creating filesystem ${_fstype} on ${_device}" ; return 1 ) - sleep 2 - fi - # create our mount directory - mkdir -p ${_dest}${_mountpoint} - # mount the bad boy - mount -t ${_fstype} ${_device} ${_dest}${_mountpoint} >$LOG 2>&1 - [ $? != 0 ] && ( show_warning "Error mounting ${_dest}${_mountpoint}" ; return 1 ) - fi - - # add to temp fstab - local _uuid="$(getuuid ${_device})" - if [ -n "${_uuid}" ]; then - _device="UUID=${_uuid}" - fi - echo -n "${_device} ${_mountpoint} ${_fstype} defaults 0 " >>$TMP_FSTAB + local _device=$2 + local _fstype=$3 + local _opts=$3 + + debug "_mkfs: _device: $1, fstype: $2, opts: $3" + # make sure the fstype is one we can handle + local knownfs=0 + for fs in xfs jfs reiserfs ext2 ext3 vfat swap; do + [ "${_fstype}" = "${fs}" ] && knownfs=1 && break + done - if [ "${_fstype}" = "swap" ]; then - echo "0" >>$TMP_FSTAB - else - echo "1" >>$TMP_FSTAB - fi + [ $knownfs -eq 0 ] && ( show_warning 'mkfs' "unknown fstype ${_fstype} for ${_device}" ; return 1 ) + local ret + case ${_fstype} in + xfs) mkfs.xfs -f ${_device} >$LOG 2>&1; ret=$? ;; + jfs) yes | mkfs.jfs ${_device} >$LOG 2>&1; ret=$? ;; + reiserfs) yes | mkreiserfs ${_device} >$LOG 2>&1; ret=$? ;; + ext2) mke2fs "${_device}" >$LOG 2>&1; ret=$? ;; + ext3) mke2fs -j ${_device} >$LOG 2>&1; ret=$? ;; + vfat) mkfs.vfat ${_device} >$LOG 2>&1; ret=$? ;; + swap) mkswap ${_device} >$LOG 2>&1; ret=$? ;; + # don't handle anything else here, we will error later + esac + [ "$ret" != 0 ] && ( show_warning mkfs "Error creating filesystem ${_fstype} on ${_device}" ; return 1 ) + sleep 2 } @@ -431,13 +405,10 @@ fix_filesystems_deprecated () # file layout: -TMP_PARTITIONS +#TMP_PARTITIONS # disk something-sfdisk-compliant -TMP_FILESYSTEMS -#blockdevice:filesystem:mountpoint(can be null for lvm/dm_crypt stuff):recreate FS? (yes/no)[:extra options for specific filesystem] - # go over each disk in $TMP_PARTITIONS and partition it process_partitions () @@ -448,6 +419,8 @@ process_partitions () # go over each filesystem in $TMP_FILESYSTEMS, reorder them so that each entry has it's correspondent block device available (eg if you need /dev/mapper/foo which only becomes available after some other entry is processed) and process them process_filesystems () { + #TODO: reorder file by strlen of mountpoint, so that we don't get 'overridden' mountpoints (eg you don't mount /a/b/c and then /a/b. checking whether the parent dir exists is not good + #TODO: 'deconstruct' the mounted filesystems in the right order before doing this (opposite order of construct) (and swapoff) debug "process_filesystems Called. checking all entries in $TMP_FILESYSTEMS" devs_avail=1 while [ $devs_avail = 1 ] @@ -472,7 +445,55 @@ process_filesystems () } +#TMP_FILESYSTEMS beware, the 'mount?' for now just matters for the location (if 'target', the target path gets prepended) +#blockdevice:filesystem:mountpoint:recreate FS?(yes/no):mount?(target,runtime,no)[:extra options for specific filesystem] + +# make a filesystem on a blockdevice and mount if requested. process_filesystem () { + [ -z "$1" ] && die_error "process_filesystem needs a FS entry" debug "process_filesystem $1" + line=$1 + BLOCK=$( echo $line | cut -d: -f 1) + FSTYPE=$(echo $line | cut -d: -f 2) + MP=$( echo $line | cut -d: -f 3) # can be null for lvm/dm_crypt stuff + DOMKFS=$(echo $line | cut -d: -f 4) + DOMNT=$( echo $line | cut -d: -f 5) + OPTS=$( echo $line | cut -d: -f 6) + + if [ "$DOMKFS" = yes ] + then + _mkfs $BLOCK $FSTYPE $OPTS || return 1 + fi + + if [ "$DOMNT" = runtime -o "$DOMNT" = target ] + then + if [ "$FSTYPE" != swap ] + then + [ "$DOMNT" = runtime ] && dst=$MP + [ "$DOMNT" = target ] && dst=$var_TARGET_DIR$MP + debug "mounting $BLOCK on $dst" + mount -t $FSTYPE $BLOCK $dst >$LOG 2>&1 || ( show_warning 'Mount' "Error mounting $BLOCK on $dst" ; return 1 ) + else + debug "swaponning $BLOCK" + swapon $BLOCK >$LOG 2>&1 || ( show_warning 'Swapon' "Error activating swap: swapon $BLOCK" ; return 1 ) + fi + fi + + # add to temp fstab + if [ $MP != null -a $DOMNT = target ] + then + local _uuid="$(getuuid $BLOCK)" + if [ -n "${_uuid}" ]; then + _device="UUID=${_uuid}" + fi + echo -n "$BLOCK ${_mountpoint} $FSTYPE defaults 0 " >>$TMP_FSTAB + if [ "$FSTYPE" = "swap" ]; then + echo "0" >>$TMP_FSTAB + else + echo "1" >>$TMP_FSTAB + fi + fi + + return 0 } \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 80d8da5ce6049581dc907c99ecaae8703d9b8334 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 21 Nov 2008 19:03:42 +0100 Subject: first steps toward dm_crypt and lvm support --- src/core/libs/lib-blockdevices-filesystems.sh | 57 ++++++++++++++++----------- 1 file changed, 35 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index c191347..81816e2 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -215,34 +215,42 @@ mapdev() { # Create and mount filesystems in our destination system directory. # # args: -# $2 device: target block device -# $3 fstype: type of filesystem located at the device (or what to create) -# $3 opts: extra opts for the mkfs program (optional) +# $1 device: target block device +# $2 fstype: type of filesystem located at the device (or what to create) +# $3 label: label/name for the FS (you can pass an empty string) (optional) +# $4 opts: extra opts for the mkfs program (optional) # returns: 1 on failure _mkfs() { - local _device=$2 - local _fstype=$3 - local _opts=$3 + local _device=$1 + local _fstype=$2 + local _label=$3 + local opts=$4 - debug "_mkfs: _device: $1, fstype: $2, opts: $3" + debug "_mkfs: _device: $1, fstype: $2, label: $3, opts: $4" # make sure the fstype is one we can handle local knownfs=0 - for fs in xfs jfs reiserfs ext2 ext3 vfat swap; do + for fs in xfs jfs reiserfs ext2 ext3 vfat swap dm_crypt lvm-pv lvm-vg lvm-lv; do [ "${_fstype}" = "${fs}" ] && knownfs=1 && break done + [ -z "$_label" ] && _label=default #TODO. when creating more then 1 VG we will get errors that it exists already. we should (per type) add incrementing numbers or something [ $knownfs -eq 0 ] && ( show_warning 'mkfs' "unknown fstype ${_fstype} for ${_device}" ; return 1 ) local ret case ${_fstype} in - xfs) mkfs.xfs -f ${_device} >$LOG 2>&1; ret=$? ;; - jfs) yes | mkfs.jfs ${_device} >$LOG 2>&1; ret=$? ;; - reiserfs) yes | mkreiserfs ${_device} >$LOG 2>&1; ret=$? ;; - ext2) mke2fs "${_device}" >$LOG 2>&1; ret=$? ;; - ext3) mke2fs -j ${_device} >$LOG 2>&1; ret=$? ;; - vfat) mkfs.vfat ${_device} >$LOG 2>&1; ret=$? ;; - swap) mkswap ${_device} >$LOG 2>&1; ret=$? ;; + xfs) mkfs.xfs -f ${_device} $opts >$LOG 2>&1; ret=$? ;; + jfs) yes | mkfs.jfs ${_device} $opts >$LOG 2>&1; ret=$? ;; + reiserfs) yes | mkreiserfs ${_device} $opts >$LOG 2>&1; ret=$? ;; + ext2) mke2fs "${_device}" $opts >$LOG 2>&1; ret=$? ;; + ext3) mke2fs -j ${_device} $opts >$LOG 2>&1; ret=$? ;; + vfat) mkfs.vfat ${_device} $opts >$LOG 2>&1; ret=$? ;; + swap) mkswap ${_device} $opts >$LOG 2>&1; ret=$? ;; + dm_crypt) [ -z "$opts" ] && opts='-c aes-xts-plain -y -s 512'; + cryptsetup $opts luksFormat ${_device} >$LOG 2>&1; ret=$? ;; + lvm-pv) pvcreate $opts ${_device} >$LOG 2>&1; ret=$? ;; + lvm-vg) vgcreate $opts $_label ${_device} >$LOG 2>&1; ret=$? ;; + lvm-lv) lvcreate $opts -n $_label ${_device} >$LOG 2>&1; ret=$? ;; #$opts is usually something like -L 10G # don't handle anything else here, we will error later esac [ "$ret" != 0 ] && ( show_warning mkfs "Error creating filesystem ${_fstype} on ${_device}" ; return 1 ) @@ -419,8 +427,9 @@ process_partitions () # go over each filesystem in $TMP_FILESYSTEMS, reorder them so that each entry has it's correspondent block device available (eg if you need /dev/mapper/foo which only becomes available after some other entry is processed) and process them process_filesystems () { - #TODO: reorder file by strlen of mountpoint, so that we don't get 'overridden' mountpoints (eg you don't mount /a/b/c and then /a/b. checking whether the parent dir exists is not good - #TODO: 'deconstruct' the mounted filesystems in the right order before doing this (opposite order of construct) (and swapoff) + #TODO: reorder file by strlen of mountpoint (or alphabetically), so that we don't get 'overridden' mountpoints (eg you don't mount /a/b/c and then /a/b. checking whether the parent dir exists is not good -> sort -t \ -k 2 + #TODO: we must make sure we have created all PV's, then reate a vg and the lv's. + #TODO: 'deconstruct' the mounted filesystems, pv's, lv's,vg's,dm_crypt's.. in the right order before doing this (opposite order of construct) and swapoff. debug "process_filesystems Called. checking all entries in $TMP_FILESYSTEMS" devs_avail=1 while [ $devs_avail = 1 ] @@ -468,15 +477,19 @@ process_filesystem () if [ "$DOMNT" = runtime -o "$DOMNT" = target ] then - if [ "$FSTYPE" != swap ] + if [ "$FSTYPE" = swap ] then + debug "swaponning $BLOCK" + swapon $BLOCK >$LOG 2>&1 || ( show_warning 'Swapon' "Error activating swap: swapon $BLOCK" ; return 1 ) + elif [ "$FSTYPE" = dm_crypt ] + then + debug "cryptsetup luksOpen $BLOCK $dst" + cryptsetup luksOpen $BLOCK $dst >$LOG 2>&1 || ( show_warning 'cryptsetup' "Error luksOpening $BLOCK on $dst" ; return 1 ) + else [ "$DOMNT" = runtime ] && dst=$MP [ "$DOMNT" = target ] && dst=$var_TARGET_DIR$MP debug "mounting $BLOCK on $dst" mount -t $FSTYPE $BLOCK $dst >$LOG 2>&1 || ( show_warning 'Mount' "Error mounting $BLOCK on $dst" ; return 1 ) - else - debug "swaponning $BLOCK" - swapon $BLOCK >$LOG 2>&1 || ( show_warning 'Swapon' "Error activating swap: swapon $BLOCK" ; return 1 ) fi fi @@ -496,4 +509,4 @@ process_filesystem () fi return 0 -} \ No newline at end of file +} -- cgit v1.2.3-54-g00ecf From 0a16fab12a9091fe834321fc8ce5103749a46e39 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 21 Nov 2008 20:30:33 +0100 Subject: interactive autoprepare ported to new block layer --- src/core/libs/lib-ui-interactive.sh | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index e0c536c..3d701eb 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -208,19 +208,22 @@ interactive_autoprepare() _dia_DIALOG --defaultno --yesno "$DISC will be COMPLETELY ERASED! Are you absolutely sure?" 0 0 \ || 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? - # For some reason the thing belows replaces everything well, but 'looses' the /home part, I don't know why, cannot reproduce it, but it happens in vbox - # 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") - - FSSPECS="/boot:$BOOT_PART_SIZE:ext2:+ swap:$SWAP_PART_SIZE:swap /:$ROOT_PART_SIZE:$FSTYPE /home:*:$FSTYPE" - debug "\$DEFAULTFS: $DEFAULTFS" - debug "\$FSSPECS : $FSSPECS" - # we assume a /dev/hdX format (or /dev/sdX) - PART_ROOT="${DEVICE}3" - - partition $DEVICE "$FSSPECS" && notify "Auto-prepare was successful" && return 0 - return 1 + + # we assume a /dev/hdX format (or /dev/sdX) + PART_ROOT="${DISC}3" + + echo "$DISC $BOOT_PART_SIZE:ext2:+ $SWAP_PART_SIZE:swap $ROOT_PART_SIZE:$FSTYPE *:$FSTYPE" > $TMP_PARTITIONS + echo "${DISC}1:ext2:/boot:yes:target" >$TMP_FILESYSTEMS + echo "${DISC}2:swap:null:yes:target" >$TMP_FILESYSTEMS + echo "${DISC}3:$FSTYPE:/:yes:target" >$TMP_FILESYSTEMS + echo "${DISC}4:$FSTYPE:/home:yes:target" >$TMP_FILESYSTEMS + + + process_disks || die_error "Something went wrong while partitioning" + process_filesystems || die_error "Something went wrong while processing the filesystems" + notify "Auto-prepare was successful" + return 0 + } -- cgit v1.2.3-54-g00ecf From 6b367253b892737547049e8b7791095e957c4490 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 21 Nov 2008 20:36:04 +0100 Subject: moved function --- src/core/libs/lib-ui-interactive.sh | 54 ++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 3d701eb..e13a952 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -17,33 +17,6 @@ check_depend () } -interactive_partition() { - target_umountall - - # Select disk to partition - DISCS=$(finddisks _) - DISCS="$DISCS OTHER - DONE +" - notify "Available Disks:\n\n$(_getavaildisks)\n" - DISC="" - while true; do - # Prompt the user with a list of known disks - ask_option no "Select the disk you want to partition (select DONE when finished)" $DISCS || return 1 - DISC=$ANSWER_OPTION - if [ "$DISC" = "OTHER" ]; then - _dia_DIALOG --inputbox "Enter the full path to the device you wish to partition" 8 65 "/dev/sda" 2>$ANSWER || return 1 - DISC=$(cat $ANSWER) - fi - # Leave our loop if the user is done partitioning - [ "$DISC" = "DONE" ] && break - # Partition disc - notify "Now you'll be put into the cfdisk program where you can partition your hard drive. You should make a swap partition and as many data partitions as you will need.\ - NOTE: cfdisk may tell you to reboot after creating partitions. If you need to reboot, just re-enter this install program, skip this step and go on to step 2." - cfdisk $DISC - done - return 0 -} - - interactive_configure_system() { [ "$EDITOR" ] || interactive_get_editor @@ -227,6 +200,33 @@ interactive_autoprepare() } +interactive_partition() { + target_umountall + + # Select disk to partition + DISCS=$(finddisks _) + DISCS="$DISCS OTHER - DONE +" + notify "Available Disks:\n\n$(_getavaildisks)\n" + DISC="" + while true; do + # Prompt the user with a list of known disks + ask_option no "Select the disk you want to partition (select DONE when finished)" $DISCS || return 1 + DISC=$ANSWER_OPTION + if [ "$DISC" = "OTHER" ]; then + _dia_DIALOG --inputbox "Enter the full path to the device you wish to partition" 8 65 "/dev/sda" 2>$ANSWER || return 1 + DISC=$(cat $ANSWER) + fi + # Leave our loop if the user is done partitioning + [ "$DISC" = "DONE" ] && break + # Partition disc + notify "Now you'll be put into the cfdisk program where you can partition your hard drive. You should make a swap partition and as many data partitions as you will need.\ + NOTE: cfdisk may tell you to reboot after creating partitions. If you need to reboot, just re-enter this install program, skip this step and go on to step 2." + cfdisk $DISC + done + return 0 +} + + interactive_mountpoints() { while [ "$PARTFINISH" != "DONE" ]; do : >$TMP_FSTAB -- cgit v1.2.3-54-g00ecf From 07a3d23197d60b357f3b42e0cc2e490d07702982 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 21 Nov 2008 22:06:44 +0100 Subject: porting of interactive_filesystems WIP --- TODO | 4 + src/core/libs/lib-blockdevices-filesystems.sh | 115 ++++++++++---------------- src/core/libs/lib-ui-interactive.sh | 51 ++++++++---- src/core/procedures/interactive | 2 +- 4 files changed, 81 insertions(+), 91 deletions(-) (limited to 'src') diff --git a/TODO b/TODO index 9c19e78..6b625dd 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,9 @@ See also the FIXME's and TODO's in the code. +* finish interactive_filesystems port to refactored code +* do the remaining bits in lib-blockdevices-filesystems +* test + ALPHA PHASE: get some people to test and suggest ideas, while fixing bugs and refactoring General: * setup bugtracker/roadmap thingie diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index 81816e2..7624b2c 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -275,10 +275,10 @@ target_configure_fstab() } -# partitions a disk , creates filesystems and mounts them +# partitions a disk. heavily altered # $1 device to partition -# $2 a string of the form: ::[:+] (the + is bootable flag) -partition_deprecated () +# $2 a string of the form: :[:+] (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" @@ -287,56 +287,38 @@ partition_deprecated () DEVICE=$1 STRING=$2 - # validate DEVICE - if [ ! -b "$DEVICE" ]; then - notify "Device '$DEVICE' is not valid" - return 1 - fi + # 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 + target_umountall - # / required - if [ $(grep -c '/:' <<< $STRING) -ne 1 ]; then - notify "Need exactly one root partition" - return 1 - fi + # setup input var for sfdisk + for fsspec in $STRING; do + fssize=$(echo $fsspec | tr -d ' ' | cut -f1 -d:) + fssize_spec=",$fssize" + [ "$fssize" = "*" ] && fssize_spec=';' - rm -f $TMP_FSTAB + fstype=$(echo $fsspec | tr -d ' ' | cut -f2 -d:) + fstype_spec="," + [ "$fstype" = "swap" ] && fstype_spec=",S" - target_umountall - # setup input var for sfdisk #TODO: even though $STRING Contains a '/home' part it doesn't go through in the loops.. is this only in vbox? - 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") + bootflag=$(echo $fsspec | tr -d ' ' | cut -f3 -d:) + bootflag_spec="" + [ "$bootflag" = "+" ] && bootflag_spec=",*" - # invoke sfdisk - debug "Partition calls: sfdisk $DEVICE -uM >$LOG 2>&1 <<< $sfdisk_input" - printk off - infofy "Partitioning $DEVICE" - sfdisk $DEVICE -uM >$LOG 2>&1 <$LOG 2>&1 <<< $sfdisk_input" + printk off + infofy "Partitioning $DEVICE" + sfdisk $DEVICE -uM >$LOG 2>&1 <&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 -c '^/$') -eq 0 ]; then - _mkfs yes ${DEVICE}${part} "$fstype" "$var_TARGET_DIR" "$mountpoint" || return 1 - fi - part=$(($part + 1)) - done - return 0 } @@ -414,13 +374,23 @@ fix_filesystems_deprecated () # file layout: #TMP_PARTITIONS -# disk something-sfdisk-compliant +# disk partition-scheme # go over each disk in $TMP_PARTITIONS and partition it -process_partitions () +process_disks () +{ + while read disk scheme + do + process_disk $disk "$scheme" + done < $TMP_PARTITIONS +} + + +process_disk () { + partition $1 $2 } @@ -431,6 +401,7 @@ process_filesystems () #TODO: we must make sure we have created all PV's, then reate a vg and the lv's. #TODO: 'deconstruct' the mounted filesystems, pv's, lv's,vg's,dm_crypt's.. in the right order before doing this (opposite order of construct) and swapoff. debug "process_filesystems Called. checking all entries in $TMP_FILESYSTEMS" + rm -f $TMP_FSTAB devs_avail=1 while [ $devs_avail = 1 ] do diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index e13a952..77b0033 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -178,8 +178,7 @@ interactive_autoprepare() SET_DEFAULTFS=1 done - _dia_DIALOG --defaultno --yesno "$DISC will be COMPLETELY ERASED! Are you absolutely sure?" 0 0 \ - || return 1 + _dia_DIALOG --defaultno --yesno "$DISC will be COMPLETELY ERASED! Are you absolutely sure?" 0 0 || return 1 # we assume a /dev/hdX format (or /dev/sdX) @@ -220,28 +219,44 @@ interactive_partition() { [ "$DISC" = "DONE" ] && break # Partition disc notify "Now you'll be put into the cfdisk program where you can partition your hard drive. You should make a swap partition and as many data partitions as you will need.\ - NOTE: cfdisk may tell you to reboot after creating partitions. If you need to reboot, just re-enter this install program, skip this step and go on to step 2." + NOTE: cfdisk may tell you to reboot after creating partitions. If you need to reboot, just re-enter this install program, skip this step and go on to the mountpoints selection step." cfdisk $DISC done return 0 } -interactive_mountpoints() { - while [ "$PARTFINISH" != "DONE" ]; do - : >$TMP_FSTAB - : >/home/arch/aif/runtime/.parts #TODO: use a variable instead of a file, we don't need to use a file for this +interactive_filesystems() { - # Determine which filesystems are available - FSOPTS="ext2 ext2 ext3 ext3" - [ "$(which mkreiserfs 2>/dev/null)" ] && FSOPTS="$FSOPTS reiserfs Reiser3" - [ "$(which mkfs.xfs 2>/dev/null)" ] && FSOPTS="$FSOPTS xfs XFS" - [ "$(which mkfs.jfs 2>/dev/null)" ] && FSOPTS="$FSOPTS jfs JFS" - [ "$(which mkfs.vfat 2>/dev/null)" ] && FSOPTS="$FSOPTS vfat VFAT" + # Determine which filesystems are available + FSOPTS="ext2 ext2 ext3 ext3" + which mkreiserfs 2>/dev/null && FSOPTS="$FSOPTS reiserfs Reiser3" + which mkfs.xfs 2>/dev/null && FSOPTS="$FSOPTS xfs XFS" + which mkfs.jfs 2>/dev/null && FSOPTS="$FSOPTS jfs JFS" + which mkfs.vfat 2>/dev/null && FSOPTS="$FSOPTS vfat VFAT" + which pvcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-pv LVM Physical Volume" + which lvcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-lv LVM Logical Volume" + which cryptsetup 2>/dev/null && FSOPTS="$FSOPTS dm_crypt DM_crypt Volume" + + notify "Available Disks:\n\n$(_getavaildisks)\n" + + # Let the user make filesystems and mountpoints + USERHAPPY=0 + while [ "$USERHAPPY" = 0 ] + do + PARTS=$(findpartitions _) + ask_option no "Add/edit partitions" $PARTS $UPCOMINGPARTS + ANSWER_OPTION + + #TODO: let user choose FS, mountpoint etc, and even create lvm pv's, dm_crypt stuff etc, create $UPCOMINGPARTS as needed + # also show the disks along with the fs, mountpoint that has been choosen (maybe) already + done + + # If the user has forgotten one or more fundamental ones, ask him now + ALLOK=true + # TODO: check all conditions that would make ALLOK untrue again + while [ "$ALLOK" != "true" ]; do - # Select mountpoints - notify "Available Disks:\n\n$(_getavaildisks)\n" - PARTS=$(findpartitions _) _dia_DIALOG --menu "Select the partition to use as swap" 21 50 13 NONE - $PARTS 2>$ANSWER || return 1 PART=$(cat $ANSWER) PARTS="$(echo $PARTS | sed -e "s#${PART}\ _##g")" @@ -283,7 +298,7 @@ interactive_mountpoints() { done DOMKFS="no" ask_yesno "Would you like to create a filesystem on $PART?\n\n(This will overwrite existing data!)" && DOMKFS="yes" - echo "$PART:$FSTYPE:$MP:$DOMKFS" >>/home/arch/aif/runtime/.parts + echo "$PART:$FSTYPE:$MP:$DOMKFS" >>file _dia_DIALOG --menu "Select any additional partitions to mount under your new root" 21 50 13 $PARTS DONE _ 2>$ANSWER || return 1 PART=$(cat $ANSWER) done @@ -292,7 +307,7 @@ interactive_mountpoints() { target_umountall - fix_filesystems /home/arch/aif/runtime/.parts && notify "Partitions were successfully mounted." && return 0 + fix_filesystems && notify "Partitions were successfully mounted." && return 0 show_warning "Failure while doing filesystems" "Something went wrong. Check your logs" return 1 diff --git a/src/core/procedures/interactive b/src/core/procedures/interactive index 1fb3378..d912091 100644 --- a/src/core/procedures/interactive +++ b/src/core/procedures/interactive @@ -165,7 +165,7 @@ worker_prepare_disks() if [ "$DISK_CONFIG_TYPE" = "auto" ]; then notify "You have already prepared your filesystems with Auto-prepare" #TODO: allow user to do this anyway. he can change his mind. else - interactive_mountpoints && ret=0 && NEXTITEM=4 && DISK_CONFIG_TYPE=manual + interactive_filesystems && ret=0 && NEXTITEM=4 && DISK_CONFIG_TYPE=manual fi ;; *) -- cgit v1.2.3-54-g00ecf From 95aa9229661a362c65eb94f6c042e92dc5277202 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 22 Nov 2008 14:28:03 +0100 Subject: made find{partitions,disks} more flexible for output control + tiny bit more work in interactive_filesystems --- src/core/libs/lib-blockdevices-filesystems.sh | 55 ++++++++++++++++----------- src/core/libs/lib-ui-interactive.sh | 21 +++++----- 2 files changed, 45 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index 7624b2c..d51bcf1 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -48,39 +48,45 @@ target_umountall() } -# literally taken from setup script +# taken from setup script, modified for separator control +# $1 set to 1 to echo a newline after device instead of a space (optional) +# $2 extra things to echo for each device (optional) finddisks() { workdir="$PWD" cd /sys/block # ide devices for dev in $(ls | egrep '^hd'); do if [ "$(cat $dev/device/media)" = "disk" ]; then - echo "/dev/$dev" - [ "$1" ] && echo $1 + echo -n "/dev/$dev" + [ "$1" = 1 ] && echo || echo -n ' ' + [ "$2" ] && echo $2 fi done #scsi/sata devices for dev in $(ls | egrep '^sd'); do # TODO: what is the significance of 5? ASKDEV if ! [ "$(cat $dev/device/type)" = "5" ]; then - echo "/dev/$dev" - [ "$1" ] && echo $1 + echo -n "/dev/$dev" + [ "$1" = 1 ] && echo || echo -n ' ' + [ "$2" ] && echo $2 fi done # cciss controllers if [ -d /dev/cciss ] ; then cd /dev/cciss for dev in $(ls | egrep -v 'p'); do - echo "/dev/cciss/$dev" - [ "$1" ] && echo $1 + echo -n "/dev/cciss/$dev" + [ "$1" = 1 ] && echo || echo -n ' ' + [ "$2" ] && echo $2 done fi # Smart 2 controllers if [ -d /dev/ida ] ; then cd /dev/ida for dev in $(ls | egrep -v 'p'); do - echo "/dev/ida/$dev" - [ "$1" ] && echo $1 + echo -n"/dev/ida/$dev" + [ "$1" = 1 ] && echo || echo -n ' ' + [ "$2" ] && echo $2 done fi cd "$workdir" @@ -101,7 +107,9 @@ getuuid() } -# taken from setup. slightly optimized. +# taken from setup script, slightly optimized and modified for separator control +# $1 set to 1 to echo a newline after device instead of a space (optional) +# $2 extra things to echo for each device (optional) findpartitions() { workdir="$PWD" for devpath in $(finddisks) @@ -115,8 +123,9 @@ findpartitions() { then if [ -d $part ] then - echo "/dev/$part" - [ "$1" ] && echo $1 + echo -n "/dev/$part" + [ "$1" = 1 ] && echo || echo -n ' ' + [ "$2" ] && echo $2 fi fi done @@ -124,16 +133,18 @@ findpartitions() { # include any mapped devices for devpath in $(ls /dev/mapper 2>/dev/null | grep -v control) do - echo "/dev/mapper/$devpath" - [ "$1" ] && echo $1 + echo -n "/dev/mapper/$devpath" + [ "$1" = 1 ] && echo || echo -n ' ' + [ "$2" ] && echo $2 done # include any raid md devices for devpath in $(ls -d /dev/md* | grep '[0-9]' 2>/dev/null) do if grep -qw $(echo $devpath /proc/mdstat | sed -e 's|/dev/||g') then - echo "$devpath" - [ "$1" ] && echo $1 + echo -n "$devpath" + [ "$1" = 1 ] && echo || echo -n ' ' + [ "$2" ] && echo $2 fi done # inlcude cciss controllers @@ -142,8 +153,9 @@ findpartitions() { cd /dev/cciss for dev in $(ls | egrep 'p') do - echo "/dev/cciss/$dev" - [ "$1" ] && echo $1 + echo -n "/dev/cciss/$dev" + [ "$1" = 1 ] && echo || echo -n ' ' + [ "$2" ] && echo $2 done fi # inlcude Smart 2 controllers @@ -152,8 +164,9 @@ findpartitions() { cd /dev/ida for dev in $(ls | egrep 'p') do - echo "/dev/ida/$dev" - [ "$1" ] && echo $1 + echo -n "/dev/ida/$dev" + [ "$1" = 1 ] && echo || echo -n ' ' + [ "$2" ] && echo $2 done fi @@ -376,8 +389,6 @@ fix_filesystems_deprecated () #TMP_PARTITIONS # disk partition-scheme - - # go over each disk in $TMP_PARTITIONS and partition it process_disks () { diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 77b0033..4b3fae3 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -109,7 +109,7 @@ interactive_autoprepare() DISCS=$(finddisks) if [ $(echo $DISCS | wc -w) -gt 1 ]; then notify "Available Disks:\n\n$(_getavaildisks)\n" - ask_option no "Select the hard drive to use" $(finddisks _) || return 1 + ask_option no "Select the hard drive to use" $(finddisks 1 _) || return 1 DISC=$ANSWER_OPTION else DISC=$DISCS @@ -203,7 +203,7 @@ interactive_partition() { target_umountall # Select disk to partition - DISCS=$(finddisks _) + DISCS=$(finddisks 1 _) DISCS="$DISCS OTHER - DONE +" notify "Available Disks:\n\n$(_getavaildisks)\n" DISC="" @@ -242,13 +242,16 @@ interactive_filesystems() { # Let the user make filesystems and mountpoints USERHAPPY=0 + TMP_MENU=/home/arch/aif/runtime/.tmpmenu + findpartitions 0 'no filesystem, no mountpoint' > $TMP_MENU while [ "$USERHAPPY" = 0 ] do - PARTS=$(findpartitions _) - ask_option no "Add/edit partitions" $PARTS $UPCOMINGPARTS - ANSWER_OPTION - - #TODO: let user choose FS, mountpoint etc, and even create lvm pv's, dm_crypt stuff etc, create $UPCOMINGPARTS as needed + ask_option no "Add/edit partitions" `cat $TMP_MENU` + part=$ANSWER_OPTION + --default-item +_dia_DIALOG --menu "Select a filesystem for / and /home:" 13 45 6 $FSOPTS 2>$ANSWER || return 1 + FSTYPE=$(cat $ANSWER) + #TODO: let user choose FS, mountpoint etc, and even create lvm pv's, dm_crypt stuff etc, update entries in $TMP_MENU and add 'fake' ones as needed # also show the disks along with the fs, mountpoint that has been choosen (maybe) already done @@ -499,8 +502,8 @@ EOF [ "$EDITOR" ] || interactive_get_editor $EDITOR $grubmenu - DEVS=$(finddisks _) - DEVS="$DEVS $(findpartitions _)" + DEVS=$(finddisks 1 _) + DEVS="$DEVS $(findpartitions 1 _)" if [ "$DEVS" = "" ]; then notify "No hard drives were found" return 1 -- cgit v1.2.3-54-g00ecf From 3cb072ae3057495c5c5a26732aa1e46e3d12abf9 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 22 Nov 2008 15:27:31 +0100 Subject: interactive_filesystems WIP --- src/core/libs/lib-ui-interactive.sh | 58 ++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 4b3fae3..6b976b3 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -228,31 +228,67 @@ interactive_partition() { interactive_filesystems() { - # Determine which filesystems are available + # Determine which filesystems/blockdevices are available FSOPTS="ext2 ext2 ext3 ext3" which mkreiserfs 2>/dev/null && FSOPTS="$FSOPTS reiserfs Reiser3" which mkfs.xfs 2>/dev/null && FSOPTS="$FSOPTS xfs XFS" which mkfs.jfs 2>/dev/null && FSOPTS="$FSOPTS jfs JFS" which mkfs.vfat 2>/dev/null && FSOPTS="$FSOPTS vfat VFAT" - which pvcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-pv LVM Physical Volume" - which lvcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-lv LVM Logical Volume" - which cryptsetup 2>/dev/null && FSOPTS="$FSOPTS dm_crypt DM_crypt Volume" + # source? mountpoint? label? exposes new, dummy blockdevice? extra opts? remarks + which pvcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-pv LVM Physical Volume" # part no no no: pv is specified as $part optional TODO: on 1 part you can make PV (or a totally different fs) but also VG if there is a PV already ! + which vgcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-vg LVM Volumegroup" # dummy part no yes /dev/mapper/$label PV's to use TODO: on 1 vg you must be able to create multiple LV's + which lvcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-lv LVM Logical Volume" # dummy part no yes /dev/mapper/$vg-$label VG and LV size + which cryptsetup 2>/dev/null && FSOPTS="$FSOPTS dm_crypt DM_crypt Volume" # dummy part no yes /dev/mapper/$label optional notify "Available Disks:\n\n$(_getavaildisks)\n" # Let the user make filesystems and mountpoints USERHAPPY=0 TMP_MENU=/home/arch/aif/runtime/.tmpmenu - findpartitions 0 'no filesystem, no mountpoint' > $TMP_MENU + findpartitions 0 'no_filesystem;no_mountpoint;no_opts;no_label' > $TMP_MENU while [ "$USERHAPPY" = 0 ] do - ask_option no "Add/edit partitions" `cat $TMP_MENU` + ask_option no "Add/edit partitions. Note that you don't *need* to specify opts or labels if you're not using lvm, dm_crypt, etc." `cat $TMP_MENU` DONE _ + [ "$ANSWER_OPTION" == DONE ] && USERHAPPY=1 && break + part=$ANSWER_OPTION - --default-item -_dia_DIALOG --menu "Select a filesystem for / and /home:" 13 45 6 $FSOPTS 2>$ANSWER || return 1 - FSTYPE=$(cat $ANSWER) - #TODO: let user choose FS, mountpoint etc, and even create lvm pv's, dm_crypt stuff etc, update entries in $TMP_MENU and add 'fake' ones as needed - # also show the disks along with the fs, mountpoint that has been choosen (maybe) already + fs=` awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 1` + mount=`awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 2` + opts=` awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 3` + label=`awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 4` + + # ask FS + default= + [ "$fs" != no_filesystem ] && default="--default-item $fs" + _dia_DIALOG --menu "Select a filesystem for $part:" $FSOPTS 2>$ANSWER || return 1 #TODO on PV part you can only make PV/vg, on vg you can only make lv etc + fs=$(cat $ANSWER) + + # ask mountpoint, if relevant + if [[ $fs != lvm-* && "$fs" != dm_crypt ]] + then + default= + [ "$mount" != no_mountpoint ] && default="$mount" + _dia_DIALOG --inputbox "Enter the mountpoint for $part" 8 65 "$default" 2>$ANSWER || return 1 + fs=$(cat $ANSWER) + fi + + # ask label, if relevant + if [ "$fs" = lvm-vg -o "$fs" = lvm-lv -o "$fs" = dm_crypt ] + then + default= + [ "$label" != no_label ] && default="$label" + _dia_DIALOG --inputbox "Enter the label/name for $part" 8 65 "$default" 2>$ANSWER || return 1 + label=$(cat $ANSWER) + fi + + # ask opts + + # update the menu + sed -i "s/^$part/$part $fs;$mount;$opts;$label/" $TMP_MENU + # if we have at least 1 lvm PV, create a dummy lvm VG if not done yet + + # TODO:create dummy 'results' of dm_crypt and lvm pv's, also remove them if we just changed from vg->ext3, dm_crypt -> fat, etc. + # TODO: find a way to make it possible to create n lv's on 1 pv done # If the user has forgotten one or more fundamental ones, ask him now -- cgit v1.2.3-54-g00ecf From 2a5aafa28f0a69a965c4e48b9fcce3acb3430336 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 22 Nov 2008 15:56:05 +0100 Subject: interactive_filesystems WIP --- src/core/libs/lib-ui-interactive.sh | 53 ++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 6b976b3..88aae42 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -234,34 +234,36 @@ interactive_filesystems() { which mkfs.xfs 2>/dev/null && FSOPTS="$FSOPTS xfs XFS" which mkfs.jfs 2>/dev/null && FSOPTS="$FSOPTS jfs JFS" which mkfs.vfat 2>/dev/null && FSOPTS="$FSOPTS vfat VFAT" - # source? mountpoint? label? exposes new, dummy blockdevice? extra opts? remarks - which pvcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-pv LVM Physical Volume" # part no no no: pv is specified as $part optional TODO: on 1 part you can make PV (or a totally different fs) but also VG if there is a PV already ! + # source? mountpoint? label? exposes new, dummy blockdevice? special params? remarks + which pvcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-pv LVM Physical Volume" # part no no no: pv is specified as $part no TODO: on 1 part you can make PV (or a totally different fs) but also VG if there is a PV already ! which vgcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-vg LVM Volumegroup" # dummy part no yes /dev/mapper/$label PV's to use TODO: on 1 vg you must be able to create multiple LV's which lvcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-lv LVM Logical Volume" # dummy part no yes /dev/mapper/$vg-$label VG and LV size - which cryptsetup 2>/dev/null && FSOPTS="$FSOPTS dm_crypt DM_crypt Volume" # dummy part no yes /dev/mapper/$label optional + which cryptsetup 2>/dev/null && FSOPTS="$FSOPTS dm_crypt DM_crypt Volume" # dummy part no yes /dev/mapper/$label no notify "Available Disks:\n\n$(_getavaildisks)\n" # Let the user make filesystems and mountpoints USERHAPPY=0 - TMP_MENU=/home/arch/aif/runtime/.tmpmenu - findpartitions 0 'no_filesystem;no_mountpoint;no_opts;no_label' > $TMP_MENU + TMP_MENU=/home/arch/aif/runtime/.tmpmenu #contains each block device along with all it's settings. note that each line must have 2 fields only, separated by 1 space! + findpartitions 0 'no_filesystem;no_mountpoint;no_opts;no_label;no_params' > $TMP_MENU while [ "$USERHAPPY" = 0 ] do - ask_option no "Add/edit partitions. Note that you don't *need* to specify opts or labels if you're not using lvm, dm_crypt, etc." `cat $TMP_MENU` DONE _ + ask_option no "Add/edit partitions. Note that you don't *need* to specify opts, labels or extra params if you're not using lvm, dm_crypt, etc." `cat $TMP_MENU` DONE _ [ "$ANSWER_OPTION" == DONE ] && USERHAPPY=1 && break part=$ANSWER_OPTION - fs=` awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 1` - mount=`awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 2` - opts=` awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 3` - label=`awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 4` + fs=` awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 1` + mount=` awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 2` + opts=` awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 3` + label=` awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 4` + params=`awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 5` # ask FS default= [ "$fs" != no_filesystem ] && default="--default-item $fs" _dia_DIALOG --menu "Select a filesystem for $part:" $FSOPTS 2>$ANSWER || return 1 #TODO on PV part you can only make PV/vg, on vg you can only make lv etc fs=$(cat $ANSWER) + [ -z "$fs" ] && fs=no_filesystem # ask mountpoint, if relevant if [[ $fs != lvm-* && "$fs" != dm_crypt ]] @@ -270,6 +272,7 @@ interactive_filesystems() { [ "$mount" != no_mountpoint ] && default="$mount" _dia_DIALOG --inputbox "Enter the mountpoint for $part" 8 65 "$default" 2>$ANSWER || return 1 fs=$(cat $ANSWER) + [ -z "$mount" ] && mount=no_mountpoint fi # ask label, if relevant @@ -279,9 +282,39 @@ interactive_filesystems() { [ "$label" != no_label ] && default="$label" _dia_DIALOG --inputbox "Enter the label/name for $part" 8 65 "$default" 2>$ANSWER || return 1 label=$(cat $ANSWER) + [ -z "$label" ] && label=no_label + fi + + # ask special params, if relevant + if [ "$fs" = lvm-vg ] + then + [ "$params" = no_params ] && params= + for pv in `sed 's/:/ /' <<< $params` + do + list="$list $pv ^ ON" + done + for pv in `grep ' lvm-pv' $TMP_MENU | awk '{print $1}'` + do + ! grep -q "$pv ^ ON" && list="$list $pv - OFF" + done + _dia_DIALOG --checklist "Which lvm PV's must this volume group span?" 19 55 12 $list 2>$ANSWER || return 1 + params="$(sed 's/ /:/' $ANSWER)" #replace spaces by colon's, we cannot have spaces anywhere in any string + [ -z "$params" ] && params=no_params + fi + + if [ "$fs" = lvm-lv ] + then + #TODO: implement this fi # ask opts + default= + [ "$opts" != no_opts ] && default="$opts" + _dia_DIALOG --inputbox "Enter any additional opts for the program that will make $fs on $part" 8 65 "$default" 2>$ANSWER || return 1 + opts=$(cat $ANSWER) + [ -z "$opts" ] && opts=no_opts + + # update the menu sed -i "s/^$part/$part $fs;$mount;$opts;$label/" $TMP_MENU -- cgit v1.2.3-54-g00ecf From ea8542dee7abda984ca80d25a8b58e7c5f6c7976 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 22 Nov 2008 16:55:16 +0100 Subject: lvm LV special params --- src/core/libs/lib-ui-interactive.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 88aae42..a5bdcb2 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -237,7 +237,7 @@ interactive_filesystems() { # source? mountpoint? label? exposes new, dummy blockdevice? special params? remarks which pvcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-pv LVM Physical Volume" # part no no no: pv is specified as $part no TODO: on 1 part you can make PV (or a totally different fs) but also VG if there is a PV already ! which vgcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-vg LVM Volumegroup" # dummy part no yes /dev/mapper/$label PV's to use TODO: on 1 vg you must be able to create multiple LV's - which lvcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-lv LVM Logical Volume" # dummy part no yes /dev/mapper/$vg-$label VG and LV size + which lvcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-lv LVM Logical Volume" # dummy part no yes /dev/mapper/$vg-$label LV size which cryptsetup 2>/dev/null && FSOPTS="$FSOPTS dm_crypt DM_crypt Volume" # dummy part no yes /dev/mapper/$label no notify "Available Disks:\n\n$(_getavaildisks)\n" @@ -304,7 +304,11 @@ interactive_filesystems() { if [ "$fs" = lvm-lv ] then - #TODO: implement this + [ "$params" = no_params ] && default='5G' + [ "$params" != no_params ] && default="$params" + _dia_DIALOG --inputbox "Enter the size for this $fs on $part (suffix K,M,G,T,P,E. default is M)" 8 65 "$default" 2>$ANSWER || return 1 + params=$(cat $ANSWER) + [ -z "$params" ] && params=no_params fi # ask opts -- cgit v1.2.3-54-g00ecf From 2598bb221ce5eafe563e7f4a7657ed0b31039d6f Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 22 Nov 2008 17:20:00 +0100 Subject: doc fix + allow to append str directly after device/partition --- src/core/libs/lib-blockdevices-filesystems.sh | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index d51bcf1..e8884a6 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -51,13 +51,14 @@ target_umountall() # taken from setup script, modified for separator control # $1 set to 1 to echo a newline after device instead of a space (optional) # $2 extra things to echo for each device (optional) +# $3 something to append directly after the device (optional) finddisks() { workdir="$PWD" cd /sys/block # ide devices for dev in $(ls | egrep '^hd'); do if [ "$(cat $dev/device/media)" = "disk" ]; then - echo -n "/dev/$dev" + echo -n "/dev/$dev$3" [ "$1" = 1 ] && echo || echo -n ' ' [ "$2" ] && echo $2 fi @@ -66,7 +67,7 @@ finddisks() { for dev in $(ls | egrep '^sd'); do # TODO: what is the significance of 5? ASKDEV if ! [ "$(cat $dev/device/type)" = "5" ]; then - echo -n "/dev/$dev" + echo -n "/dev/$dev$3" [ "$1" = 1 ] && echo || echo -n ' ' [ "$2" ] && echo $2 fi @@ -75,7 +76,7 @@ finddisks() { if [ -d /dev/cciss ] ; then cd /dev/cciss for dev in $(ls | egrep -v 'p'); do - echo -n "/dev/cciss/$dev" + echo -n "/dev/cciss/$dev$3" [ "$1" = 1 ] && echo || echo -n ' ' [ "$2" ] && echo $2 done @@ -84,7 +85,7 @@ finddisks() { if [ -d /dev/ida ] ; then cd /dev/ida for dev in $(ls | egrep -v 'p'); do - echo -n"/dev/ida/$dev" + echo -n"/dev/ida/$dev$3" [ "$1" = 1 ] && echo || echo -n ' ' [ "$2" ] && echo $2 done @@ -108,8 +109,9 @@ getuuid() # taken from setup script, slightly optimized and modified for separator control -# $1 set to 1 to echo a newline after device instead of a space (optional) -# $2 extra things to echo for each device (optional) +# $1 set to 1 to echo a newline after partition instead of a space (optional) +# $2 extra things to echo for each partition (optional) +# $3 something to append directly after the partition (optional) findpartitions() { workdir="$PWD" for devpath in $(finddisks) @@ -123,7 +125,7 @@ findpartitions() { then if [ -d $part ] then - echo -n "/dev/$part" + echo -n "/dev/$part$3" [ "$1" = 1 ] && echo || echo -n ' ' [ "$2" ] && echo $2 fi @@ -133,7 +135,7 @@ findpartitions() { # include any mapped devices for devpath in $(ls /dev/mapper 2>/dev/null | grep -v control) do - echo -n "/dev/mapper/$devpath" + echo -n "/dev/mapper/$devpath$3" [ "$1" = 1 ] && echo || echo -n ' ' [ "$2" ] && echo $2 done @@ -142,7 +144,7 @@ findpartitions() { do if grep -qw $(echo $devpath /proc/mdstat | sed -e 's|/dev/||g') then - echo -n "$devpath" + echo -n "$devpath$3" [ "$1" = 1 ] && echo || echo -n ' ' [ "$2" ] && echo $2 fi @@ -153,7 +155,7 @@ findpartitions() { cd /dev/cciss for dev in $(ls | egrep 'p') do - echo -n "/dev/cciss/$dev" + echo -n "/dev/cciss/$dev$3" [ "$1" = 1 ] && echo || echo -n ' ' [ "$2" ] && echo $2 done @@ -164,7 +166,7 @@ findpartitions() { cd /dev/ida for dev in $(ls | egrep 'p') do - echo -n "/dev/ida/$dev" + echo -n "/dev/ida/$dev$3" [ "$1" = 1 ] && echo || echo -n ' ' [ "$2" ] && echo $2 done -- cgit v1.2.3-54-g00ecf From 4d86faa01498df968295d7341db52b5c54f5bbd9 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 22 Nov 2008 18:37:45 +0100 Subject: much more refactoring in interactive_filesystems, decoupling filesystem-blockdevice more etc etc --- src/core/libs/lib-ui-interactive.sh | 107 +++++++++++++++++++++++++----------- 1 file changed, 76 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index a5bdcb2..9f46cb6 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -228,36 +228,61 @@ interactive_partition() { interactive_filesystems() { - # Determine which filesystems/blockdevices are available - FSOPTS="ext2 ext2 ext3 ext3" - which mkreiserfs 2>/dev/null && FSOPTS="$FSOPTS reiserfs Reiser3" - which mkfs.xfs 2>/dev/null && FSOPTS="$FSOPTS xfs XFS" - which mkfs.jfs 2>/dev/null && FSOPTS="$FSOPTS jfs JFS" - which mkfs.vfat 2>/dev/null && FSOPTS="$FSOPTS vfat VFAT" - # source? mountpoint? label? exposes new, dummy blockdevice? special params? remarks - which pvcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-pv LVM Physical Volume" # part no no no: pv is specified as $part no TODO: on 1 part you can make PV (or a totally different fs) but also VG if there is a PV already ! - which vgcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-vg LVM Volumegroup" # dummy part no yes /dev/mapper/$label PV's to use TODO: on 1 vg you must be able to create multiple LV's - which lvcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-lv LVM Logical Volume" # dummy part no yes /dev/mapper/$vg-$label LV size - which cryptsetup 2>/dev/null && FSOPTS="$FSOPTS dm_crypt DM_crypt Volume" # dummy part no yes /dev/mapper/$label no - notify "Available Disks:\n\n$(_getavaildisks)\n" # Let the user make filesystems and mountpoints USERHAPPY=0 - TMP_MENU=/home/arch/aif/runtime/.tmpmenu #contains each block device along with all it's settings. note that each line must have 2 fields only, separated by 1 space! - findpartitions 0 'no_filesystem;no_mountpoint;no_opts;no_label;no_params' > $TMP_MENU + TMP_MENU=/home/arch/aif/runtime/.tmpmenu + + # $TMP_MENU entry: + # (type[,label]) empty/ # note that each line must have 2 fields only, separated by 1 space! + # FS-string: + # type;mountpoint;opts;label;params[|FS-string|...] + + findpartitions 0 'empty' '(raw') > $TMP_MENU #TODO: add label of partition too while [ "$USERHAPPY" = 0 ] do - ask_option no "Add/edit partitions. Note that you don't *need* to specify opts, labels or extra params if you're not using lvm, dm_crypt, etc." `cat $TMP_MENU` DONE _ + ask_option no "Manage filesystems, block devices and virtual devices. Note that you don't *need* to specify opts, labels or extra params if you're not using lvm, dm_crypt, etc." `cat $TMP_MENU` DONE _ [ "$ANSWER_OPTION" == DONE ] && USERHAPPY=1 && break - part=$ANSWER_OPTION - fs=` awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 1` - mount=` awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 2` - opts=` awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 3` - label=` awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 4` - params=`awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 5` - + part=`sed 's/(.*)$//' <<< $ANSWER_OPTION` + part_type=`sed 's/.*(\(.*\))$/\1/' <<< $ANSWER_OPTION` + part_label=` + fs=` awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 1` ; old_fs=$fs + mount=` awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 2` ; old_mount=$mount + opts=` awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 3` ; old_opts=$opts + label=` awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 4` ; old_label=$label + params=`awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 5` ; old_params=$params + + # Possible filesystems/software layers on partitions/block devices + + # name on top of mountpoint? label? DM device? theoretical device? opts? special params? remarks + + # swap raw/lvm-lv/dm_crypt no no no no no no + # ext 2 raw/lvm-lv/dm_crypt optional optional no no optional no + # ext 3 raw/lvm-lv/dm_crypt optional optional no no optional no + # reiserFS raw/lvm-lv/dm_crypt optional optional no no optional no + # xfs raw/lvm-lv/dm_crypt optional optional no no optional no + # jfs raw/lvm-lv/dm_crypt optional optional no no optional no + # vfat raw/lvm-lv/dm_crypt optional opt i guess no no optional no + # lvm-pv raw/dm_crypt no no no. $pv = $part yes. $part(lvm-pv) optional no + # lvm-vg lvm-pv no yes /dev/mapper/$label =dm device optional PV's to use TODO: on 1 vg you must be able to create multiple LV's + # lvm-lv lvm-vg no yes /dev/mapper/$part_label-$label =dm device optional LV size + # dm_crypt raw/rvm-lv no yes /dev/mapper/$label =dm device optional no + + + # Determine which filesystems/blockdevices are available + FSOPTS="ext2 ext2 ext3 ext3" + which mkreiserfs 2>/dev/null && FSOPTS="$FSOPTS reiserfs Reiser3" + which mkfs.xfs 2>/dev/null && FSOPTS="$FSOPTS xfs XFS" + which mkfs.jfs 2>/dev/null && FSOPTS="$FSOPTS jfs JFS" + which mkfs.vfat 2>/dev/null && FSOPTS="$FSOPTS vfat VFAT" + which pvcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-pv LVM Physical Volume" + which vgcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-vg LVM Volumegroup" + which lvcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-lv LVM Logical Volume" + which cryptsetup 2>/dev/null && FSOPTS="$FSOPTS dm_crypt DM_crypt Volume" +# TODO: implement 0..n FS's logic. default fs: no_filesystem;no_mountpoint;no_opts;no_label;no_params + #TODO: for each $part_type, select only relevant/possible FSOPTS # ask FS default= [ "$fs" != no_filesystem ] && default="--default-item $fs" @@ -301,7 +326,6 @@ interactive_filesystems() { params="$(sed 's/ /:/' $ANSWER)" #replace spaces by colon's, we cannot have spaces anywhere in any string [ -z "$params" ] && params=no_params fi - if [ "$fs" = lvm-lv ] then [ "$params" = no_params ] && default='5G' @@ -319,12 +343,33 @@ interactive_filesystems() { [ -z "$opts" ] && opts=no_opts - # update the menu - sed -i "s/^$part/$part $fs;$mount;$opts;$label/" $TMP_MENU - # if we have at least 1 lvm PV, create a dummy lvm VG if not done yet + sed -i "s/^$part($part_type).*/$part($part_type) $fs;$mount;$opts;$label;$params/" $TMP_MENU + + # add new dummy blockdevice, if relevant + if [ "$fs" = lvm-vg ] + then + echo "/dev/mapper/$label($fs) no_filesystem;no_mountpoint;no_opts;no_label;no_params" >> $TMP_MENU + elif [ "$fs" = lvm-pv ] + then + echo "$part($fs) no_filesystem;no_mountpoint;no_opts;no_label;no_params" >> $TMP_MENU + elif [ "$fs" = lvm-lv ] + then + #TODO: $vg is not set yet + echo "/dev/mapper/$vg-$label($fs) no_filesystem;no_mountpoint;no_opts;no_label;no_params" >> $TMP_MENU + elif [ "$fs" = dm_crypt ] + then + echo "/dev/mapper/$label($fs) no_filesystem;no_mountpoint;no_opts;no_label;no_params" >> $TMP_MENU + fi + + # cascading remove (dummy) blockdevice(s), if relevant ( eg if we just changed from vg->ext3, dm_crypt -> fat, etc) + if [[ $old_fs = lvm-* || $old_fs = dm_crypt ]] && [[ $fs != lvm-* && "$fs" != dm_crypt ]] + then + [ "$fs" = lvm-vg -o "$fs" = dm_cryp ] && target="/dev/mapper/$label" + [ "$fs" = lvm-lv ] && target="/dev/mapper/$vg-$label" #TODO: $vg not set + sed -i "#$target#d" $TMP_MENU #TODO: check affected items, delete those, etc etc. + fi - # TODO:create dummy 'results' of dm_crypt and lvm pv's, also remove them if we just changed from vg->ext3, dm_crypt -> fat, etc. # TODO: find a way to make it possible to create n lv's on 1 pv done @@ -381,11 +426,11 @@ interactive_filesystems() { ask_yesno "Would you like to create and mount the filesytems like this?\n\nSyntax\n------\nDEVICE:TYPE:MOUNTPOINT:FORMAT\n\n$(for i in $(cat /home/arch/aif/runtime/.parts); do echo "$i\n";done)" && PARTFINISH="DONE" done - target_umountall - - fix_filesystems && notify "Partitions were successfully mounted." && return 0 +# TODO: should not need this anymore target_umountall + # TODO: prepend $var_TARGET_DIR before handing over - show_warning "Failure while doing filesystems" "Something went wrong. Check your logs" + process_filesystems && notify "Partitions were successfully created." && return 0 + show_warning "Something went wrong while processing the filesystems" return 1 } -- cgit v1.2.3-54-g00ecf From d584ea5cdd121a8155cb1638cbcad5d0a3c27c93 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 23 Nov 2008 11:43:04 +0100 Subject: partition label fix --- src/core/libs/lib-ui-interactive.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 9f46cb6..75ca06d 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -235,19 +235,19 @@ interactive_filesystems() { TMP_MENU=/home/arch/aif/runtime/.tmpmenu # $TMP_MENU entry: - # (type[,label]) empty/ # note that each line must have 2 fields only, separated by 1 space! + # (type,[label]) empty/ # note that each line must have 2 fields only, separated by 1 space! # FS-string: # type;mountpoint;opts;label;params[|FS-string|...] - findpartitions 0 'empty' '(raw') > $TMP_MENU #TODO: add label of partition too + findpartitions 0 'empty' '(raw,)') > $TMP_MENU while [ "$USERHAPPY" = 0 ] do ask_option no "Manage filesystems, block devices and virtual devices. Note that you don't *need* to specify opts, labels or extra params if you're not using lvm, dm_crypt, etc." `cat $TMP_MENU` DONE _ [ "$ANSWER_OPTION" == DONE ] && USERHAPPY=1 && break part=`sed 's/(.*)$//' <<< $ANSWER_OPTION` - part_type=`sed 's/.*(\(.*\))$/\1/' <<< $ANSWER_OPTION` - part_label=` + part_type=` sed 's/.*(\(.*\))$/\1/' <<< $ANSWER_OPTION | cut -d ',' -f 1` + part_label=`sed 's/.*(\(.*\))$/\1/' <<< $ANSWER_OPTION | cut -d ',' -f 2` fs=` awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 1` ; old_fs=$fs mount=` awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 2` ; old_mount=$mount opts=` awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 3` ; old_opts=$opts @@ -281,6 +281,8 @@ interactive_filesystems() { which vgcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-vg LVM Volumegroup" which lvcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-lv LVM Logical Volume" which cryptsetup 2>/dev/null && FSOPTS="$FSOPTS dm_crypt DM_crypt Volume" + + #TODO: make separate function interactive_filesystem # TODO: implement 0..n FS's logic. default fs: no_filesystem;no_mountpoint;no_opts;no_label;no_params #TODO: for each $part_type, select only relevant/possible FSOPTS # ask FS -- cgit v1.2.3-54-g00ecf From ecc499acc3559ff370608d1e3910b7f5e5269577 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 23 Nov 2008 12:26:10 +0100 Subject: moving filesystem adding/editing/deleting in separate function --- src/core/libs/lib-ui-interactive.sh | 215 ++++++++++++++++++++++-------------- 1 file changed, 130 insertions(+), 85 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 75ca06d..1c2223d 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -226,97 +226,104 @@ interactive_partition() { } -interactive_filesystems() { - - notify "Available Disks:\n\n$(_getavaildisks)\n" - - # Let the user make filesystems and mountpoints - USERHAPPY=0 - TMP_MENU=/home/arch/aif/runtime/.tmpmenu - - # $TMP_MENU entry: - # (type,[label]) empty/ # note that each line must have 2 fields only, separated by 1 space! - # FS-string: - # type;mountpoint;opts;label;params[|FS-string|...] - - findpartitions 0 'empty' '(raw,)') > $TMP_MENU - while [ "$USERHAPPY" = 0 ] - do - ask_option no "Manage filesystems, block devices and virtual devices. Note that you don't *need* to specify opts, labels or extra params if you're not using lvm, dm_crypt, etc." `cat $TMP_MENU` DONE _ - [ "$ANSWER_OPTION" == DONE ] && USERHAPPY=1 && break +# create new, delete, or edit a filesystem +interactive_filesystem () +{ + part=$1 + part_type=$2 + part_label=$3 + fs=$4 + NEW_FILESYSTEM= + if [ $fs = empty ] + then + fs_type= + fs_mount= + fs_opts= + fs_label= + fs_params= + else + ask_option edit "What do you want to do on $part ($part_type,$part_label) ?" edit EDIT delete 'DELETE (revert to raw partition)' + if [ "$ANSWER_OPTION" = delete ] + then + NEW_FILESYSTEM=empty + return 0 + else + fs_type=` cut -d ';' -f 1 <<< $fs` + fs_mount=` cut -d ';' -f 2 <<< $fs` + fs_opts=` cut -d ';' -f 3 <<< $fs` + fs_label=` cut -d ';' -f 4 <<< $fs` + fs_params=`cut -d ';' -f 5 <<< $fs` + [ "$fs_type" = no_type ] && fs_type= + [ "$fs_mount" = no_mount ] && fs_mount= + [ "$fs_opts" = no_opts ] && fs_opts= + [ "$fs_label" = no_label ] && fs_label= + [ "$fs_params" = no_params ] && fs_params= + old_fs_type=$fs_type + old_fs_mount=$fs_mount + old_fs_opts=$fs_opts + old_fs_label=$fs_label + old_fs_params=$fs_params + fi + fi + + # Possible filesystems/software layers on partitions/block devices + + # name on top of mountpoint? label? DM device? theoretical device? opts? special params? + + # swap raw/lvm-lv/dm_crypt no no no no no no + # ext 2 raw/lvm-lv/dm_crypt optional optional no no optional no + # ext 3 raw/lvm-lv/dm_crypt optional optional no no optional no + # reiserFS raw/lvm-lv/dm_crypt optional optional no no optional no + # xfs raw/lvm-lv/dm_crypt optional optional no no optional no + # jfs raw/lvm-lv/dm_crypt optional optional no no optional no + # vfat raw/lvm-lv/dm_crypt optional opt i guess no no optional no + # lvm-pv raw/dm_crypt no no no. $pv = $part yes. $part(lvm-pv) optional no + # lvm-vg lvm-pv no yes /dev/mapper/$label =dm device optional PV's to use + # lvm-lv lvm-vg no yes /dev/mapper/$part_label-$label =dm device optional LV size + # dm_crypt raw/rvm-lv no yes /dev/mapper/$label =dm device optional no + + + # Determine which filesystems/blockdevices are available + FSOPTS= + [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.ext2 2>/dev/null && FSOPTS="$FSOPTS ext2 Ext2" + [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.ext2 2>/dev/null && FSOPTS="$FSOPTS ext3 Ext3" + [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkreiserfs 2>/dev/null && FSOPTS="$FSOPTS reiserfs Reiser3" + [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.xfs 2>/dev/null && FSOPTS="$FSOPTS xfs XFS" + [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.jfs 2>/dev/null && FSOPTS="$FSOPTS jfs JFS" + [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.vfat 2>/dev/null && FSOPTS="$FSOPTS vfat VFAT" + [ $part_type = raw -o $part_type = dm_crypt ] && which pvcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-pv LVM Physical Volume" + [ $part_type = lvm-pv ] && which vgcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-vg LVM Volumegroup" + [ $part_type = lvm-vg ] && which lvcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-lv LVM Logical Volume" + [ $part_type = raw -o $part_type = lvm-lv ] && which cryptsetup 2>/dev/null && FSOPTS="$FSOPTS dm_crypt DM_crypt Volume" - part=`sed 's/(.*)$//' <<< $ANSWER_OPTION` - part_type=` sed 's/.*(\(.*\))$/\1/' <<< $ANSWER_OPTION | cut -d ',' -f 1` - part_label=`sed 's/.*(\(.*\))$/\1/' <<< $ANSWER_OPTION | cut -d ',' -f 2` - fs=` awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 1` ; old_fs=$fs - mount=` awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 2` ; old_mount=$mount - opts=` awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 3` ; old_opts=$opts - label=` awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 4` ; old_label=$label - params=`awk "/^$part/ {print \$2} $TMP_MENU" | cut -d ';' -f 5` ; old_params=$params - - # Possible filesystems/software layers on partitions/block devices - - # name on top of mountpoint? label? DM device? theoretical device? opts? special params? remarks - - # swap raw/lvm-lv/dm_crypt no no no no no no - # ext 2 raw/lvm-lv/dm_crypt optional optional no no optional no - # ext 3 raw/lvm-lv/dm_crypt optional optional no no optional no - # reiserFS raw/lvm-lv/dm_crypt optional optional no no optional no - # xfs raw/lvm-lv/dm_crypt optional optional no no optional no - # jfs raw/lvm-lv/dm_crypt optional optional no no optional no - # vfat raw/lvm-lv/dm_crypt optional opt i guess no no optional no - # lvm-pv raw/dm_crypt no no no. $pv = $part yes. $part(lvm-pv) optional no - # lvm-vg lvm-pv no yes /dev/mapper/$label =dm device optional PV's to use TODO: on 1 vg you must be able to create multiple LV's - # lvm-lv lvm-vg no yes /dev/mapper/$part_label-$label =dm device optional LV size - # dm_crypt raw/rvm-lv no yes /dev/mapper/$label =dm device optional no - - - # Determine which filesystems/blockdevices are available - FSOPTS="ext2 ext2 ext3 ext3" - which mkreiserfs 2>/dev/null && FSOPTS="$FSOPTS reiserfs Reiser3" - which mkfs.xfs 2>/dev/null && FSOPTS="$FSOPTS xfs XFS" - which mkfs.jfs 2>/dev/null && FSOPTS="$FSOPTS jfs JFS" - which mkfs.vfat 2>/dev/null && FSOPTS="$FSOPTS vfat VFAT" - which pvcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-pv LVM Physical Volume" - which vgcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-vg LVM Volumegroup" - which lvcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-lv LVM Logical Volume" - which cryptsetup 2>/dev/null && FSOPTS="$FSOPTS dm_crypt DM_crypt Volume" - - #TODO: make separate function interactive_filesystem -# TODO: implement 0..n FS's logic. default fs: no_filesystem;no_mountpoint;no_opts;no_label;no_params - #TODO: for each $part_type, select only relevant/possible FSOPTS # ask FS default= - [ "$fs" != no_filesystem ] && default="--default-item $fs" - _dia_DIALOG --menu "Select a filesystem for $part:" $FSOPTS 2>$ANSWER || return 1 #TODO on PV part you can only make PV/vg, on vg you can only make lv etc - fs=$(cat $ANSWER) - [ -z "$fs" ] && fs=no_filesystem + [ -n "$fs_type" ] && default="--default-item $fs_type" + _dia_DIALOG --menu "Select a filesystem for $part:" $FSOPTS 2>$ANSWER || return 1 + fs_type=$(cat $ANSWER) # ask mountpoint, if relevant - if [[ $fs != lvm-* && "$fs" != dm_crypt ]] + if [[ $fs_type != lvm-* && "$fs_type" != dm_crypt ]] then default= - [ "$mount" != no_mountpoint ] && default="$mount" + [ -n "$fs_mount" ] && default="$fs_mount" _dia_DIALOG --inputbox "Enter the mountpoint for $part" 8 65 "$default" 2>$ANSWER || return 1 - fs=$(cat $ANSWER) - [ -z "$mount" ] && mount=no_mountpoint + fs_mount=$(cat $ANSWER) fi # ask label, if relevant - if [ "$fs" = lvm-vg -o "$fs" = lvm-lv -o "$fs" = dm_crypt ] + if [ "$fs_type" = lvm-vg -o "$fs_type" = lvm-lv -o "$fs_type" = dm_crypt ] then default= - [ "$label" != no_label ] && default="$label" + [ -n "$fs_label" ] && default="$fs_label" _dia_DIALOG --inputbox "Enter the label/name for $part" 8 65 "$default" 2>$ANSWER || return 1 - label=$(cat $ANSWER) - [ -z "$label" ] && label=no_label + fs_label=$(cat $ANSWER) fi # ask special params, if relevant - if [ "$fs" = lvm-vg ] + if [ "$fs_type" = lvm-vg ] then - [ "$params" = no_params ] && params= - for pv in `sed 's/:/ /' <<< $params` + for pv in `sed 's/:/ /' <<< $fs_params` do list="$list $pv ^ ON" done @@ -325,24 +332,62 @@ interactive_filesystems() { ! grep -q "$pv ^ ON" && list="$list $pv - OFF" done _dia_DIALOG --checklist "Which lvm PV's must this volume group span?" 19 55 12 $list 2>$ANSWER || return 1 - params="$(sed 's/ /:/' $ANSWER)" #replace spaces by colon's, we cannot have spaces anywhere in any string - [ -z "$params" ] && params=no_params + fs_params="$(sed 's/ /:/' $ANSWER)" #replace spaces by colon's, we cannot have spaces anywhere in any string fi - if [ "$fs" = lvm-lv ] + if [ "$fs_type" = lvm-lv ] then - [ "$params" = no_params ] && default='5G' - [ "$params" != no_params ] && default="$params" - _dia_DIALOG --inputbox "Enter the size for this $fs on $part (suffix K,M,G,T,P,E. default is M)" 8 65 "$default" 2>$ANSWER || return 1 - params=$(cat $ANSWER) - [ -z "$params" ] && params=no_params + [ -z "$fs_params" ] && default='5G' + [ -n "$fs_params" ] && default="$fs_params" + _dia_DIALOG --inputbox "Enter the size for this $fs_type on $part (suffix K,M,G,T,P,E. default is M)" 8 65 "$default" 2>$ANSWER || return 1 + fs_params=$(cat $ANSWER) fi # ask opts default= - [ "$opts" != no_opts ] && default="$opts" - _dia_DIALOG --inputbox "Enter any additional opts for the program that will make $fs on $part" 8 65 "$default" 2>$ANSWER || return 1 - opts=$(cat $ANSWER) - [ -z "$opts" ] && opts=no_opts + [ -n "$fs_opts" ] && default="$fs_opts" + _dia_DIALOG --inputbox "Enter any additional opts for the program that will make $fs_type on $part" 8 65 "$default" 2>$ANSWER || return 1 + fs_opts=$(cat $ANSWER) + + [ -z "$fs_type" ] && fs_type=no_type + [ -z "$fs_mount" ] && fs_mount=no_mount + [ -z "$fs_opts" ] && fs_opts=no_opts + [ -z "$fs_label" ] && fs_label=no_label + [ -z "$fs_params" ] && fs_params=no_params + NEW_FILESYSTEM="$fs_type;$fs_mount;$fs_opts;$fs_label;$fs_params" +} + +interactive_filesystems() { + + notify "Available Disks:\n\n$(_getavaildisks)\n" + + # Let the user make filesystems and mountpoints + USERHAPPY=0 + TMP_MENU=/home/arch/aif/runtime/.tmpmenu + + # $TMP_MENU entry: + # (type,[label]) empty/ # note that each line must have 2 fields only, separated by 1 space! + # FS-string: + # type;mountpoint;opts;label;params[|FS-string|...] + + findpartitions 0 'empty' '(raw,)') > $TMP_MENU + while [ "$USERHAPPY" = 0 ] + do + ask_option no "Manage filesystems, block devices and virtual devices. Note that you don't *need* to specify opts, labels or extra params if you're not using lvm, dm_crypt, etc." `cat $TMP_MENU` DONE _ + [ "$ANSWER_OPTION" == DONE ] && USERHAPPY=1 && break + + part=`sed 's/(.*)$//' <<< $ANSWER_OPTION` + part_type=` sed 's/.*(\(.*\))$/\1/' <<< $ANSWER_OPTION | cut -d ',' -f 1` + part_label=`sed 's/.*(\(.*\))$/\1/' <<< $ANSWER_OPTION | cut -d ',' -f 2` + fs=`awk "/^$part/ {print \$2} $TMP_MENU"` + if [ $part_type = lvm-vg ] + then + #TODO: menu here where you can add/edit 0..n lv's + else + interactive_filesystem $part $part_type $part_label $fs + fi + + + # TODO: handle $NEW_FILESYSTEM # update the menu -- cgit v1.2.3-54-g00ecf From 7b229a75088b480c282c90d6d29ce2d5ef181a9c Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 23 Nov 2008 12:45:34 +0100 Subject: more interactive filesystem(s) WIP --- src/core/libs/lib-ui-interactive.sh | 77 +++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 1c2223d..42db4ec 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -354,6 +354,29 @@ interactive_filesystem () [ -z "$fs_label" ] && fs_label=no_label [ -z "$fs_params" ] && fs_params=no_params NEW_FILESYSTEM="$fs_type;$fs_mount;$fs_opts;$fs_label;$fs_params" + + # add new theoretical blockdevice, if relevant + if [ "$fs_type" = lvm-vg ] + then + echo "/dev/mapper/$fs_label($fs_type) empty" >> $TMP_MENU + elif [ "$fs_type" = lvm-pv ] + then + echo "$part($fs_type) empty" >> $TMP_MENU + elif [ "$fs_type" = lvm-lv ] + then + echo "/dev/mapper/$part_label-$fs_label($fs_type) empty" >> $TMP_MENU + elif [ "$fs_type" = dm_crypt ] + then + echo "/dev/mapper/$fs_label($fs_type) empty" >> $TMP_MENU + fi + + # TODO: cascading remove theoretical blockdevice(s), if relevant ( eg if we just changed from vg->ext3, dm_crypt -> fat, or if we changed the label of something, etc) + if [[ $old_fs = lvm-* || $old_fs = dm_crypt ]] && [[ $fs != lvm-* && "$fs" != dm_crypt ]] + then + [ "$fs" = lvm-vg -o "$fs" = dm_cryp ] && target="/dev/mapper/$label" + [ "$fs" = lvm-lv ] && target="/dev/mapper/$vg-$label" #TODO: $vg not set + sed -i "#$target#d" $TMP_MENU #TODO: check affected items, delete those, etc etc. + fi } interactive_filesystems() { @@ -379,45 +402,30 @@ interactive_filesystems() { part_type=` sed 's/.*(\(.*\))$/\1/' <<< $ANSWER_OPTION | cut -d ',' -f 1` part_label=`sed 's/.*(\(.*\))$/\1/' <<< $ANSWER_OPTION | cut -d ',' -f 2` fs=`awk "/^$part/ {print \$2} $TMP_MENU"` - if [ $part_type = lvm-vg ] + + if [ $part_type = lvm-vg ] # one lvm VG can host multiple LV's so that's a bit a special blockdevice... then - #TODO: menu here where you can add/edit 0..n lv's + list= + if [ $fs != empty ] + then + for lv in `sed '/|/ /' <<< $fs` + do + list="$list $lv" + done + fi + list="$list empty NEW" + ask_option empty "Edit/create new LV's on this VG:" $list + interactive_filesystem $ANSWER_OPTION + #TODO: for now we just append, that's obviously wrong + fs="$fs|$NEW_FILESYSTEM" else interactive_filesystem $part $part_type $part_label $fs + fs=$NEW_FILESYSTEM fi - - # TODO: handle $NEW_FILESYSTEM - - # update the menu - sed -i "s/^$part($part_type).*/$part($part_type) $fs;$mount;$opts;$label;$params/" $TMP_MENU - - # add new dummy blockdevice, if relevant - if [ "$fs" = lvm-vg ] - then - echo "/dev/mapper/$label($fs) no_filesystem;no_mountpoint;no_opts;no_label;no_params" >> $TMP_MENU - elif [ "$fs" = lvm-pv ] - then - echo "$part($fs) no_filesystem;no_mountpoint;no_opts;no_label;no_params" >> $TMP_MENU - elif [ "$fs" = lvm-lv ] - then - #TODO: $vg is not set yet - echo "/dev/mapper/$vg-$label($fs) no_filesystem;no_mountpoint;no_opts;no_label;no_params" >> $TMP_MENU - elif [ "$fs" = dm_crypt ] - then - echo "/dev/mapper/$label($fs) no_filesystem;no_mountpoint;no_opts;no_label;no_params" >> $TMP_MENU - fi - - # cascading remove (dummy) blockdevice(s), if relevant ( eg if we just changed from vg->ext3, dm_crypt -> fat, etc) - if [[ $old_fs = lvm-* || $old_fs = dm_crypt ]] && [[ $fs != lvm-* && "$fs" != dm_crypt ]] - then - [ "$fs" = lvm-vg -o "$fs" = dm_cryp ] && target="/dev/mapper/$label" - [ "$fs" = lvm-lv ] && target="/dev/mapper/$vg-$label" #TODO: $vg not set - sed -i "#$target#d" $TMP_MENU #TODO: check affected items, delete those, etc etc. - fi + sed -i "s/^$part($part_type,$part_label).*/$part($part_type,$part_label) $fs/" $TMP_MENU - # TODO: find a way to make it possible to create n lv's on 1 pv done # If the user has forgotten one or more fundamental ones, ask him now @@ -473,8 +481,9 @@ interactive_filesystems() { ask_yesno "Would you like to create and mount the filesytems like this?\n\nSyntax\n------\nDEVICE:TYPE:MOUNTPOINT:FORMAT\n\n$(for i in $(cat /home/arch/aif/runtime/.parts); do echo "$i\n";done)" && PARTFINISH="DONE" done -# TODO: should not need this anymore target_umountall - # TODO: prepend $var_TARGET_DIR before handing over + # TODO: should not need this anymore target_umountall + # TODO: prepend $var_TARGET_DIR before handing over + # TODO: convert our format to what process_filesystems will understand process_filesystems && notify "Partitions were successfully created." && return 0 show_warning "Something went wrong while processing the filesystems" -- cgit v1.2.3-54-g00ecf From a3a16f42b8ae950cf81b4a41fb3e9802af035181 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Tue, 2 Dec 2008 22:37:15 +0100 Subject: syntax bugfix --- src/core/libs/lib-ui-interactive.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 42db4ec..c4e1ea1 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -392,7 +392,7 @@ interactive_filesystems() { # FS-string: # type;mountpoint;opts;label;params[|FS-string|...] - findpartitions 0 'empty' '(raw,)') > $TMP_MENU + findpartitions 0 'empty' '(raw,)' > $TMP_MENU while [ "$USERHAPPY" = 0 ] do ask_option no "Manage filesystems, block devices and virtual devices. Note that you don't *need* to specify opts, labels or extra params if you're not using lvm, dm_crypt, etc." `cat $TMP_MENU` DONE _ -- cgit v1.2.3-54-g00ecf From 029d2c3604f85c3f930ddc4cb93dddf0de155068 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Tue, 2 Dec 2008 23:12:51 +0100 Subject: todo add --- src/core/libs/lib-blockdevices-filesystems.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index e8884a6..b95fa9a 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -111,7 +111,7 @@ getuuid() # taken from setup script, slightly optimized and modified for separator control # $1 set to 1 to echo a newline after partition instead of a space (optional) # $2 extra things to echo for each partition (optional) -# $3 something to append directly after the partition (optional) +# $3 something to append directly after the partition (optional) TODO: refactor code so there's a space in between, merge $2 and $3. use echo -e to print whatever user wants findpartitions() { workdir="$PWD" for devpath in $(finddisks) -- cgit v1.2.3-54-g00ecf From b7f196f697efa6bf8e25dbf44efc9d03e41b69b8 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Tue, 2 Dec 2008 23:13:45 +0100 Subject: partition data vs menu layout separation WIP --- src/core/libs/lib-ui-interactive.sh | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index c4e1ea1..1a9a604 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -388,20 +388,29 @@ interactive_filesystems() { TMP_MENU=/home/arch/aif/runtime/.tmpmenu # $TMP_MENU entry: - # (type,[label]) empty/ # note that each line must have 2 fields only, separated by 1 space! + # old -> (type,[label]) empty/ # TODO / WIP !!!!: separate menu formatting from datafile syntax -> allow spaces here + # new -> type label/no_label /no_fs # FS-string: # type;mountpoint;opts;label;params[|FS-string|...] - findpartitions 0 'empty' '(raw,)' > $TMP_MENU + findpartitions 0 'no_fs' ' raw no_label' > $TMP_MENU while [ "$USERHAPPY" = 0 ] do - ask_option no "Manage filesystems, block devices and virtual devices. Note that you don't *need* to specify opts, labels or extra params if you're not using lvm, dm_crypt, etc." `cat $TMP_MENU` DONE _ + menu_list= + while read $part $type $label $fs + do + menu_list="$menu_list $part" + done < $TMP_MENU + + ask_option no "Manage filesystems, block devices and virtual devices. Note that you don't *need* to specify opts, labels or extra params if you're not using lvm, dm_crypt, etc." $menu_list DONE _ [ "$ANSWER_OPTION" == DONE ] && USERHAPPY=1 && break - part=`sed 's/(.*)$//' <<< $ANSWER_OPTION` - part_type=` sed 's/.*(\(.*\))$/\1/' <<< $ANSWER_OPTION | cut -d ',' -f 1` - part_label=`sed 's/.*(\(.*\))$/\1/' <<< $ANSWER_OPTION | cut -d ',' -f 2` - fs=`awk "/^$part/ {print \$2} $TMP_MENU"` + part=$ANSWER_OPTION + part_type=` awk "/^$part/ {print \$2}" $TMP_MENU` + part_label=`awk "/^$part/ {print \$3}" $TMP_MENU` + fs=` awk "/^$part/ {print \$4}" $TMP_MENU` + [ "$part_label" == no_label ] && part_label= + [ "$fs" == no_fs ] && fs= if [ $part_type = lvm-vg ] # one lvm VG can host multiple LV's so that's a bit a special blockdevice... then -- cgit v1.2.3-54-g00ecf From f23ee6c857e3ad8f6244ab8ed70648de88c2b12f Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Tue, 2 Dec 2008 23:24:16 +0100 Subject: partition data vs menu layout separation should work now, pretty much --- src/core/libs/lib-ui-interactive.sh | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 1a9a604..e051838 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -242,7 +242,7 @@ interactive_filesystem () fs_label= fs_params= else - ask_option edit "What do you want to do on $part ($part_type,$part_label) ?" edit EDIT delete 'DELETE (revert to raw partition)' + ask_option edit "What do you want to do on $part (type:$part_type,label:$part_label) ?" edit EDIT delete 'DELETE (revert to raw partition)' if [ "$ANSWER_OPTION" = delete ] then NEW_FILESYSTEM=empty @@ -327,7 +327,7 @@ interactive_filesystem () do list="$list $pv ^ ON" done - for pv in `grep ' lvm-pv' $TMP_MENU | awk '{print $1}'` + for pv in `grep ' lvm-pv' $BLOCK_DATA | awk '{print $1}'` do ! grep -q "$pv ^ ON" && list="$list $pv - OFF" done @@ -358,16 +358,16 @@ interactive_filesystem () # add new theoretical blockdevice, if relevant if [ "$fs_type" = lvm-vg ] then - echo "/dev/mapper/$fs_label($fs_type) empty" >> $TMP_MENU + echo "/dev/mapper/$fs_label $fs_type $fs_label no_fs" >> $BLOCK_DATA elif [ "$fs_type" = lvm-pv ] then - echo "$part($fs_type) empty" >> $TMP_MENU + echo "$part $fs_type no_label no_fs" >> $BLOCK_DATA elif [ "$fs_type" = lvm-lv ] then - echo "/dev/mapper/$part_label-$fs_label($fs_type) empty" >> $TMP_MENU + echo "/dev/mapper/$part_label-$fs_label $fs_type no_label no_fs" >> $BLOCK_DATA elif [ "$fs_type" = dm_crypt ] then - echo "/dev/mapper/$fs_label($fs_type) empty" >> $TMP_MENU + echo "/dev/mapper/$fs_label $fs_type no_label no_fs" >> $BLOCK_DATA fi # TODO: cascading remove theoretical blockdevice(s), if relevant ( eg if we just changed from vg->ext3, dm_crypt -> fat, or if we changed the label of something, etc) @@ -375,7 +375,7 @@ interactive_filesystem () then [ "$fs" = lvm-vg -o "$fs" = dm_cryp ] && target="/dev/mapper/$label" [ "$fs" = lvm-lv ] && target="/dev/mapper/$vg-$label" #TODO: $vg not set - sed -i "#$target#d" $TMP_MENU #TODO: check affected items, delete those, etc etc. + sed -i "#$target#d" $BLOCK_DATA #TODO: check affected items, delete those, etc etc. fi } @@ -385,30 +385,30 @@ interactive_filesystems() { # Let the user make filesystems and mountpoints USERHAPPY=0 - TMP_MENU=/home/arch/aif/runtime/.tmpmenu + BLOCK_DATA=/home/arch/aif/runtime/.blockdata - # $TMP_MENU entry: - # old -> (type,[label]) empty/ # TODO / WIP !!!!: separate menu formatting from datafile syntax -> allow spaces here - # new -> type label/no_label /no_fs + # $BLOCK_DATA entry. easily parsable.: + # type label/no_label /no_fs # FS-string: # type;mountpoint;opts;label;params[|FS-string|...] - findpartitions 0 'no_fs' ' raw no_label' > $TMP_MENU + findpartitions 0 'no_fs' ' raw no_label' > $BLOCK_DATA while [ "$USERHAPPY" = 0 ] do + # generate a menu based on the information in the datafile menu_list= while read $part $type $label $fs do - menu_list="$menu_list $part" - done < $TMP_MENU + menu_list="$menu_list $part (type:$type,label:$label,fs:$fs)" #don't add extra spaces, dialog doesn't like that. + done < $BLOCK_DATA ask_option no "Manage filesystems, block devices and virtual devices. Note that you don't *need* to specify opts, labels or extra params if you're not using lvm, dm_crypt, etc." $menu_list DONE _ [ "$ANSWER_OPTION" == DONE ] && USERHAPPY=1 && break part=$ANSWER_OPTION - part_type=` awk "/^$part/ {print \$2}" $TMP_MENU` - part_label=`awk "/^$part/ {print \$3}" $TMP_MENU` - fs=` awk "/^$part/ {print \$4}" $TMP_MENU` + part_type=` awk "/^$part/ {print \$2}" $BLOCK_DATA` + part_label=`awk "/^$part/ {print \$3}" $BLOCK_DATA` + fs=` awk "/^$part/ {print \$4}" $BLOCK_DATA` [ "$part_label" == no_label ] && part_label= [ "$fs" == no_fs ] && fs= @@ -433,7 +433,7 @@ interactive_filesystems() { fi # update the menu - sed -i "s/^$part($part_type,$part_label).*/$part($part_type,$part_label) $fs/" $TMP_MENU + sed -i "s/^$part $part_type $part_label.*/$part $part_type $part_label $fs/" $BLOCK_DATA done -- cgit v1.2.3-54-g00ecf From 55d02e8eac1abf142e71dbefd80dd9afc5cf25b5 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Wed, 3 Dec 2008 22:48:13 +0100 Subject: clearer step name --- src/core/procedures/interactive | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/procedures/interactive b/src/core/procedures/interactive index d912091..66efaec 100644 --- a/src/core/procedures/interactive +++ b/src/core/procedures/interactive @@ -147,7 +147,7 @@ worker_prepare_disks() ask_option $default "Prepare Hard Drive" \ "1" "Auto-Prepare (erases the ENTIRE hard drive and sets up partitions and filesystems)" \ "2" "Partition Hard Drives" \ - "3" "Set Filesystem Mountpoints" \ + "3" "Configure block devices, filesystems and mountpoints" \ "4" "Return to Main Menu" case $ANSWER_OPTION in -- cgit v1.2.3-54-g00ecf From c83cb8f996ff574d9f514492eb0ab87ddc9c3cad Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Wed, 3 Dec 2008 22:56:15 +0100 Subject: allow user to cancel in cli ask option --- src/core/libs/lib-ui.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index d54ea0d..61fface 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -155,6 +155,7 @@ ask_number () # $2 title # shift;shift; $@ list of options. first tag. then name. (eg tagA itemA "tag B" 'item B' ) # the response will be echoed to stdout. but also $ANSWER_OPTION will be set. take that because the former method seems to not work. +# $? if user cancelled. 0 otherwise ask_option () { [ "$var_UI_TYPE" = dia ] && { _dia_ask_option "$@" ; return $? ; } @@ -237,12 +238,15 @@ _cli_ask_option () echo "$1 ] $2" shift 2 done + echo "CANCEL ] CANCEL" [ -n "$DEFAULT" ] && echo -n " > [ $DEFAULT ] " [ -z "$DEFAULT" ] && echo -n " > " read ANSWER_OPTION [ -z "$ANSWER_OPTION" -a -n "$DEFAULT" ] && ANSWER_OPTION="$DEFAULT" debug "cli_ask_option: User choose $ANSWER_OPTION" echo "$ANSWER_OPTION" + [ "$ANSWER_OPTION" = CANCEL ] && return 1 + return 0 } -- cgit v1.2.3-54-g00ecf From d1857226fba6fdb27e55154ebb51ff6735816d20 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Wed, 3 Dec 2008 23:02:33 +0100 Subject: few fixes --- src/core/libs/lib-ui-interactive.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index e051838..0fcef00 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -242,7 +242,8 @@ interactive_filesystem () fs_label= fs_params= else - ask_option edit "What do you want to do on $part (type:$part_type,label:$part_label) ?" edit EDIT delete 'DELETE (revert to raw partition)' + ask_option edit "Alter $part (type:$part_type,label:$part_label) ?" edit EDIT delete 'DELETE (revert to raw partition)' + [ $? -gt 0 ] && NEW_FILESYSTEM=$fs && return 0 if [ "$ANSWER_OPTION" = delete ] then NEW_FILESYSTEM=empty @@ -403,6 +404,7 @@ interactive_filesystems() { done < $BLOCK_DATA ask_option no "Manage filesystems, block devices and virtual devices. Note that you don't *need* to specify opts, labels or extra params if you're not using lvm, dm_crypt, etc." $menu_list DONE _ + [ $? -gt 0 ] && USERHAPPY=1 && break [ "$ANSWER_OPTION" == DONE ] && USERHAPPY=1 && break part=$ANSWER_OPTION @@ -415,11 +417,11 @@ interactive_filesystems() { if [ $part_type = lvm-vg ] # one lvm VG can host multiple LV's so that's a bit a special blockdevice... then list= - if [ $fs != empty ] + if [ $fs != no_fs ] then for lv in `sed '/|/ /' <<< $fs` do - list="$list $lv" + list="$list $lv" #TODO: this is probably incorrect done fi list="$list empty NEW" -- cgit v1.2.3-54-g00ecf From c1c7a7da454dd7d0f45b1cb767bc1f07459ff54d Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Wed, 3 Dec 2008 23:17:41 +0100 Subject: few fixes --- src/core/libs/lib-ui-interactive.sh | 8 ++++---- src/core/libs/lib-ui.sh | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 0fcef00..c399b08 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -398,7 +398,7 @@ interactive_filesystems() { do # generate a menu based on the information in the datafile menu_list= - while read $part $type $label $fs + while read part type label fs do menu_list="$menu_list $part (type:$type,label:$label,fs:$fs)" #don't add extra spaces, dialog doesn't like that. done < $BLOCK_DATA @@ -408,9 +408,9 @@ interactive_filesystems() { [ "$ANSWER_OPTION" == DONE ] && USERHAPPY=1 && break part=$ANSWER_OPTION - part_type=` awk "/^$part/ {print \$2}" $BLOCK_DATA` - part_label=`awk "/^$part/ {print \$3}" $BLOCK_DATA` - fs=` awk "/^$part/ {print \$4}" $BLOCK_DATA` + part_type=` awk "/^${part//\//\\\/}/ {print \$2}" $BLOCK_DATA` # the bash substition replaces all /'s with \/'s otherwise awk complains + part_label=`awk "/^${part//\//\\\/}/ {print \$3}" $BLOCK_DATA` + fs=` awk "/^${part//\//\\\/}/ {print \$4}" $BLOCK_DATA` [ "$part_label" == no_label ] && part_label= [ "$fs" == no_fs ] && fs= diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 61fface..d4520bc 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -224,6 +224,7 @@ _dia_ask_option () _cli_ask_option () { #TODO: strip out color codes + #TODO: if user entered incorrect choice, ask him again DEFAULT="" [ "$1" != 'no' ] && DEFAULT=$1 [ -z "$2" ] && die_error "ask_option \$2 must be the title" -- cgit v1.2.3-54-g00ecf From 2d77f595a405ebd5668cbea87b0f55177e316372 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Wed, 3 Dec 2008 23:36:34 +0100 Subject: todo add --- src/core/libs/lib-ui-interactive.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index c399b08..74b4fbb 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -408,6 +408,7 @@ interactive_filesystems() { [ "$ANSWER_OPTION" == DONE ] && USERHAPPY=1 && break part=$ANSWER_OPTION + # TODO: Something goes wrong here.. all these 3 become the complete line part_type=` awk "/^${part//\//\\\/}/ {print \$2}" $BLOCK_DATA` # the bash substition replaces all /'s with \/'s otherwise awk complains part_label=`awk "/^${part//\//\\\/}/ {print \$3}" $BLOCK_DATA` fs=` awk "/^${part//\//\\\/}/ {print \$4}" $BLOCK_DATA` -- cgit v1.2.3-54-g00ecf From c1202f83da0f6286ec1f984e34bd544d0cce1d0b Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 5 Dec 2008 17:43:10 +0100 Subject: cleaner --- src/core/libs/lib-ui-interactive.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 74b4fbb..7e4a995 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -409,9 +409,10 @@ interactive_filesystems() { part=$ANSWER_OPTION # TODO: Something goes wrong here.. all these 3 become the complete line - part_type=` awk "/^${part//\//\\\/}/ {print \$2}" $BLOCK_DATA` # the bash substition replaces all /'s with \/'s otherwise awk complains - part_label=`awk "/^${part//\//\\\/}/ {print \$3}" $BLOCK_DATA` - fs=` awk "/^${part//\//\\\/}/ {print \$4}" $BLOCK_DATA` + declare part_escaped=${part//\//\\/} # the bash substition replaces all /'s with \/'s otherwise awk complains + part_type=` awk "/^$part_escaped/ {print \$2}" $BLOCK_DATA` + part_label=`awk "/^$part_escaped/ {print \$3}" $BLOCK_DATA` + fs=` awk "/^$part_escaped/ {print \$4}" $BLOCK_DATA` [ "$part_label" == no_label ] && part_label= [ "$fs" == no_fs ] && fs= -- cgit v1.2.3-54-g00ecf From c4dc338aaba9595e5e8e0372b7c2aba233b1ec2b Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 5 Dec 2008 18:23:21 +0100 Subject: workaround for the weird awk problem --- src/core/libs/lib-ui-interactive.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 7e4a995..9f8b990 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -408,11 +408,11 @@ interactive_filesystems() { [ "$ANSWER_OPTION" == DONE ] && USERHAPPY=1 && break part=$ANSWER_OPTION - # TODO: Something goes wrong here.. all these 3 become the complete line + declare part_escaped=${part//\//\\/} # the bash substition replaces all /'s with \/'s otherwise awk complains - part_type=` awk "/^$part_escaped/ {print \$2}" $BLOCK_DATA` - part_label=`awk "/^$part_escaped/ {print \$3}" $BLOCK_DATA` - fs=` awk "/^$part_escaped/ {print \$4}" $BLOCK_DATA` + part_type=$( awk "/^$part_escaped/ {print \$2}" $BLOCK_DATA) + part_label=$(awk "/^$part_escaped/ {print \$3}" $BLOCK_DATA) + fs=$( awk "/^$part_escaped/ {print \$4}" $BLOCK_DATA) [ "$part_label" == no_label ] && part_label= [ "$fs" == no_fs ] && fs= -- cgit v1.2.3-54-g00ecf From 6f431563d3ceee532e4866a59181053f0c59f71b Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 5 Dec 2008 18:30:55 +0100 Subject: cleanups and fixes --- src/core/libs/lib-ui-interactive.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 9f8b990..8cb0b79 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -286,22 +286,22 @@ interactive_filesystem () # Determine which filesystems/blockdevices are available FSOPTS= - [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.ext2 2>/dev/null && FSOPTS="$FSOPTS ext2 Ext2" - [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.ext2 2>/dev/null && FSOPTS="$FSOPTS ext3 Ext3" - [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkreiserfs 2>/dev/null && FSOPTS="$FSOPTS reiserfs Reiser3" - [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.xfs 2>/dev/null && FSOPTS="$FSOPTS xfs XFS" - [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.jfs 2>/dev/null && FSOPTS="$FSOPTS jfs JFS" - [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.vfat 2>/dev/null && FSOPTS="$FSOPTS vfat VFAT" - [ $part_type = raw -o $part_type = dm_crypt ] && which pvcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-pv LVM Physical Volume" - [ $part_type = lvm-pv ] && which vgcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-vg LVM Volumegroup" - [ $part_type = lvm-vg ] && which lvcreate 2>/dev/null && FSOPTS="$FSOPTS lvm-lv LVM Logical Volume" - [ $part_type = raw -o $part_type = lvm-lv ] && which cryptsetup 2>/dev/null && FSOPTS="$FSOPTS dm_crypt DM_crypt Volume" + [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.ext2 &>/dev/null && FSOPTS="$FSOPTS ext2 Ext2" + [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.ext2 &>/dev/null && FSOPTS="$FSOPTS ext3 Ext3" + [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkreiserfs &>/dev/null && FSOPTS="$FSOPTS reiserfs Reiser3" + [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.xfs &>/dev/null && FSOPTS="$FSOPTS xfs XFS" + [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.jfs &>/dev/null && FSOPTS="$FSOPTS jfs JFS" + [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.vfat &>/dev/null && FSOPTS="$FSOPTS vfat VFAT" + [ $part_type = raw -o $part_type = dm_crypt ] && which pvcreate &>/dev/null && FSOPTS="$FSOPTS lvm-pv LVM Physical Volume" + [ $part_type = lvm-pv ] && which vgcreate &>/dev/null && FSOPTS="$FSOPTS lvm-vg LVM Volumegroup" + [ $part_type = lvm-vg ] && which lvcreate &>/dev/null && FSOPTS="$FSOPTS lvm-lv LVM Logical Volume" + [ $part_type = raw -o $part_type = lvm-lv ] && which cryptsetup &>/dev/null && FSOPTS="$FSOPTS dm_crypt DM_crypt Volume" # ask FS default= [ -n "$fs_type" ] && default="--default-item $fs_type" - _dia_DIALOG --menu "Select a filesystem for $part:" $FSOPTS 2>$ANSWER || return 1 - fs_type=$(cat $ANSWER) + ask_option no "Select a filesystem for $part:" $FSOPTS || return 1 + fs_type=$ANSWER_OPTION # ask mountpoint, if relevant if [[ $fs_type != lvm-* && "$fs_type" != dm_crypt ]] @@ -430,10 +430,10 @@ interactive_filesystems() { ask_option empty "Edit/create new LV's on this VG:" $list interactive_filesystem $ANSWER_OPTION #TODO: for now we just append, that's obviously wrong - fs="$fs|$NEW_FILESYSTEM" + [ $? -eq 0 ] && fs="$fs|$NEW_FILESYSTEM" else interactive_filesystem $part $part_type $part_label $fs - fs=$NEW_FILESYSTEM + [ $? -eq 0 ] && fs=$NEW_FILESYSTEM fi # update the menu -- cgit v1.2.3-54-g00ecf From 81f23c78763d8c21c82c146f3821988cd9b3a338 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 5 Dec 2008 18:40:06 +0100 Subject: cleanups and fixes --- src/core/libs/lib-ui-interactive.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 8cb0b79..c58e371 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -229,12 +229,13 @@ interactive_partition() { # create new, delete, or edit a filesystem interactive_filesystem () { + # these variables can be empty strings! part=$1 part_type=$2 part_label=$3 fs=$4 NEW_FILESYSTEM= - if [ $fs = empty ] + if [ -z "$fs" ] then fs_type= fs_mount= @@ -284,7 +285,7 @@ interactive_filesystem () # dm_crypt raw/rvm-lv no yes /dev/mapper/$label =dm device optional no - # Determine which filesystems/blockdevices are available + # Determine which filesystems/blockdevices are possible for this blockdevice FSOPTS= [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.ext2 &>/dev/null && FSOPTS="$FSOPTS ext2 Ext2" [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.ext2 &>/dev/null && FSOPTS="$FSOPTS ext3 Ext3" @@ -292,10 +293,10 @@ interactive_filesystem () [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.xfs &>/dev/null && FSOPTS="$FSOPTS xfs XFS" [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.jfs &>/dev/null && FSOPTS="$FSOPTS jfs JFS" [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.vfat &>/dev/null && FSOPTS="$FSOPTS vfat VFAT" - [ $part_type = raw -o $part_type = dm_crypt ] && which pvcreate &>/dev/null && FSOPTS="$FSOPTS lvm-pv LVM Physical Volume" - [ $part_type = lvm-pv ] && which vgcreate &>/dev/null && FSOPTS="$FSOPTS lvm-vg LVM Volumegroup" - [ $part_type = lvm-vg ] && which lvcreate &>/dev/null && FSOPTS="$FSOPTS lvm-lv LVM Logical Volume" - [ $part_type = raw -o $part_type = lvm-lv ] && which cryptsetup &>/dev/null && FSOPTS="$FSOPTS dm_crypt DM_crypt Volume" + [ $part_type = raw -o $part_type = dm_crypt ] && which pvcreate &>/dev/null && FSOPTS="$FSOPTS lvm-pv LVM_Physical_Volume" + [ $part_type = lvm-pv ] && which vgcreate &>/dev/null && FSOPTS="$FSOPTS lvm-vg LVM_Volumegroup" + [ $part_type = lvm-vg ] && which lvcreate &>/dev/null && FSOPTS="$FSOPTS lvm-lv LVM_Logical_Volume" + [ $part_type = raw -o $part_type = lvm-lv ] && which cryptsetup &>/dev/null && FSOPTS="$FSOPTS dm_crypt DM_crypt_Volume" # ask FS default= -- cgit v1.2.3-54-g00ecf From e22f3102ca185b43ca975ee3f960e949aa0e8185 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 5 Dec 2008 18:51:20 +0100 Subject: cleanups and fixes --- src/core/libs/lib-blockdevices-filesystems.sh | 17 +++++++++++++++++ src/core/libs/lib-ui-interactive.sh | 7 ++++--- 2 files changed, 21 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index b95fa9a..8e49fbf 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -494,3 +494,20 @@ process_filesystem () return 0 } + + +# $1 filesystem type +get_filesystem_program () +{ + [ -z "$1" ] && die_error "get_filesystem_program needs a filesystem id as \$1" + [ $1 = ext2 ] && echo mkfs.ext2 + [ $1 = ext3 ] && echo mkfs.ext3 + [ $1 = reiserfs ] && echo mkreiserfs + [ $1 = xfs ] && echo mkfs.xfs + [ $1 = jfs ] && echo mkfs.jfs + [ $1 = vfat ] && echo mkfs.vfat + [ $1 = lvm-pv ] && echo pvcreate + [ $1 = lvm-vg ] && echo vgcreate + [ $1 = lvg-lv ] && echo lvcreate + [ $1 = dm_crypt ] && echo cryptsetup +} \ No newline at end of file diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index c58e371..4a77227 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -288,7 +288,7 @@ interactive_filesystem () # Determine which filesystems/blockdevices are possible for this blockdevice FSOPTS= [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.ext2 &>/dev/null && FSOPTS="$FSOPTS ext2 Ext2" - [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.ext2 &>/dev/null && FSOPTS="$FSOPTS ext3 Ext3" + [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.ext3 &>/dev/null && FSOPTS="$FSOPTS ext3 Ext3" [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkreiserfs &>/dev/null && FSOPTS="$FSOPTS reiserfs Reiser3" [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.xfs &>/dev/null && FSOPTS="$FSOPTS xfs XFS" [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.jfs &>/dev/null && FSOPTS="$FSOPTS jfs JFS" @@ -347,7 +347,8 @@ interactive_filesystem () # ask opts default= [ -n "$fs_opts" ] && default="$fs_opts" - _dia_DIALOG --inputbox "Enter any additional opts for the program that will make $fs_type on $part" 8 65 "$default" 2>$ANSWER || return 1 + program=`get_filesystem_program $fs_type` + _dia_DIALOG --inputbox "Enter any additional opts for $program" 8 65 "$default" 2>$ANSWER || return 1 fs_opts=$(cat $ANSWER) [ -z "$fs_type" ] && fs_type=no_type @@ -438,7 +439,7 @@ interactive_filesystems() { fi # update the menu - sed -i "s/^$part $part_type $part_label.*/$part $part_type $part_label $fs/" $BLOCK_DATA + sed -i "s#^$part $part_type $part_label.*#$part $part_type $part_label $fs#" $BLOCK_DATA # '#' is a forbidden character ! done -- cgit v1.2.3-54-g00ecf From 0e218b0e861e54f2bfde428605bcb5b2e7cfc0cf Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 5 Dec 2008 18:57:11 +0100 Subject: stupid fixes --- src/core/libs/lib-ui-interactive.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 4a77227..255acb4 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -421,7 +421,7 @@ interactive_filesystems() { if [ $part_type = lvm-vg ] # one lvm VG can host multiple LV's so that's a bit a special blockdevice... then list= - if [ $fs != no_fs ] + if [ -n "$fs" ] then for lv in `sed '/|/ /' <<< $fs` do @@ -439,6 +439,8 @@ interactive_filesystems() { fi # update the menu + [ -z "$part_label" ] && part_label=no_label + [ -z "$fs" ] && fs=no_fs sed -i "s#^$part $part_type $part_label.*#$part $part_type $part_label $fs#" $BLOCK_DATA # '#' is a forbidden character ! done -- cgit v1.2.3-54-g00ecf From 717b25d71de73085c7dae4eee78af024993ace8e Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 5 Dec 2008 19:10:50 +0100 Subject: stupid fixes --- src/core/libs/lib-ui-interactive.sh | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 255acb4..88341bf 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -270,19 +270,19 @@ interactive_filesystem () # Possible filesystems/software layers on partitions/block devices - # name on top of mountpoint? label? DM device? theoretical device? opts? special params? + # name on top of mountpoint? label? DM device? theoretical device? opts? special params? - # swap raw/lvm-lv/dm_crypt no no no no no no - # ext 2 raw/lvm-lv/dm_crypt optional optional no no optional no - # ext 3 raw/lvm-lv/dm_crypt optional optional no no optional no - # reiserFS raw/lvm-lv/dm_crypt optional optional no no optional no - # xfs raw/lvm-lv/dm_crypt optional optional no no optional no - # jfs raw/lvm-lv/dm_crypt optional optional no no optional no - # vfat raw/lvm-lv/dm_crypt optional opt i guess no no optional no - # lvm-pv raw/dm_crypt no no no. $pv = $part yes. $part(lvm-pv) optional no - # lvm-vg lvm-pv no yes /dev/mapper/$label =dm device optional PV's to use - # lvm-lv lvm-vg no yes /dev/mapper/$part_label-$label =dm device optional LV size - # dm_crypt raw/rvm-lv no yes /dev/mapper/$label =dm device optional no + # swap raw/lvm-lv/dm_crypt no no no no no no + # ext 2 raw/lvm-lv/dm_crypt optional optional no no optional no + # ext 3 raw/lvm-lv/dm_crypt optional optional no no optional no + # reiserFS raw/lvm-lv/dm_crypt optional optional no no optional no + # xfs raw/lvm-lv/dm_crypt optional optional no no optional no + # jfs raw/lvm-lv/dm_crypt optional optional no no optional no + # vfat raw/lvm-lv/dm_crypt optional opt i guess no no optional no + # lvm-pv raw/dm_crypt no no no. $pv = $part $part+ (+ is to differentiate from $part) optional no + # lvm-vg lvm-pv no yes /dev/mapper/$label =dm device optional PV's to use + # lvm-lv lvm-vg no yes /dev/mapper/$part_label-$label =dm device optional LV size + # dm_crypt raw/rvm-lv no yes /dev/mapper/$label =dm device optional no # Determine which filesystems/blockdevices are possible for this blockdevice @@ -349,7 +349,7 @@ interactive_filesystem () [ -n "$fs_opts" ] && default="$fs_opts" program=`get_filesystem_program $fs_type` _dia_DIALOG --inputbox "Enter any additional opts for $program" 8 65 "$default" 2>$ANSWER || return 1 - fs_opts=$(cat $ANSWER) + fs_opts=$(cat $ANSWER | sed 's/ /_/g') #TODO: clean up all whitespace (tabs and shit) [ -z "$fs_type" ] && fs_type=no_type [ -z "$fs_mount" ] && fs_mount=no_mount @@ -364,7 +364,7 @@ interactive_filesystem () echo "/dev/mapper/$fs_label $fs_type $fs_label no_fs" >> $BLOCK_DATA elif [ "$fs_type" = lvm-pv ] then - echo "$part $fs_type no_label no_fs" >> $BLOCK_DATA + echo "$part+ $fs_type no_label no_fs" >> $BLOCK_DATA elif [ "$fs_type" = lvm-lv ] then echo "/dev/mapper/$part_label-$fs_label $fs_type no_label no_fs" >> $BLOCK_DATA @@ -393,7 +393,7 @@ interactive_filesystems() { # $BLOCK_DATA entry. easily parsable.: # type label/no_label /no_fs # FS-string: - # type;mountpoint;opts;label;params[|FS-string|...] + # type;mountpoint;opts;label;params[|FS-string|...] where opts have _'s instead of whitespace findpartitions 0 'no_fs' ' raw no_label' > $BLOCK_DATA while [ "$USERHAPPY" = 0 ] @@ -438,7 +438,7 @@ interactive_filesystems() { [ $? -eq 0 ] && fs=$NEW_FILESYSTEM fi - # update the menu + # update the menu # NOTE that part_type remains raw for basic filesystems! [ -z "$part_label" ] && part_label=no_label [ -z "$fs" ] && fs=no_fs sed -i "s#^$part $part_type $part_label.*#$part $part_type $part_label $fs#" $BLOCK_DATA # '#' is a forbidden character ! -- cgit v1.2.3-54-g00ecf From 60e53af497d8dbe11b2305ea83b702d71ae13bd2 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 5 Dec 2008 19:27:24 +0100 Subject: + sign bugfix --- src/core/libs/lib-ui-interactive.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 88341bf..7fb91df 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -411,7 +411,8 @@ interactive_filesystems() { part=$ANSWER_OPTION - declare part_escaped=${part//\//\\/} # the bash substition replaces all /'s with \/'s otherwise awk complains + declare part_escaped=${part//\//\\/} # escape all slashes otherwise awk complains + declare part_escaped=${part_escaped/+/\\+} # escape the + sign too part_type=$( awk "/^$part_escaped/ {print \$2}" $BLOCK_DATA) part_label=$(awk "/^$part_escaped/ {print \$3}" $BLOCK_DATA) fs=$( awk "/^$part_escaped/ {print \$4}" $BLOCK_DATA) -- cgit v1.2.3-54-g00ecf From 25785c78530311c77b89c04b11a60f4ff83822f0 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 5 Dec 2008 19:58:53 +0100 Subject: fix for no choice in FS --- src/core/libs/lib-ui-interactive.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 7fb91df..ca1bb7f 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -298,11 +298,18 @@ interactive_filesystem () [ $part_type = lvm-vg ] && which lvcreate &>/dev/null && FSOPTS="$FSOPTS lvm-lv LVM_Logical_Volume" [ $part_type = raw -o $part_type = lvm-lv ] && which cryptsetup &>/dev/null && FSOPTS="$FSOPTS dm_crypt DM_crypt_Volume" - # ask FS - default= - [ -n "$fs_type" ] && default="--default-item $fs_type" - ask_option no "Select a filesystem for $part:" $FSOPTS || return 1 - fs_type=$ANSWER_OPTION + # determine FS + fsopts=($FSOPTS); + if [ ${#fsopts[*]} -lt 4 ] # less then 4 words in the $FSOPTS string. eg only one option + then + infofy "Automatically picked ${fsopts[1]}. It's the only option for $part_type blockdevices" + fs_type=${fsopts[0]} + else + default= + [ -n "$fs_type" ] && default="--default-item $fs_type" + ask_option no "Select a filesystem for $part:" $FSOPTS || return 1 + fs_type=$ANSWER_OPTION + fi # ask mountpoint, if relevant if [[ $fs_type != lvm-* && "$fs_type" != dm_crypt ]] -- cgit v1.2.3-54-g00ecf From f0a54a12f56c5810759bcd030f977d06f6a35df8 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 5 Dec 2008 20:12:33 +0100 Subject: fixes for LVM vgs --- src/core/libs/lib-ui-interactive.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index ca1bb7f..d964c1c 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -332,13 +332,16 @@ interactive_filesystem () # ask special params, if relevant if [ "$fs_type" = lvm-vg ] then + # add $part to $fs_params if it's not in there because the user wants this enabled by default + grep -q ":$part:" <<< $fs_params || grep -q ":$part\$" <<< $fs_params || fs_params="$fs_params:$part" + for pv in `sed 's/:/ /' <<< $fs_params` do list="$list $pv ^ ON" done for pv in `grep ' lvm-pv' $BLOCK_DATA | awk '{print $1}'` do - ! grep -q "$pv ^ ON" && list="$list $pv - OFF" + ! grep -q "$pv ^ ON" $BLOCK_DATA && list="$list $pv - OFF" done _dia_DIALOG --checklist "Which lvm PV's must this volume group span?" 19 55 12 $list 2>$ANSWER || return 1 fs_params="$(sed 's/ /:/' $ANSWER)" #replace spaces by colon's, we cannot have spaces anywhere in any string -- cgit v1.2.3-54-g00ecf From aa0b04044dd43882cfd6f01884727e5608c4ecb2 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 5 Dec 2008 20:20:38 +0100 Subject: fixes for LVM vgs --- src/core/libs/lib-ui-interactive.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index d964c1c..9cb4489 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -333,15 +333,16 @@ interactive_filesystem () if [ "$fs_type" = lvm-vg ] then # add $part to $fs_params if it's not in there because the user wants this enabled by default - grep -q ":$part:" <<< $fs_params || grep -q ":$part\$" <<< $fs_params || fs_params="$fs_params:$part" + pv=${part/+/} + grep -q ":$pv:" <<< $fs_params || grep -q ":$pv\$" <<< $fs_params || fs_params="$fs_params:$pv" for pv in `sed 's/:/ /' <<< $fs_params` do list="$list $pv ^ ON" done - for pv in `grep ' lvm-pv' $BLOCK_DATA | awk '{print $1}'` + for pv in `grep '+ lvm-pv' $BLOCK_DATA | awk '{print $1}' | sed 's/\+$//'` # find PV's to be added: their blockdevice ends on + and has lvm-pv as type do - ! grep -q "$pv ^ ON" $BLOCK_DATA && list="$list $pv - OFF" + grep -q "$pv ^ ON" <<< "$list" || list="$list $pv - OFF" done _dia_DIALOG --checklist "Which lvm PV's must this volume group span?" 19 55 12 $list 2>$ANSWER || return 1 fs_params="$(sed 's/ /:/' $ANSWER)" #replace spaces by colon's, we cannot have spaces anywhere in any string -- cgit v1.2.3-54-g00ecf From 60bd5f1c459f3f1be6201b13ea5094c4ff1c81db Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 5 Dec 2008 21:16:22 +0100 Subject: debug output for ask option functions --- src/core/libs/lib-ui.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index d4520bc..a5c8dec 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -208,7 +208,7 @@ _dia_ask_option () DEFAULT="" [ "$1" != 'no' ] && DEFAULT="--default-item $1" [ -z "$2" ] && die_error "ask_option \$2 must be the title" - [ -z "$6" ] && die_error "ask_option makes only sense if you specify at least 2 things (with tag and name)" + [ -z "$6" ] && debug "_dia_ask_option args: $@" && die_error "ask_option makes only sense if you specify at least 2 things (with tag and name)" DIA_MENU_TITLE=$2 shift 2 @@ -228,7 +228,7 @@ _cli_ask_option () DEFAULT="" [ "$1" != 'no' ] && DEFAULT=$1 [ -z "$2" ] && die_error "ask_option \$2 must be the title" - [ -z "$6" ] && die_error "ask_option makes only sense if you specify at least 2 things (with tag and name)" + [ -z "$6" ] && debug "_cli_ask_option args: $@" && die_error "ask_option makes only sense if you specify at least 2 things (with tag and name)" CLI_MENU_TITLE=$2 shift 2 -- cgit v1.2.3-54-g00ecf From c6207bad456bac6a9f20556a6c68926a03909b8d Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 5 Dec 2008 21:33:51 +0100 Subject: fix for LV selecter --- src/core/libs/lib-ui-interactive.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 9cb4489..c6f2e8d 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -437,11 +437,16 @@ interactive_filesystems() { then for lv in `sed '/|/ /' <<< $fs` do - list="$list $lv" #TODO: this is probably incorrect + label=$(cut -d ';' -f 4 <<< $lv) + mountpoint=$(cut -d ';' -f 2 <<< $lv) + list="$list $label $mountpoint" done + else + list="XXX no-LV's-defined-yet-make-a-new-one" fi list="$list empty NEW" ask_option empty "Edit/create new LV's on this VG:" $list + [ "$ANSWER_OPTION" = XXX ] && ANSWER_OPTION=empty interactive_filesystem $ANSWER_OPTION #TODO: for now we just append, that's obviously wrong [ $? -eq 0 ] && fs="$fs|$NEW_FILESYSTEM" -- cgit v1.2.3-54-g00ecf From 7cb4b7a0d62defb5a622c968b9ca160e904b4e20 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 5 Dec 2008 22:12:59 +0100 Subject: cleaned up code a bit + added functions for dia ask password, int and string --- src/core/libs/lib-ui.sh | 281 ++++++++++++++++++++++++++++-------------------- 1 file changed, 166 insertions(+), 115 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index a5c8dec..c67dbbf 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -9,6 +9,7 @@ DIA_MENU_TEXT="Use the UP and DOWN arrows to navigate menus. Use TAB to switch ### Functions that your code can use. Cli/dialog mode is fully transparant. This library takes care of it ### + # display error message and die die_error () { @@ -100,44 +101,35 @@ debug () } -# ask the user a password. return is stored in $PASSWORD or $_PASSWORD -# $1 type (optional. eg 'svn', 'ssh'). -ask_password () +# taken from setup +printk() { - [ "$var_UI_TYPE" = dia ] && { _dia_ask_password "$@" ; return $? ; } - [ "$var_UI_TYPE" = cli ] && { _cli_ask_password "$@" ; return $? ; } + case $1 in + "on") echo 4 >/proc/sys/kernel/printk ;; + "off") echo 0 >/proc/sys/kernel/printk ;; + esac } -# ask a yes/no question. -# $1 question -# returns 0 if response is yes/y (case insensitive). 1 otherwise -# TODO: support for default answer -ask_yesno () +# TODO: pass disks as argument to decouple backend logic +# Get a list of available disks for use in the "Available disks" dialogs. This +# will print the disks as follows, getting size info from hdparm: +# /dev/sda: 640133 MBytes (640 GB) +# /dev/sdb: 640135 MBytes (640 GB) +_getavaildisks() { - [ -z "$1" ] && die_error "ask_yesno needs a question!" - [ "$var_UI_TYPE" = dia ] && { _dia_ask_yesno "$@" ; return $? ; } - [ "$var_UI_TYPE" = cli ] && { _cli_ask_yesno "$@" ; return $? ; } + # NOTE: to test as non-root, stick in a 'sudo' before the hdparm call + for i in $(finddisks); do echo -n "$i: "; hdparm -I $i | grep -F '1000*1000' | sed "s/.*1000:[ \t]*\(.*\)/\1/"; echo "\n"; done } -# ask for a string. -# $1 question -# echo's the string the user gave. -# returns 1 if the user cancelled, 0 otherwise -ask_string () -{ - [ -z "$1" ] && die_error "ask_string needs a question!" - [ "$var_UI_TYPE" = dia ] && { _dia_ask_string "$@" ; return $? ; } - [ "$var_UI_TYPE" = cli ] && { _cli_ask_string "$@" ; return $? ; } -} - -# TODO: we should have a wrapper around this function that keeps trying until the user entered a valid numeric? +# TODO: we should have a wrapper around this function that keeps trying until the user entered a valid numeric?, maybe a wrapper that wraps all functions # ask for a number. # $1 question # $2 lower limit (optional) # $3 upper limit (optional) +# TODO: implement a default number # echo's the number the user said # returns 1 if the user cancelled or did not enter a numeric, 0 otherwise ask_number () @@ -148,7 +140,7 @@ ask_number () [ "$var_UI_TYPE" = dia ] && { _dia_ask_number "$1" "$2" "$3" ; return $? ; } [ "$var_UI_TYPE" = cli ] && { _cli_ask_number "$1" "$2" "$3" ; return $? ; } } - + # ask the user to choose something # $1 default item (set to 'no' for none) @@ -163,6 +155,43 @@ ask_option () } +# ask the user a password. return is stored in $PASSWORD or $_PASSWORD +# $1 type (optional. eg 'svn', 'ssh'). +ask_password () +{ + [ "$var_UI_TYPE" = dia ] && { _dia_ask_password "$@" ; return $? ; } + [ "$var_UI_TYPE" = cli ] && { _cli_ask_password "$@" ; return $? ; } +} + + +# ask for a string. +# $1 question +# $2 default (optional) +# echo's the string the user gave. +# returns 1 if the user cancelled, 0 otherwise +ask_string () +{ + [ -z "$1" ] && die_error "ask_string needs a question!" + [ "$var_UI_TYPE" = dia ] && { _dia_ask_string "$1" "$2" ; return $? ; } + [ "$var_UI_TYPE" = cli ] && { _cli_ask_string "$1" "$2" ; return $? ; } +} + + +# ask a yes/no question. +# $1 question +# returns 0 if response is yes/y (case insensitive). 1 otherwise +# TODO: support for default answer +ask_yesno () +{ + [ -z "$1" ] && die_error "ask_yesno needs a question!" + [ "$var_UI_TYPE" = dia ] && { _dia_ask_yesno "$@" ; return $? ; } + [ "$var_UI_TYPE" = cli ] && { _cli_ask_yesno "$@" ; return $? ; } +} + + + + + # follow the progress of something by showing it's log, updating real-time # $1 title # $2 logfile @@ -175,15 +204,6 @@ follow_progress () } -# taken from setup -printk() -{ - case $1 in - "on") echo 4 >/proc/sys/kernel/printk ;; - "off") echo 0 >/proc/sys/kernel/printk ;; - esac -} - @@ -203,6 +223,31 @@ _dia_DIALOG() } +_dia_ask_number () +{ + #TODO: i'm not entirely sure this works perfectly. what if user doesnt give anything or wants to abort? + while true + do + str="$1" + [ -n "$2" ] && str2="min $2" + [ -n "$3" ] && str2="$str2 max $3" + [ -n "$str2" ] && str="$str ( $str2 )" + _dia_DIALOG --inputbox "$str" 8 65 "$4" 2>$ANSWER + ret=$? + ANSWER_NUMBER=`cat $ANSWER` + if [[ $ANSWER_NUMBER = *[^0-9]* ]] #TODO: handle exit state + then + show_warning "$ANSWER_NUMBER is not a number! try again." + else + break + fi + done + echo "$ANSWER_NUMBER" + debug "_dia_ask_number: user entered: $ANSWER_NUMBER" + [ -z "$ANSWER_NUMBER" ] && return 1 + return $? +} + _dia_ask_option () { DEFAULT="" @@ -221,6 +266,84 @@ _dia_ask_option () } +_dia_ask_password () +{ + if [ -n "$1" ] + then + type_l=`tr '[:upper:]' '[:lower:]' <<< $1` + type_u=`tr '[:lower:]' '[:upper:]' <<< $1` + else + type_l= + type_u= + fi + + _dia_DIALOG --passwordbox "Enter your $type_l password" 8 65 "$2" 2>$ANSWER + ret=$? + [ -n "$type_u" ] && read ${type_u}_PASSWORD < $ANSWER + [ -z "$type_u" ] && read PASSWORD < $ANSWER + cat $ANSWER + debug "_dia_ask_password: user entered <>" + return $ret +} + + +_dia_ask_string () +{ + _dia_DIALOG --inputbox "$1" 8 65 "$2" 2>$ANSWER + ret=$? + ANSWER_STRING=`cat $ANSWER` + echo $ANSWER_STRING + debug "_dia_ask_string: user entered $ANSWER_STRING" + return $ret +} + + +_dia_ask_yesno () +{ + height=$((`echo -e "$1" | wc -l` +7)) + dialog --yesno "$1" $height 55 # returns 0 for yes, 1 for no + ret=$? + [ $ret -eq 0 ] && debug "dia_ask_yesno: User picked YES" + [ $ret -gt 0 ] && debug "dia_ask_yesno: User picked NO" + return $ret +} + + +_dia_follow_progress () +{ + title=$1 + logfile=$2 + _dia_DIALOG --title "$1" --no-kill --tailboxbg "$2" 18 70 2>$ANSWER +} + + + + +_cli_ask_number () +{ + #TODO: i'm not entirely sure this works perfectly. what if user doesnt give anything or wants to abort? + while true + do + str="$1" + [ -n "$2" ] && str2="min $2" + [ -n "$3" ] && str2="$str2 max $3" + [ -n "$str2" ] && str="$str ( $str2 )" + echo "$str" + read ANSWER_NUMBER + if [[ $ANSWER_NUMBER = *[^0-9]* ]] + then + show_warning "$ANSWER_NUMBER is not a number! try again." + else + break + fi + done + echo "$ANSWER_NUMBER" + debug "cli_ask_number: user entered: $ANSWER_NUMBER" + [ -z "$ANSWER_NUMBER" ] && return 1 + return 0 +} + + _cli_ask_option () { #TODO: strip out color codes @@ -250,58 +373,23 @@ _cli_ask_option () return 0 } - -# TODO: pass disks as argument to decouple backend logic -# Get a list of available disks for use in the "Available disks" dialogs. This -# will print the disks as follows, getting size info from hdparm: -# /dev/sda: 640133 MBytes (640 GB) -# /dev/sdb: 640135 MBytes (640 GB) -_getavaildisks() -{ - # NOTE: to test as non-root, stick in a 'sudo' before the hdparm call - for i in $(finddisks); do echo -n "$i: "; hdparm -I $i | grep -F '1000*1000' | sed "s/.*1000:[ \t]*\(.*\)/\1/"; echo "\n"; done -} - - -_dia_follow_progress () +_cli_ask_password () { - title=$1 - logfile=$2 - _dia_DIALOG --title "$1" --no-kill --tailboxbg "$2" 18 70 2>$ANSWER } -_dia_ask_yesno () +_cli_ask_string () #TODO: implement default answer { - height=$((`echo -e "$1" | wc -l` +7)) - dialog --yesno "$1" $height 55 # returns 0 for yes, 1 for no - ret=$? - [ $ret -eq 0 ] && debug "dia_ask_yesno: User picked YES" - [ $ret -gt 0 ] && debug "dia_ask_yesno: User picked NO" - return $ret + echo -n "$@: " + read ANSWER_STRING + echo "$ANSWER_STRING" + debug "cli_ask_string: User entered: $ANSWER_STRING" + [ -z "$ANSWER_STRING" ] && return 1 + return 0 } -_cli_ask_password () -{ - if [ -n "$1" ] - then - type_l=`tr '[:upper:]' '[:lower:]' <<< $1` - type_u=`tr '[:lower:]' '[:upper:]' <<< $1` - else - type_l= - type_u= - fi - - echo -n "Enter your $type_l password: " - stty -echo - [ -n "$type_u" ] && read ${type_u}_PASSWORD - [ -z "$type_u" ] && read PASSWORD - stty echo - echo -} - _cli_ask_yesno () { echo -n "$1 (y/n): " @@ -318,42 +406,6 @@ _cli_ask_yesno () } -_cli_ask_string () -{ - echo -n "$@: " - read answ - echo "$answ" - debug "cli_ask_string: User entered: $answ" - [ -z "$answ" ] && return 1 - return 0 -} - - -_cli_ask_number () -{ - #TODO: i'm not entirely sure this works perfectly. what if user doesnt give anything or wants to abort? - while true - do - str="$1" - [ -n "$2" ] && str2="min $2" - [ -n "$3" ] && str2="$str2 max $3" - [ -n "$str2" ] && str="$str ( $str2 )" - echo "$str" - read answ - if [[ $answ = *[^0-9]* ]] - then - show_warning "$answ is not a number! try again." - else - break - fi - done - echo "$answ" - debug "cli_ask_number: user entered: $answ" - [ -z "$answ" ] && return 1 - return 0 -} - - _cli_follow_progress () { title=$1 @@ -362,4 +414,3 @@ _cli_follow_progress () tail -f $2 #TODO: don't block anymore when it's done } - -- cgit v1.2.3-54-g00ecf From 268cba8c4c879a49c1720a2536dc0c6a8af2e4f4 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 5 Dec 2008 22:19:36 +0100 Subject: skeleton for new checklist function --- src/core/libs/lib-ui.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index c67dbbf..72052c0 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -123,6 +123,12 @@ _getavaildisks() } +ask_checklist () #TODO +{ + true +} + + # TODO: we should have a wrapper around this function that keeps trying until the user entered a valid numeric?, maybe a wrapper that wraps all functions # ask for a number. @@ -223,6 +229,12 @@ _dia_DIALOG() } +_dia_ask_checklist () #TODO: implement this +{ + _dia_DIALOG --checklist "$1" $list +} + + _dia_ask_number () { #TODO: i'm not entirely sure this works perfectly. what if user doesnt give anything or wants to abort? -- cgit v1.2.3-54-g00ecf From 98580fe64c10317a61a9232066e2300ebf6179d6 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 5 Dec 2008 22:19:48 +0100 Subject: abstracted some UI stuff --- src/core/libs/lib-ui-interactive.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index c6f2e8d..d5d37c8 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -316,8 +316,8 @@ interactive_filesystem () then default= [ -n "$fs_mount" ] && default="$fs_mount" - _dia_DIALOG --inputbox "Enter the mountpoint for $part" 8 65 "$default" 2>$ANSWER || return 1 - fs_mount=$(cat $ANSWER) + ask_string "Enter the mountpoint for $part" "$default" || return 1 + fs_mount=$ANSWER_STRING fi # ask label, if relevant @@ -325,8 +325,8 @@ interactive_filesystem () then default= [ -n "$fs_label" ] && default="$fs_label" - _dia_DIALOG --inputbox "Enter the label/name for $part" 8 65 "$default" 2>$ANSWER || return 1 - fs_label=$(cat $ANSWER) + ask_string "Enter the label/name for $part" "$default" || return 1 + fs_label=$ANSWER_STRING fi # ask special params, if relevant @@ -351,16 +351,16 @@ interactive_filesystem () then [ -z "$fs_params" ] && default='5G' [ -n "$fs_params" ] && default="$fs_params" - _dia_DIALOG --inputbox "Enter the size for this $fs_type on $part (suffix K,M,G,T,P,E. default is M)" 8 65 "$default" 2>$ANSWER || return 1 - fs_params=$(cat $ANSWER) + ask_string "Enter the size for this $fs_type on $part (suffix K,M,G,T,P,E. default is M)" "$default" || return 1 + fs_params=$ANSWER_STRING fi # ask opts default= [ -n "$fs_opts" ] && default="$fs_opts" program=`get_filesystem_program $fs_type` - _dia_DIALOG --inputbox "Enter any additional opts for $program" 8 65 "$default" 2>$ANSWER || return 1 - fs_opts=$(cat $ANSWER | sed 's/ /_/g') #TODO: clean up all whitespace (tabs and shit) + ask_string "Enter any additional opts for $program" "$default" || return 1 + fs_opts=$(sed 's/ /_/g' <<< "$ANSWER_STRING") #TODO: clean up all whitespace (tabs and shit) [ -z "$fs_type" ] && fs_type=no_type [ -z "$fs_mount" ] && fs_mount=no_mount -- cgit v1.2.3-54-g00ecf From dbeb438b0c9f1abda89d009cbe17129f4f3413af Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 5 Dec 2008 22:29:02 +0100 Subject: regression fix n shit --- src/core/libs/lib-ui.sh | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 72052c0..6f31887 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -260,6 +260,7 @@ _dia_ask_number () return $? } + _dia_ask_option () { DEFAULT="" @@ -388,16 +389,41 @@ _cli_ask_option () _cli_ask_password () { + if [ -n "$1" ] + then + type_l=`tr '[:upper:]' '[:lower:]' <<< $1` + type_u=`tr '[:lower:]' '[:upper:]' <<< $1` + else + type_l= + type_u= + fi + + echo -n "Enter your $type_l password: " + stty -echo + [ -n "$type_u" ] && read ${type_u}_PASSWORD + [ -z "$type_u" ] && read PASSWORD + stty echo + echo } -_cli_ask_string () #TODO: implement default answer +_cli_ask_string () { - echo -n "$@: " + echo "$1: " + [ -n "$2" ] && echo "(Press enter for default. Default: $2)" + echo -n ">" read ANSWER_STRING echo "$ANSWER_STRING" debug "cli_ask_string: User entered: $ANSWER_STRING" - [ -z "$ANSWER_STRING" ] && return 1 + if [ -z "$ANSWER_STRING" ] + then + if [ -n "$2" ] + then + ANSWER_STRING=$2 + else + return 1 + fi + fi return 0 } -- cgit v1.2.3-54-g00ecf From 7c3297a4a93e7bf441a45c74b7ddd23ced6237ae Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 5 Dec 2008 22:42:01 +0100 Subject: strings can be empty sometimes --- src/core/libs/lib-ui-interactive.sh | 4 ++-- src/core/libs/lib-ui.sh | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index d5d37c8..744dc54 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -325,7 +325,7 @@ interactive_filesystem () then default= [ -n "$fs_label" ] && default="$fs_label" - ask_string "Enter the label/name for $part" "$default" || return 1 + ask_string "Enter the label/name for $part" "$default" 0 || return 1 fs_label=$ANSWER_STRING fi @@ -359,7 +359,7 @@ interactive_filesystem () default= [ -n "$fs_opts" ] && default="$fs_opts" program=`get_filesystem_program $fs_type` - ask_string "Enter any additional opts for $program" "$default" || return 1 + ask_string "Enter any additional opts for $program" "$default" 0 || return 1 fs_opts=$(sed 's/ /_/g' <<< "$ANSWER_STRING") #TODO: clean up all whitespace (tabs and shit) [ -z "$fs_type" ] && fs_type=no_type diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 6f31887..679a182 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -173,6 +173,7 @@ ask_password () # ask for a string. # $1 question # $2 default (optional) +# $3 exitcode to use when string is empty and there was no default, or default was ignored (1 default) # echo's the string the user gave. # returns 1 if the user cancelled, 0 otherwise ask_string () @@ -302,11 +303,13 @@ _dia_ask_password () _dia_ask_string () { + exitcode=${3:-1} _dia_DIALOG --inputbox "$1" 8 65 "$2" 2>$ANSWER ret=$? ANSWER_STRING=`cat $ANSWER` echo $ANSWER_STRING debug "_dia_ask_string: user entered $ANSWER_STRING" + [ -z "$ANSWER_STRING" ] && return $exitcode return $ret } @@ -407,8 +410,10 @@ _cli_ask_password () } +# $3 -z string behavior: always take default if applicable, but if no default then $3 is the returncode (1 is default) _cli_ask_string () { + exitcode=${3:-1} echo "$1: " [ -n "$2" ] && echo "(Press enter for default. Default: $2)" echo -n ">" @@ -421,7 +426,7 @@ _cli_ask_string () then ANSWER_STRING=$2 else - return 1 + return $exitcode fi fi return 0 -- cgit v1.2.3-54-g00ecf From bb1279c913a359dbf72b33cf67f3474896f24597 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 5 Dec 2008 22:59:46 +0100 Subject: almost time for bed --- src/core/libs/lib-ui-interactive.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 744dc54..0c91023 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -325,7 +325,7 @@ interactive_filesystem () then default= [ -n "$fs_label" ] && default="$fs_label" - ask_string "Enter the label/name for $part" "$default" 0 || return 1 + ask_string "Enter the label/name for $part" "$default" 0 fs_label=$ANSWER_STRING fi @@ -359,7 +359,7 @@ interactive_filesystem () default= [ -n "$fs_opts" ] && default="$fs_opts" program=`get_filesystem_program $fs_type` - ask_string "Enter any additional opts for $program" "$default" 0 || return 1 + ask_string "Enter any additional opts for $program" "$default" 0 fs_opts=$(sed 's/ /_/g' <<< "$ANSWER_STRING") #TODO: clean up all whitespace (tabs and shit) [ -z "$fs_type" ] && fs_type=no_type -- cgit v1.2.3-54-g00ecf From cd2bb8486f1bf870e35c783568a652a7d2431e0a Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 5 Dec 2008 23:03:02 +0100 Subject: ui bugfix empty strings --- src/core/libs/lib-ui.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 679a182..26e7e5d 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -179,8 +179,8 @@ ask_password () ask_string () { [ -z "$1" ] && die_error "ask_string needs a question!" - [ "$var_UI_TYPE" = dia ] && { _dia_ask_string "$1" "$2" ; return $? ; } - [ "$var_UI_TYPE" = cli ] && { _cli_ask_string "$1" "$2" ; return $? ; } + [ "$var_UI_TYPE" = dia ] && { _dia_ask_string "$1" "$2" "$3"; return $? ; } + [ "$var_UI_TYPE" = cli ] && { _cli_ask_string "$1" "$2" "$3"; return $? ; } } -- cgit v1.2.3-54-g00ecf From a00532eb1e00f3b6b86b23fb892075c5faceab02 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 5 Dec 2008 23:22:35 +0100 Subject: fix for LV's on VG's and shit --- src/core/libs/lib-ui-interactive.sh | 41 ++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 0c91023..644db61 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -229,11 +229,10 @@ interactive_partition() { # create new, delete, or edit a filesystem interactive_filesystem () { - # these variables can be empty strings! - part=$1 - part_type=$2 - part_label=$3 - fs=$4 + part=$1 # must be given and a valid device TODO: check it + part_type=$2 # a part should always have a type + part_label=$3 # can be empty + fs=$4 # can be empty NEW_FILESYSTEM= if [ -z "$fs" ] then @@ -325,7 +324,7 @@ interactive_filesystem () then default= [ -n "$fs_label" ] && default="$fs_label" - ask_string "Enter the label/name for $part" "$default" 0 + ask_string "Enter the label/name for $part" "$default" 0 #TODO: check that you can't give LV's labels that have been given already or the installer will break fs_label=$ANSWER_STRING fi @@ -446,10 +445,32 @@ interactive_filesystems() { fi list="$list empty NEW" ask_option empty "Edit/create new LV's on this VG:" $list - [ "$ANSWER_OPTION" = XXX ] && ANSWER_OPTION=empty - interactive_filesystem $ANSWER_OPTION - #TODO: for now we just append, that's obviously wrong - [ $? -eq 0 ] && fs="$fs|$NEW_FILESYSTEM" + if [ "$ANSWER_OPTION" = XXX -o "$ANSWER_OPTION" = empty ] + then + # a new LV must be created on this VG + if interactive_filesystem $part $part_type $part_label '' + then + [ -z "$fs" ] && fs=$NEW_FILESYSTEM + [ -n "$fs" ] && fs="$fs|$NEW_FILESYSTEM" + fi + else + # an existing LV will be edited and it's settings updated + for lv in `sed '/|/ /' <<< $fs` + do + label=$(cut -d ';' -f 4 <<< $lv) + [ "$label" = "$ANSWER_OPTION" ] && found_lv="$lv" + done + interactive_filesystem $part $part_type $part_label "$found_lv" + fs= + for lv in `sed '/|/ /' <<< $fs` + do + label=$(cut -d ';' -f 4 <<< $lv) + add=$lv + [ "$label" = "$ANSWER_OPTION" ] && add=$NEW_FILESYSTEM + [ -z "$fs" ] && fs=$add + [ -n "$fs" ] && fs="$fs|$add" + done + fi else interactive_filesystem $part $part_type $part_label $fs [ $? -eq 0 ] && fs=$NEW_FILESYSTEM -- cgit v1.2.3-54-g00ecf From 4e1bf134a61b8682513192ea2f25f10c000255c8 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 6 Dec 2008 12:21:30 +0100 Subject: support for checklists + default values for yesno + todo add --- src/core/libs/lib-ui.sh | 59 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 26e7e5d..1ca87d5 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -1,5 +1,6 @@ #!/bin/sh # TODO: lot's of implementation work still open in this library. especially the dialog & $var_UI_TYPE stuff +# TODO: get rid of the echoing of the variables at the end. passing output as $ANSWER_ is more useful # Taken from setup. we store dialog output in a file. TODO: can't we do this with variables? ASKDEV @@ -123,9 +124,15 @@ _getavaildisks() } -ask_checklist () #TODO +# ask the user to make a selection from a certain group of things +# $1 question +# shift;shift; $@ list of options. first tag. then ON/OFF +ask_checklist () { - true + [ -z "$1" ] && die_error "ask_checklist needs a question!" + [ -z "$3" ] && debug "ask_checklist args: $@" && die_error "ask_checklist makes only sense if you specify at least 1 thing (incl ON/OFF switch)" + [ "$var_UI_TYPE" = dia ] && { _dia_ask_option "$@" ; return $? ; } + [ "$var_UI_TYPE" = cli ] && { _cli_ask_option "$@" ; return $? ; } } @@ -186,8 +193,8 @@ ask_string () # ask a yes/no question. # $1 question +# $2 default answer yes/no (optional) # returns 0 if response is yes/y (case insensitive). 1 otherwise -# TODO: support for default answer ask_yesno () { [ -z "$1" ] && die_error "ask_yesno needs a question!" @@ -230,9 +237,23 @@ _dia_DIALOG() } -_dia_ask_checklist () #TODO: implement this +_dia_ask_checklist () { - _dia_DIALOG --checklist "$1" $list + str=$1 + shift + list= + while [ -n "$1" ] + do + [ -z "$2" ] && die_error "no ON/OFF switch given for element $1" + [ "$2" = ON ] && newlist="$1 ^ ON" + [ "$2" = OFF ] && newlist="$1 - OFF" + shift 2 + done + _dia_DIALOG --checklist "$str" $list 2>$ANSWER + ret=$? + ANSWER_CHECKLIST=`cat $ANSWER` + debug "_dia_ask_checklist: user checked ON: $ANSWER_CHECKLIST" + return $ret } @@ -317,7 +338,10 @@ _dia_ask_string () _dia_ask_yesno () { height=$((`echo -e "$1" | wc -l` +7)) - dialog --yesno "$1" $height 55 # returns 0 for yes, 1 for no + str=$1 + #TODO: i think dialog doesnt support a default value for yes/no, so we need this workaround: + [ -n "$2" ] && str="$str (default: $2)" + dialog --yesno "$str" $height 55 # returns 0 for yes, 1 for no ret=$? [ $ret -eq 0 ] && debug "dia_ask_yesno: User picked YES" [ $ret -gt 0 ] && debug "dia_ask_yesno: User picked NO" @@ -335,6 +359,22 @@ _dia_follow_progress () +_cli_ask_checklist () +{ + str=$1 + shift + output= + while [ -n "$1" ] + do + [ -z "$2" ] && die_error "no ON/OFF switch given for element $1" + [ "$2" = ON ] && ask_yesno "Enable $1 ?" yes && output="$output $1" + [ "$2" = OFF ] && ask_yesno "Enable $1 ?" no && output="$output $1" + done + ANSWER_CHECKLIST=$output + return 0 +} + + _cli_ask_number () { #TODO: i'm not entirely sure this works perfectly. what if user doesnt give anything or wants to abort? @@ -435,10 +475,13 @@ _cli_ask_string () _cli_ask_yesno () { - echo -n "$1 (y/n): " + [ -z "$2" ] && echo -n "$1 (y/n): " + [ "$2" = yes ] && echo -n "$1 (Y/n): " + [ "$2" = no ] && echo -n "$1 (y/N): " + read answer answer=`tr '[:upper:]' '[:lower:]' <<< $answer` - if [ "$answer" = y -o "$answer" = yes ] + if [ "$answer" = y -o "$answer" = yes ] || [ -z "$answer" -a "$2" = yes ] then debug "cli_ask_yesno: User picked YES" return 0 -- cgit v1.2.3-54-g00ecf From 53765f15d0cc9de8d25591f4cf8b60674cfde9d5 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 6 Dec 2008 12:28:39 +0100 Subject: small fix + ui abstract calls for disk stuff --- src/core/libs/lib-ui-interactive.sh | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 644db61..cf61866 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -127,8 +127,8 @@ interactive_autoprepare() [ "$(which mkfs.xfs 2>/dev/null)" ] && FSOPTS="$FSOPTS xfs XFS" [ "$(which mkfs.jfs 2>/dev/null)" ] && FSOPTS="$FSOPTS jfs JFS" while [ "$BOOT_PART_SET" = "" ]; do - _dia_DIALOG --inputbox "Enter the size (MB) of your /boot partition. Minimum value is 16.\n\nDisk space left: $DISC_SIZE MB" 8 65 "32" 2>$ANSWER || return 1 - BOOT_PART_SIZE="$(cat $ANSWER)" + ask_string "Enter the size (MB) of your /boot partition. Minimum value is 16.\n\nDisk space left: $DISC_SIZE MB" "32" || return 1 + BOOT_PART_SIZE=$ANSWER_STRING if [ "$BOOT_PART_SIZE" = "" ]; then notify "ERROR: You have entered an invalid size, please enter again." else @@ -144,8 +144,8 @@ interactive_autoprepare() done DISC_SIZE=$(($DISC_SIZE-$BOOT_PART_SIZE)) while [ "$SWAP_PART_SET" = "" ]; do - _dia_DIALOG --inputbox "Enter the size (MB) of your swap partition. Minimum value is > 0.\n\nDisk space left: $DISC_SIZE MB" 8 65 "256" 2>$ANSWER || return 1 - SWAP_PART_SIZE=$(cat $ANSWER) + ask_string "Enter the size (MB) of your swap partition. Minimum value is > 0.\n\nDisk space left: $DISC_SIZE MB" "256" || return 1 + SWAP_PART_SIZE=$ANSWER_STRING if [ "$SWAP_PART_SIZE" = "" -o "$SWAP_PART_SIZE" -le "0" ]; then notify "ERROR: You have entered an invalid size, please enter again." else @@ -158,8 +158,8 @@ interactive_autoprepare() done DISC_SIZE=$(($DISC_SIZE-$SWAP_PART_SIZE)) while [ "$ROOT_PART_SET" = "" ]; do - _dia_DIALOG --inputbox "Enter the size (MB) of your / partition. The /home partition will use the remaining space.\n\nDisk space left: $DISC_SIZE MB" 8 65 "7500" 2>$ANSWER || return 1 - ROOT_PART_SIZE=$(cat $ANSWER) + ask_string "Enter the size (MB) of your / partition. The /home partition will use the remaining space.\n\nDisk space left: $DISC_SIZE MB" "7500" || return 1 + ROOT_PART_SIZE=$ANSWER_STRING if [ "$ROOT_PART_SIZE" = "" -o "$ROOT_PART_SIZE" -le "0" ]; then notify "ERROR: You have entered an invalid size, please enter again." else @@ -171,14 +171,14 @@ interactive_autoprepare() fi done while [ "$CHOSEN_FS" = "" ]; do - _dia_DIALOG --menu "Select a filesystem for / and /home:" 13 45 6 $FSOPTS 2>$ANSWER || return 1 - FSTYPE=$(cat $ANSWER) + ask_option "Select a filesystem for / and /home:" $FSOPTS || return 1 + FSTYPE=$ANSWER_OPTION ask_yesno "$FSTYPE will be used for / and /home. Is this OK?" && CHOSEN_FS=1 done SET_DEFAULTFS=1 done - _dia_DIALOG --defaultno --yesno "$DISC will be COMPLETELY ERASED! Are you absolutely sure?" 0 0 || return 1 + ask_yesno "$DISC will be COMPLETELY ERASED! Are you absolutely sure?" || return 1 # we assume a /dev/hdX format (or /dev/sdX) @@ -212,8 +212,8 @@ interactive_partition() { ask_option no "Select the disk you want to partition (select DONE when finished)" $DISCS || return 1 DISC=$ANSWER_OPTION if [ "$DISC" = "OTHER" ]; then - _dia_DIALOG --inputbox "Enter the full path to the device you wish to partition" 8 65 "/dev/sda" 2>$ANSWER || return 1 - DISC=$(cat $ANSWER) + ask_string "Enter the full path to the device you wish to partition" "/dev/sda" || return 1 + DISC=$ANSWER_STRING fi # Leave our loop if the user is done partitioning [ "$DISC" = "DONE" ] && break @@ -229,11 +229,12 @@ interactive_partition() { # create new, delete, or edit a filesystem interactive_filesystem () { - part=$1 # must be given and a valid device TODO: check it + part=$1 # must be given and a valid device part_type=$2 # a part should always have a type part_label=$3 # can be empty fs=$4 # can be empty NEW_FILESYSTEM= + [ -b $part ] || die_error "interactive_filesystem \$1 must be a blockdevice! ($part given)" if [ -z "$fs" ] then fs_type= @@ -337,14 +338,14 @@ interactive_filesystem () for pv in `sed 's/:/ /' <<< $fs_params` do - list="$list $pv ^ ON" + list="$list $pv ON" done for pv in `grep '+ lvm-pv' $BLOCK_DATA | awk '{print $1}' | sed 's/\+$//'` # find PV's to be added: their blockdevice ends on + and has lvm-pv as type do - grep -q "$pv ^ ON" <<< "$list" || list="$list $pv - OFF" + grep -q "$pv ON" <<< "$list" || list="$list $pv OFF" done - _dia_DIALOG --checklist "Which lvm PV's must this volume group span?" 19 55 12 $list 2>$ANSWER || return 1 - fs_params="$(sed 's/ /:/' $ANSWER)" #replace spaces by colon's, we cannot have spaces anywhere in any string + ask_checklist "Which lvm PV's must this volume group span?" $list || return 1 + fs_params="$(sed 's/ /:/' <<< "$ANSWER_CHECKLIST")" #replace spaces by colon's, we cannot have spaces anywhere in any string fi if [ "$fs_type" = lvm-lv ] then -- cgit v1.2.3-54-g00ecf From 31a4a4b45fd6184e1d090820010a20aa67abbdfe Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 6 Dec 2008 12:33:51 +0100 Subject: ui fix --- src/core/libs/lib-ui-interactive.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index cf61866..dc1dfa3 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -302,7 +302,7 @@ interactive_filesystem () fsopts=($FSOPTS); if [ ${#fsopts[*]} -lt 4 ] # less then 4 words in the $FSOPTS string. eg only one option then - infofy "Automatically picked ${fsopts[1]}. It's the only option for $part_type blockdevices" + notify "Automatically picked ${fsopts[1]}. It's the only option for $part_type blockdevices" fs_type=${fsopts[0]} else default= -- cgit v1.2.3-54-g00ecf From ba32e0816e86cbd44db7baa38ef4def7fe806b86 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 6 Dec 2008 13:25:30 +0100 Subject: fix + show size of part in menu --- src/core/libs/lib-blockdevices-filesystems.sh | 13 ++++++++++++- src/core/libs/lib-ui-interactive.sh | 6 ++++-- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index 8e49fbf..b271900 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -510,4 +510,15 @@ get_filesystem_program () [ $1 = lvm-vg ] && echo vgcreate [ $1 = lvg-lv ] && echo lvcreate [ $1 = dm_crypt ] && echo cryptsetup -} \ No newline at end of file +} + + +# $1 blockdevice +# output will be in $BLOCKDEVICE_SIZE in MB +get_blockdevice_size () +{ + [ -b "$1" ] || die_error "get_blockdevice_size needs a blockdevice as \$1 ($1 given)" + blocks=`fdisk -s $1` + #NOTE: on some interwebs they say 1 block = 512B, on other internets they say 1 block = 1kiB. 1kiB seems to work for me. don't sue me if it doesn't for you + BLOCKDEVICE_SIZE=$(($blocks/1024)) +} diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index dc1dfa3..aa00f5c 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -234,7 +234,8 @@ interactive_filesystem () part_label=$3 # can be empty fs=$4 # can be empty NEW_FILESYSTEM= - [ -b $part ] || die_error "interactive_filesystem \$1 must be a blockdevice! ($part given)" + real_part=${part/+/} # strip away an extra '+' which is used for lvm pv's + [ -b $real_part ] || die_error "interactive_filesystem \$1 must be a blockdevice! ($part given)" if [ -z "$fs" ] then fs_type= @@ -413,7 +414,8 @@ interactive_filesystems() { menu_list= while read part type label fs do - menu_list="$menu_list $part (type:$type,label:$label,fs:$fs)" #don't add extra spaces, dialog doesn't like that. + get_blockdevice_size ${part/+/} + menu_list="$menu_list $part size:${BLOCKDEVICE_SIZE}MB,type:$type,label:$label,fs:$fs" #don't add extra spaces, dialog doesn't like that. done < $BLOCK_DATA ask_option no "Manage filesystems, block devices and virtual devices. Note that you don't *need* to specify opts, labels or extra params if you're not using lvm, dm_crypt, etc." $menu_list DONE _ -- cgit v1.2.3-54-g00ecf From c3f3d5e22832fe98dafb6a853b79706a4f642bb7 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 6 Dec 2008 13:40:49 +0100 Subject: fix for only 1 lvm PV breakage --- src/core/libs/lib-ui-interactive.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index aa00f5c..392a618 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -345,8 +345,15 @@ interactive_filesystem () do grep -q "$pv ON" <<< "$list" || list="$list $pv OFF" done - ask_checklist "Which lvm PV's must this volume group span?" $list || return 1 - fs_params="$(sed 's/ /:/' <<< "$ANSWER_CHECKLIST")" #replace spaces by colon's, we cannot have spaces anywhere in any string + list2=($list) + if [ ${#list2[*]} -lt 4 ] # less then 4 words in the list. eg only one option + then + notify "Automatically picked PV ${list2[0]}. It's the only available lvm PV" + fs_params=${list2[0]} + else + ask_checklist "Which lvm PV's must this volume group span?" $list || return 1 + fs_params="$(sed 's/ /:/' <<< "$ANSWER_CHECKLIST")" #replace spaces by colon's, we cannot have spaces anywhere in any string + fi fi if [ "$fs_type" = lvm-lv ] then -- cgit v1.2.3-54-g00ecf From 26fc8b46047f01ce0cc350d40b56de488ecb5ec3 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 6 Dec 2008 13:50:01 +0100 Subject: several small fixes --- src/core/libs/lib-blockdevices-filesystems.sh | 2 +- src/core/libs/lib-ui-interactive.sh | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index b271900..d285580 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -518,7 +518,7 @@ get_filesystem_program () get_blockdevice_size () { [ -b "$1" ] || die_error "get_blockdevice_size needs a blockdevice as \$1 ($1 given)" - blocks=`fdisk -s $1` + blocks=`fdisk -s $1` || show_warning "Fdisk problem" "Something failed when trying to do fdisk -s $1" #NOTE: on some interwebs they say 1 block = 512B, on other internets they say 1 block = 1kiB. 1kiB seems to work for me. don't sue me if it doesn't for you BLOCKDEVICE_SIZE=$(($blocks/1024)) } diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 392a618..86d5da7 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -303,7 +303,7 @@ interactive_filesystem () fsopts=($FSOPTS); if [ ${#fsopts[*]} -lt 4 ] # less then 4 words in the $FSOPTS string. eg only one option then - notify "Automatically picked ${fsopts[1]}. It's the only option for $part_type blockdevices" + notify "Automatically picked the ${fsopts[1]} filesystem. It's the only option for $part_type blockdevices" fs_type=${fsopts[0]} else default= @@ -341,14 +341,14 @@ interactive_filesystem () do list="$list $pv ON" done - for pv in `grep '+ lvm-pv' $BLOCK_DATA | awk '{print $1}' | sed 's/\+$//'` # find PV's to be added: their blockdevice ends on + and has lvm-pv as type + for pv in `grep '+ lvm-pv' $BLOCK_DATA | awk '{print $1}' | sed 's/\+$//'` # find PV's to be added: their blockdevice ends on + and has lvm-pv as type #TODO: i'm not sure we check which pv's are taken already do grep -q "$pv ON" <<< "$list" || list="$list $pv OFF" done list2=($list) if [ ${#list2[*]} -lt 4 ] # less then 4 words in the list. eg only one option then - notify "Automatically picked PV ${list2[0]}. It's the only available lvm PV" + notify "Automatically picked PV ${list2[0]} to use for this VG. It's the only available lvm PV" fs_params=${list2[0]} else ask_checklist "Which lvm PV's must this volume group span?" $list || return 1 @@ -421,8 +421,9 @@ interactive_filesystems() { menu_list= while read part type label fs do - get_blockdevice_size ${part/+/} - menu_list="$menu_list $part size:${BLOCKDEVICE_SIZE}MB,type:$type,label:$label,fs:$fs" #don't add extra spaces, dialog doesn't like that. + infostring="type:$type,label:$label,fs:$fs" + [ -b "$part" ] && get_blockdevice_size ${part/+/} && infostring="size:${BLOCKDEVICE_SIZE}MB,$infostring" # add size in MB for existing blockdevices (eg not for mapper devices that are not yet created yet) + menu_list="$menu_list $part $infostring" #don't add extra spaces, dialog doesn't like that. done < $BLOCK_DATA ask_option no "Manage filesystems, block devices and virtual devices. Note that you don't *need* to specify opts, labels or extra params if you're not using lvm, dm_crypt, etc." $menu_list DONE _ -- cgit v1.2.3-54-g00ecf From e85258bb9394fa74fd97f98966368f821b3d3bf2 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 6 Dec 2008 13:55:13 +0100 Subject: fix for -b requirement --- src/core/libs/lib-ui-interactive.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 86d5da7..cb19b3e 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -229,13 +229,11 @@ interactive_partition() { # create new, delete, or edit a filesystem interactive_filesystem () { - part=$1 # must be given and a valid device + part=$1 # must be given and (scheduled to become) a valid device -> don't do [ -b "$1" ] because the device might not exist *yet* part_type=$2 # a part should always have a type part_label=$3 # can be empty fs=$4 # can be empty NEW_FILESYSTEM= - real_part=${part/+/} # strip away an extra '+' which is used for lvm pv's - [ -b $real_part ] || die_error "interactive_filesystem \$1 must be a blockdevice! ($part given)" if [ -z "$fs" ] then fs_type= -- cgit v1.2.3-54-g00ecf From a576218155ca5b631e5e4074a0a47e9a0773564b Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 6 Dec 2008 14:07:36 +0100 Subject: clarity fix --- src/core/libs/lib-ui-interactive.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index cb19b3e..e120385 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -324,7 +324,7 @@ interactive_filesystem () then default= [ -n "$fs_label" ] && default="$fs_label" - ask_string "Enter the label/name for $part" "$default" 0 #TODO: check that you can't give LV's labels that have been given already or the installer will break + ask_string "Enter the label/name for this $fs_type on $part" "$default" 0 #TODO: check that you can't give LV's labels that have been given already or the installer will break fs_label=$ANSWER_STRING fi -- cgit v1.2.3-54-g00ecf From 43b7fbbced07f2ad3ea941d66d0aaa65a1a99f30 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 6 Dec 2008 19:54:33 +0100 Subject: partial implementation of process_filesystems + necessary refactoring in lib-ui-interactive --- src/core/libs/lib-blockdevices-filesystems.sh | 105 ++++++++++++++++++++++---- src/core/libs/lib-ui-interactive.sh | 37 ++++----- 2 files changed, 112 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index d285580..a06aa6f 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -9,7 +9,7 @@ modprobe aes-i586 || show_warning modprobe 'Could not modprobe aes-i586. no supp TMP_DEV_MAP=/home/arch/aif/runtime/dev.map TMP_FSTAB=/home/arch/aif/runtime/.fstab TMP_PARTITIONS=/home/arch/aif/runtime/.partitions -TMP_FILESYSTEMS=/home/arch/aif/runtime/.filesystems +TMP_FILESYSTEMS=/home/arch/aif/runtime/.filesystems # Only used internally by this library. Do not even think about using this as interface to this library. it won't work # procedural code from quickinst functionized and fixed. # there were functions like this in the setup script too, with some subtle differences. see below @@ -38,7 +38,7 @@ target_special_fs () # taken from setup # Disable swap and all mounted partitions for the destination system. Unmount -# the destination root partition last! +# the destination root partition last! TODO: only taking care of / is not enough, we can have the same problem on another level (eg /a/b/c and /a/b) target_umountall() { infofy "Disabling swapspace, unmounting already mounted disk devices..." @@ -407,13 +407,81 @@ process_disk () } -# go over each filesystem in $TMP_FILESYSTEMS, reorder them so that each entry has it's correspondent block device available (eg if you need /dev/mapper/foo which only becomes available after some other entry is processed) and process them +generate_filesystem_list () +{ + echo -n > $TMP_FILESYSTEMS + while read part type label fs_string + do + if [ "$fs_string" != no_fs ] + then + for fs in `sed 's/|/ /g' <<< $fs_string` # this splits multiple fs'es up, or just takes the one if there is only one (lvm vg's can have more then one lv) + do + fs_type=` cut -d ';' -f 1 <<< $fs` + fs_create=` cut -d ';' -f 2 <<< $fs` + fs_mountpoint=` cut -d ';' -f 3 <<< $fs` + fs_mount=` cut -d ';' -f 4 <<< $fs` + fs_opts=` cut -d ';' -f 5 <<< $fs` + fs_label=` cut -d ';' -f 6 <<< $fs` + fs_params=` cut -d ';' -f 7 <<< $fs` + echo "$part $part_type $part_label $fs_type $fs_create $fs_mountpoint $fs_mount $fs_opts $fs_label $fs_params" >> $TMP_FILESYSTEMS + done + fi + done < $BLOCK_DATA + +} + + +# process all entries in $BLOCK_DATA, create all blockdevices and filesystems and mount them correctly, destroying what's necessary first. process_filesystems () { - #TODO: reorder file by strlen of mountpoint (or alphabetically), so that we don't get 'overridden' mountpoints (eg you don't mount /a/b/c and then /a/b. checking whether the parent dir exists is not good -> sort -t \ -k 2 - #TODO: we must make sure we have created all PV's, then reate a vg and the lv's. - #TODO: 'deconstruct' the mounted filesystems, pv's, lv's,vg's,dm_crypt's.. in the right order before doing this (opposite order of construct) and swapoff. - debug "process_filesystems Called. checking all entries in $TMP_FILESYSTEMS" + generate_filesystem_list + + # phase 1: deconstruct all mounts in the vfs that are about to be reconstructed. (and also swapoff where appropriate) + # re-order list so that we umount in the correct order. eg first umount /a/b/c, then /a/b. we sort alphabetically, which has the side-effect of sorting by stringlength, hence by vfs dependencies. + + sort -t \ -k 2 test $TMP_FILESYSTEMS | tac | while read part part_type part_label fs_type fs_create fs_mountpoint fs_mount fs_opts fs_label fs_params + do + if [ "$fs_type" = swap ] + then + swapoff $part + elif [ "$fs_mountpoint" != no_mount ] + then + [ "$fs_mount" = target ] && fs_mountpoint=$var_TARGET_DIR$fs_mountpoint + umount $fs_mountpoint + fi + done + + # TODO: phase 2: deconstruct blockdevices if they would exist already (destroy any lvm things, dm_crypt devices etc in the correct order) + # in theory devices with same names could be stacked on each other with different dependencies. I hope that's not the case for now. In the future maybe we should deconstruct things we need and who are in /etc/mtab or something. + # targets for deconstruction: /dev/mapper devices and lvm PV's who contain no fs, or a non-lvm/dm_crypt fs. TODO: improve regexes + # after deconstructing. the parent must be updated to reflect the vanished child. + +# TODO: as long as devices in this list remains and exist physically +# TODO: abort when there still are physical devices listed, but we tried to deconstruct them already, give error + + egrep '\+|mapper' $BLOCK_DATA | egrep -v ' lvm-pv;| lvm-vg;| lvm-lv;| dm_crypt;' | while read part part_type part_label fs + do + real_part=${part/+/} + if [ -b "$real_part" ] + then + debug "Attempting deconstruction of device $part (type $part_type)" + [ "$part_type" = lvm-pv ] && ( pvremove $part || show_warning "process_filesystems blockdevice deconstruction" "Could not pvremove $part") + [ "$part_type" = lvm-vg ] && ( vgremove -f $part || show_warning "process_filesystems blockdevice deconstruction" "Could not vgremove -f $part") + [ "$part_type" = lvm-lv ] && ( lvremove -f $part || show_warning "process_filesystems blockdevice deconstruction" "Could not lvremove -f $part") + [ "$part_type" = dm_crypt ] && ( cryptsetup luksClose $part || show_warning "process_filesystems blockdevice deconstruction" "Could not cryptsetup luksClose $part") + else + debug "Skipping deconstruction of device $part (type $part_type) because it doesn't exist" + fi + done + + # TODO: phase 3: create all blockdevices in the correct order (for each fs, the underlying block device must be available so dependencies must be resolved. for lvm:first pv's, then vg's, then lv's etc, but all device mapper devices need attention) + + # TODO: phase 4: mount all filesystems in the vfs in the correct order. (also swapon where appropriate) + # reorder file by strlen of mountpoint (or alphabetically), so that we don't get 'overridden' mountpoints (eg you don't mount /a/b/c and then /a/b. checking whether the parent dir exists is not good -> sort -t \ -k 2 + sort -t \ -k 2 test + + + debug "process_filesystems Called. checking all entries in $BLOCK_DATA" rm -f $TMP_FSTAB devs_avail=1 while [ $devs_avail = 1 ] @@ -421,25 +489,36 @@ process_filesystems () devs_avail=0 for part in `findpartitions` do - if entry=`grep ^$part $TMP_FILESYSTEMS` + if entry=`grep ^$part $BLOCK_DATA` then - process_filesystem "$entry" && sed -i "/^$part/d" $TMP_FILESYSTEMS && debug "$part processed and removed from $TMP_FILESYSTEMS" + process_filesystem "$entry" && sed -i "/^$part/d" $BLOCK_DATA && debug "$part processed and removed from $BLOCK_DATA" devs_avail=1 fi done done - entries=`wc -l $TMP_FILESYSTEMS` + entries=`wc -l $BLOCK_DATA` if [ $entries -gt 0 ] then - die_error "Could not process all entries because not all available blockdevices became available. Unprocessed:`awk '{print \$1}' $TMP_FILESYSTEMS`" + die_error "Could not process all entries because not all available blockdevices became available. Unprocessed:`awk '{print \$1}' $BLOCK_DATA`" else debug "All entries processed..." fi } +# NOTE: beware, the 'mount?' for now just matters for the location (if 'target', the target path gets prepended) + +# FORMAT DEFINITION: + +# MAIN FORMAT FOR $BLOCK_DATA (format used to interface with this library): one line per blockdevice, multiple fs'es in 1 'fs-string' +# $BLOCK_DATA entry. +# type label/no_label /no_fs +# FS-string: +# type;recreate(yes/no);mountpoint;mount?(target,runtime,no);opts;label;params[|FS-string|...] where opts have _'s instead of whitespace + + +# ADDITIONAL INTERNAL FORMAT FOR $TMP_FILESYSTEMS: each filesystem on a separate line, so block devices can be on multiple lines +# part part_type part_label fs_type fs_create fs_mountpoint fs_mount fs_opts fs_label fs_params -#TMP_FILESYSTEMS beware, the 'mount?' for now just matters for the location (if 'target', the target path gets prepended) -#blockdevice:filesystem:mountpoint:recreate FS?(yes/no):mount?(target,runtime,no)[:extra options for specific filesystem] # make a filesystem on a blockdevice and mount if requested. process_filesystem () diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index e120385..735fc00 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -104,7 +104,7 @@ interactive_set_clock() } -interactive_autoprepare() +interactive_autoprepare() #TODO: port this to use the $BLOCK_DATA format { DISCS=$(finddisks) if [ $(echo $DISCS | wc -w) -gt 1 ]; then @@ -227,7 +227,7 @@ interactive_partition() { # create new, delete, or edit a filesystem -interactive_filesystem () +interactive_filesystem () #TODO: make it possible to edit 1 specific aspect of a FS (eg mountpoint, type etc) { part=$1 # must be given and (scheduled to become) a valid device -> don't do [ -b "$1" ] because the device might not exist *yet* part_type=$2 # a part should always have a type @@ -237,7 +237,7 @@ interactive_filesystem () if [ -z "$fs" ] then fs_type= - fs_mount= + fs_mountpoint= fs_opts= fs_label= fs_params= @@ -249,18 +249,20 @@ interactive_filesystem () NEW_FILESYSTEM=empty return 0 else - fs_type=` cut -d ';' -f 1 <<< $fs` - fs_mount=` cut -d ';' -f 2 <<< $fs` - fs_opts=` cut -d ';' -f 3 <<< $fs` - fs_label=` cut -d ';' -f 4 <<< $fs` - fs_params=`cut -d ';' -f 5 <<< $fs` + fs_type=` cut -d ';' -f 1 <<< $fs` + fs_create=` cut -d ';' -f 2 <<< $fs` #not asked for to the user. this is always 'yes' for now + fs_mountpoint=` cut -d ';' -f 3 <<< $fs` + fs_mount=` cut -d ';' -f 4 <<< $fs` #we dont need to ask this to the user. this is always 'target' for 99.99% of the users + fs_opts=` cut -d ';' -f 5 <<< $fs` + fs_label=` cut -d ';' -f 6 <<< $fs` + fs_params=` cut -d ';' -f 7 <<< $fs` [ "$fs_type" = no_type ] && fs_type= - [ "$fs_mount" = no_mount ] && fs_mount= + [ "$fs_mountpoint" = no_mount ] && fs_mountpoint= [ "$fs_opts" = no_opts ] && fs_opts= [ "$fs_label" = no_label ] && fs_label= [ "$fs_params" = no_params ] && fs_params= old_fs_type=$fs_type - old_fs_mount=$fs_mount + old_fs_mountpoint=$fs_mountpoint old_fs_opts=$fs_opts old_fs_label=$fs_label old_fs_params=$fs_params @@ -314,9 +316,9 @@ interactive_filesystem () if [[ $fs_type != lvm-* && "$fs_type" != dm_crypt ]] then default= - [ -n "$fs_mount" ] && default="$fs_mount" + [ -n "$fs_mountpoint" ] && default="$fs_mountpoint" ask_string "Enter the mountpoint for $part" "$default" || return 1 - fs_mount=$ANSWER_STRING + fs_mountpoint=$ANSWER_STRING fi # ask label, if relevant @@ -369,11 +371,11 @@ interactive_filesystem () fs_opts=$(sed 's/ /_/g' <<< "$ANSWER_STRING") #TODO: clean up all whitespace (tabs and shit) [ -z "$fs_type" ] && fs_type=no_type - [ -z "$fs_mount" ] && fs_mount=no_mount + [ -z "$fs_mountpoint" ] && fs_mountpoint=no_mount [ -z "$fs_opts" ] && fs_opts=no_opts [ -z "$fs_label" ] && fs_label=no_label [ -z "$fs_params" ] && fs_params=no_params - NEW_FILESYSTEM="$fs_type;$fs_mount;$fs_opts;$fs_label;$fs_params" + NEW_FILESYSTEM="$fs_type;yes;$fs_mountpoint;target;$fs_opts;$fs_label;$fs_params" #TODO: make re-creation yes/no asking available in this UI. # add new theoretical blockdevice, if relevant if [ "$fs_type" = lvm-vg ] @@ -410,7 +412,7 @@ interactive_filesystems() { # $BLOCK_DATA entry. easily parsable.: # type label/no_label /no_fs # FS-string: - # type;mountpoint;opts;label;params[|FS-string|...] where opts have _'s instead of whitespace + # type;recreate;mountpoint;mount?(target,runtime,no);opts;label;params[|FS-string|...] where opts have _'s instead of whitespace findpartitions 0 'no_fs' ' raw no_label' > $BLOCK_DATA while [ "$USERHAPPY" = 0 ] @@ -443,7 +445,7 @@ interactive_filesystems() { list= if [ -n "$fs" ] then - for lv in `sed '/|/ /' <<< $fs` + for lv in `sed 's/|/ /g' <<< $fs` do label=$(cut -d ';' -f 4 <<< $lv) mountpoint=$(cut -d ';' -f 2 <<< $lv) @@ -492,7 +494,7 @@ interactive_filesystems() { done - # If the user has forgotten one or more fundamental ones, ask him now + #TODO: If the user has forgotten one or more fundamental ones, send him back to the main editor ALLOK=true # TODO: check all conditions that would make ALLOK untrue again while [ "$ALLOK" != "true" ]; do @@ -549,6 +551,7 @@ interactive_filesystems() { # TODO: prepend $var_TARGET_DIR before handing over # TODO: convert our format to what process_filesystems will understand + process_filesystems && notify "Partitions were successfully created." && return 0 show_warning "Something went wrong while processing the filesystems" return 1 -- cgit v1.2.3-54-g00ecf From d9c3efb6fa5c701a0c0833bf8bd94c9791bd39ed Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 7 Dec 2008 15:11:22 +0100 Subject: support for "health checks" on configured blockdevices/filesystems and letting user go back + cleanups --- src/core/libs/lib-ui-interactive.sh | 219 +++++++++++++++--------------------- 1 file changed, 93 insertions(+), 126 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 735fc00..40bda7b 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -405,8 +405,6 @@ interactive_filesystems() { notify "Available Disks:\n\n$(_getavaildisks)\n" - # Let the user make filesystems and mountpoints - USERHAPPY=0 BLOCK_DATA=/home/arch/aif/runtime/.blockdata # $BLOCK_DATA entry. easily parsable.: @@ -415,148 +413,117 @@ interactive_filesystems() { # type;recreate;mountpoint;mount?(target,runtime,no);opts;label;params[|FS-string|...] where opts have _'s instead of whitespace findpartitions 0 'no_fs' ' raw no_label' > $BLOCK_DATA - while [ "$USERHAPPY" = 0 ] + + ALLOK=0 + while [ "$ALLOK" = 0 ] do - # generate a menu based on the information in the datafile - menu_list= - while read part type label fs + # Let the user make filesystems and mountpoints + USERHAPPY=0 + + while [ "$USERHAPPY" = 0 ] do - infostring="type:$type,label:$label,fs:$fs" - [ -b "$part" ] && get_blockdevice_size ${part/+/} && infostring="size:${BLOCKDEVICE_SIZE}MB,$infostring" # add size in MB for existing blockdevices (eg not for mapper devices that are not yet created yet) - menu_list="$menu_list $part $infostring" #don't add extra spaces, dialog doesn't like that. - done < $BLOCK_DATA - - ask_option no "Manage filesystems, block devices and virtual devices. Note that you don't *need* to specify opts, labels or extra params if you're not using lvm, dm_crypt, etc." $menu_list DONE _ - [ $? -gt 0 ] && USERHAPPY=1 && break - [ "$ANSWER_OPTION" == DONE ] && USERHAPPY=1 && break - - part=$ANSWER_OPTION - - declare part_escaped=${part//\//\\/} # escape all slashes otherwise awk complains - declare part_escaped=${part_escaped/+/\\+} # escape the + sign too - part_type=$( awk "/^$part_escaped/ {print \$2}" $BLOCK_DATA) - part_label=$(awk "/^$part_escaped/ {print \$3}" $BLOCK_DATA) - fs=$( awk "/^$part_escaped/ {print \$4}" $BLOCK_DATA) - [ "$part_label" == no_label ] && part_label= - [ "$fs" == no_fs ] && fs= - - if [ $part_type = lvm-vg ] # one lvm VG can host multiple LV's so that's a bit a special blockdevice... - then - list= - if [ -n "$fs" ] - then - for lv in `sed 's/|/ /g' <<< $fs` - do - label=$(cut -d ';' -f 4 <<< $lv) - mountpoint=$(cut -d ';' -f 2 <<< $lv) - list="$list $label $mountpoint" - done - else - list="XXX no-LV's-defined-yet-make-a-new-one" - fi - list="$list empty NEW" - ask_option empty "Edit/create new LV's on this VG:" $list - if [ "$ANSWER_OPTION" = XXX -o "$ANSWER_OPTION" = empty ] + # generate a menu based on the information in the datafile + menu_list= + while read part type label fs + do + infostring="type:$type,label:$label,fs:$fs" + [ -b "$part" ] && get_blockdevice_size ${part/+/} && infostring="size:${BLOCKDEVICE_SIZE}MB,$infostring" # add size in MB for existing blockdevices (eg not for mapper devices that are not yet created yet) + menu_list="$menu_list $part $infostring" #don't add extra spaces, dialog doesn't like that. + done < $BLOCK_DATA + + ask_option no "Manage filesystems, block devices and virtual devices. Note that you don't *need* to specify opts, labels or extra params if you're not using lvm, dm_crypt, etc." $menu_list DONE _ + [ $? -gt 0 ] && USERHAPPY=1 && break + [ "$ANSWER_OPTION" == DONE ] && USERHAPPY=1 && break + + part=$ANSWER_OPTION + + declare part_escaped=${part//\//\\/} # escape all slashes otherwise awk complains + declare part_escaped=${part_escaped/+/\\+} # escape the + sign too + part_type=$( awk "/^$part_escaped/ {print \$2}" $BLOCK_DATA) + part_label=$(awk "/^$part_escaped/ {print \$3}" $BLOCK_DATA) + fs=$( awk "/^$part_escaped/ {print \$4}" $BLOCK_DATA) + [ "$part_label" == no_label ] && part_label= + [ "$fs" == no_fs ] && fs= + + if [ $part_type = lvm-vg ] # one lvm VG can host multiple LV's so that's a bit a special blockdevice... then - # a new LV must be created on this VG - if interactive_filesystem $part $part_type $part_label '' + list= + if [ -n "$fs" ] + then + for lv in `sed 's/|/ /g' <<< $fs` + do + label=$(cut -d ';' -f 4 <<< $lv) + mountpoint=$(cut -d ';' -f 2 <<< $lv) + list="$list $label $mountpoint" + done + else + list="XXX no-LV's-defined-yet-make-a-new-one" + fi + list="$list empty NEW" + ask_option empty "Edit/create new LV's on this VG:" $list + if [ "$ANSWER_OPTION" = XXX -o "$ANSWER_OPTION" = empty ] then - [ -z "$fs" ] && fs=$NEW_FILESYSTEM - [ -n "$fs" ] && fs="$fs|$NEW_FILESYSTEM" + # a new LV must be created on this VG + if interactive_filesystem $part $part_type $part_label '' + then + [ -z "$fs" ] && fs=$NEW_FILESYSTEM + [ -n "$fs" ] && fs="$fs|$NEW_FILESYSTEM" + fi + else + # an existing LV will be edited and it's settings updated + for lv in `sed '/|/ /' <<< $fs` + do + label=$(cut -d ';' -f 4 <<< $lv) + [ "$label" = "$ANSWER_OPTION" ] && found_lv="$lv" + done + interactive_filesystem $part $part_type $part_label "$found_lv" + fs= + for lv in `sed '/|/ /' <<< $fs` + do + label=$(cut -d ';' -f 4 <<< $lv) + add=$lv + [ "$label" = "$ANSWER_OPTION" ] && add=$NEW_FILESYSTEM + [ -z "$fs" ] && fs=$add + [ -n "$fs" ] && fs="$fs|$add" + done fi else - # an existing LV will be edited and it's settings updated - for lv in `sed '/|/ /' <<< $fs` - do - label=$(cut -d ';' -f 4 <<< $lv) - [ "$label" = "$ANSWER_OPTION" ] && found_lv="$lv" - done - interactive_filesystem $part $part_type $part_label "$found_lv" - fs= - for lv in `sed '/|/ /' <<< $fs` - do - label=$(cut -d ';' -f 4 <<< $lv) - add=$lv - [ "$label" = "$ANSWER_OPTION" ] && add=$NEW_FILESYSTEM - [ -z "$fs" ] && fs=$add - [ -n "$fs" ] && fs="$fs|$add" - done + interactive_filesystem $part $part_type $part_label $fs + [ $? -eq 0 ] && fs=$NEW_FILESYSTEM fi - else - interactive_filesystem $part $part_type $part_label $fs - [ $? -eq 0 ] && fs=$NEW_FILESYSTEM - fi - # update the menu # NOTE that part_type remains raw for basic filesystems! - [ -z "$part_label" ] && part_label=no_label - [ -z "$fs" ] && fs=no_fs - sed -i "s#^$part $part_type $part_label.*#$part $part_type $part_label $fs#" $BLOCK_DATA # '#' is a forbidden character ! + # update the menu # NOTE that part_type remains raw for basic filesystems! + [ -z "$part_label" ] && part_label=no_label + [ -z "$fs" ] && fs=no_fs + sed -i "s#^$part $part_type $part_label.*#$part $part_type $part_label $fs#" $BLOCK_DATA # '#' is a forbidden character ! - done + done - #TODO: If the user has forgotten one or more fundamental ones, send him back to the main editor - ALLOK=true - # TODO: check all conditions that would make ALLOK untrue again - while [ "$ALLOK" != "true" ]; do - - _dia_DIALOG --menu "Select the partition to use as swap" 21 50 13 NONE - $PARTS 2>$ANSWER || return 1 - PART=$(cat $ANSWER) - PARTS="$(echo $PARTS | sed -e "s#${PART}\ _##g")" - if [ "$PART" != "NONE" ]; then - DOMKFS="no" - ask_yesno "Would you like to create a filesystem on $PART?\n\n(This will overwrite existing data!)" && DOMKFS="yes" - echo "$PART:swap:swap:$DOMKFS" >>/home/arch/aif/runtime/.parts - fi + # Check all conditions that need to be fixed and ask the user if he wants to go back and correct them + errors= + warnings= - _dia_DIALOG --menu "Select the partition to mount as /" 21 50 13 $PARTS 2>$ANSWER || return 1 - PART=$(cat $ANSWER) - PARTS="$(echo $PARTS | sed -e "s#${PART}\ _##g")" - PART_ROOT=$PART - # Select root filesystem type - _dia_DIALOG --menu "Select a filesystem for $PART" 13 45 6 $FSOPTS 2>$ANSWER || return 1 - FSTYPE=$(cat $ANSWER) - DOMKFS="no" - ask_yesno "Would you like to create a filesystem on $PART?\n\n(This will overwrite existing data!)" && DOMKFS="yes" - echo "$PART:$FSTYPE:/:$DOMKFS" >>/home/arch/aif/runtime/.parts - - # - # Additional partitions - # - _dia_DIALOG --menu "Select any additional partitions to mount under your new root (select DONE when finished)" 21 50 13 $PARTS DONE _ 2>$ANSWER || return 1 - PART=$(cat $ANSWER) - while [ "$PART" != "DONE" ]; do - PARTS="$(echo $PARTS | sed -e "s#${PART}\ _##g")" - # Select a filesystem type - _dia_DIALOG --menu "Select a filesystem for $PART" 13 45 6 $FSOPTS 2>$ANSWER || return 1 - FSTYPE=$(cat $ANSWER) - MP="" - while [ "${MP}" = "" ]; do - _dia_DIALOG --inputbox "Enter the mountpoint for $PART" 8 65 "/boot" 2>$ANSWER || return 1 - MP=$(cat $ANSWER) - if grep ":$MP:" /home/arch/aif/runtime/.parts; then - notify "ERROR: You have defined 2 identical mountpoints! Please select another mountpoint." - MP="" - fi - done - DOMKFS="no" - ask_yesno "Would you like to create a filesystem on $PART?\n\n(This will overwrite existing data!)" && DOMKFS="yes" - echo "$PART:$FSTYPE:$MP:$DOMKFS" >>file - _dia_DIALOG --menu "Select any additional partitions to mount under your new root" 21 50 13 $PARTS DONE _ 2>$ANSWER || return 1 - PART=$(cat $ANSWER) - done - ask_yesno "Would you like to create and mount the filesytems like this?\n\nSyntax\n------\nDEVICE:TYPE:MOUNTPOINT:FORMAT\n\n$(for i in $(cat /home/arch/aif/runtime/.parts); do echo "$i\n";done)" && PARTFINISH="DONE" - done + grep -q ';/boot;' || warnings="$warnings\n-No separate /boot filesystem" + grep -q ';/;' || errors="$errors\n-No filesystem with mountpoint /" + grep -q ' swap;' || grep -q '|swap;' || warnings="$warnings\n-No swap partition defined" - # TODO: should not need this anymore target_umountall - # TODO: prepend $var_TARGET_DIR before handing over - # TODO: convert our format to what process_filesystems will understand + if [ -n "$errors$warnings" ] + then + str="The following issues have been detected:\n" + [ -n "$errors" ] && str="$str\n - Errors: $errors" + [ -n "$warnings" ] && str="$str\n - Warnings: $warnings" + ask_yesno "$str\n Do you want to back to fix (one of) these issues?" || ALLOK=1 + fi + + done process_filesystems && notify "Partitions were successfully created." && return 0 - show_warning "Something went wrong while processing the filesystems" + show_warning "Filesystem processing" "Something went wrong while processing the filesystems" return 1 } + # select_packages() # prompts the user to select packages to install # -- cgit v1.2.3-54-g00ecf From 8831c7d1fec0ac9e427bcdc9d4d1611e0411464c Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 7 Dec 2008 15:11:58 +0100 Subject: cleanup/reordering --- src/core/libs/lib-blockdevices-filesystems.sh | 53 +++++++++++++-------------- 1 file changed, 26 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index a06aa6f..4914472 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -434,6 +434,8 @@ generate_filesystem_list () # process all entries in $BLOCK_DATA, create all blockdevices and filesystems and mount them correctly, destroying what's necessary first. process_filesystems () { + debug "process_filesystems Called. checking all entries in $BLOCK_DATA" + rm -f $TMP_FSTAB generate_filesystem_list # phase 1: deconstruct all mounts in the vfs that are about to be reconstructed. (and also swapoff where appropriate) @@ -451,13 +453,34 @@ process_filesystems () fi done - # TODO: phase 2: deconstruct blockdevices if they would exist already (destroy any lvm things, dm_crypt devices etc in the correct order) +# devs_avail=1 +# while [ $devs_avail = 1 ] +# do +# devs_avail=0 +# for part in `findpartitions` +# do +# if entry=`grep ^$part $BLOCK_DATA` +# then +# process_filesystem "$entry" && sed -i "/^$part/d" $BLOCK_DATA && debug "$part processed and removed from $BLOCK_DATA" +# devs_avail=1 +# fi +# done +# done +# entries=`wc -l $BLOCK_DATA` +# if [ $entries -gt 0 ] +# then +# die_error "Could not process all entries because not all available blockdevices became available. Unprocessed:`awk '{print \$1}' $BLOCK_DATA`" +# else +# debug "All entries processed..." +# fi + + # phase 2: deconstruct blockdevices if they would exist already (destroy any lvm things, dm_crypt devices etc in the correct order) # in theory devices with same names could be stacked on each other with different dependencies. I hope that's not the case for now. In the future maybe we should deconstruct things we need and who are in /etc/mtab or something. # targets for deconstruction: /dev/mapper devices and lvm PV's who contain no fs, or a non-lvm/dm_crypt fs. TODO: improve regexes # after deconstructing. the parent must be updated to reflect the vanished child. -# TODO: as long as devices in this list remains and exist physically -# TODO: abort when there still are physical devices listed, but we tried to deconstruct them already, give error + # TODO: do this as long as devices in this list remains and exist physically + # TODO: abort when there still are physical devices listed, but we tried to deconstruct them already, give error egrep '\+|mapper' $BLOCK_DATA | egrep -v ' lvm-pv;| lvm-vg;| lvm-lv;| dm_crypt;' | while read part part_type part_label fs do @@ -478,31 +501,7 @@ process_filesystems () # TODO: phase 4: mount all filesystems in the vfs in the correct order. (also swapon where appropriate) # reorder file by strlen of mountpoint (or alphabetically), so that we don't get 'overridden' mountpoints (eg you don't mount /a/b/c and then /a/b. checking whether the parent dir exists is not good -> sort -t \ -k 2 - sort -t \ -k 2 test - - debug "process_filesystems Called. checking all entries in $BLOCK_DATA" - rm -f $TMP_FSTAB - devs_avail=1 - while [ $devs_avail = 1 ] - do - devs_avail=0 - for part in `findpartitions` - do - if entry=`grep ^$part $BLOCK_DATA` - then - process_filesystem "$entry" && sed -i "/^$part/d" $BLOCK_DATA && debug "$part processed and removed from $BLOCK_DATA" - devs_avail=1 - fi - done - done - entries=`wc -l $BLOCK_DATA` - if [ $entries -gt 0 ] - then - die_error "Could not process all entries because not all available blockdevices became available. Unprocessed:`awk '{print \$1}' $BLOCK_DATA`" - else - debug "All entries processed..." - fi } # NOTE: beware, the 'mount?' for now just matters for the location (if 'target', the target path gets prepended) -- cgit v1.2.3-54-g00ecf From a7dab1762fe0011aefae910b542af711e4c31f4c Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 7 Dec 2008 15:15:27 +0100 Subject: abstraction of which program to use --- src/core/libs/lib-ui-interactive.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 40bda7b..4a562a0 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -288,16 +288,16 @@ interactive_filesystem () #TODO: make it possible to edit 1 specific aspect of a # Determine which filesystems/blockdevices are possible for this blockdevice FSOPTS= - [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.ext2 &>/dev/null && FSOPTS="$FSOPTS ext2 Ext2" - [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.ext3 &>/dev/null && FSOPTS="$FSOPTS ext3 Ext3" - [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkreiserfs &>/dev/null && FSOPTS="$FSOPTS reiserfs Reiser3" - [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.xfs &>/dev/null && FSOPTS="$FSOPTS xfs XFS" - [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.jfs &>/dev/null && FSOPTS="$FSOPTS jfs JFS" - [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which mkfs.vfat &>/dev/null && FSOPTS="$FSOPTS vfat VFAT" - [ $part_type = raw -o $part_type = dm_crypt ] && which pvcreate &>/dev/null && FSOPTS="$FSOPTS lvm-pv LVM_Physical_Volume" - [ $part_type = lvm-pv ] && which vgcreate &>/dev/null && FSOPTS="$FSOPTS lvm-vg LVM_Volumegroup" - [ $part_type = lvm-vg ] && which lvcreate &>/dev/null && FSOPTS="$FSOPTS lvm-lv LVM_Logical_Volume" - [ $part_type = raw -o $part_type = lvm-lv ] && which cryptsetup &>/dev/null && FSOPTS="$FSOPTS dm_crypt DM_crypt_Volume" + [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which `get_filesystem_program ext2` &>/dev/null && FSOPTS="$FSOPTS ext2 Ext2" + [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which `get_filesystem_program ext3` &>/dev/null && FSOPTS="$FSOPTS ext3 Ext3" + [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which `get_filesystem_program reiserfs` &>/dev/null && FSOPTS="$FSOPTS reiserfs Reiser3" + [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which `get_filesystem_program xfs` &>/dev/null && FSOPTS="$FSOPTS xfs XFS" + [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which `get_filesystem_program jfs` &>/dev/null && FSOPTS="$FSOPTS jfs JFS" + [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which `get_filesystem_program vfat` &>/dev/null && FSOPTS="$FSOPTS vfat VFAT" + [ $part_type = raw -o $part_type = dm_crypt ] && which `get_filesystem_program lvm-pv` &>/dev/null && FSOPTS="$FSOPTS lvm-pv LVM_Physical_Volume" + [ $part_type = lvm-pv ] && which `get_filesystem_program lvm-vg` &>/dev/null && FSOPTS="$FSOPTS lvm-vg LVM_Volumegroup" + [ $part_type = lvm-vg ] && which `get_filesystem_program lvm-lv` &>/dev/null && FSOPTS="$FSOPTS lvm-lv LVM_Logical_Volume" + [ $part_type = raw -o $part_type = lvm-lv ] && which `get_filesystem_program dm_crypt` &>/dev/null && FSOPTS="$FSOPTS dm_crypt DM_crypt_Volume" # determine FS fsopts=($FSOPTS); -- cgit v1.2.3-54-g00ecf From cc258490000e54a1897d7905fe5d642cced5779e Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 7 Dec 2008 15:20:40 +0100 Subject: todo updates --- src/core/libs/lib-ui-interactive.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 4a562a0..dd3f495 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -227,7 +227,9 @@ interactive_partition() { # create new, delete, or edit a filesystem -interactive_filesystem () #TODO: make it possible to edit 1 specific aspect of a FS (eg mountpoint, type etc) +# At first I had the idea of a menu where all properties of a filesystem and you could pick one to update only that one (eg mountpoint, type etc)\ +# but I think it's better to go through them all and by default always show the previous choice. +interactive_filesystem () { part=$1 # must be given and (scheduled to become) a valid device -> don't do [ -b "$1" ] because the device might not exist *yet* part_type=$2 # a part should always have a type -- cgit v1.2.3-54-g00ecf From 7500ef53598f2ee2c128bd9b93d5c94b1aa7b6e9 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 7 Dec 2008 15:55:55 +0100 Subject: refactored/cleanup datetime/timezone stuff --- src/core/libs/lib-ui-interactive.sh | 63 +++++++++++++++++-------------------- src/core/libs/lib-ui.sh | 28 +++++++++++++++++ src/core/procedures/base | 10 +----- src/core/procedures/interactive | 12 +------ 4 files changed, 58 insertions(+), 55 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index dd3f495..0725644 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -62,45 +62,38 @@ interactive_configure_system() # returns: 1 on failure interactive_set_clock() { - # utc or local? - ask_option no "Is your hardware clock in UTC or local time?" \ - "UTC" " " \ - "local" " " \ - || return 1 - HARDWARECLOCK=$ANSWER_OPTION + # utc or local? + ask_option no "Is your hardware clock in UTC or local time?" "UTC" " " "local" " " || return 1 + HARDWARECLOCK=$ANSWER_OPTION - # timezone? - TIMEZONE=`tzselect` || return 1 + # timezone? + ask_timezone || return 1 + TIMEZONE=$ANSWER_TIMEZONE + # set system clock from hwclock - stolen from rc.sysinit + local HWCLOCK_PARAMS="" + if [ "$HARDWARECLOCK" = "UTC" ] + then + HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc" + else + HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime" + fi - # set system clock from hwclock - stolen from rc.sysinit - local HWCLOCK_PARAMS="" - if [ "$HARDWARECLOCK" = "UTC" ]; then - HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc" - else - HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime" - fi - if [ "$TIMEZONE" != "" -a -e "/usr/share/zoneinfo/$TIMEZONE" ]; then - /bin/rm -f /etc/localtime - /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime - fi - /sbin/hwclock --hctosys $HWCLOCK_PARAMS --noadjfile - - # display and ask to set date/time - dialog --calendar "Set the date.\nUse to navigate and arrow keys to change values." 0 0 0 0 0 2> $ANSWER || return 1 - local _date="$(cat $ANSWER)" - dialog --timebox "Set the time.\nUse to navigate and up/down to change values." 0 0 2> $ANSWER || return 1 - local _time="$(cat $ANSWER)" - echo "date: $_date time: $_time" >$LOG - - # save the time - # DD/MM/YYYY hh:mm:ss -> YYYY-MM-DD hh:mm:ss - local _datetime="$(echo "$_date" "$_time" | sed 's#\(..\)/\(..\)/\(....\) \(..\):\(..\):\(..\)#\3-\2-\1 \4:\5:\6#g')" - echo "setting date to: $_datetime" >$LOG - date -s "$_datetime" 2>&1 >$LOG - /sbin/hwclock --systohc $HWCLOCK_PARAMS --noadjfile + if [ "$TIMEZONE" != "" -a -e "/usr/share/zoneinfo/$TIMEZONE" ] + then + /bin/rm -f /etc/localtime + /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime + fi + /sbin/hwclock --hctosys $HWCLOCK_PARAMS --noadjfile - return 0 + # display and ask to set date/time + ask_datetime + + # save the time + date -s $ANSWER_DATETIME || show_warning "Date/time setting failed" "Something went wrong when doing date -s $ANSWER_DATETIME" + /sbin/hwclock --systohc $HWCLOCK_PARAMS --noadjfile + + return 0 } diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 1ca87d5..9191998 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -137,6 +137,28 @@ ask_checklist () +ask_datetime () +{ + if [ "$var_UI_TYPE" = dia ] + then + # display and ask to set date/time + dialog --calendar "Set the date.\nUse to navigate and arrow keys to change values." 0 0 0 0 0 2> $ANSWER || return 1 + local _date="$(cat $ANSWER)" # form like: 07/12/2008 + dialog --timebox "Set the time.\nUse to navigate and up/down to change values." 0 0 2> $ANSWER || return 1 + local _time="$(cat $ANSWER)" # form like: 15:26:46 + echo "date: $_date time: $_time" >$LOG + + # DD/MM/YYYY hh:mm:ss -> MMDDhhmmYYYY.ss (date default format, set like date $ANSWER_DATETIME) Not enabled because there is no use for it i think. + # ANSWER_DATETIME=$(echo "$_date" "$_time" | sed 's#\(..\)/\(..\)/\(....\) \(..\):\(..\):\(..\)#\2\1\4\5\3\6#g') + # DD/MM/YYYY hh:mm:ss -> YYYY-MM-DD hh:mm:ss ( date string format, set like date -s $ANSWER_DATETIME) + ANSWER_DATETIME="$(echo "$_date" "$_time" | sed 's#\(..\)/\(..\)/\(....\) \(..\):\(..\):\(..\)#\3-\2-\1 \4:\5:\6#g')" + elif [ "$var_UI_TYPE" = cli ] + ask_string "Enter date [YYYY-MM-DD hh:mm:ss]" + ANSWER_DATETIME=$ANSWER_STRING + fi +} + + # TODO: we should have a wrapper around this function that keeps trying until the user entered a valid numeric?, maybe a wrapper that wraps all functions # ask for a number. # $1 question @@ -191,6 +213,12 @@ ask_string () } +ask_timezone () # TODO: how to do this in dia? +{ + ANSWER_TIMEZONE=`tzselect` +} + + # ask a yes/no question. # $1 question # $2 default answer yes/no (optional) diff --git a/src/core/procedures/base b/src/core/procedures/base index 7af1452..8a586fb 100644 --- a/src/core/procedures/base +++ b/src/core/procedures/base @@ -62,15 +62,7 @@ worker_runtime_packages () worker_set_clock () { - HARDWARECLOCK=utc - TIMEZONE=`tzselect` - HWCLOCK_PARAMS=" --utc" - if [ "$TIMEZONE" != "" -a -e "/usr/share/zoneinfo/$TIMEZONE" ] - then - cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime - fi - /sbin/hwclock --hctosys $HWCLOCK_PARAMS --noadjfile - #TODO: user must set date/time and store it + interactive_set_clock } diff --git a/src/core/procedures/interactive b/src/core/procedures/interactive index 66efaec..ce63bd1 100644 --- a/src/core/procedures/interactive +++ b/src/core/procedures/interactive @@ -1,5 +1,5 @@ #!/bin/sh -depend_procedure core base # esp for auto_{network,locale,fstab} workers +depend_procedure core base # esp for auto_{network,locale,fstab} and set_clock workers # This is a port of the original /arch/setup script. It doesn't use aif phases but uses it's own menu-based flow (phase) control @@ -176,16 +176,6 @@ worker_prepare_disks() } -# set_clock() -# prompts user to set hardware clock and timezone -# -# params: none -set_clock() -{ - interactive_set_clock -} - - worker_select_source () { #TODO: how to handle user going here again? discard previous settings, warn him that he already done it? -- cgit v1.2.3-54-g00ecf From a4aed416e347a83f105e916d6a32dafa5d24ddd7 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 7 Dec 2008 16:07:04 +0100 Subject: ported interactive_autoprepare to new format + mountpoint fix --- src/core/libs/lib-ui-interactive.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 0725644..1809beb 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -97,7 +97,7 @@ interactive_set_clock() } -interactive_autoprepare() #TODO: port this to use the $BLOCK_DATA format +interactive_autoprepare() { DISCS=$(finddisks) if [ $(echo $DISCS | wc -w) -gt 1 ]; then @@ -178,10 +178,11 @@ interactive_autoprepare() #TODO: port this to use the $BLOCK_DATA format PART_ROOT="${DISC}3" echo "$DISC $BOOT_PART_SIZE:ext2:+ $SWAP_PART_SIZE:swap $ROOT_PART_SIZE:$FSTYPE *:$FSTYPE" > $TMP_PARTITIONS - echo "${DISC}1:ext2:/boot:yes:target" >$TMP_FILESYSTEMS - echo "${DISC}2:swap:null:yes:target" >$TMP_FILESYSTEMS - echo "${DISC}3:$FSTYPE:/:yes:target" >$TMP_FILESYSTEMS - echo "${DISC}4:$FSTYPE:/home:yes:target" >$TMP_FILESYSTEMS + + echo "${DISC}1 raw no_label ext2;yes;/boot;target;no_opts;no_label;no_params" >$BLOCK_DATA + echo "${DISC}2 raw no_label swap;yes;no_mountpoint;target;no_opts;no_label;no_params" >$BLOCK_DATA + echo "${DISC}3 raw no_label $FSTYPE;yes;/;target;no_opts;no_label;no_params" >$BLOCK_DATA + echo "${DISC}4 raw no_label $FSTYPE;yes;/home;target;no_opts;no_label;no_params" >$BLOCK_DATA process_disks || die_error "Something went wrong while partitioning" @@ -252,7 +253,7 @@ interactive_filesystem () fs_label=` cut -d ';' -f 6 <<< $fs` fs_params=` cut -d ';' -f 7 <<< $fs` [ "$fs_type" = no_type ] && fs_type= - [ "$fs_mountpoint" = no_mount ] && fs_mountpoint= + [ "$fs_mountpoint" = no_mountpoint ] && fs_mountpoint= [ "$fs_opts" = no_opts ] && fs_opts= [ "$fs_label" = no_label ] && fs_label= [ "$fs_params" = no_params ] && fs_params= @@ -366,7 +367,7 @@ interactive_filesystem () fs_opts=$(sed 's/ /_/g' <<< "$ANSWER_STRING") #TODO: clean up all whitespace (tabs and shit) [ -z "$fs_type" ] && fs_type=no_type - [ -z "$fs_mountpoint" ] && fs_mountpoint=no_mount + [ -z "$fs_mountpoint" ] && fs_mountpoint=no_mountpoint [ -z "$fs_opts" ] && fs_opts=no_opts [ -z "$fs_label" ] && fs_label=no_label [ -z "$fs_params" ] && fs_params=no_params -- cgit v1.2.3-54-g00ecf From 247e453f1390a94e1e0ae8482fff50aa7e2ee4b6 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 7 Dec 2008 16:22:49 +0100 Subject: cleanup of old cruft code + some fixes/enhancements --- src/core/libs/lib-blockdevices-filesystems.sh | 184 ++++++++++---------------- 1 file changed, 68 insertions(+), 116 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index 4914472..fcf5ca7 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -1,5 +1,21 @@ #!/bin/sh + +# FORMAT DEFINITIONS: + +# MAIN FORMAT FOR $BLOCK_DATA (format used to interface with this library): one line per blockdevice, multiple fs'es in 1 'fs-string' +# $BLOCK_DATA entry. +# type label/no_label /no_fs +# FS-string: +# type;recreate(yes/no);mountpoint;mount?(target,runtime,no);opts;label;params[|FS-string|...] where opts have _'s instead of whitespace +# NOTE: the 'mount?' for now just matters for the location (if 'target', the target path gets prepended and mounted in the runtime system) + + +# ADDITIONAL INTERNAL FORMAT FOR $TMP_FILESYSTEMS: each filesystem on a separate line, so block devices can appear multiple times be on multiple lines (eg LVM volumegroups with more lvm LV's) +# part part_type part_label fs_type fs_create fs_mountpoint fs_mount fs_opts fs_label fs_params + + + #TODO: this should be fixed on the installcd. modprobe dm-crypt || show_warning modprobe 'Could not modprobe dm-crypt. no support for disk encryption' modprobe aes-i586 || show_warning modprobe 'Could not modprobe aes-i586. no support for disk encryption' @@ -226,52 +242,6 @@ mapdev() { } -# _mkfs() taken from setup code and altered. -# Create and mount filesystems in our destination system directory. -# -# args: -# $1 device: target block device -# $2 fstype: type of filesystem located at the device (or what to create) -# $3 label: label/name for the FS (you can pass an empty string) (optional) -# $4 opts: extra opts for the mkfs program (optional) - - -# returns: 1 on failure -_mkfs() { - local _device=$1 - local _fstype=$2 - local _label=$3 - local opts=$4 - - debug "_mkfs: _device: $1, fstype: $2, label: $3, opts: $4" - # make sure the fstype is one we can handle - local knownfs=0 - for fs in xfs jfs reiserfs ext2 ext3 vfat swap dm_crypt lvm-pv lvm-vg lvm-lv; do - [ "${_fstype}" = "${fs}" ] && knownfs=1 && break - done - - [ -z "$_label" ] && _label=default #TODO. when creating more then 1 VG we will get errors that it exists already. we should (per type) add incrementing numbers or something - [ $knownfs -eq 0 ] && ( show_warning 'mkfs' "unknown fstype ${_fstype} for ${_device}" ; return 1 ) - local ret - case ${_fstype} in - xfs) mkfs.xfs -f ${_device} $opts >$LOG 2>&1; ret=$? ;; - jfs) yes | mkfs.jfs ${_device} $opts >$LOG 2>&1; ret=$? ;; - reiserfs) yes | mkreiserfs ${_device} $opts >$LOG 2>&1; ret=$? ;; - ext2) mke2fs "${_device}" $opts >$LOG 2>&1; ret=$? ;; - ext3) mke2fs -j ${_device} $opts >$LOG 2>&1; ret=$? ;; - vfat) mkfs.vfat ${_device} $opts >$LOG 2>&1; ret=$? ;; - swap) mkswap ${_device} $opts >$LOG 2>&1; ret=$? ;; - dm_crypt) [ -z "$opts" ] && opts='-c aes-xts-plain -y -s 512'; - cryptsetup $opts luksFormat ${_device} >$LOG 2>&1; ret=$? ;; - lvm-pv) pvcreate $opts ${_device} >$LOG 2>&1; ret=$? ;; - lvm-vg) vgcreate $opts $_label ${_device} >$LOG 2>&1; ret=$? ;; - lvm-lv) lvcreate $opts -n $_label ${_device} >$LOG 2>&1; ret=$? ;; #$opts is usually something like -L 10G - # don't handle anything else here, we will error later - esac - [ "$ret" != 0 ] && ( show_warning mkfs "Error creating filesystem ${_fstype} on ${_device}" ; return 1 ) - sleep 2 -} - # auto_fstab(). taken from setup # preprocess fstab file @@ -347,46 +317,6 @@ EOF } -# makes and mounts filesystems #TODO: don't use files but pass variables, integrate this with other functions -# $1 file with setup -fix_filesystems_deprecated () -{ - [ -z "$1" -o ! -f "$1" ] && die_error "Fix_filesystems needs a file with the setup structure in it" - - # Umount all things first, umount / last. After that create/mount stuff again, with / first - # TODO: we now rely on the fact that the manual mountpoint selecter uses this order 'swap,/, /<*>'. It works for now but it's not the most solid - - for line in $(tac $1); do - MP=$(echo $line | cut -d: -f 3) - umount ${var_TARGET_DIR}${MP} - done - for line in $(cat $1); do - PART=$(echo $line | cut -d: -f 1) - FSTYPE=$(echo $line | cut -d: -f 2) - MP=$(echo $line | cut -d: -f 3) - DOMKFS=$(echo $line | cut -d: -f 4) - if [ "$DOMKFS" = "yes" ]; then - if [ "$FSTYPE" = "swap" ]; then - infofy "Creating and activating swapspace on $PART" - else - infofy "Creating $FSTYPE on $PART, mounting to ${var_TARGET_DIR}${MP}" - fi - _mkfs yes $PART $FSTYPE $var_TARGET_DIR $MP || return 1 - else - if [ "$FSTYPE" = "swap" ]; then - infofy "Activating swapspace on $PART" - else - infofy "Mounting $PART to ${var_TARGET_DIR}${MP}" - fi - _mkfs no $PART $FSTYPE $var_TARGET_DIR $MP || return 1 - fi - sleep 1 - done - - return 0 -} - - # file layout: #TMP_PARTITIONS # disk partition-scheme @@ -440,16 +370,16 @@ process_filesystems () # phase 1: deconstruct all mounts in the vfs that are about to be reconstructed. (and also swapoff where appropriate) # re-order list so that we umount in the correct order. eg first umount /a/b/c, then /a/b. we sort alphabetically, which has the side-effect of sorting by stringlength, hence by vfs dependencies. - + # TODO: this is not entirely correct: what if something is mounted in a previous run that is now not anymore in $BLOCK_DATA ? that needs to be cleaned up too. sort -t \ -k 2 test $TMP_FILESYSTEMS | tac | while read part part_type part_label fs_type fs_create fs_mountpoint fs_mount fs_opts fs_label fs_params do if [ "$fs_type" = swap ] then - swapoff $part + swapoff $part # could be that it was not swappedon yet. that's not a problem at all. elif [ "$fs_mountpoint" != no_mount ] then [ "$fs_mount" = target ] && fs_mountpoint=$var_TARGET_DIR$fs_mountpoint - umount $fs_mountpoint + umount $fs_mountpoint # could be that this was not mounted yet. no problem. fi done @@ -497,27 +427,12 @@ process_filesystems () fi done - # TODO: phase 3: create all blockdevices in the correct order (for each fs, the underlying block device must be available so dependencies must be resolved. for lvm:first pv's, then vg's, then lv's etc, but all device mapper devices need attention) + # TODO: phase 3: create all blockdevices and filesystems in the correct order (for each fs, the underlying block/lvm/devicemapper device must be available so dependencies must be resolved. for lvm:first pv's, then vg's, then lv's etc) # TODO: phase 4: mount all filesystems in the vfs in the correct order. (also swapon where appropriate) - # reorder file by strlen of mountpoint (or alphabetically), so that we don't get 'overridden' mountpoints (eg you don't mount /a/b/c and then /a/b. checking whether the parent dir exists is not good -> sort -t \ -k 2 - -} - -# NOTE: beware, the 'mount?' for now just matters for the location (if 'target', the target path gets prepended) - -# FORMAT DEFINITION: - -# MAIN FORMAT FOR $BLOCK_DATA (format used to interface with this library): one line per blockdevice, multiple fs'es in 1 'fs-string' -# $BLOCK_DATA entry. -# type label/no_label /no_fs -# FS-string: -# type;recreate(yes/no);mountpoint;mount?(target,runtime,no);opts;label;params[|FS-string|...] where opts have _'s instead of whitespace -# ADDITIONAL INTERNAL FORMAT FOR $TMP_FILESYSTEMS: each filesystem on a separate line, so block devices can be on multiple lines -# part part_type part_label fs_type fs_create fs_mountpoint fs_mount fs_opts fs_label fs_params - +} # make a filesystem on a blockdevice and mount if requested. process_filesystem () @@ -571,23 +486,60 @@ process_filesystem () fi return 0 + + local _device=$1 + local _fstype=$2 + local _label=$3 + local opts=$4 + + debug "_mkfs: _device: $1, fstype: $2, label: $3, opts: $4" + # make sure the fstype is one we can handle TODO: we can use get_filesystem_program for that + local knownfs=0 + for fs in xfs jfs reiserfs ext2 ext3 vfat swap dm_crypt lvm-pv lvm-vg lvm-lv; do + [ "${_fstype}" = "${fs}" ] && knownfs=1 && break + done + + [ -z "$_label" ] && _label=default #TODO. when creating more then 1 VG we will get errors that it exists already. we should (per type) add incrementing numbers or something + [ $knownfs -eq 0 ] && ( show_warning 'mkfs' "unknown fstype ${_fstype} for ${_device}" ; return 1 ) + local ret + case ${_fstype} in + xfs) mkfs.xfs -f ${_device} $opts >$LOG 2>&1; ret=$? ;; + jfs) yes | mkfs.jfs ${_device} $opts >$LOG 2>&1; ret=$? ;; + reiserfs) yes | mkreiserfs ${_device} $opts >$LOG 2>&1; ret=$? ;; + ext2) mke2fs "${_device}" $opts >$LOG 2>&1; ret=$? ;; + ext3) mke2fs -j ${_device} $opts >$LOG 2>&1; ret=$? ;; + vfat) mkfs.vfat ${_device} $opts >$LOG 2>&1; ret=$? ;; + swap) mkswap ${_device} $opts >$LOG 2>&1; ret=$? ;; + dm_crypt) [ -z "$opts" ] && opts='-c aes-xts-plain -y -s 512'; + cryptsetup $opts luksFormat ${_device} >$LOG 2>&1; ret=$? ;; + lvm-pv) pvcreate $opts ${_device} >$LOG 2>&1; ret=$? ;; + lvm-vg) vgcreate $opts $_label ${_device} >$LOG 2>&1; ret=$? ;; + lvm-lv) lvcreate $opts -n $_label ${_device} >$LOG 2>&1; ret=$? ;; #$opts is usually something like -L 10G + # don't handle anything else here, we will error later + esac + [ "$ret" != 0 ] && ( show_warning mkfs "Error creating filesystem ${_fstype} on ${_device}" ; return 1 ) + sleep 2 } + + + # $1 filesystem type get_filesystem_program () { [ -z "$1" ] && die_error "get_filesystem_program needs a filesystem id as \$1" - [ $1 = ext2 ] && echo mkfs.ext2 - [ $1 = ext3 ] && echo mkfs.ext3 - [ $1 = reiserfs ] && echo mkreiserfs - [ $1 = xfs ] && echo mkfs.xfs - [ $1 = jfs ] && echo mkfs.jfs - [ $1 = vfat ] && echo mkfs.vfat - [ $1 = lvm-pv ] && echo pvcreate - [ $1 = lvm-vg ] && echo vgcreate - [ $1 = lvg-lv ] && echo lvcreate - [ $1 = dm_crypt ] && echo cryptsetup + [ $1 = ext2 ] && echo mkfs.ext2 && return 0 + [ $1 = ext3 ] && echo mkfs.ext3 && return 0 + [ $1 = reiserfs ] && echo mkreiserfs && return 0 + [ $1 = xfs ] && echo mkfs.xfs && return 0 + [ $1 = jfs ] && echo mkfs.jfs && return 0 + [ $1 = vfat ] && echo mkfs.vfat && return 0 + [ $1 = lvm-pv ] && echo pvcreate && return 0 + [ $1 = lvm-vg ] && echo vgcreate && return 0 + [ $1 = lvg-lv ] && echo lvcreate && return 0 + [ $1 = dm_crypt ] && echo cryptsetup && return 0 + return 1 } -- cgit v1.2.3-54-g00ecf From 61c149b050831fbb3359d4381187ff7486efe40f Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 7 Dec 2008 17:22:20 +0100 Subject: refactor/implementation of process_filesystem(s) WIP --- src/core/libs/lib-blockdevices-filesystems.sh | 179 ++++++++++++++++---------- 1 file changed, 108 insertions(+), 71 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index fcf5ca7..b2beb62 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -368,11 +368,13 @@ process_filesystems () rm -f $TMP_FSTAB generate_filesystem_list - # phase 1: deconstruct all mounts in the vfs that are about to be reconstructed. (and also swapoff where appropriate) + # phase 1: destruct all mounts in the vfs that are about to be reconstructed. (and also swapoff where appropriate) # re-order list so that we umount in the correct order. eg first umount /a/b/c, then /a/b. we sort alphabetically, which has the side-effect of sorting by stringlength, hence by vfs dependencies. # TODO: this is not entirely correct: what if something is mounted in a previous run that is now not anymore in $BLOCK_DATA ? that needs to be cleaned up too. - sort -t \ -k 2 test $TMP_FILESYSTEMS | tac | while read part part_type part_label fs_type fs_create fs_mountpoint fs_mount fs_opts fs_label fs_params + + sort -t \ -k 2 $TMP_FILESYSTEMS | tac | while read part part_type part_label fs_type fs_create fs_mountpoint fs_mount fs_opts fs_label fs_params do + debug "umounting/swapoffing $part" if [ "$fs_type" = swap ] then swapoff $part # could be that it was not swappedon yet. that's not a problem at all. @@ -404,55 +406,114 @@ process_filesystems () # debug "All entries processed..." # fi - # phase 2: deconstruct blockdevices if they would exist already (destroy any lvm things, dm_crypt devices etc in the correct order) - # in theory devices with same names could be stacked on each other with different dependencies. I hope that's not the case for now. In the future maybe we should deconstruct things we need and who are in /etc/mtab or something. - # targets for deconstruction: /dev/mapper devices and lvm PV's who contain no fs, or a non-lvm/dm_crypt fs. TODO: improve regexes - # after deconstructing. the parent must be updated to reflect the vanished child. + + # phase 2: destruct blockdevices if they would exist already (destroy any lvm things, dm_crypt devices etc in the correct order) + # in theory devices with same names could be stacked on each other with different dependencies. I hope that's not the case for now. In the future maybe we should destruct things we need and who are in /etc/mtab or something. + # targets for destruction: /dev/mapper devices and lvm PV's who contain no fs, or a non-lvm/dm_crypt fs. TODO: improve regexes + # after destructing. the parent must be updated to reflect the vanished child. + + # NOTE: an alternative approach could be to just go over all /dev/mapper devices or normal devices that are lvm PV's (by using finddisks etc instead of $BLOCK_DATA, or even better by using finddisks and only doing it if they are in $BLOCK_DATA ) and attempt to destruct. + # do that a few times and the ones that blocked because something else on it will probable have become freed and possible to destruct # TODO: do this as long as devices in this list remains and exist physically - # TODO: abort when there still are physical devices listed, but we tried to deconstruct them already, give error + # TODO: abort when there still are physical devices listed, but we tried to destruct them already, give error egrep '\+|mapper' $BLOCK_DATA | egrep -v ' lvm-pv;| lvm-vg;| lvm-lv;| dm_crypt;' | while read part part_type part_label fs do real_part=${part/+/} if [ -b "$real_part" ] then - debug "Attempting deconstruction of device $part (type $part_type)" - [ "$part_type" = lvm-pv ] && ( pvremove $part || show_warning "process_filesystems blockdevice deconstruction" "Could not pvremove $part") - [ "$part_type" = lvm-vg ] && ( vgremove -f $part || show_warning "process_filesystems blockdevice deconstruction" "Could not vgremove -f $part") - [ "$part_type" = lvm-lv ] && ( lvremove -f $part || show_warning "process_filesystems blockdevice deconstruction" "Could not lvremove -f $part") - [ "$part_type" = dm_crypt ] && ( cryptsetup luksClose $part || show_warning "process_filesystems blockdevice deconstruction" "Could not cryptsetup luksClose $part") + debug "Attempting destruction of device $part (type $part_type)" + [ "$part_type" = lvm-pv ] && ( pvremove $part || show_warning "process_filesystems blockdevice destruction" "Could not pvremove $part") + [ "$part_type" = lvm-vg ] && ( vgremove -f $part || show_warning "process_filesystems blockdevice destruction" "Could not vgremove -f $part") + [ "$part_type" = lvm-lv ] && ( lvremove -f $part || show_warning "process_filesystems blockdevice destruction" "Could not lvremove -f $part") + [ "$part_type" = dm_crypt ] && ( cryptsetup luksClose $part || show_warning "process_filesystems blockdevice destruction" "Could not cryptsetup luksClose $part") else - debug "Skipping deconstruction of device $part (type $part_type) because it doesn't exist" + debug "Skipping destruction of device $part (type $part_type) because it doesn't exist" fi done + # TODO: phase 3: create all blockdevices and filesystems in the correct order (for each fs, the underlying block/lvm/devicemapper device must be available so dependencies must be resolved. for lvm:first pv's, then vg's, then lv's etc) - # TODO: phase 4: mount all filesystems in the vfs in the correct order. (also swapon where appropriate) + while read part part_type part_label fs_type fs_create fs_mountpoint fs_mount fs_opts fs_label fs_params + do + if [ -b "$part" -a "$fs_create" = yes ] + then + # don't ask to mount. we take care of all that ourselves in the next phase + process_filesystem $part $fs_type $fs_create $fs_mountpoint no_mount $fs_opts $fs_label $fs_params + fi + done < $TMP_FILESYSTEMS + + + # phase 4: mount all filesystems in the vfs in the correct order. (also swapon where appropriate) + sort -t \ -k 2 $TMP_FILESYSTEMS | while read part part_type part_label fs_type fs_create fs_mountpoint fs_mount fs_opts fs_label fs_params + do + debug "mounting/swaponning $part" + process_filesystem $part $fs_type no $fs_mountpoint $fs_mount $fs_opts $fs_label $fs_params + done } -# make a filesystem on a blockdevice and mount if requested. + +# make a filesystem on a blockdevice and mount if needed. +# $1 partition +# $2 fs_type +# $3 fs_create (optional. defaults to yes) +# $4 fs_mountpoint (optional. defaults to no_mountpoint) +# $5 fs_mount (optional. defaults to no_mount) +# $6 fs_opts (optional. defaults to no_opts) +# $7 fs_label (optional. defaults to no_label or for lvm volumes who need a label (VG's and LV's) vg1,vg2,lv1 etc). Note that if there's no label for a VG you probably did something wrong, because you probably want LV's on it so you need a label for the VG. +# $8 fs_params (optional. defaults to no_params) + process_filesystem () { - [ -z "$1" ] && die_error "process_filesystem needs a FS entry" - debug "process_filesystem $1" - line=$1 - BLOCK=$( echo $line | cut -d: -f 1) - FSTYPE=$(echo $line | cut -d: -f 2) - MP=$( echo $line | cut -d: -f 3) # can be null for lvm/dm_crypt stuff - DOMKFS=$(echo $line | cut -d: -f 4) - DOMNT=$( echo $line | cut -d: -f 5) - OPTS=$( echo $line | cut -d: -f 6) - - if [ "$DOMKFS" = yes ] + [ -z "$1" -o ! -b "$1" ] && die_error "process_filesystem needs a partition as \$1" + [ -z "$2" ] && die_error "process_filesystem needs a filesystem type as \$2" + debug "process_filesystem $@" + part=$1 + fs_type=$2 + fs_create=${3:-yes} + fs_mountpoint=${4:-no_mountpoint} + fs_mount=${5:-no_mount} + fs_opts=${6:-no_opts} + fs_label=${7:-no_label} + fs_params=${8:-no_params} + + # Create the FS + if [ "$fs_create" = yes ] then - _mkfs $BLOCK $FSTYPE $OPTS || return 1 + if ! program=`get_filesystem_program $fs_type` + then + show_warning "process_filesystem error" "Cannot determine filesystem program for $fs_type on $part. Not creating this FS" + return 1 + fi + [ "$fs_label" = no_label ] && [ "$fs_type" = lvm-vg -o "$fs_type" = lvm-pv ] && fs_label=default #TODO. implement the incrementing numbers label for lvm vg's and lv's + + ret=0 + case ${_fstype} in + xfs) mkfs.xfs -f ${_device} $opts >$LOG 2>&1; ret=$? ;; + jfs) yes | mkfs.jfs ${_device} $opts >$LOG 2>&1; ret=$? ;; + reiserfs) yes | mkreiserfs ${_device} $opts >$LOG 2>&1; ret=$? ;; + ext2) mke2fs "${_device}" $opts >$LOG 2>&1; ret=$? ;; + ext3) mke2fs -j ${_device} $opts >$LOG 2>&1; ret=$? ;; + vfat) mkfs.vfat ${_device} $opts >$LOG 2>&1; ret=$? ;; + swap) mkswap ${_device} $opts >$LOG 2>&1; ret=$? ;; + dm_crypt) [ -z "$opts" ] && opts='-c aes-xts-plain -y -s 512'; + cryptsetup $opts luksFormat ${_device} >$LOG 2>&1; ret=$? ;; + cryptsetup luksOpen $BLOCK $dst >$LOG 2>&1; ret=$? || ( show_warning 'cryptsetup' "Error luksOpening $BLOCK on $dst" ) + lvm-pv) pvcreate $opts ${_device} >$LOG 2>&1; ret=$? ;; + lvm-vg) vgcreate $opts $_label ${_device} >$LOG 2>&1; ret=$? ;; + lvm-lv) lvcreate $opts -n $_label ${_device} >$LOG 2>&1; ret=$? ;; #$opts is usually something like -L 10G + # don't handle anything else here, we will error later + esac + [ "$ret" -gt 0 ] && ( show_warning "process_filesystem error" "Error creating filesystem $fs_type on $part." ; return 1 ) + sleep 2 fi - if [ "$DOMNT" = runtime -o "$DOMNT" = target ] + # Mount it, if requested + if [ "$DOMNT" = runtime -o "$DOMNT" = target ] #TODO: ONLY RAW TYPE I THINK then if [ "$FSTYPE" = swap ] then @@ -461,7 +522,6 @@ process_filesystem () elif [ "$FSTYPE" = dm_crypt ] then debug "cryptsetup luksOpen $BLOCK $dst" - cryptsetup luksOpen $BLOCK $dst >$LOG 2>&1 || ( show_warning 'cryptsetup' "Error luksOpening $BLOCK on $dst" ; return 1 ) else [ "$DOMNT" = runtime ] && dst=$MP [ "$DOMNT" = target ] && dst=$var_TARGET_DIR$MP @@ -470,7 +530,17 @@ process_filesystem () fi fi - # add to temp fstab + if [ "$fs_type" = swap ] + then + swapon $part + elif [ "$fs_mountpoint" != no_mount ] + then + [ "$fs_mount" = target ] && fs_mountpoint=$var_TARGET_DIR$fs_mountpoint + mount $part $fs_mountpoint + fi + + + # Add to temp fstab, if not already there: TODO: check if it's already there if [ $MP != null -a $DOMNT = target ] then local _uuid="$(getuuid $BLOCK)" @@ -486,39 +556,6 @@ process_filesystem () fi return 0 - - local _device=$1 - local _fstype=$2 - local _label=$3 - local opts=$4 - - debug "_mkfs: _device: $1, fstype: $2, label: $3, opts: $4" - # make sure the fstype is one we can handle TODO: we can use get_filesystem_program for that - local knownfs=0 - for fs in xfs jfs reiserfs ext2 ext3 vfat swap dm_crypt lvm-pv lvm-vg lvm-lv; do - [ "${_fstype}" = "${fs}" ] && knownfs=1 && break - done - - [ -z "$_label" ] && _label=default #TODO. when creating more then 1 VG we will get errors that it exists already. we should (per type) add incrementing numbers or something - [ $knownfs -eq 0 ] && ( show_warning 'mkfs' "unknown fstype ${_fstype} for ${_device}" ; return 1 ) - local ret - case ${_fstype} in - xfs) mkfs.xfs -f ${_device} $opts >$LOG 2>&1; ret=$? ;; - jfs) yes | mkfs.jfs ${_device} $opts >$LOG 2>&1; ret=$? ;; - reiserfs) yes | mkreiserfs ${_device} $opts >$LOG 2>&1; ret=$? ;; - ext2) mke2fs "${_device}" $opts >$LOG 2>&1; ret=$? ;; - ext3) mke2fs -j ${_device} $opts >$LOG 2>&1; ret=$? ;; - vfat) mkfs.vfat ${_device} $opts >$LOG 2>&1; ret=$? ;; - swap) mkswap ${_device} $opts >$LOG 2>&1; ret=$? ;; - dm_crypt) [ -z "$opts" ] && opts='-c aes-xts-plain -y -s 512'; - cryptsetup $opts luksFormat ${_device} >$LOG 2>&1; ret=$? ;; - lvm-pv) pvcreate $opts ${_device} >$LOG 2>&1; ret=$? ;; - lvm-vg) vgcreate $opts $_label ${_device} >$LOG 2>&1; ret=$? ;; - lvm-lv) lvcreate $opts -n $_label ${_device} >$LOG 2>&1; ret=$? ;; #$opts is usually something like -L 10G - # don't handle anything else here, we will error later - esac - [ "$ret" != 0 ] && ( show_warning mkfs "Error creating filesystem ${_fstype} on ${_device}" ; return 1 ) - sleep 2 } @@ -529,15 +566,15 @@ process_filesystem () get_filesystem_program () { [ -z "$1" ] && die_error "get_filesystem_program needs a filesystem id as \$1" - [ $1 = ext2 ] && echo mkfs.ext2 && return 0 - [ $1 = ext3 ] && echo mkfs.ext3 && return 0 + [ $1 = ext2 ] && echo mkfs.ext2 && return 0 + [ $1 = ext3 ] && echo mkfs.ext3 && return 0 [ $1 = reiserfs ] && echo mkreiserfs && return 0 - [ $1 = xfs ] && echo mkfs.xfs && return 0 - [ $1 = jfs ] && echo mkfs.jfs && return 0 - [ $1 = vfat ] && echo mkfs.vfat && return 0 - [ $1 = lvm-pv ] && echo pvcreate && return 0 - [ $1 = lvm-vg ] && echo vgcreate && return 0 - [ $1 = lvg-lv ] && echo lvcreate && return 0 + [ $1 = xfs ] && echo mkfs.xfs && return 0 + [ $1 = jfs ] && echo mkfs.jfs && return 0 + [ $1 = vfat ] && echo mkfs.vfat && return 0 + [ $1 = lvm-pv ] && echo pvcreate && return 0 + [ $1 = lvm-vg ] && echo vgcreate && return 0 + [ $1 = lvg-lv ] && echo lvcreate && return 0 [ $1 = dm_crypt ] && echo cryptsetup && return 0 return 1 } -- cgit v1.2.3-54-g00ecf From 15b4f74b63f636693c71c658866d43fa070c8f9f Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 7 Dec 2008 17:59:06 +0100 Subject: refactor/implementation of process_filesystem(s) WIP.. it might even start to work sort off.. + fs_params for dm_crypt in lib-ui-interactive --- src/core/libs/lib-blockdevices-filesystems.sh | 91 +++++++++++++-------------- src/core/libs/lib-ui-interactive.sh | 9 ++- 2 files changed, 51 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index b2beb62..b03e2b0 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -449,8 +449,11 @@ process_filesystems () # phase 4: mount all filesystems in the vfs in the correct order. (also swapon where appropriate) sort -t \ -k 2 $TMP_FILESYSTEMS | while read part part_type part_label fs_type fs_create fs_mountpoint fs_mount fs_opts fs_label fs_params do - debug "mounting/swaponning $part" - process_filesystem $part $fs_type no $fs_mountpoint $fs_mount $fs_opts $fs_label $fs_params + if [ "$part_type" = raw ] + then + debug "mounting/swaponning $part" + process_filesystem $part $fs_type no $fs_mountpoint $fs_mount $fs_opts $fs_label $fs_params + fi done @@ -492,66 +495,61 @@ process_filesystem () [ "$fs_label" = no_label ] && [ "$fs_type" = lvm-vg -o "$fs_type" = lvm-pv ] && fs_label=default #TODO. implement the incrementing numbers label for lvm vg's and lv's ret=0 - case ${_fstype} in - xfs) mkfs.xfs -f ${_device} $opts >$LOG 2>&1; ret=$? ;; - jfs) yes | mkfs.jfs ${_device} $opts >$LOG 2>&1; ret=$? ;; - reiserfs) yes | mkreiserfs ${_device} $opts >$LOG 2>&1; ret=$? ;; - ext2) mke2fs "${_device}" $opts >$LOG 2>&1; ret=$? ;; - ext3) mke2fs -j ${_device} $opts >$LOG 2>&1; ret=$? ;; - vfat) mkfs.vfat ${_device} $opts >$LOG 2>&1; ret=$? ;; - swap) mkswap ${_device} $opts >$LOG 2>&1; ret=$? ;; - dm_crypt) [ -z "$opts" ] && opts='-c aes-xts-plain -y -s 512'; - cryptsetup $opts luksFormat ${_device} >$LOG 2>&1; ret=$? ;; - cryptsetup luksOpen $BLOCK $dst >$LOG 2>&1; ret=$? || ( show_warning 'cryptsetup' "Error luksOpening $BLOCK on $dst" ) - lvm-pv) pvcreate $opts ${_device} >$LOG 2>&1; ret=$? ;; - lvm-vg) vgcreate $opts $_label ${_device} >$LOG 2>&1; ret=$? ;; - lvm-lv) lvcreate $opts -n $_label ${_device} >$LOG 2>&1; ret=$? ;; #$opts is usually something like -L 10G + #TODO: health checks on $fs_params etc + case ${_fstype} in #TODO: implement label, opts etc decently + xfs) mkfs.xfs -f $part $opts >$LOG 2>&1; ret=$? ;; + jfs) yes | mkfs.jfs $part $opts >$LOG 2>&1; ret=$? ;; + reiserfs) yes | mkreiserfs $part $opts >$LOG 2>&1; ret=$? ;; + ext2) mke2fs "$part" $opts >$LOG 2>&1; ret=$? ;; + ext3) mke2fs -j $part $opts >$LOG 2>&1; ret=$? ;; + vfat) mkfs.vfat $part $opts >$LOG 2>&1; ret=$? ;; + swap) mkswap $part $opts >$LOG 2>&1; ret=$? ;; + dm_crypt) [ -z "$fs_params" ] && fs_params='-c aes-xts-plain -y -s 512'; + fs_params=${fs_params//_/ } + cryptsetup $fs_params $opts luksFormat $part >$LOG 2>&1; ret=$? ;; + cryptsetup luksOpen $part /dev/mapper/$fs_label >$LOG 2>&1; ret=$? || ( show_warning 'cryptsetup' "Error luksOpening $part on /dev/mapper/$fs_label" ) + lvm-pv) pvcreate $opts $part >$LOG 2>&1; ret=$? ;; + lvm-vg) # $fs_params: ':'-separated list of PV's + vgcreate $opts $_label ${fs_params//:/ } >$LOG 2>&1; ret=$? ;; + lvm-lv) # $fs_params = size string (eg '5G') + lvcreate -L $fs_params $fs_opts -n $_label $part >$LOG 2>&1; ret=$? ;; #$opts is usually something like -L 10G # don't handle anything else here, we will error later esac [ "$ret" -gt 0 ] && ( show_warning "process_filesystem error" "Error creating filesystem $fs_type on $part." ; return 1 ) sleep 2 fi - # Mount it, if requested - if [ "$DOMNT" = runtime -o "$DOMNT" = target ] #TODO: ONLY RAW TYPE I THINK + # Mount it, if requested. Note that it's your responsability to figure out if you want this or not before calling me. This will only work for 'raw' filesystems (ext,reiser,xfs, swap etc. not lvm stuff,dm_crypt etc) + if [ "$fs_mount" = runtime -o "$fs_mount" = target ] then - if [ "$FSTYPE" = swap ] - then - debug "swaponning $BLOCK" - swapon $BLOCK >$LOG 2>&1 || ( show_warning 'Swapon' "Error activating swap: swapon $BLOCK" ; return 1 ) - elif [ "$FSTYPE" = dm_crypt ] + if [ "$fs_type" = swap ] then - debug "cryptsetup luksOpen $BLOCK $dst" + debug "swaponning $part" + swapon $part >$LOG 2>&1 || ( show_warning 'Swapon' "Error activating swap: swapon $part" ; return 1 ) else - [ "$DOMNT" = runtime ] && dst=$MP - [ "$DOMNT" = target ] && dst=$var_TARGET_DIR$MP - debug "mounting $BLOCK on $dst" - mount -t $FSTYPE $BLOCK $dst >$LOG 2>&1 || ( show_warning 'Mount' "Error mounting $BLOCK on $dst" ; return 1 ) + [ "$fs_mount" = runtime ] && dst=$fs_mountpoint + [ "$fs_mount" = target ] && dst=$var_TARGET_DIR$fs_mountpoint + debug "mounting $part on $dst" + mount -t $fs_type $part $dst >$LOG 2>&1 || ( show_warning 'Mount' "Error mounting $part on $dst" ; return 1 ) fi fi - if [ "$fs_type" = swap ] - then - swapon $part - elif [ "$fs_mountpoint" != no_mount ] - then - [ "$fs_mount" = target ] && fs_mountpoint=$var_TARGET_DIR$fs_mountpoint - mount $part $fs_mountpoint - fi - - # Add to temp fstab, if not already there: TODO: check if it's already there - if [ $MP != null -a $DOMNT = target ] + # Add to temp fstab, if not already there. + if [ $fs_mountpoint != no_mountpoint -a $fs_mount = target ] then - local _uuid="$(getuuid $BLOCK)" + local _uuid="$(getuuid $part)" if [ -n "${_uuid}" ]; then _device="UUID=${_uuid}" fi - echo -n "$BLOCK ${_mountpoint} $FSTYPE defaults 0 " >>$TMP_FSTAB - if [ "$FSTYPE" = "swap" ]; then - echo "0" >>$TMP_FSTAB - else - echo "1" >>$TMP_FSTAB + if ! grep -q "$part $fs_mountpoint $fs_type defaults 0 " $TMP_FSTAB + then + echo -n "$part $fs_mountpoint $fs_type defaults 0 " >> $TMP_FSTAB + if [ "$FSTYPE" = "swap" ]; then + echo "0" >>$TMP_FSTAB + else + echo "1" >>$TMP_FSTAB + fi fi fi @@ -559,9 +557,6 @@ process_filesystem () } - - - # $1 filesystem type get_filesystem_program () { diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 1809beb..2d46872 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -358,6 +358,13 @@ interactive_filesystem () ask_string "Enter the size for this $fs_type on $part (suffix K,M,G,T,P,E. default is M)" "$default" || return 1 fs_params=$ANSWER_STRING fi + if [ "$fs_type" = dm_crypt ] + then + [ -z "$fs_params" ] && default='-c aes-xts-plain -y -s 512' + [ -n "$fs_params" ] && default="${fs_params//_/ }" + ask_string "Enter the options for this $fs_type on $part" "$default" || return 1 + fs_params="${ANSWER_STRING// /_}" + fi # ask opts default= @@ -406,7 +413,7 @@ interactive_filesystems() { # $BLOCK_DATA entry. easily parsable.: # type label/no_label /no_fs # FS-string: - # type;recreate;mountpoint;mount?(target,runtime,no);opts;label;params[|FS-string|...] where opts have _'s instead of whitespace + # type;recreate;mountpoint;mount?(target,runtime,no);opts;label;params[|FS-string|...] where opts/params have _'s instead of whitespace if needed findpartitions 0 'no_fs' ' raw no_label' > $BLOCK_DATA -- cgit v1.2.3-54-g00ecf From 22138bec81f6278551a5a0b5c839b711818b3d35 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 7 Dec 2008 18:02:53 +0100 Subject: syntax fixes --- src/core/libs/lib-blockdevices-filesystems.sh | 4 ++-- src/core/libs/lib-ui.sh | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index b03e2b0..5421801 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -506,8 +506,8 @@ process_filesystem () swap) mkswap $part $opts >$LOG 2>&1; ret=$? ;; dm_crypt) [ -z "$fs_params" ] && fs_params='-c aes-xts-plain -y -s 512'; fs_params=${fs_params//_/ } - cryptsetup $fs_params $opts luksFormat $part >$LOG 2>&1; ret=$? ;; - cryptsetup luksOpen $part /dev/mapper/$fs_label >$LOG 2>&1; ret=$? || ( show_warning 'cryptsetup' "Error luksOpening $part on /dev/mapper/$fs_label" ) + cryptsetup $fs_params $opts luksFormat $part >$LOG 2>&1; ret=$? + cryptsetup luksOpen $part /dev/mapper/$fs_label >$LOG 2>&1; ret=$? || ( show_warning 'cryptsetup' "Error luksOpening $part on /dev/mapper/$fs_label" ) ;; lvm-pv) pvcreate $opts $part >$LOG 2>&1; ret=$? ;; lvm-vg) # $fs_params: ':'-separated list of PV's vgcreate $opts $_label ${fs_params//:/ } >$LOG 2>&1; ret=$? ;; diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 9191998..517efe3 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -153,6 +153,7 @@ ask_datetime () # DD/MM/YYYY hh:mm:ss -> YYYY-MM-DD hh:mm:ss ( date string format, set like date -s $ANSWER_DATETIME) ANSWER_DATETIME="$(echo "$_date" "$_time" | sed 's#\(..\)/\(..\)/\(....\) \(..\):\(..\):\(..\)#\3-\2-\1 \4:\5:\6#g')" elif [ "$var_UI_TYPE" = cli ] + then ask_string "Enter date [YYYY-MM-DD hh:mm:ss]" ANSWER_DATETIME=$ANSWER_STRING fi -- cgit v1.2.3-54-g00ecf From 571aa60fb30d1141e93a7b2d6f4d71e149d7e8d2 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 7 Dec 2008 18:05:22 +0100 Subject: syntax fixes --- src/core/libs/lib-ui-interactive.sh | 2 +- src/core/libs/lib-ui.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 2d46872..7eccadf 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -90,7 +90,7 @@ interactive_set_clock() ask_datetime # save the time - date -s $ANSWER_DATETIME || show_warning "Date/time setting failed" "Something went wrong when doing date -s $ANSWER_DATETIME" + date -s "$ANSWER_DATETIME" || show_warning "Date/time setting failed" "Something went wrong when doing date -s $ANSWER_DATETIME" /sbin/hwclock --systohc $HWCLOCK_PARAMS --noadjfile return 0 diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 517efe3..a1a3528 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -150,7 +150,7 @@ ask_datetime () # DD/MM/YYYY hh:mm:ss -> MMDDhhmmYYYY.ss (date default format, set like date $ANSWER_DATETIME) Not enabled because there is no use for it i think. # ANSWER_DATETIME=$(echo "$_date" "$_time" | sed 's#\(..\)/\(..\)/\(....\) \(..\):\(..\):\(..\)#\2\1\4\5\3\6#g') - # DD/MM/YYYY hh:mm:ss -> YYYY-MM-DD hh:mm:ss ( date string format, set like date -s $ANSWER_DATETIME) + # DD/MM/YYYY hh:mm:ss -> YYYY-MM-DD hh:mm:ss ( date string format, set like date -s "$ANSWER_DATETIME") ANSWER_DATETIME="$(echo "$_date" "$_time" | sed 's#\(..\)/\(..\)/\(....\) \(..\):\(..\):\(..\)#\3-\2-\1 \4:\5:\6#g')" elif [ "$var_UI_TYPE" = cli ] then -- cgit v1.2.3-54-g00ecf From fc7280a2f861de1c9158b15d40f201228f8dc16e Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 7 Dec 2008 18:50:13 +0100 Subject: cleanup interactive_autoprepare + better suppor for min/max in ask_number and support SI/IEC formats in get_blockdevice_size --- src/core/libs/lib-blockdevices-filesystems.sh | 17 +++- src/core/libs/lib-ui-interactive.sh | 113 ++++++++++---------------- src/core/libs/lib-ui.sh | 10 ++- 3 files changed, 65 insertions(+), 75 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index 5421801..9e79454 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -576,11 +576,20 @@ get_filesystem_program () # $1 blockdevice -# output will be in $BLOCKDEVICE_SIZE in MB +# $2 standard SI for 1000*n, IEC for 1024*n (optional. defaults to SI) +# output will be in $BLOCKDEVICE_SIZE in MB/MiB get_blockdevice_size () { [ -b "$1" ] || die_error "get_blockdevice_size needs a blockdevice as \$1 ($1 given)" - blocks=`fdisk -s $1` || show_warning "Fdisk problem" "Something failed when trying to do fdisk -s $1" - #NOTE: on some interwebs they say 1 block = 512B, on other internets they say 1 block = 1kiB. 1kiB seems to work for me. don't sue me if it doesn't for you - BLOCKDEVICE_SIZE=$(($blocks/1024)) + standard=${2:-SI} + + if [ "$2" = SI ] + then + BLOCKDEVICE_SIZE=$(hdparm -I $1 | grep -F '1000*1000' | sed "s/^.*:[ \t]*\([0-9]*\) MBytes.*$/\1/") + elif [ "$2" = IEC ] + then + blocks=`fdisk -s $1` || show_warning "Fdisk problem" "Something failed when trying to do fdisk -s $1" + #NOTE: on some interwebs they say 1 block = 512B, on other internets they say 1 block = 1kiB. 1kiB seems to work for me. don't sue me if it doesn't for you + BLOCKDEVICE_SIZE=$(($blocks/1024)) + fi } diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 7eccadf..dbdb299 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -99,79 +99,52 @@ interactive_set_clock() interactive_autoprepare() { - DISCS=$(finddisks) - if [ $(echo $DISCS | wc -w) -gt 1 ]; then - notify "Available Disks:\n\n$(_getavaildisks)\n" - ask_option no "Select the hard drive to use" $(finddisks 1 _) || return 1 - DISC=$ANSWER_OPTION - else - DISC=$DISCS - fi - SET_DEFAULTFS="" - BOOT_PART_SET="" - SWAP_PART_SET="" - ROOT_PART_SET="" - CHOSEN_FS="" - # get just the disk size in 1000*1000 MB - DISC_SIZE=$(hdparm -I /dev/sda | grep -F '1000*1000' | sed "s/^.*:[ \t]*\([0-9]*\) MBytes.*$/\1/") - while [ "$SET_DEFAULTFS" = "" ]; do - FSOPTS="ext2 ext2 ext3 ext3" - [ "$(which mkreiserfs 2>/dev/null)" ] && FSOPTS="$FSOPTS reiserfs Reiser3" - [ "$(which mkfs.xfs 2>/dev/null)" ] && FSOPTS="$FSOPTS xfs XFS" - [ "$(which mkfs.jfs 2>/dev/null)" ] && FSOPTS="$FSOPTS jfs JFS" - while [ "$BOOT_PART_SET" = "" ]; do - ask_string "Enter the size (MB) of your /boot partition. Minimum value is 16.\n\nDisk space left: $DISC_SIZE MB" "32" || return 1 - BOOT_PART_SIZE=$ANSWER_STRING - if [ "$BOOT_PART_SIZE" = "" ]; then - notify "ERROR: You have entered an invalid size, please enter again." - else - if [ "$BOOT_PART_SIZE" -ge "$DISC_SIZE" -o "$SBOOT_PART_SIZE" = "$DISC_SIZE" ]; then - notify "ERROR: You have entered a too large size, please enter again." - elif [ "$BOOT_PART_SIZE" -lt "16" ]; - then - notify "ERROR: You have entered a too small size, please enter again." - else - BOOT_PART_SET=1 - fi - fi - done - DISC_SIZE=$(($DISC_SIZE-$BOOT_PART_SIZE)) - while [ "$SWAP_PART_SET" = "" ]; do - ask_string "Enter the size (MB) of your swap partition. Minimum value is > 0.\n\nDisk space left: $DISC_SIZE MB" "256" || return 1 - SWAP_PART_SIZE=$ANSWER_STRING - if [ "$SWAP_PART_SIZE" = "" -o "$SWAP_PART_SIZE" -le "0" ]; then - notify "ERROR: You have entered an invalid size, please enter again." - else - if [ "$SWAP_PART_SIZE" -ge "$DISC_SIZE" ]; then - notify "ERROR: You have entered a too large size, please enter again." - else - SWAP_PART_SET=1 - fi - fi - done - DISC_SIZE=$(($DISC_SIZE-$SWAP_PART_SIZE)) - while [ "$ROOT_PART_SET" = "" ]; do - ask_string "Enter the size (MB) of your / partition. The /home partition will use the remaining space.\n\nDisk space left: $DISC_SIZE MB" "7500" || return 1 - ROOT_PART_SIZE=$ANSWER_STRING - if [ "$ROOT_PART_SIZE" = "" -o "$ROOT_PART_SIZE" -le "0" ]; then - notify "ERROR: You have entered an invalid size, please enter again." - else - if [ "$ROOT_PART_SIZE" -ge "$DISC_SIZE" ]; then - notify "ERROR: You have entered a too large size, please enter again." - else - ask_yesno "$(($DISC_SIZE-$ROOT_PART_SIZE)) MB will be used for your /home partition. Is this OK?" && ROOT_PART_SET=1 - fi - fi + DISCS=$(finddisks) + if [ $(echo $DISCS | wc -w) -gt 1 ] + then + notify "Available Disks:\n\n$(_getavaildisks)\n" + ask_option no "Select the hard drive to use" $(finddisks 1 _) || return 1 + DISC=$ANSWER_OPTION + else + DISC=$DISCS + fi + + get_blockdevice_size $DISC SI + FSOPTS= + which `get_filesystem_program ext2` &>/dev/null && FSOPTS="$FSOPTS ext2 Ext2" + which `get_filesystem_program ext3` &>/dev/null && FSOPTS="$FSOPTS ext3 Ext3" + which `get_filesystem_program reiserfs` &>/dev/null && FSOPTS="$FSOPTS reiserfs Reiser3" + which `get_filesystem_program xfs` &>/dev/null && FSOPTS="$FSOPTS xfs XFS" + which `get_filesystem_program jfs` &>/dev/null && FSOPTS="$FSOPTS jfs JFS" + which `get_filesystem_program vfat` &>/dev/null && FSOPTS="$FSOPTS vfat VFAT" + + ask_number "Enter the size (MB) of your /boot partition. Recommended size: 100MB\n\nDisk space left: $BLOCKDEVICE_SIZE MB" 16 $BLOCKDEVICE_SIZE || return 1 + BOOT_PART_SIZE=$ANSWER_NUMBER + + BLOCKDEVICE_SIZE=$(($BLOCKDEVICE_SIZE-$BOOT_PART_SIZE)) + + ask_number "Enter the size (MB) of your swap partition. Recommended size: 256MB\n\nDisk space left: $BLOCKDEVICE_SIZE MB" 1 $BLOCKDEVICE_SIZE || return 1 + SWAP_PART_SIZE=$ANSWER_NUMBER + + BLOCKDEVICE_SIZE=$(($BLOCKDEVICE_SIZE-$SWAP_PART_SIZE)) + + ROOT_PART_SET="" + while [ "$ROOT_PART_SET" = "" ] + do + ask_number "Enter the size (MB) of your / partition. Recommended size:7500. The /home partition will use the remaining space.\n\nDisk space left: $BLOCKDEVICE_SIZE MB" 1 $BLOCKDEVICE_SIZE || return 1 + ROOT_PART_SIZE=$ANSWER_NUMBER + ask_yesno "$(($BLOCKDEVICE_SIZE-$ROOT_PART_SIZE)) MB will be used for your /home partition. Is this OK?" && ROOT_PART_SET=1 done - while [ "$CHOSEN_FS" = "" ]; do - ask_option "Select a filesystem for / and /home:" $FSOPTS || return 1 - FSTYPE=$ANSWER_OPTION - ask_yesno "$FSTYPE will be used for / and /home. Is this OK?" && CHOSEN_FS=1 + + CHOSEN_FS="" + while [ "$CHOSEN_FS" = "" ] + do + ask_option "Select a filesystem for / and /home:" $FSOPTS || return 1 + FSTYPE=$ANSWER_OPTION + ask_yesno "$FSTYPE will be used for / and /home. Is this OK?" yes && CHOSEN_FS=1 done - SET_DEFAULTFS=1 - done - ask_yesno "$DISC will be COMPLETELY ERASED! Are you absolutely sure?" || return 1 + ask_yesno "$DISC will be COMPLETELY ERASED! Are you absolutely sure?" || return 1 # we assume a /dev/hdX format (or /dev/sdX) diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index a1a3528..2a83d17 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -302,7 +302,15 @@ _dia_ask_number () then show_warning "$ANSWER_NUMBER is not a number! try again." else - break + if [ -n "$3" -a $ANSWER_NUMBER -gt $3 ] + then + show_warning "$ANSWER_NUMBER is bigger then the maximum,$3! try again." + elif [ -n "$2" -a $ANSWER_NUMBER -lt $2 ] + then + show_warning "$ANSWER_NUMBER is smaller then the minimum,$2! try again." + else + break + fi fi done echo "$ANSWER_NUMBER" -- cgit v1.2.3-54-g00ecf From f67c3e73ad3784f053afaaa03b5fe04d061ad125 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 7 Dec 2008 19:03:14 +0100 Subject: support for swap can be useful --- src/core/libs/lib-blockdevices-filesystems.sh | 1 + src/core/libs/lib-ui-interactive.sh | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index 9e79454..df055de 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -561,6 +561,7 @@ process_filesystem () get_filesystem_program () { [ -z "$1" ] && die_error "get_filesystem_program needs a filesystem id as \$1" + [ $1 = swap ] && echo mkswap && return 0 [ $1 = ext2 ] && echo mkfs.ext2 && return 0 [ $1 = ext3 ] && echo mkfs.ext3 && return 0 [ $1 = reiserfs ] && echo mkreiserfs && return 0 diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index dbdb299..a6b94fb 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -133,7 +133,7 @@ interactive_autoprepare() do ask_number "Enter the size (MB) of your / partition. Recommended size:7500. The /home partition will use the remaining space.\n\nDisk space left: $BLOCKDEVICE_SIZE MB" 1 $BLOCKDEVICE_SIZE || return 1 ROOT_PART_SIZE=$ANSWER_NUMBER - ask_yesno "$(($BLOCKDEVICE_SIZE-$ROOT_PART_SIZE)) MB will be used for your /home partition. Is this OK?" && ROOT_PART_SET=1 + ask_yesno "$(($BLOCKDEVICE_SIZE-$ROOT_PART_SIZE)) MB will be used for your /home partition. Is this OK?" yes && ROOT_PART_SET=1 done CHOSEN_FS="" @@ -257,6 +257,7 @@ interactive_filesystem () # Determine which filesystems/blockdevices are possible for this blockdevice FSOPTS= + [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which `get_filesystem_program swap` &>/dev/null && FSOPTS="$FSOPTS swap Swap" [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which `get_filesystem_program ext2` &>/dev/null && FSOPTS="$FSOPTS ext2 Ext2" [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which `get_filesystem_program ext3` &>/dev/null && FSOPTS="$FSOPTS ext3 Ext3" [ $part_type = raw -o $part_type = lvm-lv -o $part_type = dm_crypt ] && which `get_filesystem_program reiserfs` &>/dev/null && FSOPTS="$FSOPTS reiserfs Reiser3" @@ -282,7 +283,7 @@ interactive_filesystem () fi # ask mountpoint, if relevant - if [[ $fs_type != lvm-* && "$fs_type" != dm_crypt ]] + if [[ $fs_type != lvm-* && "$fs_type" != dm_crypt && $fs_type != swap ]] then default= [ -n "$fs_mountpoint" ] && default="$fs_mountpoint" -- cgit v1.2.3-54-g00ecf From 3a01621b8382964d348c35084840c8404f8257a9 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 7 Dec 2008 19:08:23 +0100 Subject: todo updates --- src/core/libs/lib-ui-interactive.sh | 4 ++-- src/core/libs/lib-ui.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index a6b94fb..3652610 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -133,7 +133,7 @@ interactive_autoprepare() do ask_number "Enter the size (MB) of your / partition. Recommended size:7500. The /home partition will use the remaining space.\n\nDisk space left: $BLOCKDEVICE_SIZE MB" 1 $BLOCKDEVICE_SIZE || return 1 ROOT_PART_SIZE=$ANSWER_NUMBER - ask_yesno "$(($BLOCKDEVICE_SIZE-$ROOT_PART_SIZE)) MB will be used for your /home partition. Is this OK?" yes && ROOT_PART_SET=1 + ask_yesno "$(($BLOCKDEVICE_SIZE-$ROOT_PART_SIZE)) MB will be used for your /home partition. Is this OK?" yes && ROOT_PART_SET=1 #TODO: when doing yes, cli mode prints option JFS all the time, dia mode goes back to disks menu done CHOSEN_FS="" @@ -273,7 +273,7 @@ interactive_filesystem () fsopts=($FSOPTS); if [ ${#fsopts[*]} -lt 4 ] # less then 4 words in the $FSOPTS string. eg only one option then - notify "Automatically picked the ${fsopts[1]} filesystem. It's the only option for $part_type blockdevices" + notify "Automatically picked the ${fsopts[1]} filesystem. It's the only option for $part_type blockdevices" #TODO: ${fsopts[1]} is empty when making an LV on a VG fs_type=${fsopts[0]} else default= diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 2a83d17..bddb739 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -329,7 +329,7 @@ _dia_ask_option () DIA_MENU_TITLE=$2 shift 2 - _dia_DIALOG $DEFAULT --colors --title " $DIA_MENU_TITLE " --menu "$DIA_MENU_TEXT" 16 55 8 "$@" 2>$ANSWER + _dia_DIALOG $DEFAULT --colors --title " $DIA_MENU_TITLE " --menu "$DIA_MENU_TEXT" 16 55 8 "$@" 2>$ANSWER #TODO: size not good! dynamically adapt? ret=$? ANSWER_OPTION=`cat $ANSWER` echo $ANSWER_OPTION -- cgit v1.2.3-54-g00ecf