diff --git a/cdist/conf/explorer/disks b/cdist/conf/explorer/disks new file mode 100644 index 00000000..52fef81e --- /dev/null +++ b/cdist/conf/explorer/disks @@ -0,0 +1,2 @@ +cd /dev +echo sd? hd? vd? diff --git a/cdist/conf/type/__cdist_preos/man.text b/cdist/conf/type/__cdist_preos/man.text new file mode 100644 index 00000000..19caa8e2 --- /dev/null +++ b/cdist/conf/type/__cdist_preos/man.text @@ -0,0 +1,38 @@ +cdist-type__cdist_preos(7) +========================== +Nico Schottelius + + +NAME +---- +cdist-type__cdist - Manage cdist installations + + +DESCRIPTION +----------- +This cdist type creates a directory containing an operating +suitable for installation using cdist. + +REQUIRED PARAMETERS +------------------- + +OPTIONAL PARAMETERS +------------------- +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__cdist_preos /tmp/random_name_for_packaging +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- cdist-type__cdist(7) + + +COPYING +------- +Copyright \(C) 2015 Nico Schottelius. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__cdist_preos/manifest b/cdist/conf/type/__cdist_preos/manifest new file mode 100755 index 00000000..78166b38 --- /dev/null +++ b/cdist/conf/type/__cdist_preos/manifest @@ -0,0 +1,79 @@ +#!/bin/sh +# +# 2015 Nico Schottelius (nico-cdist at schottelius.org) +# +# 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 . +# +# + +destination="/$__object_id" + +os=$(cat "$__global/explorer/os") + +case "$os" in + archlinux) + kernel=/boot/vmlinuz-linux + initramfs=/boot/initramfs-linux-fallback.img + required_pkg="cdrkit syslinux" + ;; + *) + 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 + ;; +esac + +# Our root +__directory "$destination" \ + --mode 0755 + +for rootdir in boot bin etc lib; do + require="__directory/$destination" __directory "$destination/$rootdir" \ + --mode 0755 +done + +require="__directory/$destination/etc" __cdistmarker \ + --destination "$destination/etc/cdist-configured" + +for pkg in $required_pkg; do + __package "$pkg" --state present +done + +# Create full dependency chain, because we don't know which file depends on which package +export CDIST_ORDER_DEPENDENCY=1 + +require="__directory/$destination/boot" __file "$destination/boot/linux" \ + --source "$kernel" --mode 0644 + +require="__directory/$destination/boot" __file "$destination/boot/initramfs" \ + --source "$initramfs" --mode 0644 + +require="__directory/$destination/boot" __file "$destination/boot/syslinux.cfg" \ + + + PROMPT 1 + TIMEOUT 50 + DEFAULT arch + + LABEL arch + LINUX ../vmlinuz-linux + APPEND root=/dev/sda2 rw + INITRD ../initramfs-linux.img + + LABEL archfallback + LINUX ../vmlinuz-linux + APPEND root=/dev/sda2 rw + INITRD ../initramfs-linux-fallback.img diff --git a/cdist/conf/type/__cdist_preos/parameter/default/branch b/cdist/conf/type/__cdist_preos/parameter/default/branch new file mode 100644 index 00000000..1f7391f9 --- /dev/null +++ b/cdist/conf/type/__cdist_preos/parameter/default/branch @@ -0,0 +1 @@ +master diff --git a/cdist/conf/type/__cdist_preos/parameter/default/source b/cdist/conf/type/__cdist_preos/parameter/default/source new file mode 100644 index 00000000..d669308f --- /dev/null +++ b/cdist/conf/type/__cdist_preos/parameter/default/source @@ -0,0 +1 @@ +git://github.com/telmich/cdist.git diff --git a/cdist/conf/type/__cdist_preos/parameter/default/username b/cdist/conf/type/__cdist_preos/parameter/default/username new file mode 100644 index 00000000..a585e141 --- /dev/null +++ b/cdist/conf/type/__cdist_preos/parameter/default/username @@ -0,0 +1 @@ +cdist diff --git a/cdist/conf/type/__cdist_preos/parameter/optional b/cdist/conf/type/__cdist_preos/parameter/optional new file mode 100644 index 00000000..a5f14343 --- /dev/null +++ b/cdist/conf/type/__cdist_preos/parameter/optional @@ -0,0 +1,4 @@ +branch +source +username +shell diff --git a/cdist/conf/type/__chroot_mount/gencode-remote b/cdist/conf/type/__chroot_mount/gencode-remote new file mode 100755 index 00000000..6d855f41 --- /dev/null +++ b/cdist/conf/type/__chroot_mount/gencode-remote @@ -0,0 +1,48 @@ +#!/bin/sh +# +# 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 . +# + +chroot="/$__object_id" + +cat << DONE +# Prepare chroot +[ -d "${chroot}/proc" ] || mkdir "${chroot}/proc" +mountpoint -q "${chroot}/proc" \ + || mount -t proc -o nosuid,noexec,nodev proc "${chroot}/proc" + +[ -d "${chroot}/sys" ] || mkdir "${chroot}/sys" +mountpoint -q "${chroot}/sys" \ + || mount -t sysfs -o nosuid,noexec,nodev sys "${chroot}/sys" + +[ -d "${chroot}/dev" ] || mkdir "${chroot}/dev" +mountpoint -q "${chroot}/dev" \ + || mount -t devtmpfs -o mode=0755,nosuid udev "${chroot}/dev" + +[ -d "${chroot}/dev/pts" ] || mkdir "${chroot}/dev/pts" +mountpoint -q "${chroot}/dev/pts" \ + || mount -t devpts -o mode=0620,gid=5,nosuid,noexec devpts "${chroot}/dev/pts" + +[ -d "${chroot}/tmp" ] || mkdir -m 1777 "${chroot}/tmp" +mountpoint -q "${chroot}/tmp" \ + || mount -t tmpfs -o mode=1777,strictatime,nodev,nosuid tmpfs "${chroot}/tmp" + +if [ ! -f "${chroot}/etc/resolv.conf" ]; then + cp /etc/resolv.conf "${chroot}/etc/" +fi +DONE diff --git a/cdist/conf/type/__chroot_mount/man.text b/cdist/conf/type/__chroot_mount/man.text new file mode 100644 index 00000000..adce80d9 --- /dev/null +++ b/cdist/conf/type/__chroot_mount/man.text @@ -0,0 +1,42 @@ +cdist-type__install_chroot_mount(7) +=================================== +Steven Armstrong + + +NAME +---- +cdist-type__install_chroot_mount - mount a chroot + + +DESCRIPTION +----------- +Mount and prepare a chroot for running commands within it. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +None. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__install_chroot_mount /path/to/chroot +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2012 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__chroot_umount/gencode-remote b/cdist/conf/type/__chroot_umount/gencode-remote new file mode 100755 index 00000000..caf2c40c --- /dev/null +++ b/cdist/conf/type/__chroot_umount/gencode-remote @@ -0,0 +1,36 @@ +#!/bin/sh +# +# 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 . +# + +chroot="/$__object_id" + +cat << DONE +umount -l "${chroot}/tmp" +umount -l "${chroot}/dev/pts" +umount -l "${chroot}/dev" +umount -l "${chroot}/sys" +umount -l "${chroot}/proc" +rm -f "${chroot}/etc/resolv.conf" +if [ -d "${chroot}/etc/resolvconf/resolv.conf.d" ]; then + # ensure /etc/resolvconf/resolv.conf.d/tail is not linked to \ + # e.g. /etc/resolvconf/resolv.conf.d/original + rm -f "${chroot}/etc/resolvconf/resolv.conf.d/tail" + touch "${chroot}/etc/resolvconf/resolv.conf.d/tail" +fi +DONE diff --git a/cdist/conf/type/__chroot_umount/man.text b/cdist/conf/type/__chroot_umount/man.text new file mode 100644 index 00000000..a5ca1ef0 --- /dev/null +++ b/cdist/conf/type/__chroot_umount/man.text @@ -0,0 +1,42 @@ +cdist-type__install_chroot_umount(7) +==================================== +Steven Armstrong + + +NAME +---- +cdist-type__install_chroot_umount - unmount a chroot mounted by __chroot_mount + + +DESCRIPTION +----------- +Undo what __chroot_mount did. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +None. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__install_chroot_umount /path/to/chroot +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2012 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__install_bootloader_grub/gencode-remote b/cdist/conf/type/__install_bootloader_grub/gencode-remote new file mode 100755 index 00000000..ed57331a --- /dev/null +++ b/cdist/conf/type/__install_bootloader_grub/gencode-remote @@ -0,0 +1,73 @@ +#!/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 . +# + +device="$(cat "$__object/parameter/device")" +chroot="$(cat "$__object/parameter/chroot")" + + +cat << DONE +os=\$( +if grep -q ^DISTRIB_ID=Ubuntu ${chroot}/etc/lsb-release 2>/dev/null; then + echo ubuntu + exit 0 +fi + +if [ -f ${chroot}/etc/arch-release ]; then + echo archlinux + exit 0 +fi + +if [ -f ${chroot}/etc/debian_version ]; then + echo debian + exit 0 +fi +) + +# Ensure /tmp exists +[ -d "${chroot}/tmp" ] || mkdir -m 1777 "${chroot}/tmp" +# Generate script to run in chroot +script=\$(mktemp "${chroot}/tmp/__install_bootloader_grub.XXXXXXXXXX") +# Link file descriptor #6 with stdout +exec 6>&1 +# Link stdout with \$script +exec > \$script + +echo "#!/bin/sh -l" +echo "grub-install $device" +case \$os in + archlinux) + # bugfix/workarround: rebuild initramfs + # FIXME: doesn't belong here + echo "mkinitcpio -p linux" + echo "grub-mkconfig -o /boot/grub/grub.cfg" + ;; + ubuntu|debian) echo "update-grub" ;; +esac + +# Restore stdout and close file descriptor #6. +exec 1>&6 6>&- + +# Make script executable +chmod +x "\$script" + +# Run script in chroot +relative_script="\${script#$chroot}" +chroot "$chroot" "\$relative_script" +DONE diff --git a/cdist/conf/type/__install_bootloader_grub/install b/cdist/conf/type/__install_bootloader_grub/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_bootloader_grub/man.text b/cdist/conf/type/__install_bootloader_grub/man.text new file mode 100644 index 00000000..858e6a67 --- /dev/null +++ b/cdist/conf/type/__install_bootloader_grub/man.text @@ -0,0 +1,47 @@ +cdist-type__install_bootloader_grub(7) +====================================== +Steven Armstrong + + +NAME +---- +cdist-type__install_bootloader_grub - install grub2 bootloader on given disk + + +DESCRIPTION +----------- +This cdist type allows you to install grub2 bootloader on given disk. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +device:: + The device to install grub to. Defaults to object_id + +chroot:: + where to chroot before running grub-install. Defaults to /target. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__install_bootloader_grub /dev/sda +__install_bootloader_grub /dev/sda --chroot /mnt/foobar +-------------------------------------------------------------------------------- + + +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). diff --git a/cdist/conf/type/__install_bootloader_grub/manifest b/cdist/conf/type/__install_bootloader_grub/manifest new file mode 100755 index 00000000..4c7c4955 --- /dev/null +++ b/cdist/conf/type/__install_bootloader_grub/manifest @@ -0,0 +1,25 @@ +#!/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 . +# + +# set defaults +device="$(cat "$__object/parameter/device" 2>/dev/null \ + || echo "/$__object_id" | tee "$__object/parameter/device")" +chroot="$(cat "$__object/parameter/chroot" 2>/dev/null \ + || echo "/target" | tee "$__object/parameter/chroot")" diff --git a/cdist/conf/type/__install_bootloader_grub/parameter/optional b/cdist/conf/type/__install_bootloader_grub/parameter/optional new file mode 100644 index 00000000..0bd1ce46 --- /dev/null +++ b/cdist/conf/type/__install_bootloader_grub/parameter/optional @@ -0,0 +1,2 @@ +device +chroot diff --git a/cdist/conf/type/__install_chroot_mount/gencode-remote b/cdist/conf/type/__install_chroot_mount/gencode-remote new file mode 120000 index 00000000..b1a5485e --- /dev/null +++ b/cdist/conf/type/__install_chroot_mount/gencode-remote @@ -0,0 +1 @@ +../__chroot_mount/gencode-remote \ No newline at end of file diff --git a/cdist/conf/type/__install_chroot_mount/install b/cdist/conf/type/__install_chroot_mount/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_chroot_mount/man.text b/cdist/conf/type/__install_chroot_mount/man.text new file mode 120000 index 00000000..e131fceb --- /dev/null +++ b/cdist/conf/type/__install_chroot_mount/man.text @@ -0,0 +1 @@ +../__chroot_mount/man.text \ No newline at end of file diff --git a/cdist/conf/type/__install_chroot_umount/gencode-remote b/cdist/conf/type/__install_chroot_umount/gencode-remote new file mode 120000 index 00000000..f2bd2681 --- /dev/null +++ b/cdist/conf/type/__install_chroot_umount/gencode-remote @@ -0,0 +1 @@ +../__chroot_umount/gencode-remote \ No newline at end of file diff --git a/cdist/conf/type/__install_chroot_umount/install b/cdist/conf/type/__install_chroot_umount/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_chroot_umount/man.text b/cdist/conf/type/__install_chroot_umount/man.text new file mode 120000 index 00000000..f615c734 --- /dev/null +++ b/cdist/conf/type/__install_chroot_umount/man.text @@ -0,0 +1 @@ +../__chroot_umount/man.text \ No newline at end of file diff --git a/cdist/conf/type/__install_config/files/remote/copy b/cdist/conf/type/__install_config/files/remote/copy new file mode 100755 index 00000000..5b6f555c --- /dev/null +++ b/cdist/conf/type/__install_config/files/remote/copy @@ -0,0 +1,48 @@ +#!/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 . +# +# +# __remote_copy script to run cdist against a chroot on a remote host via ssh. +# +# Usage: +# __remote_copy="/path/to/this/script /path/to/your/chroot" cdist config target-id +# + +log() { + echo "$@" | logger -t "__install_config copy" + : +} + +chroot="$1"; shift +target_host="$__target_host" + +scp="scp -o User=root -q" + +# postfix target_host with chroot location +code="$(echo "$@" | sed "s|$target_host:|$target_host:$chroot|g")" + +log "target_host: $target_host" +log "chroot: $chroot" +log "@: $@" +log "code: $code" + +# copy files into chroot +$scp $code + +log "-----" diff --git a/cdist/conf/type/__install_config/files/remote/exec b/cdist/conf/type/__install_config/files/remote/exec new file mode 100755 index 00000000..58e6b162 --- /dev/null +++ b/cdist/conf/type/__install_config/files/remote/exec @@ -0,0 +1,48 @@ +#!/bin/sh +# +# 2011-2013 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 . +# +# +# __remote_exec script to run cdist against a chroot on a remote host via ssh. +# +# Usage: +# __remote_exec="/path/to/this/script /path/to/your/chroot" cdist config target-id +# + +log() { + echo "$@" | logger -t "__install_config exec" + : +} + +chroot="$1"; shift +target_host="$__target_host" +# In exec mode the first argument is the __target_host which we already got from env. Get rid of it. +shift + +ssh="ssh -o User=root -q $target_host" +code="$ssh chroot $chroot sh -c '$@'" + +log "target_host: $target_host" +log "chroot: $chroot" +log "@: $@" +log "code: $code" + +# Run the code +$code + +log "-----" diff --git a/cdist/conf/type/__install_config/gencode-local b/cdist/conf/type/__install_config/gencode-local new file mode 100755 index 00000000..674dec25 --- /dev/null +++ b/cdist/conf/type/__install_config/gencode-local @@ -0,0 +1,50 @@ +#!/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 . +# + +chroot="$(cat "$__object/parameter/chroot")" +remote_exec="$__type/files/remote/exec" +remote_copy="$__type/files/remote/copy" + +cdist_args="-v" +[ "$__debug" = "yes" ] && cdist_args="$cdist_args -d" + +cat << DONE +#echo "__apt_noautostart --state present" \ +# | cdist $cdist_args \ +# config \ +# --initial-manifest - \ +# --remote-exec="$remote_exec $chroot" \ +# --remote-copy="$remote_copy $chroot" \ +# $__target_host + +cdist $cdist_args \ + config \ + --remote-exec="$remote_exec $chroot" \ + --remote-copy="$remote_copy $chroot" \ + $__target_host + +#echo "__apt_noautostart --state absent" \ +# | cdist $cdist_args \ +# config \ +# --initial-manifest - \ +# --remote-exec="$remote_exec $chroot" \ +# --remote-copy="$remote_copy $chroot" \ +# $__target_host +DONE diff --git a/cdist/conf/type/__install_config/install b/cdist/conf/type/__install_config/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_config/man.text b/cdist/conf/type/__install_config/man.text new file mode 100644 index 00000000..def0439b --- /dev/null +++ b/cdist/conf/type/__install_config/man.text @@ -0,0 +1,47 @@ +cdist-type__install_config(7) +============================= +Steven Armstrong + + +NAME +---- +cdist-type__install_config - run cdist config as part of the installation + + +DESCRIPTION +----------- +This cdist type allows you to run cdist config as part of the installation. +It does this by using a custom __remote_{copy,exec} prefix which runs +cdist config against the /target chroot on the remote host. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +chroot:: + where to chroot before running grub-install. Defaults to /target. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__install_config + +__install_config --chroot /mnt/somewhere +-------------------------------------------------------------------------------- + + +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). diff --git a/cdist/conf/type/__install_config/manifest b/cdist/conf/type/__install_config/manifest new file mode 100755 index 00000000..f26297b4 --- /dev/null +++ b/cdist/conf/type/__install_config/manifest @@ -0,0 +1,23 @@ +#!/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 . +# + +# set defaults +chroot="$(cat "$__object/parameter/chroot" 2>/dev/null \ + || echo "/target" | tee "$__object/parameter/chroot")" diff --git a/cdist/conf/type/__install_config/parameter/optional b/cdist/conf/type/__install_config/parameter/optional new file mode 100644 index 00000000..fa32393d --- /dev/null +++ b/cdist/conf/type/__install_config/parameter/optional @@ -0,0 +1 @@ +chroot diff --git a/cdist/conf/type/__install_config/singleton b/cdist/conf/type/__install_config/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_file/explorer b/cdist/conf/type/__install_file/explorer new file mode 120000 index 00000000..8479ee44 --- /dev/null +++ b/cdist/conf/type/__install_file/explorer @@ -0,0 +1 @@ +../__file/explorer \ No newline at end of file diff --git a/cdist/conf/type/__install_file/gencode-local b/cdist/conf/type/__install_file/gencode-local new file mode 120000 index 00000000..9ce4e805 --- /dev/null +++ b/cdist/conf/type/__install_file/gencode-local @@ -0,0 +1 @@ +../__file/gencode-local \ No newline at end of file diff --git a/cdist/conf/type/__install_file/gencode-remote b/cdist/conf/type/__install_file/gencode-remote new file mode 120000 index 00000000..f390bba4 --- /dev/null +++ b/cdist/conf/type/__install_file/gencode-remote @@ -0,0 +1 @@ +../__file/gencode-remote \ No newline at end of file diff --git a/cdist/conf/type/__install_file/install b/cdist/conf/type/__install_file/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_file/man.text b/cdist/conf/type/__install_file/man.text new file mode 120000 index 00000000..ba483161 --- /dev/null +++ b/cdist/conf/type/__install_file/man.text @@ -0,0 +1 @@ +../__file/man.text \ No newline at end of file diff --git a/cdist/conf/type/__install_file/parameter b/cdist/conf/type/__install_file/parameter new file mode 120000 index 00000000..e5099e86 --- /dev/null +++ b/cdist/conf/type/__install_file/parameter @@ -0,0 +1 @@ +../__file/parameter \ No newline at end of file diff --git a/cdist/conf/type/__install_fstab/install b/cdist/conf/type/__install_fstab/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_fstab/man.text b/cdist/conf/type/__install_fstab/man.text new file mode 100644 index 00000000..7c509427 --- /dev/null +++ b/cdist/conf/type/__install_fstab/man.text @@ -0,0 +1,48 @@ +cdist-type__install_fstab(7) +============================ +Steven Armstrong + + +NAME +---- +cdist-type__install_fstab - generate /etc/fstab during installation + + +DESCRIPTION +----------- +Uses __install_generate_fstab to generate a /etc/fstab file and uploads it +to the target machine at ${prefix}/etc/fstab. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +prefix:: + The prefix under which to generate the /etc/fstab file. + Defaults to /target. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__install_fstab +__install_fstab --prefix /mnt/target +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- cdist-type__install_mount(7) +- cdist-type__install_generate_fstab(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). diff --git a/cdist/conf/type/__install_fstab/manifest b/cdist/conf/type/__install_fstab/manifest new file mode 100755 index 00000000..74af53c0 --- /dev/null +++ b/cdist/conf/type/__install_fstab/manifest @@ -0,0 +1,29 @@ +#!/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 . +# + +prefix="$(cat "$__object/parameter/prefix" 2>/dev/null || echo "/target")" + +[ -d "$__object/files" ] || mkdir "$__object/files" +__install_generate_fstab --uuid --destination "$__object/files/fstab" +require="__install_generate_fstab" \ + __install_file "${prefix}/etc/fstab" --source "$__object/files/fstab" \ + --mode 644 \ + --owner root \ + --group root diff --git a/cdist/conf/type/__install_fstab/parameter/optional b/cdist/conf/type/__install_fstab/parameter/optional new file mode 100644 index 00000000..f73f3093 --- /dev/null +++ b/cdist/conf/type/__install_fstab/parameter/optional @@ -0,0 +1 @@ +file diff --git a/cdist/conf/type/__install_fstab/singleton b/cdist/conf/type/__install_fstab/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_generate_fstab/files/fstab.header b/cdist/conf/type/__install_generate_fstab/files/fstab.header new file mode 100644 index 00000000..7653cc78 --- /dev/null +++ b/cdist/conf/type/__install_generate_fstab/files/fstab.header @@ -0,0 +1 @@ +# Generated by cdist __install_generate_fstab diff --git a/cdist/conf/type/__install_generate_fstab/gencode-local b/cdist/conf/type/__install_generate_fstab/gencode-local new file mode 100755 index 00000000..d10e5b92 --- /dev/null +++ b/cdist/conf/type/__install_generate_fstab/gencode-local @@ -0,0 +1,59 @@ +#!/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 . +# + +destination="$(cat "$__object/parameter/destination")" +cat "$__type/files/fstab.header" > "$destination" + +mkdir "$__object/files" +# get current UUID's from target_host +$__remote_exec $__target_host blkid > "$__object/files/blkid" + +for object in $(find "$__global/object/__install_mount" -path "*.cdist"); do + device="$(cat "$object/parameter/device")" + dir="$(cat "$object/parameter/dir")" + prefix="$(cat "$object/parameter/prefix")" + type="$(cat "$object/parameter/type")" + if [ -f "$object/parameter/options" ]; then + options="$(cat "$object/parameter/options")" + else + options="defaults" + fi + dump=0 + case "$type" in + swap) + pass=0 + dir="$type" + ;; + tmpfs) + pass=0 + ;; + *) + pass=1 + ;; + esac + if [ -f "$__object/parameter/uuid" ]; then + uuid="$(grep -w $device "$__object/files/blkid" | awk '{print $2}')" + if [ -n "$uuid" ]; then + echo "# $dir was on $device during installation" >> "$destination" + device="$uuid" + fi + fi + echo "$device $dir $type $options $dump $pass" >> "$destination" +done diff --git a/cdist/conf/type/__install_generate_fstab/install b/cdist/conf/type/__install_generate_fstab/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_generate_fstab/man.text b/cdist/conf/type/__install_generate_fstab/man.text new file mode 100644 index 00000000..d229f4df --- /dev/null +++ b/cdist/conf/type/__install_generate_fstab/man.text @@ -0,0 +1,52 @@ +cdist-type__install_generate_fstab(7) +===================================== +Steven Armstrong + + +NAME +---- +cdist-type__install_generate_fstab - generate /etc/fstab during installation + + +DESCRIPTION +----------- +Generates a /etc/fstab file from information retrieved from +__install_mount definitions. + + +REQUIRED PARAMETERS +------------------- +destination:: + The path where to store the generated fstab file. + Note that this is a path on the server, where cdist is running, not the target host. + + +OPTIONAL PARAMETERS +------------------- +None. + + +BOOLEAN PARAMETERS +------------------- +uuid:: + use UUID instead of device in fstab + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__install_generate_fstab --destination /path/where/you/want/fstab +__install_generate_fstab --uuid --destination /path/where/you/want/fstab +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2012 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__install_generate_fstab/parameter/boolean b/cdist/conf/type/__install_generate_fstab/parameter/boolean new file mode 100644 index 00000000..43ab6159 --- /dev/null +++ b/cdist/conf/type/__install_generate_fstab/parameter/boolean @@ -0,0 +1 @@ +uuid diff --git a/cdist/conf/type/__install_generate_fstab/parameter/required b/cdist/conf/type/__install_generate_fstab/parameter/required new file mode 100644 index 00000000..ac459b09 --- /dev/null +++ b/cdist/conf/type/__install_generate_fstab/parameter/required @@ -0,0 +1 @@ +destination diff --git a/cdist/conf/type/__install_generate_fstab/singleton b/cdist/conf/type/__install_generate_fstab/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_mkfs/gencode-remote b/cdist/conf/type/__install_mkfs/gencode-remote new file mode 100755 index 00000000..2fe680e5 --- /dev/null +++ b/cdist/conf/type/__install_mkfs/gencode-remote @@ -0,0 +1,53 @@ +#!/bin/sh +# +# 2011-2013 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 . +# + +device="$(cat "$__object/parameter/device")" +type="$(cat "$__object/parameter/type")" + +case "$type" in + swap) + echo "mkswap $device" + ;; + xfs) + command="mkfs.xfs -f -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" + ;; + *) + 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" +esac diff --git a/cdist/conf/type/__install_mkfs/install b/cdist/conf/type/__install_mkfs/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_mkfs/man.text b/cdist/conf/type/__install_mkfs/man.text new file mode 100644 index 00000000..3a9a325d --- /dev/null +++ b/cdist/conf/type/__install_mkfs/man.text @@ -0,0 +1,57 @@ +cdist-type__install_mkfs(7) +=========================== +Steven Armstrong + + +NAME +---- +cdist-type__install_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 used with 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 +__install_mkfs /dev/sda5 --type reiserfs +# same thing with explicit device +__install_mkfs whatever --device /dev/sda5 --type reiserfs + +# jfs with journal on /dev/sda2 +__install_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). diff --git a/cdist/conf/type/__install_mkfs/manifest b/cdist/conf/type/__install_mkfs/manifest new file mode 100755 index 00000000..e9d275a4 --- /dev/null +++ b/cdist/conf/type/__install_mkfs/manifest @@ -0,0 +1,31 @@ +#!/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 . +# + +# 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")" + +options="(cat "$__object/parameter/options")" diff --git a/cdist/conf/type/__install_mkfs/parameter/optional b/cdist/conf/type/__install_mkfs/parameter/optional new file mode 100644 index 00000000..86aeae30 --- /dev/null +++ b/cdist/conf/type/__install_mkfs/parameter/optional @@ -0,0 +1,3 @@ +device +options +blocks diff --git a/cdist/conf/type/__install_mkfs/parameter/required b/cdist/conf/type/__install_mkfs/parameter/required new file mode 100644 index 00000000..aa80e646 --- /dev/null +++ b/cdist/conf/type/__install_mkfs/parameter/required @@ -0,0 +1 @@ +type diff --git a/cdist/conf/type/__install_mount/gencode-remote b/cdist/conf/type/__install_mount/gencode-remote new file mode 100755 index 00000000..3a35c139 --- /dev/null +++ b/cdist/conf/type/__install_mount/gencode-remote @@ -0,0 +1,59 @@ +#!/bin/sh +# +# 2011-2013 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 . +# + +get_type_from_mkfs() { + _device="$1" + for mkfs_object in $(find "$__global/object/__install_mkfs" -path "*.cdist"); do + mkfs_device="$(cat "$mkfs_object/parameter/device")" + if [ "$_device" = "$mkfs_device" ]; then + cat "$mkfs_object/parameter/type" + break + fi + done + unset _device + unset mkfs_device + unset mkfs_object +} + +device="$(cat "$__object/parameter/device")" +dir="$(cat "$__object/parameter/dir")" +prefix="$(cat "$__object/parameter/prefix")" +if [ -f "$__object/parameter/type" ]; then + type="$(cat "$__object/parameter/type")" +else + type="$(get_type_from_mkfs "$device")" + # store for later use by others + echo "$type" > "$__object/parameter/type" +fi +[ -n "$type" ] || die "Can't determine type for $__object" +if [ "$type" = "swap" ]; then + echo "swapon \"$device\"" +else + if [ -f "$__object/parameter/options" ]; then + options="$(cat "$__object/parameter/options")" + else + options="" + fi + [ -n "$options" ] && options="-o $options" + mount_point="${prefix}${dir}" + + echo "[ -d \"$mount_point\" ] || mkdir -p \"$mount_point\"" + echo "mount -t \"$type\" $options \"$device\" \"$mount_point\"" +fi diff --git a/cdist/conf/type/__install_mount/install b/cdist/conf/type/__install_mount/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_mount/man.text b/cdist/conf/type/__install_mount/man.text new file mode 100644 index 00000000..b55cb83e --- /dev/null +++ b/cdist/conf/type/__install_mount/man.text @@ -0,0 +1,61 @@ +cdist-type__install_mount(7) +============================ +Steven Armstrong + + +NAME +---- +cdist-type__install_mount - mount filesystems in the installer + + +DESCRIPTION +----------- +Mounts filesystems in the installer. Collects data to generate /etc/fstab. + + +REQUIRED PARAMETERS +------------------- +device:: + the device to mount + + +OPTIONAL PARAMETERS +------------------- +dir:: + where to mount device. Defaults to object_id. + +options:: + mount options passed to mount(8) and used in /etc/fstab + +type:: + filesystem type passed to mount(8) and used in /etc/fstab. + If type is swap, 'dir' is ignored. + Defaults to the filesystem used in __install_mkfs for the same 'device'. + +prefix:: + the prefix to prepend to 'dir' when mounting in the installer. + Defaults to /target. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__install_mount slash --dir / --device /dev/sda5 --options noatime +require="__install_mount/slash" __install_mount /boot --device /dev/sda1 +__install_mount swap --device /dev/sda2 --type swap +require="__install_mount/slash" __install_mount /tmp --device tmpfs --type tmpfs +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- cdist-type__install_mount_apply(7) +- cdist-type__install_mkfs(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). diff --git a/cdist/conf/type/__install_mount/manifest b/cdist/conf/type/__install_mount/manifest new file mode 100755 index 00000000..5afae7fc --- /dev/null +++ b/cdist/conf/type/__install_mount/manifest @@ -0,0 +1,29 @@ +#!/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 . +# + +# set defaults +if [ ! -f "$__object/parameter/dir" ]; then + dir="/$__object_id" + echo "$dir" > "$__object/parameter/dir" +fi +if [ ! -f "$__object/parameter/prefix" ]; then + prefix="/target" + echo "$prefix" > "$__object/parameter/prefix" +fi diff --git a/cdist/conf/type/__install_mount/parameter/optional b/cdist/conf/type/__install_mount/parameter/optional new file mode 100644 index 00000000..08b6ad04 --- /dev/null +++ b/cdist/conf/type/__install_mount/parameter/optional @@ -0,0 +1,3 @@ +dir +type +options diff --git a/cdist/conf/type/__install_mount/parameter/required b/cdist/conf/type/__install_mount/parameter/required new file mode 100644 index 00000000..f89ee6a8 --- /dev/null +++ b/cdist/conf/type/__install_mount/parameter/required @@ -0,0 +1 @@ +device diff --git a/cdist/conf/type/__install_partition_msdos/install b/cdist/conf/type/__install_partition_msdos/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_partition_msdos/man.text b/cdist/conf/type/__install_partition_msdos/man.text new file mode 100644 index 00000000..82d81ac5 --- /dev/null +++ b/cdist/conf/type/__install_partition_msdos/man.text @@ -0,0 +1,62 @@ +cdist-type__install_partition_msdos(7) +====================================== +Steven Armstrong + + +NAME +---- +cdist-type__install_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 +__install_partition_msdos /dev/sda1 --type 83 --size 128M --bootable true +# 512MB, swap +__install_partition_msdos /dev/sda2 --type 82 --size 512M +# 100GB, extended +__install_partition_msdos /dev/sda3 --type extended --size 100G +# 10GB, linux +__install_partition_msdos /dev/sda5 --type 83 --size 10G +# 50% of the free space of the extended partition, linux +__install_partition_msdos /dev/sda6 --type 83 --size 50% +# rest of the extended partition, linux +__install_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). diff --git a/cdist/conf/type/__install_partition_msdos/manifest b/cdist/conf/type/__install_partition_msdos/manifest new file mode 100755 index 00000000..e55d3f24 --- /dev/null +++ b/cdist/conf/type/__install_partition_msdos/manifest @@ -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 . +# + +# 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" __install_partition_msdos_apply diff --git a/cdist/conf/type/__install_partition_msdos/parameter/optional b/cdist/conf/type/__install_partition_msdos/parameter/optional new file mode 100644 index 00000000..b2b0a4c2 --- /dev/null +++ b/cdist/conf/type/__install_partition_msdos/parameter/optional @@ -0,0 +1,3 @@ +partition +bootable +size diff --git a/cdist/conf/type/__install_partition_msdos/parameter/required b/cdist/conf/type/__install_partition_msdos/parameter/required new file mode 100644 index 00000000..aa80e646 --- /dev/null +++ b/cdist/conf/type/__install_partition_msdos/parameter/required @@ -0,0 +1 @@ +type diff --git a/cdist/conf/type/__install_partition_msdos_apply/explorer/partitions b/cdist/conf/type/__install_partition_msdos_apply/explorer/partitions new file mode 100755 index 00000000..6be61af4 --- /dev/null +++ b/cdist/conf/type/__install_partition_msdos_apply/explorer/partitions @@ -0,0 +1,3 @@ +#!/bin/sh + +cat /proc/partitions diff --git a/cdist/conf/type/__install_partition_msdos_apply/files/lib.sh b/cdist/conf/type/__install_partition_msdos_apply/files/lib.sh new file mode 100644 index 00000000..cddc575d --- /dev/null +++ b/cdist/conf/type/__install_partition_msdos_apply/files/lib.sh @@ -0,0 +1,68 @@ +die() { + echo "[__install_partition_msdos_apply] $@" >&2 + exit 1 +} +debug() { + #echo "[__install_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" + ret=$? + # give disk some time + sleep 1 + return $ret +} + +create_disklabel() { + local device=$1 + + debug create_disklabel "creating new msdos disklabel" + fdisk_command ${device} "o" + return $? +} + +toggle_bootable() { + local device="$1" + local minor="$2" + fdisk_command ${device} "a\n${minor}\n" + 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 $? +} diff --git a/cdist/conf/type/__install_partition_msdos_apply/gencode-remote b/cdist/conf/type/__install_partition_msdos_apply/gencode-remote new file mode 100755 index 00000000..a1547296 --- /dev/null +++ b/cdist/conf/type/__install_partition_msdos_apply/gencode-remote @@ -0,0 +1,159 @@ +#!/bin/sh +# +# 2011-2013 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 . +# + +die() { + echo "[__install_partition_msdos_apply] $@" >&2 + exit 1 +} +debug() { + #echo "[__install_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]\+\)\([KkMmGg%]\)[Bb]\?:\1|\2:')" + local number="$(echo ${number_suffix} | cut -d '|' -f1)" + local suffix="$(echo ${number_suffix} | cut -d '|' -f2)" + + case "$suffix" in + K|k) + size="$(( $number / 1024 ))" + ;; + M|m) + size="$number" + ;; + G|g) + size="$(( $number * 1024 ))" + ;; + %) + size="$(( $available_size * $number / 100 ))" + ;; + *) + size="-1" + esac + echo "$size" +} + +get_objects() { + objects_file=$(mktemp) + for object in $(find "$__global/object/__install_partition_msdos" -path "*.cdist"); do + object_device="$(cat "$object/parameter/device")" + object_minor="$(cat "$object/parameter/minor")" + echo "$object_device $object_minor $object" >> $objects_file + done + sort -k 1,2 $objects_file | cut -d' ' -f 3 + rm $objects_file + unset objects_file + unset object + unset object_device + unset object_minor +} + +# include function library for use on target +cat "$__type/files/lib.sh" + +partitions="$__object/explorer/partitions" +objects=$(get_objects) +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'" + + if [ "$bootable" = "true" ]; then + echo "toggle_bootable '$device' '$minor' || die 'Failed to toogle bootable flag for partition: $partition'" + fi +done diff --git a/cdist/conf/type/__install_partition_msdos_apply/install b/cdist/conf/type/__install_partition_msdos_apply/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_partition_msdos_apply/man.text b/cdist/conf/type/__install_partition_msdos_apply/man.text new file mode 100644 index 00000000..5399afb7 --- /dev/null +++ b/cdist/conf/type/__install_partition_msdos_apply/man.text @@ -0,0 +1,42 @@ +cdist-type__install_partition_msdos_apply(7) +============================================ +Steven Armstrong + + +NAME +---- +cdist-type__install_partition_msdos_apply - Apply dos partition settings + + +DESCRIPTION +----------- +Create the partitions defined with __install_partition_msdos + + +REQUIRED PARAMETERS +------------------- +None + + +OPTIONAL PARAMETERS +------------------- +None. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__install_partition_msdos_apply +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- cdist-type__install_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). diff --git a/cdist/conf/type/__install_partition_msdos_apply/singleton b/cdist/conf/type/__install_partition_msdos_apply/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_reboot/gencode-remote b/cdist/conf/type/__install_reboot/gencode-remote new file mode 100755 index 00000000..4358347d --- /dev/null +++ b/cdist/conf/type/__install_reboot/gencode-remote @@ -0,0 +1,23 @@ +#!/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 . +# + +options="$(cat "$__object/parameter/options")" + +echo "reboot $options" diff --git a/cdist/conf/type/__install_reboot/install b/cdist/conf/type/__install_reboot/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_reboot/man.text b/cdist/conf/type/__install_reboot/man.text new file mode 100644 index 00000000..91aec19a --- /dev/null +++ b/cdist/conf/type/__install_reboot/man.text @@ -0,0 +1,43 @@ +cdist-type__install_reboot(7) +============================= +Steven Armstrong + + +NAME +---- +cdist-type__install_reboot - run reboot + + +DESCRIPTION +----------- +This cdist type allows you to reboot a machine. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +options:: + options to pass to the reboot command. e.g. -f + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__install_reboot +-------------------------------------------------------------------------------- + + +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). diff --git a/cdist/conf/type/__install_reboot/manifest b/cdist/conf/type/__install_reboot/manifest new file mode 100755 index 00000000..fab80a1e --- /dev/null +++ b/cdist/conf/type/__install_reboot/manifest @@ -0,0 +1,23 @@ +#!/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 . +# + +# set defaults +options="$(cat "$__object/parameter/options" 2>/dev/null \ + || echo "" | tee "$__object/parameter/options")" diff --git a/cdist/conf/type/__install_reboot/singleton b/cdist/conf/type/__install_reboot/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_reset_disk/gencode-remote b/cdist/conf/type/__install_reset_disk/gencode-remote new file mode 100755 index 00000000..e8e9cf8c --- /dev/null +++ b/cdist/conf/type/__install_reset_disk/gencode-remote @@ -0,0 +1,65 @@ +#!/bin/sh +# +# 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 . +# + +disk="/$__object_id" +disk_name="${disk##*/}" + +cat << DONE +# stop lvm's if any +if find /sys/class/block/$disk_name*/holders/ -mindepth 1 | grep -q holders/dm; then + if command -v vgchange >/dev/null; then + vgchange -a n + else + echo "WARNING: vgchange command not found" >&2 + fi +fi + +# stop mdadm raids if any +if [ -r /proc/mdstat ]; then + md_name="\$(awk "/$disk_name/ {print \$1}" /proc/mdstat)" + if [ -n "\$md_name" ]; then + if command -v mdadm >/dev/null; then + mdadm --stop "/dev/\$md_name" + else + echo "WARNING: mdadm command not found" >&2 + echo "WARNING: could not stop active mdadm raid for disk $disk" >&2 + fi + fi +fi + +if command -v pvremove >/dev/null; then + pvremove --force --force --yes "$disk" || true +else + echo "WARNING: pvremove command not found" >&2 +fi +if command -v mdadm >/dev/null; then + mdadm --zero-superblock --force "$disk" || true +else + echo "WARNING: mdadm command not found" >&2 +fi +# clean disks from any legacy signatures +if command -v wipefs >/dev/null; then + wipefs -a "$disk" || true +fi + +# erase partition table +dd if=/dev/zero of=$disk bs=512 count=1 +printf 'w\n' | fdisk -u -c $disk || true +DONE diff --git a/cdist/conf/type/__install_reset_disk/install b/cdist/conf/type/__install_reset_disk/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_reset_disk/man.text b/cdist/conf/type/__install_reset_disk/man.text new file mode 100644 index 00000000..542d68ba --- /dev/null +++ b/cdist/conf/type/__install_reset_disk/man.text @@ -0,0 +1,43 @@ +cdist-type__install_reset_disk(7) +================================= +Steven Armstrong + + +NAME +---- +cdist-type__install_reset_disk - reset a disk + + +DESCRIPTION +----------- +Remove partition table. +Remove all lvm labels. +Remove mdadm superblock. + + +REQUIRED PARAMETERS +------------------- +None. + +OPTIONAL PARAMETERS +------------------- +None. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__install_reset_disk /dev/sdb +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2012 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__install_stage/gencode-remote b/cdist/conf/type/__install_stage/gencode-remote new file mode 100755 index 00000000..3b83ea61 --- /dev/null +++ b/cdist/conf/type/__install_stage/gencode-remote @@ -0,0 +1,32 @@ +#!/bin/sh +# +# 2011-2013 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 . +# + +uri="$(cat "$__object/parameter/uri" 2>/dev/null \ + || echo "$__object_id")" +target="$(cat "$__object/parameter/target")" + +[ "$__debug" = "yes" ] && curl="curl" || curl="curl -s" +[ "$__debug" = "yes" ] && tar="tar -xvzp" || tar="tar -xzp" + +if [ -f "$__object/parameter/insecure" ] ; then + curl="$curl -k" +fi + +echo "$curl '$uri' | $tar -C '$target'" diff --git a/cdist/conf/type/__install_stage/install b/cdist/conf/type/__install_stage/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_stage/man.text b/cdist/conf/type/__install_stage/man.text new file mode 100644 index 00000000..289c8621 --- /dev/null +++ b/cdist/conf/type/__install_stage/man.text @@ -0,0 +1,58 @@ +cdist-type__install_stage(7) +============================ +Steven Armstrong + + +NAME +---- +cdist-type__install_stage - download and unpack a stage file + + +DESCRIPTION +----------- +Downloads a operating system stage using curl and unpacks it to /target +using tar. The stage tarball is expected to be gzip compressed. + + +REQUIRED PARAMETERS +------------------- +uri:: + The uri from which to fetch the tarball. + Can be anything understood by curl, e.g: + http://path/to/stage.tgz + tftp:///path/to/stage.tgz + file:///local/path/stage.tgz + + +OPTIONAL PARAMETERS +------------------- +target:: + where to unpack the tarball to. Defaults to /target. + + +BOOLEAN PARAMETERS +------------------ +insecure:: + run curl in insecure mode so it does not check the servers ssl certificate + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__install_stage --uri tftp:///path/to/stage.tgz +__install_stage --uri http://path/to/stage.tgz --target /mnt/foobar +__install_stage --uri file:///path/to/stage.tgz --target /target +__install_stage --uri https://path/to/stage.tgz --target /mnt/foobar --insecure +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2011 - 2013 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__install_stage/parameter/boolean b/cdist/conf/type/__install_stage/parameter/boolean new file mode 100644 index 00000000..e86bf3fc --- /dev/null +++ b/cdist/conf/type/__install_stage/parameter/boolean @@ -0,0 +1 @@ +insecure diff --git a/cdist/conf/type/__install_stage/parameter/default/target b/cdist/conf/type/__install_stage/parameter/default/target new file mode 100644 index 00000000..ea8c4bf7 --- /dev/null +++ b/cdist/conf/type/__install_stage/parameter/default/target @@ -0,0 +1 @@ +/target diff --git a/cdist/conf/type/__install_stage/parameter/optional b/cdist/conf/type/__install_stage/parameter/optional new file mode 100644 index 00000000..eb5a316c --- /dev/null +++ b/cdist/conf/type/__install_stage/parameter/optional @@ -0,0 +1 @@ +target diff --git a/cdist/conf/type/__install_stage/parameter/required b/cdist/conf/type/__install_stage/parameter/required new file mode 100644 index 00000000..c7954952 --- /dev/null +++ b/cdist/conf/type/__install_stage/parameter/required @@ -0,0 +1 @@ +uri diff --git a/cdist/conf/type/__install_stage/singleton b/cdist/conf/type/__install_stage/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_umount/gencode-remote b/cdist/conf/type/__install_umount/gencode-remote new file mode 100755 index 00000000..c275fe5d --- /dev/null +++ b/cdist/conf/type/__install_umount/gencode-remote @@ -0,0 +1,25 @@ +#!/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 . +# + +target="$(cat "$__object/parameter/target")" + +echo "swapoff -a" +echo "umount -l ${target}/* || true" +echo "umount -l ${target}" diff --git a/cdist/conf/type/__install_umount/install b/cdist/conf/type/__install_umount/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_umount/man.text b/cdist/conf/type/__install_umount/man.text new file mode 100644 index 00000000..8d9d1f55 --- /dev/null +++ b/cdist/conf/type/__install_umount/man.text @@ -0,0 +1,43 @@ +cdist-type__install_umount(7) +============================= +Steven Armstrong + + +NAME +---- +cdist-type__install_umount - umount target directory + + +DESCRIPTION +----------- +This cdist type allows you to recursively umount the given target directory. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +target:: + the mount point to umount. Defaults to object_id + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__install_umount /target +-------------------------------------------------------------------------------- + + +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). diff --git a/cdist/conf/type/__install_umount/manifest b/cdist/conf/type/__install_umount/manifest new file mode 100755 index 00000000..c547e167 --- /dev/null +++ b/cdist/conf/type/__install_umount/manifest @@ -0,0 +1,23 @@ +#!/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 . +# + +# set defaults +target="$(cat "$__object/parameter/target" 2>/dev/null \ + || echo "/target" | tee "$__object/parameter/target")" diff --git a/cdist/emulator.py b/cdist/emulator.py index 6744de8b..cdbe5b08 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # 2011-2015 Nico Schottelius (nico-cdist at schottelius.org) -# 2012 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012-2013 Steven Armstrong (steven-cdist at armstrong.cc) # 2014 Daniel Heule (hda at sfs.biz) # # This file is part of cdist. diff --git a/cdist/install.py b/cdist/install.py new file mode 100644 index 00000000..4530029a --- /dev/null +++ b/cdist/install.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# 2013 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 . +# +# + +import cdist.config +import cdist.core + + +class Install(cdist.config.Config): + def object_list(self): + """Short name for object list retrieval. + In install mode, we only care about install objects. + """ + for cdist_object in cdist.core.CdistObject.list_objects(self.local.object_path, + self.local.type_path): + if cdist_object.cdist_type.is_install: + yield cdist_object + else: + self.log.debug("Running in install mode, ignoring non install object: {0}".format(cdist_object)) diff --git a/cdist/test/cdist_type/__init__.py b/cdist/test/cdist_type/__init__.py index feb5fa15..6ed3f87c 100644 --- a/cdist/test/cdist_type/__init__.py +++ b/cdist/test/cdist_type/__init__.py @@ -113,6 +113,16 @@ class TypeTestCase(test.CdistTestCase): cdist_type = core.CdistType(base_path, '__not_singleton') self.assertFalse(cdist_type.is_singleton) + def test_install_is_install(self): + base_path = fixtures + cdist_type = core.CdistType(base_path, '__install') + self.assertTrue(cdist_type.is_install) + + def test_not_install_is_install(self): + base_path = fixtures + cdist_type = core.CdistType(base_path, '__not_install') + self.assertFalse(cdist_type.is_install) + def test_with_explorers(self): base_path = fixtures cdist_type = core.CdistType(base_path, '__with_explorers') diff --git a/docs/changelog b/docs/changelog index 1b7de44f..9519f2b3 100644 --- a/docs/changelog +++ b/docs/changelog @@ -1,6 +1,9 @@ Changelog --------- +next: + * All: Merge install feature from 4.0-pre-not-stable (Darko Poljak) + 4.3.2: 2016-10-13 * Documentation: Update no longer existing links (Simon Walter) * Core: Add warning message for faulty dependencies case (Darko Poljak) diff --git a/docs/dev/logs/2013-11-28.preos b/docs/dev/logs/2013-11-28.preos new file mode 100644 index 00000000..f8561135 --- /dev/null +++ b/docs/dev/logs/2013-11-28.preos @@ -0,0 +1,2 @@ +- debootstrap for the moment +- add triggers: https://github.com/telmich/cdist/issues/214 diff --git a/docs/dev/logs/2014-01-09.preos b/docs/dev/logs/2014-01-09.preos new file mode 100644 index 00000000..1a3f2ddc --- /dev/null +++ b/docs/dev/logs/2014-01-09.preos @@ -0,0 +1,109 @@ +- debootstrap + x setup arch + x allow cdist to configure debootstrapped directory using cdist + x include sshd + x configure network (eth0, dhcp) + x various mkfs variants + - various fdisk tools + + x add option for different initial manifest + x allow -, stdin usage + x allow to replace current manifest (later) + + x trigger + - can be handled in the manifest of the user + + - remove /var/cache/apt/archives/* ? + - later, optimisation level + + + - bug: cdist config als root! + + - fix linux-image name (amd64) + + - ln -s /sbin/init /init + + - blog! + - self configuring + + x pxe + /pxe/ + - pxelinux.0 + - linux + - initramfs + - pxelinux.cfg/ + - default + + - iso + - later + - usb stick (+efi version) + - later + + - add unit tests + +- testing with qemu + [22:43] bento:vm-tests% qemu-system-x86_64 -m 2G -boot order=cn -drive file=testhd1,if=virtio -net nic -net user,tftp=$(pwd -P)/tftp,bootfile=/pxelinux.0,hostfwd=tcp::7777-:22 -enable-kvm + +- create preos + [22:43] bento:preos-tests% echo __panter_root_ssh_keys | sudo cdist preos -vp /home/users/nico/vm-tests/tftp -c /home/users/nico/preos-tests/preos03/ -i - + + +-------------------------------------------------------------------------------- + +[1:16] bento:~% sudo cdist preos -vc ~nico/preos-tests/preos03 +INFO: cdist: version 3.0.0-38-gea286c6 +INFO: /home/users/nico/preos-tests/preos03: Running global explorers +INFO: /home/users/nico/preos-tests/preos03: Running initial manifest /tmp/tmpxbquwe/manifest +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __file/etc/network/interfaces +INFO: /home/users/nico/preos-tests/preos03: Generating code for __file/etc/network/interfaces +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/xfsprogs +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/reiser4progs +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/jfsutils +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/e2fsprogs +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/btrfs-tools +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/file +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/syslinux +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/openssh-server +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/linux-image-amd64 +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/linux-image-amd64 +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/linux-image-amd64 +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/openssh-server +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/openssh-server +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/syslinux +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/syslinux +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/file +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/file +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/btrfs-tools +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/btrfs-tools +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/e2fsprogs +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/e2fsprogs +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/jfsutils +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/jfsutils +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/reiser4progs +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/reiser4progs +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/xfsprogs +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/xfsprogs +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/xfsprogs +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/reiser4progs +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/jfsutils +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/e2fsprogs +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/btrfs-tools +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/file +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/syslinux +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/openssh-server +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/linux-image-amd64 +INFO: /home/users/nico/preos-tests/preos03: Finished successful run in 2.546635866165161 seconds +[1:16] bento:~% + +-------------------------------------------------------------------------------- +[21:14] bento:vm-tests% qemu-system-x86_64 -m 2G -boot order=cn -drive file=testhd1,if=virtio -net nic -net user,tftp=$(pwd -P)/tftp,bootfile=/pxelinux.0 + +-------------------------------------------------------------------------------- +[21:16] bento:preos-tests% sudo cdist preos -vp /home/users/nico/vm-tests/tftp /home/users/nico/preos-tests/preos03/ +INFO: cdist: version 3.0.0-42-g0d78ab3 +INFO: cdist.preos: Creating kernel ... +INFO: cdist.preos: Creating initramfs ... +760780 blocks +INFO: cdist.preos: Creating pxe configuration ... +INFO: cdist.preos: Creating pxelinux.0 ... + diff --git a/docs/dev/logs/2015-02-10.installation_from_usb_stick b/docs/dev/logs/2015-02-10.installation_from_usb_stick new file mode 100644 index 00000000..b655bc18 --- /dev/null +++ b/docs/dev/logs/2015-02-10.installation_from_usb_stick @@ -0,0 +1,49 @@ +Objective: + + Create a bootable media that contains everything to install and configure a system. + +Ideas: + +* usb stick +** uefi vs. bios +** contains cdist config +** static ip (?) (if at all) +** hostname setup to localhost +** install and config support +* preos from existing OS? +** requires kernel +** requires initramfs (self build) +** missing tools: cdist preos --config hostname... +* testing with qemu +* syslinux/isolinux? + +Program: + +- get tools +- get kernel + - provide fallback on cdist page + - archlinux: /boot/vmlinuz-linux +- create initramfs? +- create bootable media + - iso + - uefi-usb + - bios-usb + +Tasks: + +- Setup test environment + - qemu launcher + /usr/bin/qemu-system-x86_64 -boot d -m 256 -cdrom '/home/users/nico/oeffentlich/rechner/projekte/cdist/cdist/cdist-preos.iso' +- Create bootable image +- Test image + +Log: + +mkdir iso +cp /boot/vmlinuz-linux iso/ +cp /usr/lib/syslinux/bios/isolinux.bin iso/ + +[22:36] freiheit:cdist% genisoimage -v -V "cdist preos v0.1" -cache-inodes -J -l -no-emul-boot -boot-load-size 4 -b isolinux.bin -c boot.cat -o cdist-preos.iso iso + +[22:38] freiheit:cdist% genisoimage -r -V "cdist preos v0.2" -cache-inodes -J -l -no-emul-boot -boot-load-size 4 -b isolinux.bin -c boot.cat -o cdist-preos.iso iso + diff --git a/docs/dev/logs/2015-03-28.preos-from-os b/docs/dev/logs/2015-03-28.preos-from-os new file mode 100644 index 00000000..93dc9e79 --- /dev/null +++ b/docs/dev/logs/2015-03-28.preos-from-os @@ -0,0 +1,32 @@ +- basics of config + - wrapping to config + - testbed for CaaS! +- allow to include .cdist +- generate + - pxe + - iso +- package... + - mkfs + - fdisk* + - kernel + +- types (?) + - iso? + - + +- based on Arch Linux + +- new types for iso? + +- change __cdistmarker to accept prefix + +- ISO / USB + genisoimage -r -V "cdist preos v0.2" -cache-inodes -J -l -no-emul-boot -boot-load-size 4 -b isolinux.bin -c boot.cat -o cdist-preos.iso iso + + - have a look at archiso? + + http://www.syslinux.org/wiki/index.php/Isohybrid + -> uefi + -> mbr + +- PXE diff --git a/hacking/.gitignore b/hacking/.gitignore new file mode 100644 index 00000000..375edb27 --- /dev/null +++ b/hacking/.gitignore @@ -0,0 +1,3 @@ +iso/ +*.iso +preos/ diff --git a/hacking/README b/hacking/README new file mode 100644 index 00000000..937564d5 --- /dev/null +++ b/hacking/README @@ -0,0 +1,33 @@ +- next step + - rootfs fix + - get working to login + - have sshd enabled + - kernel -> initramfs? + http://jootamam.net/howto-initramfs-image.htm + - busybox!! + +- everything into initramfs? + +- permission problem on various files below /etc + +- Target: + - get working iso + - have it configured and gathered by cdist? + + +- boot process via ...? + - systemd? + +- packaging via ... + - packages? + - binlist + - bootstrap of os + -> root permissions! + +- boot device + +- uefi support + [9:15] wurzel:hacking% pacman -Ql syslinux | grep ldlin + syslinux /usr/lib/syslinux/bios/ldlinux.c32 + syslinux /usr/lib/syslinux/efi32/ldlinux.e32 + syslinux /usr/lib/syslinux/efi64/ldlinux.e64 diff --git a/hacking/v1-debootstrap-pacstrap/arch_bootstrap.sh b/hacking/v1-debootstrap-pacstrap/arch_bootstrap.sh new file mode 100644 index 00000000..0472bf3c --- /dev/null +++ b/hacking/v1-debootstrap-pacstrap/arch_bootstrap.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +fakeroot pacman -r $(pwd -P)/preos -Syu --noconfirm --cachedir $(pwd -P)/preos/var/cache/pacman base + diff --git a/hacking/v1-debootstrap-pacstrap/debian_bootstrap.sh b/hacking/v1-debootstrap-pacstrap/debian_bootstrap.sh new file mode 100644 index 00000000..75628116 --- /dev/null +++ b/hacking/v1-debootstrap-pacstrap/debian_bootstrap.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +fakeroot debootstrap jessie ./preos-debootstrap/ diff --git a/hacking/v2-initramfs-from-os/add_kernel_isolinux.sh b/hacking/v2-initramfs-from-os/add_kernel_isolinux.sh new file mode 100755 index 00000000..ec7b610c --- /dev/null +++ b/hacking/v2-initramfs-from-os/add_kernel_isolinux.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +# FIXME: Write cdist type / explorer that finds +# package for a file, distro independent + +if [ "$#" -ne 1 ]; then + echo "$0 dir-out" + exit 1 +fi + +dir=$1; shift +boot=$dir/boot + +mkdir -p "$boot" +cp /boot/vmlinuz-linux \ + /boot/initramfs-linux-fallback.img \ + /usr/lib/syslinux/bios/isolinux.bin \ + "$boot" + +cp /usr/lib/syslinux/bios/ldlinux.c32 \ + "$dir" + +cat > "$dir/isolinux.cfg" << eof +default preos +label preos +title cdist PreOS +linux /boot/vmlinuz-linux +initrd /boot/initramfs-linux-fallback.img +eof diff --git a/hacking/v2-initramfs-from-os/all.sh b/hacking/v2-initramfs-from-os/all.sh new file mode 100755 index 00000000..fe3d6d11 --- /dev/null +++ b/hacking/v2-initramfs-from-os/all.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +set -e + +dir=./iso +iso=preos.iso + +./filelist_from_package.sh | ./filelist_to_dir.sh "$dir" +echo "MISSING: copy libraries" >&2 +./add_kernel_isolinux.sh "$dir" +./create_iso.sh "$dir" "$iso" diff --git a/hacking/v2-initramfs-from-os/bin_to_pkg.sh b/hacking/v2-initramfs-from-os/bin_to_pkg.sh new file mode 100755 index 00000000..111b1fa9 --- /dev/null +++ b/hacking/v2-initramfs-from-os/bin_to_pkg.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +abspath=$(command -v "$1") +pacman -Qoq "$abspath" diff --git a/hacking/v2-initramfs-from-os/copy_files_for_iso.sh b/hacking/v2-initramfs-from-os/copy_files_for_iso.sh new file mode 100755 index 00000000..0318c072 --- /dev/null +++ b/hacking/v2-initramfs-from-os/copy_files_for_iso.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +set -ex + +testdir=./iso-root-dir + +# Create base +rm -rf "$testdir" +mkdir "$testdir" + +# Copy binaries + +# Copy kernel +mkdir -p "$testdir/boot" +cp /boot/vmlinuz-linux "$testdir/boot/kernel" +cp /boot/initramfs-linux-fallback.img "$testdir/boot/initramfs" + +# Create iso +genisoimage -v -V "cdist preos v0.1" \ + -cache-inodes -J -l \ + -r -no-emul-boot \ + -boot-load-size 4 -b isolinux.bin -c boot.cat -o cdist-preos.iso iso + diff --git a/hacking/v2-initramfs-from-os/file_list_of_packages.sh b/hacking/v2-initramfs-from-os/file_list_of_packages.sh new file mode 100644 index 00000000..608fdfbc --- /dev/null +++ b/hacking/v2-initramfs-from-os/file_list_of_packages.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +pacman -Qlq "$@" diff --git a/hacking/v2-initramfs-from-os/filelist_from_package.sh b/hacking/v2-initramfs-from-os/filelist_from_package.sh new file mode 100755 index 00000000..5652ba66 --- /dev/null +++ b/hacking/v2-initramfs-from-os/filelist_from_package.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# Generate filelist excluding stuff that takes only space +( + for pkg in systemd openssh \ + bash bzip2 coreutils cryptsetup device-mapper dhcpcd \ + diffutils e2fsprogs file filesystem findutils gawk \ + gettext glibc grep gzip inetutils iproute2 \ + iputils jfsutils less licenses linux logrotate lvm2 \ + man-db man-pages mdadm nano pacman pciutils \ + pcmciautils procps-ng psmisc reiserfsprogs \ + s-nail sed shadow sysfsutils systemd-sysvcompat tar \ + usbutils util-linux vi which xfsprogs \ + ; do + pacman -Qlq $pkg | grep -v \ + -e /usr/share/man/ \ + -e /usr/share/doc/ \ + -e /usr/include + + done +) | sort | uniq diff --git a/hacking/v2-initramfs-from-os/filelist_to_dir.sh b/hacking/v2-initramfs-from-os/filelist_to_dir.sh new file mode 100755 index 00000000..3ce19b9f --- /dev/null +++ b/hacking/v2-initramfs-from-os/filelist_to_dir.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +if [ "$#" -ne 1 ]; then + echo "$0 outdir" + exit 1 +fi + +outdir=$1; shift + +mkdir -p "$outdir" + +while read file; do + if [ -d "$file" ]; then + mkdir -p "$outdir$file" + else + cp --preserve=mode,links "$file" "$outdir$file" + fi +done diff --git a/hacking/v2-initramfs-from-os/packages_arch b/hacking/v2-initramfs-from-os/packages_arch new file mode 100644 index 00000000..ed879512 --- /dev/null +++ b/hacking/v2-initramfs-from-os/packages_arch @@ -0,0 +1,29 @@ +base syslinux + +[10:06] wurzel:hacking% sudo !! +sudo pacman -S base +[sudo] password for nico: +:: linux is in IgnorePkg/IgnoreGroup. Install anyway? [Y/n] y +:: There are 50 members in group base: +:: Repository core + 1) bash 2) bzip2 3) coreutils 4) cryptsetup 5) device-mapper 6) dhcpcd 7) diffutils 8) e2fsprogs 9) file + 10) filesystem 11) findutils 12) gawk 13) gcc-libs 14) gettext 15) glibc 16) grep 17) gzip 18) inetutils + 19) iproute2 20) iputils 21) jfsutils 22) less 23) licenses 24) linux 25) logrotate 26) lvm2 27) man-db + 28) man-pages 29) mdadm 30) nano 31) netctl 32) pacman 33) pciutils 34) pcmciautils 35) perl 36) procps-ng + 37) psmisc 38) reiserfsprogs 39) s-nail 40) sed 41) shadow 42) sysfsutils 43) systemd-sysvcompat 44) tar + 45) texinfo 46) usbutils 47) util-linux 48) vi 49) which 50) xfsprogs + +Enter a selection (default=all): + +:18,23s/ [0-9]*)//g + + bash bzip2 coreutils cryptsetup device-mapper dhcpcd diffutils e2fsprogs file + filesystem findutils gawk gcc-libs gettext glibc grep gzip inetutils + iproute2 iputils jfsutils less licenses linux logrotate lvm2 man-db + man-pages mdadm nano netctl pacman pciutils pcmciautils perl procps-ng + psmisc reiserfsprogs s-nail sed shadow sysfsutils systemd-sysvcompat tar + texinfo usbutils util-linux vi which xfsprogs + +6J + +bash bzip2 coreutils cryptsetup device-mapper dhcpcd diffutils e2fsprogs file filesystem findutils gawk gcc-libs gettext glibc grep gzip inetutils iproute2 iputils jfsutils less licenses linux logrotate lvm2 man-db man-pages mdadm nano netctl pacman pciutils pcmciautils perl procps-ng psmisc reiserfsprogs s-nail sed shadow sysfsutils systemd-sysvcompat tar texinfo usbutils util-linux vi which xfsprogs diff --git a/hacking/v3-busybox/add_kernel_isolinux.sh b/hacking/v3-busybox/add_kernel_isolinux.sh new file mode 100755 index 00000000..ac5d495b --- /dev/null +++ b/hacking/v3-busybox/add_kernel_isolinux.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +# FIXME: distro specific kernel location + +if [ "$#" -ne 1 ]; then + echo "$0 dir-out" + exit 1 +fi + +dir=$1; shift +boot=$dir/boot + +mkdir -p "$boot" +cp /boot/vmlinuz-linux "$boot/linux" +cp /usr/lib/syslinux/bios/isolinux.bin "$boot" +cp /usr/lib/syslinux/bios/ldlinux.c32 "$dir" + +cat > "$dir/isolinux.cfg" << eof +default preos +label preos +title cdist PreOS +linux /boot/linux +initrd /boot/initramfs +eof diff --git a/hacking/v3-busybox/all.sh b/hacking/v3-busybox/all.sh new file mode 100755 index 00000000..65a3706b --- /dev/null +++ b/hacking/v3-busybox/all.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +rm -rf preos +mkdir -p preos/boot + +./create_initramfs.sh > preos/boot/initramfs +./add_kernel_isolinux.sh preos +./copy_bin_with_libs.sh preos +./create_iso.sh preos preos.iso diff --git a/hacking/v3-busybox/copy_bin_with_libs.sh b/hacking/v3-busybox/copy_bin_with_libs.sh new file mode 100755 index 00000000..ee2b532e --- /dev/null +++ b/hacking/v3-busybox/copy_bin_with_libs.sh @@ -0,0 +1,60 @@ +#!/bin/sh +# Nico Schottelius +# Fri May 1 17:31:50 CEST 2015 + + +PATH=/bin:/sbin:/usr/bin:/usr/sbin + +if [ "$#" -ne 1 ]; then + echo "$0 dir-out" + exit 1 +fi + + +out_dir=$1 + +#bin_list="udevadm bash fdisk mount syslinux umount rm mv" +bin_list="udevadm fdisk" + +libs=$(mktemp /tmp/cdist-preos-libs.XXXXXXXXXXXXX) + +mkdir -p "$out_dir/bin" "$out_dir/lib" + +( + for bin in $bin_list; do + src=$(which "$bin") + cp "$src" "$out_dir/bin" + + ldd "$src" | sed -e 's/=>//' -e 's/(.*//' | awk '{ if(NF == 2) { print $2 } else { print $1 } }' + done +) | sort | uniq > "$libs" + + +while read lib; do + if echo $lib | grep '^/'; then + # echo "Copying fqdn lib $lib ..." + cp "$lib" "$out_dir/lib" + else + echo "How to copy $lib ?" + fi +done < "$libs" + + +rm -f "$libs" + +exit 0 + + +bin=$1 + +# Not used alternatives +# new_list=$(objdump -p /usr/bin/ls | awk '$1 ~ /NEEDED/ { print $2 }') +# ldconfig -p | grep 'libBrokenLocale.so.1$' | sed 's/.* => //' + + +for new_item in $new_list; do + + +done + +ldconfig -p | diff --git a/hacking/v3-busybox/create_initramfs.sh b/hacking/v3-busybox/create_initramfs.sh new file mode 100755 index 00000000..f87a7ef6 --- /dev/null +++ b/hacking/v3-busybox/create_initramfs.sh @@ -0,0 +1,32 @@ +#!/bin/sh +set -ex + + +initramfs_dir=$(mktemp -d /tmp/cdist-preos.XXXXXXX) +# initramfs_dir=$1 + +for dir in bin sbin etc proc sys newroot usr/bin usr/sbin; do + mkdir -p ${initramfs_dir}/$dir +done +touch ${initramfs_dir}/etc/mdev.conf + +cp init "${initramfs_dir}/init" +cp $(which busybox) "${initramfs_dir}/bin" + +for link in sh mount; do + ln -fs busybox "${initramfs_dir}/bin/$link" +done + +cd "${initramfs_dir}" +find . | cpio -H newc -o | gzip + +rm -rf "${initramfs_dir}" + +exit 0 + +# TODO: +# - Kernel modules +# - ssh +# - various mkfs +# - libs + diff --git a/hacking/v3-busybox/create_iso.sh b/hacking/v3-busybox/create_iso.sh new file mode 100755 index 00000000..c6b39be6 --- /dev/null +++ b/hacking/v3-busybox/create_iso.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# FIXME: include os explorer to name preos + +if [ "$#" -ne 2 ]; then + echo "$0 dir-in iso-out" + exit 1 +fi + +indir=$1; shift +iso=$1; shift + +version=0.4 + +out=preos-${version}.iso + + # -cache-inodes \ +genisoimage -r -J -l \ + -V "cdist PreOS $version" \ + -b boot/isolinux.bin -no-emul-boot -c boot.cat -boot-load-size 4 -boot-info-table \ + -o "$iso" "$indir" diff --git a/hacking/v3-busybox/init b/hacking/v3-busybox/init new file mode 100755 index 00000000..a961526f --- /dev/null +++ b/hacking/v3-busybox/init @@ -0,0 +1,61 @@ +#!/bin/sh + +#Create all the symlinks to /bin/busybox +/bin/busybox --install -s + +#Mount things needed by this script +mount -t proc proc /proc +mount -t sysfs sysfs /sys + +#Disable kernel messages from popping onto the screen +echo 0 > /proc/sys/kernel/printk + + +#Create device nodes +mknod /dev/null c 1 3 +mknod /dev/tty c 5 0 +mdev -s + +#Function for parsing command line options with "=" in them +# get_opt("init=/sbin/init") will return "/sbin/init" +get_opt() { + echo "$@" | cut -d "=" -f 2 +} + +#Defaults +init="/sbin/init" +root="/dev/hda1" + +#Process command line options +for i in $(cat /proc/cmdline); do + case $i in + root\=*) + root=$(get_opt $i) + ;; + init\=*) + init=$(get_opt $i) + ;; + esac +done + + +exec sh + +# Skipping the rest + +#Mount the root device +mount "${root}" /newroot + +#Check if $init exists and is executable +if [[ -x "/newroot/${init}" ]] ; then + #Unmount all other mounts so that the ram used by + #the initramfs can be cleared after switch_root + umount /sys /proc + + #Switch to the new root and execute init + exec switch_root /newroot "${init}" +fi + +#This will only be run if the exec above failed +echo "Failed to switch_root, dropping to a shell" +exec sh diff --git a/hacking/v3-busybox/qemu-test.sh b/hacking/v3-busybox/qemu-test.sh new file mode 100755 index 00000000..02afc2e6 --- /dev/null +++ b/hacking/v3-busybox/qemu-test.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +if [ "$#" -ne 1 ]; then + echo "$0 iso" + exit 1 +fi + +iso=$1; shift + +qemu-system-x86_64 -m 512 -boot order=cd \ + -drive file=$iso,media=cdrom + diff --git a/scripts/cdist b/scripts/cdist index 91dec2c9..badf0f76 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -61,6 +61,7 @@ def commandline(): import cdist.banner import cdist.config + import cdist.install import cdist.shell import shutil import os @@ -161,6 +162,11 @@ def commandline(): ' should be POSIX compatible shell.')) parser['shell'].set_defaults(func=cdist.shell.Shell.commandline) + # Install + parser['install'] = parser['sub'].add_parser('install', add_help=False, + parents=[parser['config']]) + parser['install'].set_defaults(func=cdist.install.Install.commandline) + for p in parser: parser[p].epilog = ( "Get cdist at http://www.nico.schottelius.org/software/cdist/")