forked from ungleich-public/cdist
Merge remote-tracking branch 'steven/backported_types'
This commit is contained in:
commit
2e9421a6e7
34 changed files with 272 additions and 486 deletions
|
@ -20,7 +20,7 @@
|
|||
|
||||
name="$__object_id"
|
||||
|
||||
__package python-software-properties --state installed
|
||||
__package python-software-properties --state present
|
||||
|
||||
require="__package/python-software-properties" \
|
||||
__file /usr/local/bin/remove-apt-repository \
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
# run 'apt-get update' if anything in /etc/apt is newer then /var/lib/apt/lists
|
||||
cat << DONE
|
||||
if find /etc/apt -cnewer /var/lib/apt/lists | grep . > /dev/null; then
|
||||
if find /etc/apt -mindepth 1 -cnewer /var/lib/apt/lists | grep . > /dev/null; then
|
||||
apt-get update || apt-get update
|
||||
fi
|
||||
DONE
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
cdist-type__partition_msdos_apply(7)
|
||||
====================================
|
||||
cdist-type__autofs(7)
|
||||
=====================
|
||||
Steven Armstrong <steven-cdist--@--armstrong.cc>
|
||||
|
||||
|
||||
NAME
|
||||
----
|
||||
cdist-type__partition_msdos_apply - Apply dos partition settings
|
||||
cdist-type__autofs - install and start autofs
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
Create the partitions defined with __partition_msdos
|
||||
This space intentionally left blank.
|
||||
|
||||
|
||||
REQUIRED PARAMETERS
|
||||
-------------------
|
||||
None
|
||||
None.
|
||||
|
||||
|
||||
OPTIONAL PARAMETERS
|
||||
|
@ -27,16 +27,16 @@ EXAMPLES
|
|||
--------
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
__partition_msdos_apply
|
||||
__autofs
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
SEE ALSO
|
||||
--------
|
||||
- cdist-type(7)
|
||||
- cdist-type__partition_msdos_apply(7)
|
||||
|
||||
|
||||
COPYING
|
||||
-------
|
||||
Copyright \(C) 2011 Steven Armstrong. Free use of this software is
|
||||
Copyright \(C) 2012 Steven Armstrong. Free use of this software is
|
||||
granted under the terms of the GNU General Public License version 3 (GPLv3).
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||
# 2012 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||
#
|
||||
# This file is part of cdist.
|
||||
#
|
||||
|
@ -18,14 +18,21 @@
|
|||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
# set defaults
|
||||
if [ -f "$__object/parameter/device" ]; then
|
||||
device="(cat "$__object/parameter/device")"
|
||||
else
|
||||
device="/$__object_id"
|
||||
echo "$device" > "$__object/parameter/device"
|
||||
fi
|
||||
|
||||
type="(cat "$__object/parameter/type")"
|
||||
os=$(cat "$__global/explorer/os")
|
||||
|
||||
options="(cat "$__object/parameter/options")"
|
||||
not_supported() {
|
||||
echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
|
||||
echo "Please contribute an implementation for it if you can." >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
case "$os" in
|
||||
ubuntu|debian|archlinux)
|
||||
__package autofs --state present
|
||||
__start_on_boot autofs --state present
|
||||
;;
|
||||
*)
|
||||
not_supported
|
||||
;;
|
||||
esac
|
50
cdist/conf/type/__autofs_map/explorer/entry
Executable file
50
cdist/conf/type/__autofs_map/explorer/entry
Executable file
|
@ -0,0 +1,50 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# 2011 - 2012 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/>.
|
||||
#
|
||||
|
||||
candidates="/etc/auto.master /etc/autofs/auto.master"
|
||||
find_auto_master() {
|
||||
# get the path of the auto.master file
|
||||
for candidate in $candidates; do
|
||||
if [ -f "$candidate" ]; then
|
||||
echo "$candidate"
|
||||
return
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
auto_master="$(find_auto_master)"
|
||||
|
||||
# no auto.master, nothing we could do
|
||||
[ -f "$auto_master" ] || exit 0
|
||||
|
||||
# NOTE: keep variables in sync in manifest/explorer/gencode-*
|
||||
prefix="#cdist:$__object_name"
|
||||
suffix="#/cdist:$__object_name"
|
||||
awk -v prefix="$prefix" -v suffix="$suffix" '{
|
||||
if (index($0,prefix)) {
|
||||
triggered=1
|
||||
}
|
||||
if (triggered) {
|
||||
if (index($0,suffix)) {
|
||||
triggered=0
|
||||
}
|
||||
print
|
||||
}
|
||||
}' "$auto_master"
|
93
cdist/conf/type/__autofs_map/gencode-remote
Executable file
93
cdist/conf/type/__autofs_map/gencode-remote
Executable file
|
@ -0,0 +1,93 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# 2011 - 2012 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/>.
|
||||
#
|
||||
|
||||
entry="$__object/files/entry"
|
||||
state_should="$(cat "$__object/parameter/state" 2>/dev/null || echo present)"
|
||||
if [ ! -s "$__object/explorer/entry" ]; then
|
||||
state_is='absent'
|
||||
else
|
||||
state_is=$(diff -q "$entry" "$__object/explorer/entry" >/dev/null \
|
||||
&& echo present \
|
||||
|| echo changed
|
||||
)
|
||||
fi
|
||||
|
||||
if [ "$state_should" = "$state_is" ]; then
|
||||
# Nothing to do, move along
|
||||
exit 0
|
||||
fi
|
||||
|
||||
cat << DONE
|
||||
candidates="/etc/auto.master /etc/autofs/auto.master"
|
||||
find_auto_master() {
|
||||
# get the path of the auto.master file
|
||||
for candidate in \$candidates; do
|
||||
if [ -f "\$candidate" ]; then
|
||||
echo "\$candidate"
|
||||
return
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
auto_master="\$(find_auto_master)"
|
||||
|
||||
if [ ! -f "\$auto_master" ]; then
|
||||
echo "Could not determine auto.master location, tried: \$candidates" >&2
|
||||
exit 1
|
||||
fi
|
||||
DONE
|
||||
|
||||
remove_entry() {
|
||||
# NOTE: keep variables in sync in manifest/explorer/gencode-*
|
||||
prefix="#cdist:$__object_name"
|
||||
suffix="#/cdist:$__object_name"
|
||||
cat << DONE
|
||||
awk -v prefix="$prefix" -v suffix="$suffix" '
|
||||
{
|
||||
if (index(\$0,prefix)) {
|
||||
triggered=1
|
||||
}
|
||||
if (triggered) {
|
||||
if (index(\$0,suffix)) {
|
||||
triggered=0
|
||||
}
|
||||
} else {
|
||||
print
|
||||
}
|
||||
}' "\$auto_master" > "\$auto_master"+
|
||||
mv -f "\$auto_master"+ "\$auto_master"
|
||||
DONE
|
||||
}
|
||||
|
||||
case "$state_should" in
|
||||
present)
|
||||
if [ "$state_is" = "changed" ]; then
|
||||
remove_entry
|
||||
fi
|
||||
cat << DONE
|
||||
cat >> "\$auto_master" << EOC
|
||||
$(cat "$entry")
|
||||
EOC
|
||||
DONE
|
||||
;;
|
||||
absent)
|
||||
remove_entry
|
||||
;;
|
||||
esac
|
|
@ -36,25 +36,35 @@ comment::
|
|||
auto.master.
|
||||
|
||||
|
||||
BOOLEAN PARAMETERS
|
||||
------------------
|
||||
noreload::
|
||||
don't reload autofs after the entry has been changed
|
||||
|
||||
|
||||
EXAMPLES
|
||||
--------
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
# Add auto mounter at /net
|
||||
# Add auto mounter at /net and reload
|
||||
__autofs_map /net --map /etc/auto.net --type program
|
||||
|
||||
# Add auto mounter at /pub
|
||||
__autofs_map /pub --map /etc/auto.pub \
|
||||
--type file --options nosuid,rw,bg,hard,intr --ghost
|
||||
# Add auto mounter at /pub and don't reload
|
||||
__autofs_map /pub \
|
||||
--map /etc/auto.pub \
|
||||
--type file \
|
||||
--options "nosuid,rw,bg,hard,intr --ghost" \
|
||||
--noreload
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
SEE ALSO
|
||||
--------
|
||||
- cdist-type(7)
|
||||
- cdist-type__autofs_reload(7)
|
||||
|
||||
|
||||
COPYING
|
||||
-------
|
||||
Copyright \(C) 2011 Steven Armstrong. Free use of this software is
|
||||
Copyright \(C) 2012 Steven Armstrong. Free use of this software is
|
||||
granted under the terms of the GNU General Public License version 3 (GPLv3).
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||
# 2011 - 2012 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||
#
|
||||
# This file is part of cdist.
|
||||
#
|
||||
|
@ -20,23 +20,36 @@
|
|||
|
||||
name="/$__object_id"
|
||||
map="$(cat "$__object/parameter/map")"
|
||||
type="$(cat "$__object/parameter/type" 2>/dev/null || echo "file")"
|
||||
options="$(cat "$__object/parameter/options" 2>/dev/null || true)"
|
||||
|
||||
if [ -f "$__object/parameter/type" ]; then
|
||||
type="$(cat "$__object/parameter/type")"
|
||||
else
|
||||
type="file"
|
||||
echo "$type" > "$__object/parameter/type"
|
||||
fi
|
||||
# NOTE: keep variables in sync in manifest/explorer/gencode-*
|
||||
prefix="#cdist:$__object_name"
|
||||
suffix="#/cdist:$__object_name"
|
||||
|
||||
# Generate entry for use in auto.master
|
||||
entry="${name} ${type}:${map}"
|
||||
if [ -f "$__object/parameter/options" ]; then
|
||||
entry="$entry $(cat "$__object/parameter/options")"
|
||||
fi
|
||||
mkdir "$__object/files"
|
||||
|
||||
# Generate entry for inclusion in auto.master
|
||||
entry="$__object/files/entry"
|
||||
echo "$prefix" > "$entry"
|
||||
if [ -f "$__object/parameter/comment" ]; then
|
||||
echo "# $(cat "$__object/parameter/comment")" > "$__object/parameter/entry"
|
||||
echo "# $(cat "$__object/parameter/comment")" >> "$entry"
|
||||
fi
|
||||
echo "$entry" >> "$__object/parameter/entry"
|
||||
|
||||
require="$__object_name" __autofs_master
|
||||
echo "$name $type:$map $options" >> $entry
|
||||
echo "$suffix" >> "$entry"
|
||||
|
||||
# Reload autofs after changes if the user wishes this
|
||||
if [ ! -f "$__object/parameter/noreload" ]; then
|
||||
state_should="$(cat "$__object/parameter/state" 2>/dev/null || echo present)"
|
||||
if [ ! -s "$__object/explorer/entry" ]; then
|
||||
state_is='absent'
|
||||
else
|
||||
state_is=$(diff -q "$entry" "$__object/explorer/entry" >/dev/null \
|
||||
&& echo present \
|
||||
|| echo changed
|
||||
)
|
||||
fi
|
||||
if [ "$state_is" != "$state_should" ]; then
|
||||
require="$__object_name" __autofs_reload
|
||||
fi
|
||||
fi
|
||||
|
|
1
cdist/conf/type/__autofs_map/parameter/boolean
Normal file
1
cdist/conf/type/__autofs_map/parameter/boolean
Normal file
|
@ -0,0 +1 @@
|
|||
noreload
|
|
@ -1,3 +0,0 @@
|
|||
# Generated from cdist __autofs_master
|
||||
# Do not change this file. Changes will be overwritten.
|
||||
|
|
@ -1 +0,0 @@
|
|||
header
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||
# 2012 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||
#
|
||||
# This file is part of cdist.
|
||||
#
|
||||
|
@ -19,13 +19,19 @@
|
|||
#
|
||||
|
||||
|
||||
if [ ! -f "$__object/parameter/header" ]; then
|
||||
echo "$__type/files/auto.master.header" > "$__object/parameter/header"
|
||||
fi
|
||||
os=$(cat "$__global/explorer/os")
|
||||
|
||||
[ -d "$__object/files" ] || mkdir "$__object/files"
|
||||
require="$__object_name" __file /etc/auto.master --source "$__object/files/auto.master" \
|
||||
--mode 644 \
|
||||
--owner root \
|
||||
--group root
|
||||
not_supported() {
|
||||
echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
|
||||
echo "Please contribute an implementation for it if you can." >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
case "$os" in
|
||||
ubuntu|debian|archlinux)
|
||||
echo "pkill -HUP automount"
|
||||
;;
|
||||
*)
|
||||
not_supported
|
||||
;;
|
||||
esac
|
|
@ -1,38 +1,33 @@
|
|||
cdist-type__autofs_master(7)
|
||||
cdist-type__autofs_reload(7)
|
||||
============================
|
||||
Steven Armstrong <steven-cdist--@--armstrong.cc>
|
||||
|
||||
|
||||
NAME
|
||||
----
|
||||
cdist-type__autofs_master - Generate the auto.master file
|
||||
cdist-type__autofs_reload - tell automounter to reload config file
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
This cdist type generates a auto.master configuration from given __autofs_map
|
||||
definitions. See cdist-type__auto_map(7).
|
||||
This space intentionally left blank.
|
||||
|
||||
|
||||
REQUIRED PARAMETERS
|
||||
-------------------
|
||||
None
|
||||
None.
|
||||
|
||||
|
||||
OPTIONAL PARAMETERS
|
||||
-------------------
|
||||
header::
|
||||
Absolute path to a file used as the header for the generated auto.master
|
||||
file.
|
||||
None.
|
||||
|
||||
|
||||
EXAMPLES
|
||||
--------
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
# auto.master with default header
|
||||
__autofs_master
|
||||
|
||||
# auto.master with custom header
|
||||
__autofs_master --header /path/to/header
|
||||
__autofs_reload
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
@ -43,5 +38,5 @@ SEE ALSO
|
|||
|
||||
COPYING
|
||||
-------
|
||||
Copyright \(C) 2011 Steven Armstrong. Free use of this software is
|
||||
Copyright \(C) 2012 Steven Armstrong. Free use of this software is
|
||||
granted under the terms of the GNU General Public License version 3 (GPLv3).
|
|
@ -27,7 +27,7 @@ exists="$(cat "$__object/explorer/exists")"
|
|||
|
||||
[ "$state_should" = "exists" -a "$exists" = "yes" ] && exit 0 # nothing to do
|
||||
|
||||
if [ "$state_should" = "present" ]; then
|
||||
if [ "$state_should" = "present" -o "$state_should" = "exists" ]; then
|
||||
if [ -f "$__object/parameter/source" ]; then
|
||||
source="$(cat "$__object/parameter/source")"
|
||||
if [ "$source" = "-" ]; then
|
||||
|
|
|
@ -26,7 +26,7 @@ state_should="$(cat "$__object/parameter/state")"
|
|||
exists="$(cat "$__object/explorer/exists")"
|
||||
|
||||
case "$state_should" in
|
||||
present)
|
||||
present|exists)
|
||||
# No source? Create empty file
|
||||
if [ ! -f "$__object/parameter/source" ]; then
|
||||
if [ "$exists" = "no" ]; then
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
#!/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/>.
|
||||
#
|
||||
|
||||
device="$(cat "$__object/parameter/device")"
|
||||
type="$(cat "$__object/parameter/type")"
|
||||
|
||||
if [ "$type" = "swap" ]; then
|
||||
echo "mkswap $device"
|
||||
else
|
||||
command="mkfs -t $type -q"
|
||||
if [ -f "$__object/parameter/options" ]; then
|
||||
options="$(cat "$__object/parameter/options")"
|
||||
command="$command $options"
|
||||
fi
|
||||
command="$command $device"
|
||||
if [ -f "$__object/parameter/blocks" ]; then
|
||||
blocks="$(cat "$__object/parameter/blocks")"
|
||||
command="$command $blocks"
|
||||
fi
|
||||
echo "$command"
|
||||
fi
|
|
@ -1,57 +0,0 @@
|
|||
cdist-type__mkfs(7)
|
||||
===================
|
||||
Steven Armstrong <steven-cdist--@--armstrong.cc>
|
||||
|
||||
|
||||
NAME
|
||||
----
|
||||
cdist-type__mkfs - build a linux file system
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
This cdist type is a wrapper for the mkfs command.
|
||||
|
||||
|
||||
REQUIRED PARAMETERS
|
||||
-------------------
|
||||
type::
|
||||
The filesystem type to use. Same as mkfs -t.
|
||||
|
||||
|
||||
OPTIONAL PARAMETERS
|
||||
-------------------
|
||||
device::
|
||||
defaults to object_id
|
||||
|
||||
options::
|
||||
file system-specific options to be passed to the mkfs command
|
||||
|
||||
blocks::
|
||||
the number of blocks to be used for the file system
|
||||
|
||||
|
||||
EXAMPLES
|
||||
--------
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
# reiserfs /dev/sda5
|
||||
__mkfs /dev/sda5 --type reiserfs
|
||||
# same thing with explicit device
|
||||
__mkfs whatever --device /dev/sda5 --type reiserfs
|
||||
|
||||
# jfs with journal on /dev/sda2
|
||||
__mkfs /dev/sda1 --type jfs --options "-j /dev/sda2"
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
SEE ALSO
|
||||
--------
|
||||
- cdist-type(7)
|
||||
- mkfs(8)
|
||||
|
||||
|
||||
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).
|
|
@ -1,3 +0,0 @@
|
|||
device
|
||||
options
|
||||
blocks
|
|
@ -1 +0,0 @@
|
|||
type
|
|
@ -1,62 +0,0 @@
|
|||
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
|
||||
# 100GB, extended
|
||||
__partition_msdos /dev/sda3 --type extended --size 100G
|
||||
# 10GB, linux
|
||||
__partition_msdos /dev/sda5 --type 83 --size 10G
|
||||
# 50% of the free space of the extended partition, linux
|
||||
__partition_msdos /dev/sda6 --type 83 --size 50%
|
||||
# rest of the extended partition, linux
|
||||
__partition_msdos /dev/sda7 --type 83 --size +
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
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).
|
|
@ -1,41 +0,0 @@
|
|||
#!/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="$__object_name" __partition_msdos_apply
|
|
@ -1,3 +0,0 @@
|
|||
partition
|
||||
bootable
|
||||
size
|
|
@ -1 +0,0 @@
|
|||
type
|
|
@ -1,3 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
cat /proc/partitions
|
|
@ -1,61 +0,0 @@
|
|||
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}"
|
||||
printf "${cmd}\nw\n" | fdisk -c -u "$device"
|
||||
# give disk some time
|
||||
sleep 1
|
||||
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" -gt "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 $?
|
||||
}
|
||||
|
|
@ -1,138 +0,0 @@
|
|||
#!/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_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\" || die 'Failed to create disklabel for $device'"
|
||||
current_device="$device"
|
||||
device_name=$(echo ${device} | sed -e 's:^/dev/::;s:/:\\/:g')
|
||||
available_device_size=$(( $(awk "/${device_name}\$/ { print \$3; }" "$partitions") / 1024))
|
||||
# make sure we don't go past the end of the drive
|
||||
available_device_size=$((available_device_size - 2))
|
||||
available_extended_size=0
|
||||
primary_count=0
|
||||
debug "----- $device"
|
||||
debug "current_device=$current_device"
|
||||
debug "available_device_size=$available_device_size"
|
||||
fi
|
||||
|
||||
type="$(cat "$object/parameter/type")"
|
||||
partition="$(cat "$object/parameter/partition")"
|
||||
minor="$(cat "$object/parameter/minor")"
|
||||
|
||||
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=""
|
||||
available_size=0
|
||||
else
|
||||
partition_size=$(size_to_mb "$size" "$available_size")
|
||||
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"
|
||||
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"
|
||||
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' \
|
||||
|| die 'Failed to create partition: $partition'"
|
||||
done
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
# This type allows to send a public ssh key from a user to the
|
||||
# authorized_keys of another
|
||||
#
|
||||
#require="__package openssh-server --state installed"
|
||||
#require="__package openssh-server --state present"
|
||||
# Get option srcuser if defined
|
||||
if [ -f "$__object/parameter/srcuser" ]; then
|
||||
srcuser=`cat "$__object/parameter/srcuser"`
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||
# 2012 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||
#
|
||||
# This file is part of cdist.
|
||||
#
|
||||
|
@ -18,9 +18,13 @@
|
|||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#
|
||||
# Generate auto.master config based on all defined __autofs_map ojbects.
|
||||
#
|
||||
# This type allows to configure the desired localtime timezone.
|
||||
|
||||
auto_master="$__object/files/auto.master"
|
||||
cat "$(cat "$__object/parameter/header")" > "$auto_master"
|
||||
find "$__global/object/__autofs_map" -path "*.cdist/parameter/entry" | xargs cat >> "$auto_master"
|
||||
timezone="$__object_id"
|
||||
os=$(cat "$__global/explorer/os")
|
||||
|
||||
case "$os" in
|
||||
ubuntu|debian)
|
||||
echo "echo \"$timezone\" > /etc/timezone"
|
||||
;;
|
||||
esac
|
|
@ -1,6 +1,7 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# 2011 Ramon Salvadó (rsalvado at gnuine dot com)
|
||||
# 2012 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||
#
|
||||
# This file is part of cdist.
|
||||
#
|
||||
|
@ -22,7 +23,25 @@
|
|||
|
||||
timezone="$__object_id"
|
||||
|
||||
__package tzdata --state installed
|
||||
os=$(cat "$__global/explorer/os")
|
||||
|
||||
not_supported() {
|
||||
echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
|
||||
echo "Please contribute an implementation for it if you can." >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
case "$os" in
|
||||
ubuntu|debian|archlinux)
|
||||
:
|
||||
;;
|
||||
*)
|
||||
not_supported
|
||||
;;
|
||||
esac
|
||||
|
||||
# same for all supported os's
|
||||
__package tzdata --state present
|
||||
require="__package/tzdata" __link /etc/localtime \
|
||||
--source "/usr/share/zoneinfo/${timezone}" \
|
||||
--type symbolic
|
||||
|
|
Loading…
Reference in a new issue