From 4f2ee73047ad16746be74f8f245aff662cac19ae Mon Sep 17 00:00:00 2001 From: Lucien Mueller Date: Wed, 5 Dec 2018 14:31:23 +0100 Subject: [PATCH] nmhw-auto-part: improved nmhw-auto-part tool help and verbosity. BugzID: 54511 Signed-off-by: Lucien Mueller --- .../nmhw-auto-part/nmhw-auto-part | 77 +++++++++++-------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/recipes-support/nmhw-auto-part/nmhw-auto-part/nmhw-auto-part b/recipes-support/nmhw-auto-part/nmhw-auto-part/nmhw-auto-part index e51fd82..e1fe598 100644 --- a/recipes-support/nmhw-auto-part/nmhw-auto-part/nmhw-auto-part +++ b/recipes-support/nmhw-auto-part/nmhw-auto-part/nmhw-auto-part @@ -1,12 +1,5 @@ #!/bin/bash - -# This scripts expands 2. (otaroot) partition on a blockdevice and appends an additional partition to the device. -# Arguments: -# $1 = device to use: e.g. /dev/sdb /dev/mmcblk1 -# $2 = size of the otaroot in MB -# $3 = 'data' or 'overlay' type of partition to append -# $4 = size of the appended partition in MB (set to 0 to fill) - +# This scripts expands the first partition on a block device and appends an additional partition to the device. green="\e[32m" normal="\e[0m" @@ -20,14 +13,14 @@ device_available(){ local partn_first partn_first=${partdevice_first: -1} if (( $partn_first > 1 )) ; then - echo "Error: Device $device has already too many partitions." + echo "Device $device has already too many partitions." echo "Please use this script only once." exit 1 else return 0 fi else - echo "Error: Device $device not available" + echo "Device $device not available." return 1 fi } @@ -183,11 +176,11 @@ interactive_mode(){ d=0 while [ $d -eq 0 ]; do - printf "Input device to expand $bold$green[/dev/mmcblk1]$normal:\n" + printf "Enter device to expand $bold$green[/dev/mmcblk1]$normal:\n" read device if [ -z ${device} ] ; then device="/dev/mmcblk1" - printf "Using $device\n" + printf "Using $device\n\n" fi device_available $device && d=1 done @@ -206,31 +199,31 @@ interactive_mode(){ d=0 while [ $d -eq 0 ]; do - printf "Input size of the otaroot in MB $bold$green[1024]$normal:\n" + printf "Enter size of the first partition in MB. 0 = keep current size. $bold$green[1024]$normal:\n" read newrootsize if [ -z ${newrootsize} ] ; then newrootsize="1024" - printf "Using $newrootsize\n" + printf "Using $newrootsize\n\n" fi rootsize_ok $devicename $otarootpartname $newrootsize && d=1 done d=0 while [ $d -eq 0 ] ; do - printf "Input type of partition to append ('data' or 'overlay') $bold$green[overlay]$normal:\n" + printf "Enter type of partition to append ('regular' or 'overlay') $bold$green[overlay]$normal:\n" read ptype if [ -z ${ptype} ] ; then ptype="overlay" - printf "Using $ptype\n" + printf "Using $ptype\n\n" fi type_available $ptype && d=1 done - printf "Size of the appended partition in MB (set to 0 to fill) $bold$green[0]$normal:\n" + printf "Enter size of the partition to append in MB. 0 = use remaining space. $bold$green[0]$normal:\n" read datasize if [ -z ${datasize} ] ; then datasize="0" - printf "Using $datasize\n" + printf "Using $datasize\n\n" fi execute } @@ -243,6 +236,7 @@ scripted_mode(){ datasize=$4 if ! device_available $device ; then + printf "Device $device " exit 1 fi @@ -270,23 +264,35 @@ scripted_mode(){ } execute(){ + printf "Expanding partition $otarootpartn of device $device. " expand_partition $device $otarootpartn $newrootsize + printf "Done.\n\n" + printf "Appending partition with size $datasize on device $device. " append_partition $device $datasize + printf "Done.\n\n" datapart=$createdPartition + printf "Mounting new partition to /mnt. " mount $datapart /mnt + printf "Done.\n\n" + + printf "Adding new partition to /etc/fstab. " echo "$datapart /mnt auto defaults,sync 0 0" >> /etc/fstab + printf "Done.\n\n" case "$ptype" in - "data") - mkdir -p /mnt/data || true - ;; "overlay") + mkdir -p /mnt/.work + printf "Creating overlay folder in /mnt. " mkdir -p /mnt/overlay + printf "Done.\n\n" + + printf "Enabling mount-overlay service. " systemctl enable mount-overlay.service >> /tmp/log/nmhw-auto-part.log 2>&1 systemctl start mount-overlay.service + printf "Done.\n\n" ;; *) echo "Error: $ptype is not an option." @@ -298,21 +304,20 @@ execute(){ } usage(){ - printf "\ - usage: nmhw-auto-part.sh [OPTION] 'devicename' 'size' 'mode' 'size' \n\n" + printf "Usage: nmhw-auto-part [-h|-i] \n" + printf " nmhw-auto-part disk size1 mode size2 \n" } description(){ printf "\ - This scripts expands 1. partition on a blockdevice and appends an additional partition to the device. \n\ - Arguments: \n\ - 1. 'devicename' = device to use: e.g. /dev/sdb /dev/mmcblk1 \n\ - 2. 'size' = size of the first partition in MB (set 0 to keep current size) \n\ - 3. 'mode' = 'data' or 'overlay'; type of partition to append \n\ - 4. 'size' = size of the appended partition in MB (set to 0 to fill) \n\ - Options:\n\ - -i interactive mode\n\ - -h help\n" +This scripts expands the first partition on a block device and appends an additional partition to the device. \n\ +Arguments: \n\ +disk : disk to use: e.g. /dev/mmcblk1 \n\ +size1 : size of the first partition in MB. 0 = keep current size. \n\ +mode : regular or overlay; type of partition to append \n\ +size2 : size of the partition to append in MB. 0 = use remaining space. \n\ +-i : interactive mode\n\ +-h : help\n" } # exit when any commands fails @@ -324,7 +329,11 @@ echo "Script run with parameters 1: $1 2: $2 3: $3 4: $4 5: $5" >> /tmp/log/nmhw echo "" >> /tmp/log/nmhw-auto-part.log echo "" >> /tmp/log/nmhw-auto-part.log -if (( $# == 1 )) ; then +if (( $# == 0 )) ; then + usage + description + exit 0 +elif (( $# == 1 )) ; then case $1 in "-i") interactive_mode @@ -340,7 +349,7 @@ elif (( $# == 4 )) ; then scripted_mode $1 $2 $3 $4 exit 0 else - echo "Error: Illegal number of parameters." + echo "${0##*/} : Illegal number of parameters." usage description exit 1