From e97854238122a6dfd2db77a96569eb32154d2471 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 2 Aug 2011 15:20:32 +0200 Subject: [PATCH 1/7] safer quoting Signed-off-by: Steven Armstrong --- conf/type/__user/gencode-remote | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf/type/__user/gencode-remote b/conf/type/__user/gencode-remote index 31c93655..c4f9123a 100755 --- a/conf/type/__user/gencode-remote +++ b/conf/type/__user/gencode-remote @@ -55,7 +55,7 @@ if grep -q "^${name}:" "$__object/explorer/passwd"; then current_value="$(awk -F: '{ print $ENVIRON["field"] }' < "$file")" if [ "$new_value" != "$current_value" ]; then - set -- "$@" "--$property" \"$new_value\" + set -- "$@" "--$property" \'$new_value\' fi done @@ -67,7 +67,7 @@ if grep -q "^${name}:" "$__object/explorer/passwd"; then else for property in $(ls .); do new_value="$(cat "$property")" - set -- "$@" "--$property" \"$new_value\" + set -- "$@" "--$property" \'$new_value\' done echo useradd "$@" "$name" From 721119a34f5bf7a3267eb906e11a6ef7c009e200 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 23 Sep 2011 16:18:55 +0200 Subject: [PATCH 2/7] quote arguments Signed-off-by: Steven Armstrong --- conf/type/__partition_msdos_apply/files/lib.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/conf/type/__partition_msdos_apply/files/lib.sh b/conf/type/__partition_msdos_apply/files/lib.sh index 0e9705d9..e24c1cb7 100644 --- a/conf/type/__partition_msdos_apply/files/lib.sh +++ b/conf/type/__partition_msdos_apply/files/lib.sh @@ -7,8 +7,8 @@ debug() { } fdisk_command() { - local device=$1 - local cmd=$2 + local device="$1" + local cmd="$2" debug fdisk_command "running fdisk command '${cmd}' on device ${device}" echo -en "${cmd}\nw\n" | fdisk -c -u "$device" @@ -24,11 +24,11 @@ create_disklabel() { } create_partition() { - local device=$1 - local minor=$2 - local size=$3 - local type=$4 - local primary_count=$5 + local device="$1" + local minor="$2" + local size="$3" + local type="$4" + local primary_count="$5" if [ "$type" = "extended" -o "$type" = "5" ]; then # Extended partition From ef97849676d0a8ce8909ac138c2887b1e6b069ed Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 23 Sep 2011 16:20:26 +0200 Subject: [PATCH 3/7] distinguish between disk size and extended partition size Signed-off-by: Steven Armstrong --- .../__partition_msdos_apply/gencode-remote | 46 +++++++++++++++---- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/conf/type/__partition_msdos_apply/gencode-remote b/conf/type/__partition_msdos_apply/gencode-remote index d352abdb..1d5c33cb 100755 --- a/conf/type/__partition_msdos_apply/gencode-remote +++ b/conf/type/__partition_msdos_apply/gencode-remote @@ -23,7 +23,8 @@ die() { exit 1 } debug() { - echo "[__partition_msdos_apply] $@" >&2 + #echo "[__partition_msdos_apply] $@" >&2 + : } # Convert a size specifier 1G 100M or 50% into the corresponding numeric MB. @@ -57,32 +58,43 @@ cat "$__type/files/lib.sh" partitions="$__object/explorer/partitions" objects=$(find "$__global/object/__partition_msdos" -path "*.cdist") current_device="" +available_device_size= +available_extended_size= available_size= primary_count=0 for object in $objects; do device="$(cat "$object/parameter/device")" if [ "$current_device" != "$device" ]; then - echo "create_disklabel $device" + echo "create_disklabel \"$device\" || die 'Failed to create disklabel for $device'" current_device="$device" device_name=$(echo ${device} | sed -e 's:^/dev/::;s:/:\\/:g') - available_size=$(( $(awk "/${device_name}\$/ { print \$3; }" "$partitions") / 1024)) + available_device_size=$(( $(awk "/${device_name}\$/ { print \$3; }" "$partitions") / 1024)) # make sure we don't go past the end of the drive - available_size=$((available_size - 2)) + available_device_size=$((available_device_size - 2)) + available_extended_size=0 primary_count=0 debug "----- $device" debug "current_device=$current_device" - debug "available_size=$available_size" + debug "available_device_size=$available_device_size" fi type="$(cat "$object/parameter/type")" partition="$(cat "$object/parameter/partition")" minor="$(cat "$object/parameter/minor")" - if [ "${minor}" -lt "5" ]; then - primary_count=$(( $primary_count + 1 )) - fi bootable="$(cat "$object/parameter/bootable")" size="$(cat "$object/parameter/size")" + + + if [ "${minor}" -lt "5" ]; then + # Primary partitions + primary_count=$(( $primary_count + 1 )) + available_size=$available_device_size + else + # Logical partitions + available_size=$available_extended_size + fi + if [ "$size" = "+" ]; then # use rest of device partition_size="" @@ -92,6 +104,18 @@ for object in $objects; do available_size="$(( $available_size - $partition_size ))" fi + if [ "${minor}" -lt "5" ]; then + # Primary partitions + available_device_size=$available_size + if [ "$type" = "extended" -o "$type" = "5" ]; then + # Extended partition + available_extended_size=$partition_size + fi + else + # Logical paritions + available_extended_size=$available_size + fi + [ "$partition_size" = "-1" ] && die "could not translate size '$size' to a usable value" debug "----- $partition" debug "primary_count=$primary_count" @@ -104,7 +128,11 @@ for object in $objects; do debug "size=$size" debug "partition_size=$partition_size" debug "available_size=$available_size" + debug "available_device_size=$available_device_size" + debug "available_extended_size=$available_extended_size" + debug "----------" - echo "create_partition $device $minor $partition_size $type $primary_count" + echo "create_partition '$device' '$minor' '$partition_size' '$type' '$primary_count' \ + || die 'Failed to create partition: $partition'" done From 5940c21fba007f9f8fad0650d696ed2056a57f8e Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 4 Oct 2011 14:56:59 +0200 Subject: [PATCH 4/7] get rid of bashism /echo -n/printf/ Signed-off-by: Steven Armstrong --- conf/type/__partition_msdos_apply/files/lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/type/__partition_msdos_apply/files/lib.sh b/conf/type/__partition_msdos_apply/files/lib.sh index e24c1cb7..01a817a8 100644 --- a/conf/type/__partition_msdos_apply/files/lib.sh +++ b/conf/type/__partition_msdos_apply/files/lib.sh @@ -11,7 +11,7 @@ fdisk_command() { local cmd="$2" debug fdisk_command "running fdisk command '${cmd}' on device ${device}" - echo -en "${cmd}\nw\n" | fdisk -c -u "$device" + printf "${cmd}\nw\n" | fdisk -c -u "$device" return $? } From 32832777c6778a881b9389e3e3b325c101b4a131 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 4 Oct 2011 15:24:19 +0200 Subject: [PATCH 5/7] give disk some time to write parition table Signed-off-by: Steven Armstrong --- conf/type/__partition_msdos_apply/files/lib.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/conf/type/__partition_msdos_apply/files/lib.sh b/conf/type/__partition_msdos_apply/files/lib.sh index 01a817a8..f0859aab 100644 --- a/conf/type/__partition_msdos_apply/files/lib.sh +++ b/conf/type/__partition_msdos_apply/files/lib.sh @@ -12,6 +12,8 @@ fdisk_command() { debug fdisk_command "running fdisk command '${cmd}' on device ${device}" printf "${cmd}\nw\n" | fdisk -c -u "$device" + # give disk some time + sleep 1 return $? } From 919f251759958403e097150e460f31a708d95ee2 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 4 Oct 2011 16:33:58 +0200 Subject: [PATCH 6/7] ++examples Signed-off-by: Steven Armstrong --- conf/type/__partition_msdos/man.text | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/conf/type/__partition_msdos/man.text b/conf/type/__partition_msdos/man.text index c9ef0cf1..78220ee0 100644 --- a/conf/type/__partition_msdos/man.text +++ b/conf/type/__partition_msdos/man.text @@ -36,20 +36,18 @@ EXAMPLES -------- -------------------------------------------------------------------------------- -# 128MB linux, bootable +# 128MB, linux, bootable __partition_msdos /dev/sda1 --type 83 --size 128M --bootable true -# 512MB swap +# 512MB, swap __partition_msdos /dev/sda2 --type 82 --size 512M -# extended +# 100GB, extended __partition_msdos /dev/sda3 --type extended --size 100G # 10GB, linux __partition_msdos /dev/sda5 --type 83 --size 10G -# 50% of free space, linux +# 50% of the free space of the extended partition, linux __partition_msdos /dev/sda6 --type 83 --size 50% -# rest of disk, linux +# rest of the extended partition, linux __partition_msdos /dev/sda7 --type 83 --size + -# same thing as -__partition_msdos /dev/sda7 --type 83 -------------------------------------------------------------------------------- From 60fab053f2a08d0aeda0a780aecdc22e0fdd5f12 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 4 Oct 2011 16:36:33 +0200 Subject: [PATCH 7/7] ++changes for 2.0.3 Signed-off-by: Nico Schottelius --- doc/changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/changelog b/doc/changelog index 9fb11307..632ddb45 100644 --- a/doc/changelog +++ b/doc/changelog @@ -1,5 +1,6 @@ 2.0.3: * Improved logging, added --verbose, by more quiet by default + * Bugfix __user: Correct quoting (Steven Armstrong) 2.0.2: 2011-09-27 * Add support for detection of OpenWall Linux (Matthias Teege)