Merge remote-tracking branch 'telmich/master'

This commit is contained in:
Steven Armstrong 2011-10-04 22:43:53 +02:00
commit 67cbfee60b
5 changed files with 55 additions and 27 deletions

View file

@ -36,20 +36,18 @@ EXAMPLES
-------- --------
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
# 128MB linux, bootable # 128MB, linux, bootable
__partition_msdos /dev/sda1 --type 83 --size 128M --bootable true __partition_msdos /dev/sda1 --type 83 --size 128M --bootable true
# 512MB swap # 512MB, swap
__partition_msdos /dev/sda2 --type 82 --size 512M __partition_msdos /dev/sda2 --type 82 --size 512M
# extended # 100GB, extended
__partition_msdos /dev/sda3 --type extended --size 100G __partition_msdos /dev/sda3 --type extended --size 100G
# 10GB, linux # 10GB, linux
__partition_msdos /dev/sda5 --type 83 --size 10G __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% __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 + __partition_msdos /dev/sda7 --type 83 --size +
# same thing as
__partition_msdos /dev/sda7 --type 83
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View file

@ -7,11 +7,13 @@ debug() {
} }
fdisk_command() { fdisk_command() {
local device=$1 local device="$1"
local cmd=$2 local cmd="$2"
debug fdisk_command "running fdisk command '${cmd}' on device ${device}" 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"
# give disk some time
sleep 1
return $? return $?
} }
@ -24,11 +26,11 @@ create_disklabel() {
} }
create_partition() { create_partition() {
local device=$1 local device="$1"
local minor=$2 local minor="$2"
local size=$3 local size="$3"
local type=$4 local type="$4"
local primary_count=$5 local primary_count="$5"
if [ "$type" = "extended" -o "$type" = "5" ]; then if [ "$type" = "extended" -o "$type" = "5" ]; then
# Extended partition # Extended partition

View file

@ -23,7 +23,8 @@ die() {
exit 1 exit 1
} }
debug() { debug() {
echo "[__partition_msdos_apply] $@" >&2 #echo "[__partition_msdos_apply] $@" >&2
:
} }
# Convert a size specifier 1G 100M or 50% into the corresponding numeric MB. # 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" partitions="$__object/explorer/partitions"
objects=$(find "$__global/object/__partition_msdos" -path "*.cdist") objects=$(find "$__global/object/__partition_msdos" -path "*.cdist")
current_device="" current_device=""
available_device_size=
available_extended_size=
available_size= available_size=
primary_count=0 primary_count=0
for object in $objects; do for object in $objects; do
device="$(cat "$object/parameter/device")" device="$(cat "$object/parameter/device")"
if [ "$current_device" != "$device" ]; then if [ "$current_device" != "$device" ]; then
echo "create_disklabel $device" echo "create_disklabel \"$device\" || die 'Failed to create disklabel for $device'"
current_device="$device" current_device="$device"
device_name=$(echo ${device} | sed -e 's:^/dev/::;s:/:\\/:g') 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 # 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 primary_count=0
debug "----- $device" debug "----- $device"
debug "current_device=$current_device" debug "current_device=$current_device"
debug "available_size=$available_size" debug "available_device_size=$available_device_size"
fi fi
type="$(cat "$object/parameter/type")" type="$(cat "$object/parameter/type")"
partition="$(cat "$object/parameter/partition")" partition="$(cat "$object/parameter/partition")"
minor="$(cat "$object/parameter/minor")" minor="$(cat "$object/parameter/minor")"
if [ "${minor}" -lt "5" ]; then
primary_count=$(( $primary_count + 1 ))
fi
bootable="$(cat "$object/parameter/bootable")" bootable="$(cat "$object/parameter/bootable")"
size="$(cat "$object/parameter/size")" 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 if [ "$size" = "+" ]; then
# use rest of device # use rest of device
partition_size="" partition_size=""
@ -92,6 +104,18 @@ for object in $objects; do
available_size="$(( $available_size - $partition_size ))" available_size="$(( $available_size - $partition_size ))"
fi 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" [ "$partition_size" = "-1" ] && die "could not translate size '$size' to a usable value"
debug "----- $partition" debug "----- $partition"
debug "primary_count=$primary_count" debug "primary_count=$primary_count"
@ -104,7 +128,11 @@ for object in $objects; do
debug "size=$size" debug "size=$size"
debug "partition_size=$partition_size" debug "partition_size=$partition_size"
debug "available_size=$available_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 done

View file

@ -1,5 +1,6 @@
2.0.3: 2.0.3:
* Improved logging, added --verbose, by more quiet by default * Improved logging, added --verbose, by more quiet by default
* Bugfix __user: Correct quoting (Steven Armstrong)
2.0.2: 2011-09-27 2.0.2: 2011-09-27
* Add support for detection of OpenWall Linux (Matthias Teege) * Add support for detection of OpenWall Linux (Matthias Teege)

View file

@ -46,9 +46,8 @@ work nor kill the authors brain:
private branch! private branch!
- Code to be included should be branched of the upstream "master" branch - Code to be included should be branched of the upstream "master" branch
- Exception: Bugfixes to a version branch - Exception: Bugfixes to a version branch
- Code submissions should be in your master branch - On a merge request, always name the branch I should pull from
- Other branches are fine as well, but you need to tell me which branch - Always ensure **all** manpages build: ./build.sh man
your work is in!
- If you developed more than **one** feature, consider submitting them in - If you developed more than **one** feature, consider submitting them in
seperate branches. This way one feature can already be included, even if seperate branches. This way one feature can already be included, even if
the other needs to be improved. the other needs to be improved.