Merge remote-tracking branch 'cdist/master'

This commit is contained in:
Steven Armstrong 2011-09-26 15:01:12 +02:00
commit 9751f16fb1
26 changed files with 1447 additions and 757 deletions

View file

@ -65,8 +65,13 @@ if [ -f /etc/SuSE-release ]; then
exit 0
fi
if uname -r | grep -s '.owl' >/dev/null 2>&1; then
echo owl
exit 0
fi
if [ -f /etc/cdist-preos ]; then
echo preos
echo cdist-preos
exit 0
fi

View file

@ -0,0 +1,64 @@
cdist-type__partition_msdos(7)
==============================
Steven Armstrong <steven-cdist--@--armstrong.cc>
NAME
----
cdist-type__partition_msdos - creates msdos partitions
DESCRIPTION
-----------
This cdist type allows you to create msdos paritions.
REQUIRED PARAMETERS
-------------------
type::
the partition type used in fdisk (such as 82 or 83) or "extended"
OPTIONAL PARAMETERS
-------------------
partition::
defaults to object_id
bootable::
mark partition as bootable, true or false, defaults to false
size::
the size of the partition (such as 32M or 15G, whole numbers
only), '+' for remaining space, or 'n%' for percentage of remaining
(these should only be used after all specific partition sizes are
specified). Defaults to +.
EXAMPLES
--------
--------------------------------------------------------------------------------
# 128MB linux, bootable
__partition_msdos /dev/sda1 --type 83 --size 128M --bootable true
# 512MB swap
__partition_msdos /dev/sda2 --type 82 --size 512M
# extended
__partition_msdos /dev/sda3 --type extended --size 100G
# 10GB, linux
__partition_msdos /dev/sda5 --type 83 --size 10G
# 50% of free space, linux
__partition_msdos /dev/sda6 --type 83 --size 50%
# rest of disk, linux
__partition_msdos /dev/sda7 --type 83 --size +
# same thing as
__partition_msdos /dev/sda7 --type 83
--------------------------------------------------------------------------------
SEE ALSO
--------
- cdist-type(7)
COPYING
-------
Copyright \(C) 2011 Steven Armstrong. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).

View file

@ -0,0 +1,41 @@
#!/bin/sh
#
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
# set defaults
if [ -f "$__object/parameter/partition" ]; then
partition="(cat "$__object/parameter/partition")"
else
partition="/$__object_id"
echo "$partition" > "$__object/parameter/partition"
fi
device="$(echo "$partition" | sed 's/[0-9]//g')"
echo "$device" > "$__object/parameter/device"
minor="$(echo "$partition" | sed 's/[^0-9]//g')"
echo "$minor" > "$__object/parameter/minor"
if [ ! -f "$__object/parameter/bootable" ]; then
echo "false" > "$__object/parameter/bootable"
fi
if [ ! -f "$__object/parameter/size" ]; then
echo "+" > "$__object/parameter/size"
fi
# pull in the type that actually does something with the above parameters
require="$__self" __partition_msdos_apply

View file

@ -0,0 +1,3 @@
partition
bootable
size

View file

@ -0,0 +1 @@
type

View file

@ -0,0 +1,3 @@
#!/bin/sh
cat /proc/partitions

View file

@ -0,0 +1,58 @@
die() {
echo "[__partition_msdos_apply] $@" >&2
exit 1
}
debug() {
echo "[__partition_msdos_apply] $@" >&2
}
fdisk_command() {
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"
return $?
}
create_disklabel() {
local device=$1
debug create_disklabel "creating new msdos disklabel"
fdisk_command ${device} "o"
return $?
}
create_partition() {
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
primary_extended="e\n"
first_minor="${minor}\n"
[ "${minor}" = "4" ] && first_minor=""
type_minor="${minor}\n"
[ "${minor}" = "1" ] && type_minor=""
type="5"
elif [ "${minor}" -lt "5" ]; then
primary_extended="p\n"
first_minor="${minor}\n"
[ "${minor}" = "4" ] && first_minor=""
type_minor="${minor}\n"
[ "${minor}" = "1" ] && type_minor=""
else
# Logical partitions
first_minor="${minor}\n"
type_minor="${minor}\n"
primary_extended="l\n"
[ "$primary_count" > "3" ] && primary_extended=""
fi
[ -n "${size}" ] && size="+${size}M"
fdisk_command ${device} "n\n${primary_extended}${first_minor}\n${size}\nt\n${type_minor}${type}\n"
return $?
}

View file

@ -0,0 +1,110 @@
#!/bin/sh
#
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
die() {
echo "[__partition_msdos_apply] $@" >&2
exit 1
}
debug() {
echo "[__partition_msdos_apply] $@" >&2
}
# Convert a size specifier 1G 100M or 50% into the corresponding numeric MB.
size_to_mb() {
local size=$1
local available_size="$2"
local number_suffix="$(echo ${size} | sed -e 's:\.[0-9]\+::' -e 's:\([0-9]\+\)\([MmGg%]\)[Bb]\?:\1|\2:')"
local number="$(echo ${number_suffix} | cut -d '|' -f1)"
local suffix="$(echo ${number_suffix} | cut -d '|' -f2)"
case "$suffix" in
M|m)
size="$number"
;;
G|g)
size="$(( $number * 1024 ))"
;;
%)
size="$(( $available_size * $number / 100 ))"
;;
*)
size="-1"
esac
echo "$size"
}
# include function library for use on target
cat "$__type/files/lib.sh"
partitions="$__object/explorer/partitions"
objects=$(find "$__global/object/__partition_msdos" -path "*.cdist")
current_device=""
available_size=
primary_count=0
for object in $objects; do
device="$(cat "$object/parameter/device")"
if [ "$current_device" != "$device" ]; then
echo "create_disklabel $device"
current_device="$device"
device_name=$(echo ${device} | sed -e 's:^/dev/::;s:/:\\/:g')
available_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))
primary_count=0
debug "----- $device"
debug "current_device=$current_device"
debug "available_size=$available_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 [ "$size" = "+" ]; then
# use rest of device
partition_size=""
available_size=0
else
partition_size=$(size_to_mb "$size" "$available_size")
available_size="$(( $available_size - $partition_size ))"
fi
[ "$partition_size" = "-1" ] && die "could not translate size '$size' to a usable value"
debug "----- $partition"
debug "primary_count=$primary_count"
debug "current_device=$current_device"
debug "device=$device"
debug "type=$type"
debug "partition=$partition"
debug "minor=$minor"
debug "bootable=$bootable"
debug "size=$size"
debug "partition_size=$partition_size"
debug "available_size=$available_size"
echo "create_partition $device $minor $partition_size $type $primary_count"
done

View file

@ -0,0 +1,42 @@
cdist-type__partition_msdos_apply(7)
====================================
Steven Armstrong <steven-cdist--@--armstrong.cc>
NAME
----
cdist-type__partition_msdos_apply
DESCRIPTION
-----------
Create the partitions defined with __partition_msdos
REQUIRED PARAMETERS
-------------------
None
OPTIONAL PARAMETERS
-------------------
None.
EXAMPLES
--------
--------------------------------------------------------------------------------
__partition_msdos_apply
--------------------------------------------------------------------------------
SEE ALSO
--------
- cdist-type(7)
- cdist-type__partition_msdos_apply(7)
COPYING
-------
Copyright \(C) 2011 Steven Armstrong. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).