From 321b39ee893c012341c988b151f1f186332a72de Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 28 Nov 2013 14:11:23 +0100 Subject: [PATCH 01/76] use new docs/ (from 2012 or so) Signed-off-by: Nico Schottelius --- {doc => docs}/dev/logs/2012-05-24.preos | 0 docs/dev/logs/2013-11-28.preos | 2 ++ 2 files changed, 2 insertions(+) rename {doc => docs}/dev/logs/2012-05-24.preos (100%) create mode 100644 docs/dev/logs/2013-11-28.preos diff --git a/doc/dev/logs/2012-05-24.preos b/docs/dev/logs/2012-05-24.preos similarity index 100% rename from doc/dev/logs/2012-05-24.preos rename to docs/dev/logs/2012-05-24.preos diff --git a/docs/dev/logs/2013-11-28.preos b/docs/dev/logs/2013-11-28.preos new file mode 100644 index 00000000..aa34f377 --- /dev/null +++ b/docs/dev/logs/2013-11-28.preos @@ -0,0 +1,2 @@ +- debootstrap for the moment +- From 65cab0d0e8adf4fac88ee0f3e909131273d4d45f Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 28 Nov 2013 14:18:24 +0100 Subject: [PATCH 02/76] add "preos" subcommand to generate preos Signed-off-by: Nico Schottelius --- cdist/preos.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ scripts/cdist | 10 +++++++++ 2 files changed, 71 insertions(+) create mode 100644 cdist/preos.py diff --git a/cdist/preos.py b/cdist/preos.py new file mode 100644 index 00000000..29181057 --- /dev/null +++ b/cdist/preos.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +# +# 2013 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 . +# +# + +import logging +import os +import subprocess + +# initialise cdist +import cdist.exec.local + +import cdist.config + +log = logging.getLogger(__name__) + +class PreOS(object): + + def __init__(self, target_dir, arch="amd64"): + + self.target_dir = target_dir + self.arch = arch + + self.command = "debootstrap" + self.suite = "wheezy" + self.options = [ "--include=openssh-server", + "--arch=%s" % self.arch ] + + def run(self): + cmd = [ self.command ] + cmd.extend(self.options) + cmd.append(self.suite) + cmd.append(self.target_dir) + + log.debug("Bootstrap: %s" % cmd) + + subprocess.call(cmd) + + + @classmethod + def commandline(cls, args): + print(args) + self = cls(target_dir=args.target_dir[0], + arch=args.arch) + self.run() diff --git a/scripts/cdist b/scripts/cdist index 39449666..f4d4ce93 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -26,6 +26,7 @@ def commandline(): import cdist.banner import cdist.config + import cdist.preos import cdist.shell # Construct parser others can reuse @@ -83,6 +84,15 @@ def commandline(): default=cdist.REMOTE_EXEC) parser['config'].set_defaults(func=cdist.config.Config.commandline) + # PreOS + parser['preos'] = parser['sub'].add_parser('preos', + parents=[parser['loglevel']]) + parser['preos'].add_argument('-a', '--arch', + help='Select architecture for preos', default="amd64") + parser['preos'].add_argument('target_dir', nargs=1, + help='Select target directory') + parser['preos'].set_defaults(func=cdist.preos.PreOS.commandline) + # Shell parser['shell'] = parser['sub'].add_parser('shell', parents=[parser['loglevel']]) From adab98799485adb826fff7b8ded384668c1df606 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 29 Nov 2013 16:02:00 +0100 Subject: [PATCH 03/76] minor updates for preos Signed-off-by: Nico Schottelius --- cdist/preos.py | 4 +++- docs/dev/logs/2013-11-28.preos | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cdist/preos.py b/cdist/preos.py index 29181057..77d6d6dc 100644 --- a/cdist/preos.py +++ b/cdist/preos.py @@ -42,7 +42,7 @@ class PreOS(object): self.options = [ "--include=openssh-server", "--arch=%s" % self.arch ] - def run(self): + def bootstrap(self): cmd = [ self.command ] cmd.extend(self.options) cmd.append(self.suite) @@ -52,6 +52,8 @@ class PreOS(object): subprocess.call(cmd) + def run(self): + self.bootstrap() @classmethod def commandline(cls, args): diff --git a/docs/dev/logs/2013-11-28.preos b/docs/dev/logs/2013-11-28.preos index aa34f377..f8561135 100644 --- a/docs/dev/logs/2013-11-28.preos +++ b/docs/dev/logs/2013-11-28.preos @@ -1,2 +1,2 @@ - debootstrap for the moment -- +- add triggers: https://github.com/telmich/cdist/issues/214 From a6e2cf853e55e7123c9923b7e86ce31b0cc618fd Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 1 Dec 2013 22:33:13 +0100 Subject: [PATCH 04/76] mkdiropt needs to be unquoted => empty if not existing Otherwise this happens: root@lilly ~ # cat /var/lib/cdist/object/__directory/vm/.cdist/code-remote rm -f "/vm" mkdir "" "/vm" which results into mkdir: cannot create directory `': No such file or directory Signed-off-by: Nico Schottelius --- cdist/conf/type/__directory/gencode-remote | 2 +- docs/changelog | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cdist/conf/type/__directory/gencode-remote b/cdist/conf/type/__directory/gencode-remote index 23fa4ed3..800fc6e4 100755 --- a/cdist/conf/type/__directory/gencode-remote +++ b/cdist/conf/type/__directory/gencode-remote @@ -75,7 +75,7 @@ case "$state_should" in set_attributes=1 cat << DONE rm -f "$destination" -mkdir "$mkdiropt" "$destination" +mkdir $mkdiropt "$destination" DONE fi diff --git a/docs/changelog b/docs/changelog index 67eaca1a..b9056fa6 100644 --- a/docs/changelog +++ b/docs/changelog @@ -9,6 +9,7 @@ Changelog * Type __file: Only remove file when state is absent (Steven Armstrong) * Type __link: Only remove link when state is absent (Steven Armstrong) * Type __directory: Only remove directory when state is absent (Steven Armstrong) + * Type __directory: Fix newly introduced quoting issue * Core: Fix backtrace when cache cannot be deleted 2.3.6: 2013-11-25 From 8af1add2a6059bf6a6c525f15a712a8a25464fa6 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 10 Jan 2014 00:04:46 +0100 Subject: [PATCH 05/76] preos: seperate parameters, create remote_exec, remote_copy and manifest on the fly Signed-off-by: Nico Schottelius --- cdist/preos.py | 98 +++++++++++++++++++++++++++++++--- docs/dev/logs/2014-01-09.preos | 20 +++++++ scripts/cdist | 9 ++++ 3 files changed, 120 insertions(+), 7 deletions(-) create mode 100644 docs/dev/logs/2014-01-09.preos diff --git a/cdist/preos.py b/cdist/preos.py index 77d6d6dc..2f53791f 100644 --- a/cdist/preos.py +++ b/cdist/preos.py @@ -22,16 +22,26 @@ import logging import os import subprocess +import stat +import tempfile -# initialise cdist -import cdist.exec.local import cdist.config +import cdist.exec.local +import cdist.exec.remote log = logging.getLogger(__name__) +class PreOSExistsError(cdist.Error): + def __init__(self, path): + self.path = path + + def __str__(self): + return 'Path %s already exists' % self.path + + class PreOS(object): - + def __init__(self, target_dir, arch="amd64"): self.target_dir = target_dir @@ -42,7 +52,53 @@ class PreOS(object): self.options = [ "--include=openssh-server", "--arch=%s" % self.arch ] + self._init_helper() + + def _init_helper(self): + self.helper = {} + self.helper["manifest"] = """ +for pkg in linux-image-amd64 openssh-server; do + __package $pkg --state present +done +""" + self.helper["remote_exec"] = """#!/bin/sh +# echo $@ +# set -x +chroot="$1"; shift + +script=$(mktemp "${chroot}/tmp/chroot-${0##*/}.XXXXXXXXXX") +trap cleanup INT TERM EXIT +cleanup() { + [ $__cdist_debug ] || rm "$script" +} + +echo "#!/bin/sh -l" > "$script" +echo "$@" >> "$script" +chmod +x "$script" + +relative_script="${script#$chroot}" + +# run in chroot +chroot "$chroot" "$relative_script" +""" + + self.helper["remote_copy"] = """#!/bin/sh + echo $@ + set -x +src=$1; shift +dst=$1; shift +real_dst=$(echo $dst | sed 's,:,,') +cp -L "$src" "$real_dst" +""" + + @property + def exists(self): + return os.path.exists(self.target_dir) + def bootstrap(self): + if self.exists: + raise PreOSExistsError(self.target_dir) + cmd = [ self.command ] cmd.extend(self.options) cmd.append(self.suite) @@ -52,12 +108,40 @@ class PreOS(object): subprocess.call(cmd) - def run(self): - self.bootstrap() + def create_helper_files(self, base_dir): + for key, val in self.helper.items(): + filename = os.path.join(base_dir, key) + with open(filename, "w") as fd: + fd.write(val) + os.chmod(filename, stat.S_IRUSR | stat.S_IXUSR) + + def config(self): + handle, path = tempfile.mkstemp(prefix='cdist.stdin.') + with tempfile.TemporaryDirectory() as tempdir: + host = self.target_dir + + self.create_helper_files(tempdir) + + local = cdist.exec.local.Local( + target_host=host, + initial_manifest=os.path.join(tempdir, "manifest") + ) + + remote = cdist.exec.remote.Remote( + target_host=host, + remote_exec=os.path.join(tempdir, "remote_exec"), + remote_copy=os.path.join(tempdir, "remote_copy"), + ) + + config = cdist.config.Config(local, remote) + config.run() @classmethod def commandline(cls, args): - print(args) self = cls(target_dir=args.target_dir[0], arch=args.arch) - self.run() + + if args.bootstrap: + self.bootstrap() + if args.config: + self.config() diff --git a/docs/dev/logs/2014-01-09.preos b/docs/dev/logs/2014-01-09.preos new file mode 100644 index 00000000..b802825d --- /dev/null +++ b/docs/dev/logs/2014-01-09.preos @@ -0,0 +1,20 @@ +- debootstrap + x setup arch + + - include trigger + - replace with cdist config later? + + - get kernel + - create initramfs + - later: + - configure chroot using cdist + + + packages: + linux-image-amd64 + + - temporary manifest + + - bugs with sudo + [22:50:04] bento:~# ln -s ~nico/.cdist/ ~ + diff --git a/scripts/cdist b/scripts/cdist index f4d4ce93..872d00ff 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -89,6 +89,15 @@ def commandline(): parents=[parser['loglevel']]) parser['preos'].add_argument('-a', '--arch', help='Select architecture for preos', default="amd64") + parser['preos'].add_argument('-b', '--bootstrap', + help='Bootstrap directory with OS', action="store_true") + parser['preos'].add_argument('-c', '--configure', + help='Configure previously bootstrapped directory', action="store_true", + dest="config") + parser['preos'].add_argument('-i', '--initramfs', + help='Create Linux initramfs', action="store_true") + parser['preos'].add_argument('-k', '--kernel', + help='Create Linux kernel', action="store_true") parser['preos'].add_argument('target_dir', nargs=1, help='Select target directory') parser['preos'].set_defaults(func=cdist.preos.PreOS.commandline) From b535e848ada9720d01861292c8df79b1cbe51677 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 10 Jan 2014 00:38:29 +0100 Subject: [PATCH 06/76] run apt-get update after deboostrap Signed-off-by: Nico Schottelius --- cdist/preos.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cdist/preos.py b/cdist/preos.py index 2f53791f..98fd7f35 100644 --- a/cdist/preos.py +++ b/cdist/preos.py @@ -108,6 +108,8 @@ cp -L "$src" "$real_dst" subprocess.call(cmd) + cmd = [ "chroot", self.target_dir, "/usr/bin/apt-get update" ] + def create_helper_files(self, base_dir): for key, val in self.helper.items(): filename = os.path.join(base_dir, key) From 4fb55b8d92065690d383c21e6015f550c70122bc Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 10 Jan 2014 10:46:09 +0100 Subject: [PATCH 07/76] various updates for preos Signed-off-by: Nico Schottelius --- cdist/preos.py | 51 +++++++++++++++++--- docs/dev/logs/2014-01-09.preos | 85 +++++++++++++++++++++++++++++----- scripts/cdist | 21 ++++++--- 3 files changed, 133 insertions(+), 24 deletions(-) diff --git a/cdist/preos.py b/cdist/preos.py index 98fd7f35..c24dbbe3 100644 --- a/cdist/preos.py +++ b/cdist/preos.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# 2013 Nico Schottelius (nico-cdist at schottelius.org) +# 2013-2014 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -39,6 +39,9 @@ class PreOSExistsError(cdist.Error): def __str__(self): return 'Path %s already exists' % self.path +class PreOSBootstrapError(cdist.Error): + pass + class PreOS(object): @@ -52,14 +55,39 @@ class PreOS(object): self.options = [ "--include=openssh-server", "--arch=%s" % self.arch ] + self.pxelinux = "/usr/lib/syslinux/pxelinux.0" + self.pxelinux-cfg = """ +DEFAULT linux +LABEL linux +KERNEL linux +INITRD initramfs +APPEND ro root=/dev/sda1 initrd=initrd.img + self._init_helper() def _init_helper(self): self.helper = {} self.helper["manifest"] = """ -for pkg in linux-image-amd64 openssh-server; do +for pkg in \ + file \ + linux-image-amd64 + openssh-server + syslinux \ + gdisk util-linux \ + btrfs-tools e2fsprogs jfsutils reiser4progs xfsprogs; do __package $pkg --state present done + +__file /etc/network/interfaces --source - --mode 0644 << eof +# The loopback network interface +auto lo +iface lo inet loopback + +# The primary network interface +auto eth0 +allow-hotplug eth0 +iface eth0 init dhcp +eof """ self.helper["remote_exec"] = """#!/bin/sh # echo $@ @@ -78,13 +106,16 @@ chmod +x "$script" relative_script="${script#$chroot}" +# ensure PATH is setup +export PATH=$PATH:/bin:/usr/bin:/sbin:/usr/sbin + # run in chroot chroot "$chroot" "$relative_script" """ self.helper["remote_copy"] = """#!/bin/sh - echo $@ - set -x +# echo $@ +# set -x src=$1; shift dst=$1; shift real_dst=$(echo $dst | sed 's,:,,') @@ -106,9 +137,14 @@ cp -L "$src" "$real_dst" log.debug("Bootstrap: %s" % cmd) - subprocess.call(cmd) +# try: + subprocess.check_call(cmd) +# except subprocess.CalledProcessError: +# raise - cmd = [ "chroot", self.target_dir, "/usr/bin/apt-get update" ] + # Required to run this - otherwise apt-get install fails + cmd = [ "chroot", self.target_dir, "/usr/bin/apt-get", "update" ] + subprocess.check_call(cmd) def create_helper_files(self, base_dir): for key, val in self.helper.items(): @@ -117,6 +153,9 @@ cp -L "$src" "$real_dst" fd.write(val) os.chmod(filename, stat.S_IRUSR | stat.S_IXUSR) + def create_pxe(self, base_dir): + pass + def config(self): handle, path = tempfile.mkstemp(prefix='cdist.stdin.') with tempfile.TemporaryDirectory() as tempdir: diff --git a/docs/dev/logs/2014-01-09.preos b/docs/dev/logs/2014-01-09.preos index b802825d..c0b840ee 100644 --- a/docs/dev/logs/2014-01-09.preos +++ b/docs/dev/logs/2014-01-09.preos @@ -1,20 +1,83 @@ - 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 - - include trigger - - replace with cdist config later? + - add option for different initial manifest + - allow -, stdin usage - - get kernel - - create initramfs - - later: - - configure chroot using cdist + - add option for additional manifest + - allow -, stdin usage + - trigger + - can be handled in the manifest of the user - packages: - linux-image-amd64 + - remove /var/cache/apt/archives/* ? - - temporary manifest + - fix linux-image name (amd64) - - bugs with sudo - [22:50:04] bento:~# ln -s ~nico/.cdist/ ~ + - blog! + - self configuring + + - pxe + /pxe/ + - pxelinux.0 + - linux + - initramfs + - pxelinux.cfg/ + - default + + - iso + + - add unit tests + +-------------------------------------------------------------------------------- + +[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:~% diff --git a/scripts/cdist b/scripts/cdist index 872d00ff..c1e1cd94 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -89,15 +89,22 @@ def commandline(): parents=[parser['loglevel']]) parser['preos'].add_argument('-a', '--arch', help='Select architecture for preos', default="amd64") + parser['preos'].add_argument('-A', '--additional-manifest', + help='Add stuff to configuration manifest', default="amd64") parser['preos'].add_argument('-b', '--bootstrap', - help='Bootstrap directory with OS', action="store_true") + help='Bootstrap directory with PreOS', action="store_true") parser['preos'].add_argument('-c', '--configure', - help='Configure previously bootstrapped directory', action="store_true", - dest="config") - parser['preos'].add_argument('-i', '--initramfs', - help='Create Linux initramfs', action="store_true") - parser['preos'].add_argument('-k', '--kernel', - help='Create Linux kernel', action="store_true") + help='Configure previously bootstrapped directory', + action="store_true", dest="config") + parser['preos'].add_argument('-i', '--initial-manifest', + help='Initial manifest for configuration (added to built in)') + parser['preos'].add_argument('-r', '--replace-manifest', + help='Instead of appending to the built in manifest, replace the internal manifest', + action="store_true") + parser['preos'].add_argument('-I', '--iso-boot', + help='Create ISO for booting in given location') + parser['preos'].add_argument('-p', '--pxe-boot', + help='Create PXE files for booting in given location') parser['preos'].add_argument('target_dir', nargs=1, help='Select target directory') parser['preos'].set_defaults(func=cdist.preos.PreOS.commandline) From 995e33afc9f62959fabc1888ec02952d6a68242a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 10 Jan 2014 17:21:42 +0100 Subject: [PATCH 08/76] add command line handling for pxe generating Signed-off-by: Nico Schottelius --- cdist/preos.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/cdist/preos.py b/cdist/preos.py index c24dbbe3..78b88f94 100644 --- a/cdist/preos.py +++ b/cdist/preos.py @@ -56,12 +56,13 @@ class PreOS(object): "--arch=%s" % self.arch ] self.pxelinux = "/usr/lib/syslinux/pxelinux.0" - self.pxelinux-cfg = """ + self.pxelinux_cfg = """ DEFAULT linux LABEL linux KERNEL linux INITRD initramfs APPEND ro root=/dev/sda1 initrd=initrd.img +""" self._init_helper() @@ -153,9 +154,29 @@ cp -L "$src" "$real_dst" fd.write(val) os.chmod(filename, stat.S_IRUSR | stat.S_IXUSR) - def create_pxe(self, base_dir): + def create_kernel(self): + cmd=[ "cp", '"$(ls boot/vmlinuz-* | tail -n1)"' ] + cmd.append + pass + def create_initramfs(self): + base_cmd="find . -print0 | sudo cpio --null -ov --format=newc | gzip -9" + + pass + + def create_iso(self, out_dir): + self.out_dir = out_dir + + raise cdist.Error("Generating ISO is not yet supported") + + def create_pxe(self, out_dir): + self.out_dir = out_dir + + self.create_kernel() + self.create_initramfs() + self.create_pxeconfig() + def config(self): handle, path = tempfile.mkstemp(prefix='cdist.stdin.') with tempfile.TemporaryDirectory() as tempdir: @@ -186,3 +207,7 @@ cp -L "$src" "$real_dst" self.bootstrap() if args.config: self.config() + if args.pxe_boot: + self.create_pxe(args.pxe_boot) + if args.iso_boot: + self.create_iso(args.pxe_boot) From c585e4876e46306afd56b9490e36e00d379b3fbd Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 11 Jan 2014 21:05:14 +0100 Subject: [PATCH 09/76] create kernel, pxeconfig and pxelinux.0 Signed-off-by: Nico Schottelius --- cdist/preos.py | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/cdist/preos.py b/cdist/preos.py index 78b88f94..1fb73ad7 100644 --- a/cdist/preos.py +++ b/cdist/preos.py @@ -20,9 +20,11 @@ # import logging +import glob import os import subprocess import stat +import shutil import tempfile @@ -57,11 +59,10 @@ class PreOS(object): self.pxelinux = "/usr/lib/syslinux/pxelinux.0" self.pxelinux_cfg = """ -DEFAULT linux -LABEL linux -KERNEL linux +DEFAULT preos +LABEL preos +KERNEL kernel INITRD initramfs -APPEND ro root=/dev/sda1 initrd=initrd.img """ self._init_helper() @@ -155,13 +156,29 @@ cp -L "$src" "$real_dst" os.chmod(filename, stat.S_IRUSR | stat.S_IXUSR) def create_kernel(self): - cmd=[ "cp", '"$(ls boot/vmlinuz-* | tail -n1)"' ] - cmd.append + dst = os.path.join(self.out_dir, "kernel") + srcglob = glob.glob("%s/boot/vmlinuz-*" % self.target_dir) + src = srcglob[0] - pass + shutil.copyfile(src, dst, follow_symlinks=True) + + def create_pxelinux(self): + dst = os.path.join(self.out_dir, "pxelinux.0") + src = "%s/usr/lib/syslinux/pxelinux.0" % self.target_dir + + shutil.copyfile(src, dst, follow_symlinks=True) + + def create_pxeconfig(self): + configdir = os.path.join(self.out_dir, "pxelinux.cfg") + configfile = os.path.join(configdir, "default") + if not os.path.isdir(configdir): + os.mkdir(configdir) + + with open(configfile, "w") as fd: + fd.write(self.pxelinux_cfg) def create_initramfs(self): - base_cmd="find . -print0 | sudo cpio --null -ov --format=newc | gzip -9" + base_cmd="find . -print0 | cpio --null -ov --format=newc | gzip -9" pass @@ -174,8 +191,9 @@ cp -L "$src" "$real_dst" self.out_dir = out_dir self.create_kernel() - self.create_initramfs() +# self.create_initramfs() self.create_pxeconfig() + self.create_pxelinux() def config(self): handle, path = tempfile.mkstemp(prefix='cdist.stdin.') @@ -210,4 +228,4 @@ cp -L "$src" "$real_dst" if args.pxe_boot: self.create_pxe(args.pxe_boot) if args.iso_boot: - self.create_iso(args.pxe_boot) + self.create_iso(args.iso_boot) From 0d78ab313ffcb81a0daf9b650f982cd3e1d1b90b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 11 Jan 2014 21:14:04 +0100 Subject: [PATCH 10/76] create initramfs Signed-off-by: Nico Schottelius --- cdist/preos.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cdist/preos.py b/cdist/preos.py index 1fb73ad7..6d473ddf 100644 --- a/cdist/preos.py +++ b/cdist/preos.py @@ -160,17 +160,20 @@ cp -L "$src" "$real_dst" srcglob = glob.glob("%s/boot/vmlinuz-*" % self.target_dir) src = srcglob[0] + log.info("Creating kernel ...") shutil.copyfile(src, dst, follow_symlinks=True) def create_pxelinux(self): dst = os.path.join(self.out_dir, "pxelinux.0") src = "%s/usr/lib/syslinux/pxelinux.0" % self.target_dir + log.info("Creating pxelinux.0 ...") shutil.copyfile(src, dst, follow_symlinks=True) def create_pxeconfig(self): configdir = os.path.join(self.out_dir, "pxelinux.cfg") configfile = os.path.join(configdir, "default") + log.info("Creating pxe configuration ...") if not os.path.isdir(configdir): os.mkdir(configdir) @@ -178,9 +181,11 @@ cp -L "$src" "$real_dst" fd.write(self.pxelinux_cfg) def create_initramfs(self): - base_cmd="find . -print0 | cpio --null -ov --format=newc | gzip -9" + out_file = os.path.join(self.out_dir, "initramfs") + cmd="cd {target_dir}; find . -print0 | cpio --null -o --format=newc | gzip -9 > {out_file}".format(target_dir = self.target_dir, out_file = out_file) - pass + log.info("Creating initramfs ...") + subprocess.check_call(cmd, shell=True) def create_iso(self, out_dir): self.out_dir = out_dir @@ -191,7 +196,7 @@ cp -L "$src" "$real_dst" self.out_dir = out_dir self.create_kernel() -# self.create_initramfs() + self.create_initramfs() self.create_pxeconfig() self.create_pxelinux() From 11ba4640b4c7d2e0018fcaafa0fab66f147a169f Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 11 Jan 2014 22:34:44 +0100 Subject: [PATCH 11/76] disable unsupported iso - create /init - include support for another initial manifest Signed-off-by: Nico Schottelius --- cdist/preos.py | 89 +++++++++++++++++++++++----------- docs/dev/logs/2014-01-09.preos | 29 +++++++++-- scripts/cdist | 6 +-- 3 files changed, 87 insertions(+), 37 deletions(-) diff --git a/cdist/preos.py b/cdist/preos.py index 6d473ddf..cbb9f23c 100644 --- a/cdist/preos.py +++ b/cdist/preos.py @@ -24,16 +24,42 @@ import glob import os import subprocess import stat +import sys import shutil import tempfile - import cdist.config import cdist.exec.local import cdist.exec.remote log = logging.getLogger(__name__) +DEFAULT_MANIFEST = """ +for pkg in \ + file \ + linux-image-amd64 \ + openssh-server \ + syslinux \ + gdisk util-linux \ + btrfs-tools e2fsprogs jfsutils reiser4progs xfsprogs; do + __package $pkg --state present +done + +# initramfs requires /init +__link /init --source /sbin/init --type symbolic + +__file /etc/network/interfaces --source - --mode 0644 << eof +# The loopback network interface +auto lo +iface lo inet loopback + +# The primary network interface +auto eth0 +allow-hotplug eth0 +iface eth0 init dhcp +eof +""" + class PreOSExistsError(cdist.Error): def __init__(self, path): self.path = path @@ -65,32 +91,9 @@ KERNEL kernel INITRD initramfs """ - self._init_helper() - def _init_helper(self): self.helper = {} - self.helper["manifest"] = """ -for pkg in \ - file \ - linux-image-amd64 - openssh-server - syslinux \ - gdisk util-linux \ - btrfs-tools e2fsprogs jfsutils reiser4progs xfsprogs; do - __package $pkg --state present -done - -__file /etc/network/interfaces --source - --mode 0644 << eof -# The loopback network interface -auto lo -iface lo inet loopback - -# The primary network interface -auto eth0 -allow-hotplug eth0 -iface eth0 init dhcp -eof -""" + self.helper["manifest"] = self.initial_manifest self.helper["remote_exec"] = """#!/bin/sh # echo $@ # set -x @@ -200,7 +203,25 @@ cp -L "$src" "$real_dst" self.create_pxeconfig() self.create_pxelinux() + + def setup_initial_manifest(self, user_initial_manifest, replace_manifest): + if user_initial_manifest: + if user_initial_manifest == '-': + user_initial_manifest_content = sys.stdin.read() + else: + with open(user_initial_manifest, "r") as fd: + user_initial_manifest_content = fd.read() + else: + user_initial_manifest_content = "" + + if replace_manifest: + self.initial_manifest = user_initial_manifest_content + else: + self.initial_manifest = "{default}\n# User supplied manifest\n{user}".format(default=DEFAULT_MANIFEST, user=user_initial_manifest_content) + def config(self): + self._init_helper() + handle, path = tempfile.mkstemp(prefix='cdist.stdin.') with tempfile.TemporaryDirectory() as tempdir: host = self.target_dir @@ -226,11 +247,21 @@ cp -L "$src" "$real_dst" self = cls(target_dir=args.target_dir[0], arch=args.arch) + # read initial manifest first - it may come from stdin + if args.config: + self.setup_initial_manifest(args.initial_manifest, args.replace_manifest) + + # Bootstrap: creates base directory if args.bootstrap: self.bootstrap() + + # Configure the OS if args.config: self.config() - if args.pxe_boot: - self.create_pxe(args.pxe_boot) - if args.iso_boot: - self.create_iso(args.iso_boot) + + # Output pxe files + if args.pxe_boot_dir: + self.create_pxe(args.pxe_boot_dir) + + #if args.iso_boot_dir: + # self.create_iso(args.iso_boot) diff --git a/docs/dev/logs/2014-01-09.preos b/docs/dev/logs/2014-01-09.preos index c0b840ee..0f0b0384 100644 --- a/docs/dev/logs/2014-01-09.preos +++ b/docs/dev/logs/2014-01-09.preos @@ -8,21 +8,25 @@ - add option for different initial manifest - allow -, stdin usage + - allow to replace current manifest (later) - - add option for additional manifest - - allow -, stdin usage - - - trigger + 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 - - pxe + x pxe /pxe/ - pxelinux.0 - linux @@ -31,6 +35,9 @@ - default - iso + - later + - usb stick (+efi version) + - later - add unit tests @@ -81,3 +88,15 @@ INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/linux- 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/scripts/cdist b/scripts/cdist index c1e1cd94..ed9d2eda 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -101,9 +101,9 @@ def commandline(): parser['preos'].add_argument('-r', '--replace-manifest', help='Instead of appending to the built in manifest, replace the internal manifest', action="store_true") - parser['preos'].add_argument('-I', '--iso-boot', - help='Create ISO for booting in given location') - parser['preos'].add_argument('-p', '--pxe-boot', +# parser['preos'].add_argument('-I', '--iso-boot-dir', +# help='Create ISO for booting in given location') + parser['preos'].add_argument('-p', '--pxe-boot-dir', help='Create PXE files for booting in given location') parser['preos'].add_argument('target_dir', nargs=1, help='Select target directory') From e7ad8f929804e02337c4c09b4045ade2859d2b85 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 11 Jan 2014 22:45:38 +0100 Subject: [PATCH 12/76] inet not init Signed-off-by: Nico Schottelius --- cdist/preos.py | 2 +- docs/dev/logs/2014-01-09.preos | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cdist/preos.py b/cdist/preos.py index cbb9f23c..8b4a9a09 100644 --- a/cdist/preos.py +++ b/cdist/preos.py @@ -56,7 +56,7 @@ iface lo inet loopback # The primary network interface auto eth0 allow-hotplug eth0 -iface eth0 init dhcp +iface eth0 inet dhcp eof """ diff --git a/docs/dev/logs/2014-01-09.preos b/docs/dev/logs/2014-01-09.preos index 0f0b0384..8d5a59b6 100644 --- a/docs/dev/logs/2014-01-09.preos +++ b/docs/dev/logs/2014-01-09.preos @@ -41,6 +41,10 @@ - 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 + + -------------------------------------------------------------------------------- [1:16] bento:~% sudo cdist preos -vc ~nico/preos-tests/preos03 From 07545f4f7f9ddc806037a61babccefa6d3fa83a5 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 11 Jan 2014 22:47:34 +0100 Subject: [PATCH 13/76] update preos notes Signed-off-by: Nico Schottelius --- docs/dev/logs/2014-01-09.preos | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/dev/logs/2014-01-09.preos b/docs/dev/logs/2014-01-09.preos index 8d5a59b6..1a3f2ddc 100644 --- a/docs/dev/logs/2014-01-09.preos +++ b/docs/dev/logs/2014-01-09.preos @@ -6,9 +6,9 @@ x various mkfs variants - various fdisk tools - - add option for different initial manifest - - allow -, stdin usage - - allow to replace current manifest (later) + 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 @@ -44,6 +44,9 @@ - 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 - + -------------------------------------------------------------------------------- From 3daa74e81dc225a9004ba276b20e25f1ad3d80be Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 11 Jan 2014 22:48:47 +0100 Subject: [PATCH 14/76] fix 'stdin: is not a tty' problem (thanks, steven) Signed-off-by: Nico Schottelius --- cdist/preos.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cdist/preos.py b/cdist/preos.py index 8b4a9a09..433cf871 100644 --- a/cdist/preos.py +++ b/cdist/preos.py @@ -58,6 +58,10 @@ auto eth0 allow-hotplug eth0 iface eth0 inet dhcp eof + +# Steven found this out - coyping it 1:1 +# fix the bloody 'stdin: is not a tty' problem +__line /root/.profile --line 'mesg n' --state absent """ class PreOSExistsError(cdist.Error): From 54815e2b29ae2642f17c600a3c7afa1e24262d7d Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 29 Aug 2013 22:32:26 +0200 Subject: [PATCH 15/76] implement cdist install Signed-off-by: Steven Armstrong --- cdist/config.py | 1 - cdist/core/cdist_type.py | 5 ++ cdist/emulator.py | 2 +- cdist/install.py | 37 ++++++++++ cdist/test/cdist_type/__init__.py | 10 +++ docs/dev/todo/steven | 118 ------------------------------ scripts/cdist | 5 ++ 7 files changed, 58 insertions(+), 120 deletions(-) create mode 100644 cdist/install.py delete mode 100644 docs/dev/todo/steven diff --git a/cdist/config.py b/cdist/config.py index 3f8a7fc6..59cf339a 100644 --- a/cdist/config.py +++ b/cdist/config.py @@ -158,7 +158,6 @@ class Config(object): self.local.save_cache() self.log.info("Finished successful run in %s seconds", time.time() - start_time) - def object_list(self): """Short name for object list retrieval""" for cdist_object in core.CdistObject.list_objects(self.local.object_path, diff --git a/cdist/core/cdist_type.py b/cdist/core/cdist_type.py index 46e126f9..ff1ebaec 100644 --- a/cdist/core/cdist_type.py +++ b/cdist/core/cdist_type.py @@ -101,6 +101,11 @@ class CdistType(object): """Check whether a type is a singleton.""" return os.path.isfile(os.path.join(self.absolute_path, "singleton")) + @property + def is_install(self): + """Check whether a type is used for installation (if not: for configuration)""" + return os.path.isfile(os.path.join(self.absolute_path, "install")) + @property def explorers(self): """Return a list of available explorers""" diff --git a/cdist/emulator.py b/cdist/emulator.py index b70ef956..b8f7b10b 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # 2011-2013 Nico Schottelius (nico-cdist at schottelius.org) -# 2012 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012-2013 Steven Armstrong (steven-cdist at armstrong.cc) # # 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 79f824d3..8cc1f2e4 100644 --- a/cdist/test/cdist_type/__init__.py +++ b/cdist/test/cdist_type/__init__.py @@ -106,6 +106,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/dev/todo/steven b/docs/dev/todo/steven deleted file mode 100644 index 2aacaa42..00000000 --- a/docs/dev/todo/steven +++ /dev/null @@ -1,118 +0,0 @@ -autorequire: - - objects defined in type manifests should be automatically prerequisites of the current object - - __foo/some-id - __other other-id --state present - => require="__other/other-id" __foo/some-id - - -metaparameters: - - steal the metaparameters from puppet: - - # I have to be there before the other one - __directory /etc/ssh \ - --before __file/etc/ssh/sshd_config - - # the other one has to be there before me - __file /etc/ssh/sshd_config \ - --after __directory/etc/ssh - - # if I change, tell the other one about it - __file /etc/ssh/sshd_config \ - --notify __init_script/etc/rc.d/sshd - - # whenever the other one changes, I want to know - __init_script /etc/rc.d/sshd \ - --subscribe __file/etc/ssh/sshd_config - - - how does a type react to a received 'event'? - - maybe something like: - __some_type/ - manifest - ... - gencode-refresh - ... - - gencode-refresh -> code-refresh -> ssh $target sh -e code-refresh - - - - -logging: - - logging from type emulator without clobbering stdout - maybe implement logging server as described here [1] - [1] http://docs.python.org/py3k/howto/logging-cookbook.html#configuration-server-example - - - use different logger to limit output to current area of interest, - e.g. - explorer.$target_host: explorer related messages for the run for $target_host - manifest.$target_host: manifest related messages for the run for $target_host - ... - then one could filter e.g. on explorer.* - - - more granular debug output, - [2] http://blog.ooz.ie/2011/03/python-logging-extending-standard.html - - - -tests: - - __init__(): - - sets up env: __target_host - - run_initial_manifest(): - - parameter is actually used (from __init__) - - ensure changing the manifest actually runs a different manifest - -> give ConfigInstall Constructor different manifest - -> different manifest is executed. - - test all submitted (from core to type manifest) variables: - - ENVIRONMENT - - they are set - - they contain the correct values - - run_type_manifest(): - - test all submitted (from core to type manifest) variables: - - ENVIRONMENT - - they are set - - they contain the correct values - - same tests as for test_initial_manifest_*? - - run_manifest(): - - test all submitted variables: - - ENVIRONMENT - - including __debug, if debug - - they are set - - they contain the correct values - - does $require work? - - check that exception raised, if manifest is not existent - - object_run(): - - ensure no object is run twice - - ensure requirements are taken into account? - - and order of run is adjusted - - check (from extern?) that all needed variables are setup - - ensure no code-{local, remote} is created, - if gencode is not producing code - - ensure THAT code-{local, remote} contains what gencode created - - abort if gencode-* fails - - abort if code-* fails - - abort == raise(FooException) - - gencode-*: ensure ENVIRONMENT is setup correctly - - run_type_explorer() - - ensure ALL type explores have been run - - ensure output is saved to correct path - - ensure a type with {0,1,2} explorers works ? - - none, one, multiple - - ensure ENVIRONMENT is setup correctly - - fails if ANY of the given explorer fails - - run_global_explorers(): - - ensure ALL type explores have been run - - ensure output is saved to correct path - - ensure a type with {0,1,2} explorers works ? - - none, one, multiple - - ensure ENVIRONMENT is setup correctly - - fails if ANY of the given explorer fails - -Code fixes needed: - - - shutil, os.mkdir, etc. everywhere: catch/reraise exceptions correctly diff --git a/scripts/cdist b/scripts/cdist index 39449666..31bd7373 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -26,6 +26,7 @@ def commandline(): import cdist.banner import cdist.config + import cdist.install import cdist.shell # Construct parser others can reuse @@ -90,6 +91,10 @@ def commandline(): help='Select shell to use, defaults to current shell') parser['shell'].set_defaults(func=cdist.shell.Shell.commandline) + # Install + parser['install'] = parser['sub'].add_parser('install', + parents=[parser['loglevel'], 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/" From 02476073aac96ce59d25e71ace119489616d4551 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 29 Aug 2013 22:33:43 +0200 Subject: [PATCH 16/76] add install types Signed-off-by: Steven Armstrong --- .../__install_bootloader_grub/gencode-remote | 73 ++++++++ .../type/__install_bootloader_grub/install | 0 .../type/__install_bootloader_grub/man.text | 47 +++++ .../type/__install_bootloader_grub/manifest | 25 +++ .../parameter/optional | 2 + .../__install_chroot_mount/gencode-remote | 1 + .../conf/type/__install_chroot_mount/install | 0 .../conf/type/__install_chroot_mount/man.text | 1 + .../__install_chroot_umount/gencode-remote | 1 + .../conf/type/__install_chroot_umount/install | 0 .../type/__install_chroot_umount/man.text | 1 + .../type/__install_config/files/remote/copy | 48 +++++ .../type/__install_config/files/remote/exec | 73 ++++++++ .../conf/type/__install_config/gencode-local | 50 +++++ cdist/conf/type/__install_config/install | 0 cdist/conf/type/__install_config/man.text | 47 +++++ cdist/conf/type/__install_config/manifest | 23 +++ .../type/__install_config/parameter/optional | 1 + cdist/conf/type/__install_config/singleton | 0 cdist/conf/type/__install_file/explorer | 1 + cdist/conf/type/__install_file/gencode-local | 1 + cdist/conf/type/__install_file/gencode-remote | 1 + cdist/conf/type/__install_file/install | 0 cdist/conf/type/__install_file/man.text | 1 + cdist/conf/type/__install_file/parameter | 1 + cdist/conf/type/__install_fstab/install | 0 cdist/conf/type/__install_fstab/man.text | 48 +++++ cdist/conf/type/__install_fstab/manifest | 29 +++ .../type/__install_fstab/parameter/optional | 1 + cdist/conf/type/__install_fstab/singleton | 0 .../files/fstab.header | 1 + .../__install_generate_fstab/gencode-local | 59 ++++++ .../type/__install_generate_fstab/install | 0 .../type/__install_generate_fstab/man.text | 52 ++++++ .../parameter/boolean | 1 + .../parameter/required | 1 + .../type/__install_generate_fstab/singleton | 0 cdist/conf/type/__install_mkfs/gencode-remote | 71 +++++++ cdist/conf/type/__install_mkfs/install | 0 cdist/conf/type/__install_mkfs/man.text | 57 ++++++ cdist/conf/type/__install_mkfs/manifest | 31 ++++ .../type/__install_mkfs/parameter/optional | 3 + .../type/__install_mkfs/parameter/required | 1 + .../conf/type/__install_mount/gencode-remote | 78 ++++++++ cdist/conf/type/__install_mount/install | 0 cdist/conf/type/__install_mount/man.text | 61 ++++++ cdist/conf/type/__install_mount/manifest | 29 +++ .../type/__install_mount/parameter/optional | 3 + .../type/__install_mount/parameter/required | 1 + .../type/__install_partition_msdos/install | 0 .../type/__install_partition_msdos/man.text | 62 +++++++ .../type/__install_partition_msdos/manifest | 41 ++++ .../parameter/optional | 3 + .../parameter/required | 1 + .../explorer/partitions | 3 + .../files/lib.sh | 68 +++++++ .../gencode-remote | 175 ++++++++++++++++++ .../__install_partition_msdos_apply/install | 0 .../__install_partition_msdos_apply/man.text | 42 +++++ .../__install_partition_msdos_apply/singleton | 0 .../conf/type/__install_reboot/gencode-remote | 23 +++ cdist/conf/type/__install_reboot/install | 0 cdist/conf/type/__install_reboot/man.text | 43 +++++ cdist/conf/type/__install_reboot/manifest | 23 +++ cdist/conf/type/__install_reboot/singleton | 0 .../type/__install_reset_disk/gencode-remote | 65 +++++++ cdist/conf/type/__install_reset_disk/install | 0 cdist/conf/type/__install_reset_disk/man.text | 43 +++++ .../conf/type/__install_stage/gencode-remote | 65 +++++++ cdist/conf/type/__install_stage/install | 0 cdist/conf/type/__install_stage/man.text | 58 ++++++ cdist/conf/type/__install_stage/manifest | 33 ++++ .../type/__install_stage/parameter/optional | 2 + .../type/__install_stage/parameter/required | 1 + cdist/conf/type/__install_stage/singleton | 0 .../conf/type/__install_umount/gencode-remote | 25 +++ cdist/conf/type/__install_umount/install | 0 cdist/conf/type/__install_umount/man.text | 43 +++++ cdist/conf/type/__install_umount/manifest | 23 +++ 79 files changed, 1767 insertions(+) create mode 100755 cdist/conf/type/__install_bootloader_grub/gencode-remote create mode 100644 cdist/conf/type/__install_bootloader_grub/install create mode 100644 cdist/conf/type/__install_bootloader_grub/man.text create mode 100755 cdist/conf/type/__install_bootloader_grub/manifest create mode 100644 cdist/conf/type/__install_bootloader_grub/parameter/optional create mode 120000 cdist/conf/type/__install_chroot_mount/gencode-remote create mode 100644 cdist/conf/type/__install_chroot_mount/install create mode 120000 cdist/conf/type/__install_chroot_mount/man.text create mode 120000 cdist/conf/type/__install_chroot_umount/gencode-remote create mode 100644 cdist/conf/type/__install_chroot_umount/install create mode 120000 cdist/conf/type/__install_chroot_umount/man.text create mode 100755 cdist/conf/type/__install_config/files/remote/copy create mode 100755 cdist/conf/type/__install_config/files/remote/exec create mode 100755 cdist/conf/type/__install_config/gencode-local create mode 100644 cdist/conf/type/__install_config/install create mode 100644 cdist/conf/type/__install_config/man.text create mode 100755 cdist/conf/type/__install_config/manifest create mode 100644 cdist/conf/type/__install_config/parameter/optional create mode 100644 cdist/conf/type/__install_config/singleton create mode 120000 cdist/conf/type/__install_file/explorer create mode 120000 cdist/conf/type/__install_file/gencode-local create mode 120000 cdist/conf/type/__install_file/gencode-remote create mode 100644 cdist/conf/type/__install_file/install create mode 120000 cdist/conf/type/__install_file/man.text create mode 120000 cdist/conf/type/__install_file/parameter create mode 100644 cdist/conf/type/__install_fstab/install create mode 100644 cdist/conf/type/__install_fstab/man.text create mode 100755 cdist/conf/type/__install_fstab/manifest create mode 100644 cdist/conf/type/__install_fstab/parameter/optional create mode 100644 cdist/conf/type/__install_fstab/singleton create mode 100644 cdist/conf/type/__install_generate_fstab/files/fstab.header create mode 100755 cdist/conf/type/__install_generate_fstab/gencode-local create mode 100644 cdist/conf/type/__install_generate_fstab/install create mode 100644 cdist/conf/type/__install_generate_fstab/man.text create mode 100644 cdist/conf/type/__install_generate_fstab/parameter/boolean create mode 100644 cdist/conf/type/__install_generate_fstab/parameter/required create mode 100644 cdist/conf/type/__install_generate_fstab/singleton create mode 100755 cdist/conf/type/__install_mkfs/gencode-remote create mode 100644 cdist/conf/type/__install_mkfs/install create mode 100644 cdist/conf/type/__install_mkfs/man.text create mode 100755 cdist/conf/type/__install_mkfs/manifest create mode 100644 cdist/conf/type/__install_mkfs/parameter/optional create mode 100644 cdist/conf/type/__install_mkfs/parameter/required create mode 100755 cdist/conf/type/__install_mount/gencode-remote create mode 100644 cdist/conf/type/__install_mount/install create mode 100644 cdist/conf/type/__install_mount/man.text create mode 100755 cdist/conf/type/__install_mount/manifest create mode 100644 cdist/conf/type/__install_mount/parameter/optional create mode 100644 cdist/conf/type/__install_mount/parameter/required create mode 100644 cdist/conf/type/__install_partition_msdos/install create mode 100644 cdist/conf/type/__install_partition_msdos/man.text create mode 100755 cdist/conf/type/__install_partition_msdos/manifest create mode 100644 cdist/conf/type/__install_partition_msdos/parameter/optional create mode 100644 cdist/conf/type/__install_partition_msdos/parameter/required create mode 100755 cdist/conf/type/__install_partition_msdos_apply/explorer/partitions create mode 100644 cdist/conf/type/__install_partition_msdos_apply/files/lib.sh create mode 100755 cdist/conf/type/__install_partition_msdos_apply/gencode-remote create mode 100644 cdist/conf/type/__install_partition_msdos_apply/install create mode 100644 cdist/conf/type/__install_partition_msdos_apply/man.text create mode 100644 cdist/conf/type/__install_partition_msdos_apply/singleton create mode 100755 cdist/conf/type/__install_reboot/gencode-remote create mode 100644 cdist/conf/type/__install_reboot/install create mode 100644 cdist/conf/type/__install_reboot/man.text create mode 100755 cdist/conf/type/__install_reboot/manifest create mode 100644 cdist/conf/type/__install_reboot/singleton create mode 100755 cdist/conf/type/__install_reset_disk/gencode-remote create mode 100644 cdist/conf/type/__install_reset_disk/install create mode 100644 cdist/conf/type/__install_reset_disk/man.text create mode 100755 cdist/conf/type/__install_stage/gencode-remote create mode 100644 cdist/conf/type/__install_stage/install create mode 100644 cdist/conf/type/__install_stage/man.text create mode 100755 cdist/conf/type/__install_stage/manifest create mode 100644 cdist/conf/type/__install_stage/parameter/optional create mode 100644 cdist/conf/type/__install_stage/parameter/required create mode 100644 cdist/conf/type/__install_stage/singleton create mode 100755 cdist/conf/type/__install_umount/gencode-remote create mode 100644 cdist/conf/type/__install_umount/install create mode 100644 cdist/conf/type/__install_umount/man.text create mode 100755 cdist/conf/type/__install_umount/manifest 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..4822bcf3 --- /dev/null +++ b/cdist/conf/type/__install_config/files/remote/exec @@ -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 . +# +# +# __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" +scp="scp -o User=root -q" + +local_script=$(mktemp "/tmp/chroot-${0##*/}.XXXXXXXXXX") +remote_script=$($ssh mktemp "${chroot}/tmp/chroot-${0##*/}.XXXXXXXXXX") +relative_script="${remote_script#$chroot}" +trap cleanup INT TERM EXIT +cleanup() { + [ $__cdist_debug ] || { + rm "$local_script" + $ssh "rm $remote_script"; + } +} + +log "chroot: $chroot" +log "target_host: $target_host" +log "local_script: $local_script" +log "remote_script: $remote_script" +log "relative_script: $relative_script" +log "@: $@" +cat > "$local_script" << DONE +#!/bin/sh -l +# FIXME: fix the dependency bug, then test if the below is required or not +#if [ -f /etc/environment ]; then +# . /etc/environment +#fi +$@ +DONE + +# Upload script to target +$scp $local_script $target_host:$remote_script +$ssh "chmod +x $remote_script" + +# run in chroot +$ssh "chroot $chroot $relative_script" + +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..da87a4ac --- /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..d7d747a0 --- /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 retreived 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..6a71b8ed --- /dev/null +++ b/cdist/conf/type/__install_mkfs/gencode-remote @@ -0,0 +1,71 @@ +#!/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")" +type="$(cat "$__object/parameter/type")" + +# show command output in debug mode +cat << DONE +__debug=$__cdist_debug +if [ "\$__debug" != "yes" ]; then + # Link file descriptor #6 with stdout + exec 6>&1 + # redirect all output to /dev/null + exec > /dev/null +fi +DONE + +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 + +cat << DONE +if [ "\$__debug" != "yes" ]; then + # Restore stdout and close file descriptor #6. + exec 1>&6 6>&- +fi +DONE 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..0ab5c069 --- /dev/null +++ b/cdist/conf/type/__install_mount/gencode-remote @@ -0,0 +1,78 @@ +#!/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 . +# + +# show command output in debug mode +cat << DONE +__debug=$__cdist_debug +if [ "\$__debug" != "yes" ]; then + # Link file descriptor #6 with stdout + exec 6>&1 + # redirect all output to /dev/null + exec > /dev/null +fi +DONE + + +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 + +cat << DONE +if [ "\$__debug" != "yes" ]; then + # Restore stdout and close file descriptor #6. + exec 1>&6 6>&- +fi +DONE 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..8d403b67 --- /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..c683673d --- /dev/null +++ b/cdist/conf/type/__install_partition_msdos_apply/gencode-remote @@ -0,0 +1,175 @@ +#!/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 . +# + +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 << DONE +__debug=$__cdist_debug +if [ "\$__debug" != "yes" ]; then + # Link file descriptor #6 with stdout + exec 6>&1 + # redirect all output to /dev/null + exec > /dev/null +fi +DONE +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 + +cat << DONE +if [ "\$__debug" != "yes" ]; then + # Restore stdout and close file descriptor #6. + exec 1>&6 6>&- +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..e9278a7e --- /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 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 + +# 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 + +# clean disks from any legacy signatures +if command -v wipefs >/dev/null; then + wipefs -a "$disk" || true +fi +if command -v mdadm >/dev/null; then + mdadm --zero-superblock --force "$disk" || true +else + echo "WARNING: mdadm command not found" >&2 +fi +if command -v pvremove >/dev/null; then + pvremove --force --force --yes "$disk" || true +else + echo "WARNING: pvremove command not found" >&2 +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..17eeda0d --- /dev/null +++ b/cdist/conf/type/__install_stage/gencode-remote @@ -0,0 +1,65 @@ +#!/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 . +# + +# show command output in debug mode +cat << DONE +__debug=$__cdist_debug +if [ "\$__debug" != "yes" ]; then + # Link file descriptor #6 with stdout + exec 6>&1 + # redirect all output to /dev/null + exec > /dev/null +fi +DONE + +uri="$(cat "$__object/parameter/uri")" +target="$(cat "$__object/parameter/target")" +post_install="$(cat "$__object/parameter/post_install" 2>/dev/null || true)" + + +[ "$__debug" = "yes" ] && curl="curl" || curl="curl -s" +[ "$__debug" = "yes" ] && tar="tar -xvzp" || tar="tar -xzp" + +echo "$curl '$uri' | $tar -C '$target'" +if [ -n "$post_install" ]; then + post_install_script="$(cat "$__object/parameter/post_install_script")" + cat << DONE +[ -d "${target}/proc" ] || mkdir "${target}/proc" +mount -t proc none "${target}/proc" +[ -d "${target}/sys" ] || mkdir "${target}/sys" +mount -t sysfs none "${target}/sys" +[ -d "${target}/dev" ] || mkdir "${target}/dev" +mount --rbind /dev "${target}/dev" +[ -d "${target}/tmp" ] || mkdir -m 1777 "${target}/tmp" +mount -t tmpfs none "${target}/tmp" +cp "$post_install_script" "${target}/tmp/post_install" +chmod +x "${target}/tmp/post_install" +cp /etc/resolv.conf "${target}/etc/" +chroot "$target" /tmp/post_install +umount -l "${target}/tmp" "${target}/dev" "${target}/sys" "${target}/proc" +DONE +fi + +cat << DONE +if [ "\$__debug" != "yes" ]; then + # Restore stdout and close file descriptor #6. + exec 1>&6 6>&- +fi +DONE 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..0e657fdc --- /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. + +post_install:: + path to an optional local script. The script is uploaded to the target and + executed inside (chroot) the target after the stage has been unpacked. + + +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 file:///path/to/stage.tgz \ + --target /target \ + --post_install /path/to/file/on/server +-------------------------------------------------------------------------------- + + +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_stage/manifest b/cdist/conf/type/__install_stage/manifest new file mode 100755 index 00000000..ab5f4d79 --- /dev/null +++ b/cdist/conf/type/__install_stage/manifest @@ -0,0 +1,33 @@ +#!/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 +uri="$(cat "$__object/parameter/uri" 2>/dev/null \ + || echo "$__object_id" | tee "$__object/parameter/uri")" +target="$(cat "$__object/parameter/target" 2>/dev/null \ + || echo "/target" | tee "$__object/parameter/target")" + +if [ -f "$__object/parameter/post_install" ]; then + post_install="$(cat "$__object/parameter/post_install")" + post_install_script="/tmp/post_install" + __install_file $post_install_script --source $post_install + echo "$post_install_script" > "$__object/parameter/post_install_script" +fi + diff --git a/cdist/conf/type/__install_stage/parameter/optional b/cdist/conf/type/__install_stage/parameter/optional new file mode 100644 index 00000000..8e1a11b5 --- /dev/null +++ b/cdist/conf/type/__install_stage/parameter/optional @@ -0,0 +1,2 @@ +target +post_install 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")" From f5aad522cc7328243c8338f29602838d789b094d Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 29 Aug 2013 23:28:15 +0200 Subject: [PATCH 17/76] dont add help to 2 parsers Signed-off-by: Steven Armstrong --- scripts/cdist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/cdist b/scripts/cdist index 31bd7373..dfdef691 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -92,7 +92,7 @@ def commandline(): parser['shell'].set_defaults(func=cdist.shell.Shell.commandline) # Install - parser['install'] = parser['sub'].add_parser('install', + parser['install'] = parser['sub'].add_parser('install', add_help=False, parents=[parser['loglevel'], parser['config']]) parser['install'].set_defaults(func=cdist.install.Install.commandline) From 82612bc312eb8c367fdac4d46f88306beee87429 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 29 Aug 2013 23:29:54 +0200 Subject: [PATCH 18/76] config already inherits from loglevel parser Signed-off-by: Steven Armstrong --- scripts/cdist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/cdist b/scripts/cdist index dfdef691..24a955ae 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -93,7 +93,7 @@ def commandline(): # Install parser['install'] = parser['sub'].add_parser('install', add_help=False, - parents=[parser['loglevel'], parser['config']]) + parents=[parser['config']]) parser['install'].set_defaults(func=cdist.install.Install.commandline) for p in parser: From 4ace4348a7386d3750eaf6ed67873a48f11f4fc4 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 30 Aug 2013 12:56:12 +0200 Subject: [PATCH 19/76] filter out install objects when running config Signed-off-by: Steven Armstrong --- cdist/config.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cdist/config.py b/cdist/config.py index 59cf339a..988695ed 100644 --- a/cdist/config.py +++ b/cdist/config.py @@ -162,7 +162,10 @@ class Config(object): """Short name for object list retrieval""" for cdist_object in core.CdistObject.list_objects(self.local.object_path, self.local.type_path): - yield cdist_object + if cdist_object.cdist_type.is_install: + self.log.debug("Running in config mode, ignoring install object: {0}".format(cdist_object)) + else: + yield cdist_object def iterate_once(self): """ From a9109c94a480ef74937ac6680aa86f2682a17b4c Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 6 Sep 2013 12:22:57 +0200 Subject: [PATCH 20/76] add missing types from private repo Signed-off-by: Steven Armstrong --- cdist/conf/type/__chroot_mount/gencode-remote | 36 ++++++++++++++++ cdist/conf/type/__chroot_mount/man.text | 42 +++++++++++++++++++ .../conf/type/__chroot_umount/gencode-remote | 33 +++++++++++++++ cdist/conf/type/__chroot_umount/man.text | 42 +++++++++++++++++++ 4 files changed, 153 insertions(+) create mode 100755 cdist/conf/type/__chroot_mount/gencode-remote create mode 100644 cdist/conf/type/__chroot_mount/man.text create mode 100755 cdist/conf/type/__chroot_umount/gencode-remote create mode 100644 cdist/conf/type/__chroot_umount/man.text diff --git a/cdist/conf/type/__chroot_mount/gencode-remote b/cdist/conf/type/__chroot_mount/gencode-remote new file mode 100755 index 00000000..ec0b83ae --- /dev/null +++ b/cdist/conf/type/__chroot_mount/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 +# Prepare chroot +[ -d "${chroot}/proc" ] || mkdir "${chroot}/proc" +mount -t proc none "${chroot}/proc" +[ -d "${chroot}/sys" ] || mkdir "${chroot}/sys" +mount -t sysfs none "${chroot}/sys" +[ -d "${chroot}/dev" ] || mkdir "${chroot}/dev" +mount --rbind /dev "${chroot}/dev" +[ -d "${chroot}/tmp" ] || mkdir -m 1777 "${chroot}/tmp" +mount -t tmpfs none "${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..aad9ac76 --- /dev/null +++ b/cdist/conf/type/__chroot_umount/gencode-remote @@ -0,0 +1,33 @@ +#!/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" +umount -l "${chroot}/sys" +umount -l "${chroot}/proc" +rm -f "${chroot}/etc/resolv.conf" +# 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" +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). From a035b52a0dfd88b0383e22edcfc9f0c42d8129b2 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Sat, 14 Sep 2013 21:55:51 +0200 Subject: [PATCH 21/76] better mounting of virtual filesystems in chroot Signed-off-by: Steven Armstrong --- cdist/conf/type/__chroot_mount/gencode-remote | 20 +++++++++++++++---- .../conf/type/__chroot_umount/gencode-remote | 11 ++++++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/cdist/conf/type/__chroot_mount/gencode-remote b/cdist/conf/type/__chroot_mount/gencode-remote index ec0b83ae..6d855f41 100755 --- a/cdist/conf/type/__chroot_mount/gencode-remote +++ b/cdist/conf/type/__chroot_mount/gencode-remote @@ -23,13 +23,25 @@ chroot="/$__object_id" cat << DONE # Prepare chroot [ -d "${chroot}/proc" ] || mkdir "${chroot}/proc" -mount -t proc none "${chroot}/proc" +mountpoint -q "${chroot}/proc" \ + || mount -t proc -o nosuid,noexec,nodev proc "${chroot}/proc" + [ -d "${chroot}/sys" ] || mkdir "${chroot}/sys" -mount -t sysfs none "${chroot}/sys" +mountpoint -q "${chroot}/sys" \ + || mount -t sysfs -o nosuid,noexec,nodev sys "${chroot}/sys" + [ -d "${chroot}/dev" ] || mkdir "${chroot}/dev" -mount --rbind /dev "${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" -mount -t tmpfs none "${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 diff --git a/cdist/conf/type/__chroot_umount/gencode-remote b/cdist/conf/type/__chroot_umount/gencode-remote index aad9ac76..caf2c40c 100755 --- a/cdist/conf/type/__chroot_umount/gencode-remote +++ b/cdist/conf/type/__chroot_umount/gencode-remote @@ -22,12 +22,15 @@ 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" -# 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" +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 From f67cdc8afa0f898986ddd628dccbf0255f0b9a85 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 17 Sep 2013 21:35:00 +0200 Subject: [PATCH 22/76] cleanup, remove unused/useless post_install parameter Signed-off-by: Steven Armstrong --- .../conf/type/__install_stage/gencode-remote | 24 ++------------ cdist/conf/type/__install_stage/man.text | 7 ---- cdist/conf/type/__install_stage/manifest | 33 ------------------- .../__install_stage/parameter/default/target | 1 + .../type/__install_stage/parameter/optional | 1 - 5 files changed, 4 insertions(+), 62 deletions(-) delete mode 100755 cdist/conf/type/__install_stage/manifest create mode 100644 cdist/conf/type/__install_stage/parameter/default/target diff --git a/cdist/conf/type/__install_stage/gencode-remote b/cdist/conf/type/__install_stage/gencode-remote index 17eeda0d..12b9f1ed 100755 --- a/cdist/conf/type/__install_stage/gencode-remote +++ b/cdist/conf/type/__install_stage/gencode-remote @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2011-2013 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -29,33 +29,15 @@ if [ "\$__debug" != "yes" ]; then fi DONE -uri="$(cat "$__object/parameter/uri")" +uri="$(cat "$__object/parameter/uri" 2>/dev/null \ + || echo "$__object_id")" target="$(cat "$__object/parameter/target")" -post_install="$(cat "$__object/parameter/post_install" 2>/dev/null || true)" [ "$__debug" = "yes" ] && curl="curl" || curl="curl -s" [ "$__debug" = "yes" ] && tar="tar -xvzp" || tar="tar -xzp" echo "$curl '$uri' | $tar -C '$target'" -if [ -n "$post_install" ]; then - post_install_script="$(cat "$__object/parameter/post_install_script")" - cat << DONE -[ -d "${target}/proc" ] || mkdir "${target}/proc" -mount -t proc none "${target}/proc" -[ -d "${target}/sys" ] || mkdir "${target}/sys" -mount -t sysfs none "${target}/sys" -[ -d "${target}/dev" ] || mkdir "${target}/dev" -mount --rbind /dev "${target}/dev" -[ -d "${target}/tmp" ] || mkdir -m 1777 "${target}/tmp" -mount -t tmpfs none "${target}/tmp" -cp "$post_install_script" "${target}/tmp/post_install" -chmod +x "${target}/tmp/post_install" -cp /etc/resolv.conf "${target}/etc/" -chroot "$target" /tmp/post_install -umount -l "${target}/tmp" "${target}/dev" "${target}/sys" "${target}/proc" -DONE -fi cat << DONE if [ "\$__debug" != "yes" ]; then diff --git a/cdist/conf/type/__install_stage/man.text b/cdist/conf/type/__install_stage/man.text index 0e657fdc..7abc77e8 100644 --- a/cdist/conf/type/__install_stage/man.text +++ b/cdist/conf/type/__install_stage/man.text @@ -29,10 +29,6 @@ OPTIONAL PARAMETERS target:: where to unpack the tarball to. Defaults to /target. -post_install:: - path to an optional local script. The script is uploaded to the target and - executed inside (chroot) the target after the stage has been unpacked. - EXAMPLES -------- @@ -41,9 +37,6 @@ 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 file:///path/to/stage.tgz \ - --target /target \ - --post_install /path/to/file/on/server -------------------------------------------------------------------------------- diff --git a/cdist/conf/type/__install_stage/manifest b/cdist/conf/type/__install_stage/manifest deleted file mode 100755 index ab5f4d79..00000000 --- a/cdist/conf/type/__install_stage/manifest +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh -# -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) -# -# This file is part of cdist. -# -# cdist is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# cdist is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with cdist. If not, see . -# - -# set defaults -uri="$(cat "$__object/parameter/uri" 2>/dev/null \ - || echo "$__object_id" | tee "$__object/parameter/uri")" -target="$(cat "$__object/parameter/target" 2>/dev/null \ - || echo "/target" | tee "$__object/parameter/target")" - -if [ -f "$__object/parameter/post_install" ]; then - post_install="$(cat "$__object/parameter/post_install")" - post_install_script="/tmp/post_install" - __install_file $post_install_script --source $post_install - echo "$post_install_script" > "$__object/parameter/post_install_script" -fi - 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 index 8e1a11b5..eb5a316c 100644 --- a/cdist/conf/type/__install_stage/parameter/optional +++ b/cdist/conf/type/__install_stage/parameter/optional @@ -1,2 +1 @@ target -post_install From bfae291cf797da1bb9ce653398aea826bc2f3535 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 17 Sep 2013 22:41:10 +0200 Subject: [PATCH 23/76] remove pseudo debug output redirection Signed-off-by: Steven Armstrong --- cdist/conf/type/__install_mkfs/gencode-remote | 20 +----------------- .../conf/type/__install_mount/gencode-remote | 21 +------------------ .../gencode-remote | 18 +--------------- .../conf/type/__install_stage/gencode-remote | 18 ---------------- 4 files changed, 3 insertions(+), 74 deletions(-) diff --git a/cdist/conf/type/__install_mkfs/gencode-remote b/cdist/conf/type/__install_mkfs/gencode-remote index 6a71b8ed..2fe680e5 100755 --- a/cdist/conf/type/__install_mkfs/gencode-remote +++ b/cdist/conf/type/__install_mkfs/gencode-remote @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2011-2013 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -21,17 +21,6 @@ device="$(cat "$__object/parameter/device")" type="$(cat "$__object/parameter/type")" -# show command output in debug mode -cat << DONE -__debug=$__cdist_debug -if [ "\$__debug" != "yes" ]; then - # Link file descriptor #6 with stdout - exec 6>&1 - # redirect all output to /dev/null - exec > /dev/null -fi -DONE - case "$type" in swap) echo "mkswap $device" @@ -62,10 +51,3 @@ case "$type" in fi echo "$command" esac - -cat << DONE -if [ "\$__debug" != "yes" ]; then - # Restore stdout and close file descriptor #6. - exec 1>&6 6>&- -fi -DONE diff --git a/cdist/conf/type/__install_mount/gencode-remote b/cdist/conf/type/__install_mount/gencode-remote index 0ab5c069..3a35c139 100755 --- a/cdist/conf/type/__install_mount/gencode-remote +++ b/cdist/conf/type/__install_mount/gencode-remote @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2011-2013 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -18,18 +18,6 @@ # along with cdist. If not, see . # -# show command output in debug mode -cat << DONE -__debug=$__cdist_debug -if [ "\$__debug" != "yes" ]; then - # Link file descriptor #6 with stdout - exec 6>&1 - # redirect all output to /dev/null - exec > /dev/null -fi -DONE - - get_type_from_mkfs() { _device="$1" for mkfs_object in $(find "$__global/object/__install_mkfs" -path "*.cdist"); do @@ -69,10 +57,3 @@ else echo "[ -d \"$mount_point\" ] || mkdir -p \"$mount_point\"" echo "mount -t \"$type\" $options \"$device\" \"$mount_point\"" fi - -cat << DONE -if [ "\$__debug" != "yes" ]; then - # Restore stdout and close file descriptor #6. - exec 1>&6 6>&- -fi -DONE diff --git a/cdist/conf/type/__install_partition_msdos_apply/gencode-remote b/cdist/conf/type/__install_partition_msdos_apply/gencode-remote index c683673d..a1547296 100755 --- a/cdist/conf/type/__install_partition_msdos_apply/gencode-remote +++ b/cdist/conf/type/__install_partition_msdos_apply/gencode-remote @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2011-2013 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -71,15 +71,6 @@ get_objects() { } # include function library for use on target -cat << DONE -__debug=$__cdist_debug -if [ "\$__debug" != "yes" ]; then - # Link file descriptor #6 with stdout - exec 6>&1 - # redirect all output to /dev/null - exec > /dev/null -fi -DONE cat "$__type/files/lib.sh" partitions="$__object/explorer/partitions" @@ -166,10 +157,3 @@ for object in $objects; do echo "toggle_bootable '$device' '$minor' || die 'Failed to toogle bootable flag for partition: $partition'" fi done - -cat << DONE -if [ "\$__debug" != "yes" ]; then - # Restore stdout and close file descriptor #6. - exec 1>&6 6>&- -fi -DONE diff --git a/cdist/conf/type/__install_stage/gencode-remote b/cdist/conf/type/__install_stage/gencode-remote index 12b9f1ed..bbc27679 100755 --- a/cdist/conf/type/__install_stage/gencode-remote +++ b/cdist/conf/type/__install_stage/gencode-remote @@ -18,17 +18,6 @@ # along with cdist. If not, see . # -# show command output in debug mode -cat << DONE -__debug=$__cdist_debug -if [ "\$__debug" != "yes" ]; then - # Link file descriptor #6 with stdout - exec 6>&1 - # redirect all output to /dev/null - exec > /dev/null -fi -DONE - uri="$(cat "$__object/parameter/uri" 2>/dev/null \ || echo "$__object_id")" target="$(cat "$__object/parameter/target")" @@ -38,10 +27,3 @@ target="$(cat "$__object/parameter/target")" [ "$__debug" = "yes" ] && tar="tar -xvzp" || tar="tar -xzp" echo "$curl '$uri' | $tar -C '$target'" - -cat << DONE -if [ "\$__debug" != "yes" ]; then - # Restore stdout and close file descriptor #6. - exec 1>&6 6>&- -fi -DONE From 2f70a0d70e5c4aae07bf93d61752e34df4f2c2eb Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 17 Sep 2013 23:33:30 +0200 Subject: [PATCH 24/76] need a way to set remote.base_path from the command line Signed-off-by: Steven Armstrong --- cdist/config.py | 3 ++- cdist/exec/remote.py | 7 ++----- scripts/cdist | 2 ++ 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cdist/config.py b/cdist/config.py index 988695ed..dcaac740 100644 --- a/cdist/config.py +++ b/cdist/config.py @@ -124,7 +124,8 @@ class Config(object): remote = cdist.exec.remote.Remote( target_host=host, remote_exec=args.remote_exec, - remote_copy=args.remote_copy) + remote_copy=args.remote_copy, + base_path=args.remote_out_path) c = cls(local, remote, dry_run=args.dry_run) c.run() diff --git a/cdist/exec/remote.py b/cdist/exec/remote.py index 7c807092..3ffda12f 100644 --- a/cdist/exec/remote.py +++ b/cdist/exec/remote.py @@ -48,15 +48,12 @@ class Remote(object): target_host, remote_exec, remote_copy, - base_path=None): + base_path="/var/lib/cdist"): self.target_host = target_host self._exec = remote_exec self._copy = remote_copy - if base_path: - self.base_path = base_path - else: - self.base_path = "/var/lib/cdist" + self.base_path = base_path self.conf_path = os.path.join(self.base_path, "conf") self.object_path = os.path.join(self.base_path, "object") diff --git a/scripts/cdist b/scripts/cdist index 24a955ae..7bd58e58 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -68,6 +68,8 @@ def commandline(): help='Do not execute code', action='store_true') parser['config'].add_argument('-o', '--out-dir', help='Directory to save cdist output in', dest="out_path") + parser['config'].add_argument('-r', '--remote-out-dir', + help='Directory to save cdist output in on the target host', dest="remote_out_path") parser['config'].add_argument('-p', '--parallel', help='Operate on multiple hosts in parallel', action='store_true', dest='parallel') From fc988a5c228e0f778aa04840b18c8f2ea8bdddd7 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 17 Sep 2013 23:48:45 +0200 Subject: [PATCH 25/76] oh my, never mind Signed-off-by: Steven Armstrong --- cdist/exec/remote.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cdist/exec/remote.py b/cdist/exec/remote.py index 3ffda12f..7c807092 100644 --- a/cdist/exec/remote.py +++ b/cdist/exec/remote.py @@ -48,12 +48,15 @@ class Remote(object): target_host, remote_exec, remote_copy, - base_path="/var/lib/cdist"): + base_path=None): self.target_host = target_host self._exec = remote_exec self._copy = remote_copy - self.base_path = base_path + if base_path: + self.base_path = base_path + else: + self.base_path = "/var/lib/cdist" self.conf_path = os.path.join(self.base_path, "conf") self.object_path = os.path.join(self.base_path, "object") From a2318983970e580492f1940d39dd7e3ab3548316 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 15 Oct 2013 22:29:58 +0200 Subject: [PATCH 26/76] get rid of unnecessary tmp files Signed-off-by: Steven Armstrong --- .../type/__install_config/files/remote/exec | 37 +++---------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/cdist/conf/type/__install_config/files/remote/exec b/cdist/conf/type/__install_config/files/remote/exec index 4822bcf3..58e6b162 100755 --- a/cdist/conf/type/__install_config/files/remote/exec +++ b/cdist/conf/type/__install_config/files/remote/exec @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2011-2013 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -35,39 +35,14 @@ target_host="$__target_host" shift ssh="ssh -o User=root -q $target_host" -scp="scp -o User=root -q" +code="$ssh chroot $chroot sh -c '$@'" -local_script=$(mktemp "/tmp/chroot-${0##*/}.XXXXXXXXXX") -remote_script=$($ssh mktemp "${chroot}/tmp/chroot-${0##*/}.XXXXXXXXXX") -relative_script="${remote_script#$chroot}" -trap cleanup INT TERM EXIT -cleanup() { - [ $__cdist_debug ] || { - rm "$local_script" - $ssh "rm $remote_script"; - } -} - -log "chroot: $chroot" log "target_host: $target_host" -log "local_script: $local_script" -log "remote_script: $remote_script" -log "relative_script: $relative_script" +log "chroot: $chroot" log "@: $@" -cat > "$local_script" << DONE -#!/bin/sh -l -# FIXME: fix the dependency bug, then test if the below is required or not -#if [ -f /etc/environment ]; then -# . /etc/environment -#fi -$@ -DONE +log "code: $code" -# Upload script to target -$scp $local_script $target_host:$remote_script -$ssh "chmod +x $remote_script" - -# run in chroot -$ssh "chroot $chroot $relative_script" +# Run the code +$code log "-----" From f9cac131c9c4e125b85cc6b152839bb97b461383 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 10 Dec 2013 11:13:25 +0100 Subject: [PATCH 27/76] add parameter to run curl in insecure mode: thanks Thorsten! Signed-off-by: Steven Armstrong --- cdist/conf/type/__install_stage/gencode-remote | 5 ++++- cdist/conf/type/__install_stage/man.text | 9 ++++++++- cdist/conf/type/__install_stage/parameter/boolean | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 cdist/conf/type/__install_stage/parameter/boolean diff --git a/cdist/conf/type/__install_stage/gencode-remote b/cdist/conf/type/__install_stage/gencode-remote index bbc27679..3b83ea61 100755 --- a/cdist/conf/type/__install_stage/gencode-remote +++ b/cdist/conf/type/__install_stage/gencode-remote @@ -22,8 +22,11 @@ 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/man.text b/cdist/conf/type/__install_stage/man.text index 7abc77e8..289c8621 100644 --- a/cdist/conf/type/__install_stage/man.text +++ b/cdist/conf/type/__install_stage/man.text @@ -30,6 +30,12 @@ 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 -------- @@ -37,6 +43,7 @@ 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 -------------------------------------------------------------------------------- @@ -47,5 +54,5 @@ SEE ALSO COPYING ------- -Copyright \(C) 2011 Steven Armstrong. Free use of this software is +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 From be8df7999be8c45206004e024eb8621ab32e0b52 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 17 Dec 2013 14:56:20 +0100 Subject: [PATCH 28/76] first stop lvm, then mdadm Signed-off-by: Steven Armstrong --- .../type/__install_reset_disk/gencode-remote | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/cdist/conf/type/__install_reset_disk/gencode-remote b/cdist/conf/type/__install_reset_disk/gencode-remote index e9278a7e..e8e9cf8c 100755 --- a/cdist/conf/type/__install_reset_disk/gencode-remote +++ b/cdist/conf/type/__install_reset_disk/gencode-remote @@ -22,6 +22,15 @@ 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)" @@ -35,28 +44,19 @@ if [ -r /proc/mdstat ]; then fi fi -# 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 - -# clean disks from any legacy signatures -if command -v wipefs >/dev/null; then - wipefs -a "$disk" || true +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 -if command -v pvremove >/dev/null; then - pvremove --force --force --yes "$disk" || true -else - echo "WARNING: pvremove command not found" >&2 +# clean disks from any legacy signatures +if command -v wipefs >/dev/null; then + wipefs -a "$disk" || true fi # erase partition table From 4ca13d59a66e49a90148166f8b623772615a7a5f Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Jan 2014 10:40:42 +0100 Subject: [PATCH 29/76] comment out __apt_noautostart for the moment Signed-off-by: Nico Schottelius --- .../conf/type/__install_config/gencode-local | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/cdist/conf/type/__install_config/gencode-local b/cdist/conf/type/__install_config/gencode-local index da87a4ac..674dec25 100755 --- a/cdist/conf/type/__install_config/gencode-local +++ b/cdist/conf/type/__install_config/gencode-local @@ -26,13 +26,13 @@ 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 +#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 \ @@ -40,11 +40,11 @@ cdist $cdist_args \ --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 +#echo "__apt_noautostart --state absent" \ +# | cdist $cdist_args \ +# config \ +# --initial-manifest - \ +# --remote-exec="$remote_exec $chroot" \ +# --remote-copy="$remote_copy $chroot" \ +# $__target_host DONE From c3f79277b226ef5c97360566c868660e1ed1fbad Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 20 Jan 2014 08:50:41 +0100 Subject: [PATCH 30/76] add some more packages for preos - fixes #267 Signed-off-by: Nico Schottelius --- cdist/preos.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cdist/preos.py b/cdist/preos.py index 433cf871..f573566d 100644 --- a/cdist/preos.py +++ b/cdist/preos.py @@ -39,8 +39,8 @@ for pkg in \ file \ linux-image-amd64 \ openssh-server \ - syslinux \ - gdisk util-linux \ + syslinux grub 2 \ + gdisk util-linux lvm2 mdadm \ btrfs-tools e2fsprogs jfsutils reiser4progs xfsprogs; do __package $pkg --state present done From 79cfdf578d1d93241648262b64c2243ffed49559 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 20 Jan 2014 09:01:04 +0100 Subject: [PATCH 31/76] remove obsolete '--additional-manifest' parameter Signed-off-by: Nico Schottelius --- scripts/cdist | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/cdist b/scripts/cdist index ed9d2eda..7b7569ee 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -89,8 +89,6 @@ def commandline(): parents=[parser['loglevel']]) parser['preos'].add_argument('-a', '--arch', help='Select architecture for preos', default="amd64") - parser['preos'].add_argument('-A', '--additional-manifest', - help='Add stuff to configuration manifest', default="amd64") parser['preos'].add_argument('-b', '--bootstrap', help='Bootstrap directory with PreOS', action="store_true") parser['preos'].add_argument('-c', '--configure', From 55f26cbe25d8c87279a8221a9ef611fc2c90b8f1 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 20 Jan 2014 09:06:02 +0100 Subject: [PATCH 32/76] - ' ' Signed-off-by: Nico Schottelius --- cdist/preos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/preos.py b/cdist/preos.py index f573566d..b76d2178 100644 --- a/cdist/preos.py +++ b/cdist/preos.py @@ -39,7 +39,7 @@ for pkg in \ file \ linux-image-amd64 \ openssh-server \ - syslinux grub 2 \ + syslinux grub2 \ gdisk util-linux lvm2 mdadm \ btrfs-tools e2fsprogs jfsutils reiser4progs xfsprogs; do __package $pkg --state present From b125c0a4f273acaf33a082f8179b69e3b765b7d0 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 20 Jan 2014 09:21:50 +0100 Subject: [PATCH 33/76] create output directory, if it does not exist Signed-off-by: Nico Schottelius --- cdist/preos.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cdist/preos.py b/cdist/preos.py index b76d2178..f3d34c21 100644 --- a/cdist/preos.py +++ b/cdist/preos.py @@ -194,14 +194,21 @@ cp -L "$src" "$real_dst" log.info("Creating initramfs ...") subprocess.check_call(cmd, shell=True) + def ensure_out_dir_exists(self): + os.makedirs(self.out_dir, exist_ok=True) + + def create_iso(self, out_dir): self.out_dir = out_dir + self.ensure_out_dir_exists() + raise cdist.Error("Generating ISO is not yet supported") def create_pxe(self, out_dir): self.out_dir = out_dir + self.ensure_out_dir_exists() self.create_kernel() self.create_initramfs() self.create_pxeconfig() From 4cfedb1787abe7af68aa3cb51bbfc84714c26f4b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 20 Jan 2014 09:42:53 +0100 Subject: [PATCH 34/76] +curl Signed-off-by: Nico Schottelius --- cdist/preos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/preos.py b/cdist/preos.py index f3d34c21..347b0cba 100644 --- a/cdist/preos.py +++ b/cdist/preos.py @@ -38,7 +38,7 @@ DEFAULT_MANIFEST = """ for pkg in \ file \ linux-image-amd64 \ - openssh-server \ + openssh-server curl \ syslinux grub2 \ gdisk util-linux lvm2 mdadm \ btrfs-tools e2fsprogs jfsutils reiser4progs xfsprogs; do From e463f84333204605d948f81de7ada5683bb0ce64 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 20 Jan 2014 10:04:42 +0100 Subject: [PATCH 35/76] add changelog for 4.x cdist series Signed-off-by: Nico Schottelius --- cdist/conf/explorer/disks | 2 ++ docs/changelog.4 | 10 ++++++++++ 2 files changed, 12 insertions(+) create mode 100644 cdist/conf/explorer/disks create mode 100644 docs/changelog.4 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/docs/changelog.4 b/docs/changelog.4 new file mode 100644 index 00000000..79478c86 --- /dev/null +++ b/docs/changelog.4 @@ -0,0 +1,10 @@ +Changelog +--------- + + * Changes are always commented with their author in (braces) + * Exception: No braces means author == Nico Schottelius + +4.0.0pre1: + * Core: Integrate initial install support + * Core: Integrate initial preos support + From b4644c9c2eae1fdabb2b5a33f69ae92a774c1bc0 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 20 Jan 2014 10:08:46 +0100 Subject: [PATCH 36/76] add readme / warning for 4.x series Signed-off-by: Nico Schottelius --- README.4 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 README.4 diff --git a/README.4 b/README.4 new file mode 100644 index 00000000..04258873 --- /dev/null +++ b/README.4 @@ -0,0 +1,24 @@ +This branch contains experimental features for cdist 4.x: + + - install support + - preos support + +They are not yet stable: + + - use them at your own risk + - all __install types may change at any time (syntax, parameter, etc.) + - explorers for install may be broken + + - core code is based on the master branch, but + contains changes for install and preos feature + + +In short: + + _ _ _ + _ _ ___ ___ __ _| |_ _ _ ___ _ _ _ __ _____ ___ __ _ __(_)___| | __ +| | | / __|/ _ \ / _` | __| | | | |/ _ \| | | | '__| / _ \ \ /\ / / '_ \ | '__| / __| |/ / +| |_| \__ \ __/ | (_| | |_ | |_| | (_) | |_| | | | (_) \ V V /| | | | | | | \__ \ < + \__,_|___/\___| \__,_|\__| \__, |\___/ \__,_|_| \___/ \_/\_/ |_| |_| |_| |_|___/_|\_\ + |___/ + From 3ca911dbc641ed22596c18293d5f4c9271133eec Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 20 Jan 2014 14:37:50 +0100 Subject: [PATCH 37/76] integrate install and preos support Signed-off-by: Nico Schottelius --- docs/changelog | 4 ++++ docs/changelog.4 | 10 ---------- 2 files changed, 4 insertions(+), 10 deletions(-) delete mode 100644 docs/changelog.4 diff --git a/docs/changelog b/docs/changelog index f43131a1..98260564 100644 --- a/docs/changelog +++ b/docs/changelog @@ -4,6 +4,10 @@ Changelog * Changes are always commented with their author in (braces) * Exception: No braces means author == Nico Schottelius +4.0.0pre1: 2014-01-20 + * Core: Integrate initial install support + * Core: Integrate initial preos support + 3.0.3: * Core: Enhance error message when requirement is missing object id * Explorer hostname: Return host name by using uname -n diff --git a/docs/changelog.4 b/docs/changelog.4 deleted file mode 100644 index 79478c86..00000000 --- a/docs/changelog.4 +++ /dev/null @@ -1,10 +0,0 @@ -Changelog ---------- - - * Changes are always commented with their author in (braces) - * Exception: No braces means author == Nico Schottelius - -4.0.0pre1: - * Core: Integrate initial install support - * Core: Integrate initial preos support - From a3c5d32a5453b25057acd238377fe002f98f9e74 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 20 Jan 2014 14:45:42 +0100 Subject: [PATCH 38/76] fix building manpage of __install_partition_msdos Signed-off-by: Nico Schottelius --- cdist/conf/type/__install_partition_msdos/man.text | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__install_partition_msdos/man.text b/cdist/conf/type/__install_partition_msdos/man.text index 8d403b67..82d81ac5 100644 --- a/cdist/conf/type/__install_partition_msdos/man.text +++ b/cdist/conf/type/__install_partition_msdos/man.text @@ -1,5 +1,5 @@ cdist-type__install_partition_msdos(7) -============================== +====================================== Steven Armstrong From 5a0a3971b0c2769bf3b1c0202b0d48be6db71bb9 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 20 Jan 2014 14:48:05 +0100 Subject: [PATCH 39/76] do not change to the masterbranch... Signed-off-by: Nico Schottelius --- bin/build-helper | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/build-helper b/bin/build-helper index 6210b907..bfd7d31c 100755 --- a/bin/build-helper +++ b/bin/build-helper @@ -247,8 +247,10 @@ eof "$0" release-git-tag # Also merge back the version branch - git checkout master - git merge "$target_branch" + if [ "$masterbranch" = yes ]; then + git checkout master + git merge "$target_branch" + fi # Publish git changes make pub From ca47ea00382a8f5da655540d6032c1338b51c8e5 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Mon, 3 Feb 2014 15:29:48 +0100 Subject: [PATCH 40/76] cleanup apt cache before packing initramfs Signed-off-by: Steven Armstrong --- cdist/preos.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cdist/preos.py b/cdist/preos.py index 347b0cba..dc400ba9 100644 --- a/cdist/preos.py +++ b/cdist/preos.py @@ -253,6 +253,12 @@ cp -L "$src" "$real_dst" config = cdist.config.Config(local, remote) config.run() + def cleanup(self): + # Remove cruft from chroot + for action in 'autoclean clean autoremove'.split(): + cmd = [ 'chroot', self.target_dir, '/usr/bin/apt-get', action] + subprocess.check_call(cmd) + @classmethod def commandline(cls, args): self = cls(target_dir=args.target_dir[0], @@ -270,6 +276,9 @@ cp -L "$src" "$real_dst" if args.config: self.config() + # Cleanup chroot + self.cleanup() + # Output pxe files if args.pxe_boot_dir: self.create_pxe(args.pxe_boot_dir) From ee5731fc960fa7849daa32f8ee4df130adc7aa66 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 6 Feb 2014 00:08:02 +0100 Subject: [PATCH 41/76] add __ccollect_source type Signed-off-by: Nico Schottelius --- .../type/__ccollect_source/explorer/cksum | 34 +++++++ .../conf/type/__ccollect_source/explorer/stat | 47 ++++++++++ .../conf/type/__ccollect_source/explorer/type | 33 +++++++ .../type/__ccollect_source/gencode-remote | 93 +++++++++++++++++++ cdist/conf/type/__ccollect_source/man.text | 64 +++++++++++++ cdist/conf/type/__ccollect_source/manifest | 53 +++++++++++ .../type/__ccollect_source/parameter/boolean | 1 + .../parameter/default/ccollectconf | 1 + .../__ccollect_source/parameter/default/state | 1 + .../type/__ccollect_source/parameter/optional | 2 + .../parameter/optional_multiple | 1 + .../type/__ccollect_source/parameter/required | 2 + 12 files changed, 332 insertions(+) create mode 100755 cdist/conf/type/__ccollect_source/explorer/cksum create mode 100755 cdist/conf/type/__ccollect_source/explorer/stat create mode 100755 cdist/conf/type/__ccollect_source/explorer/type create mode 100755 cdist/conf/type/__ccollect_source/gencode-remote create mode 100644 cdist/conf/type/__ccollect_source/man.text create mode 100755 cdist/conf/type/__ccollect_source/manifest create mode 100644 cdist/conf/type/__ccollect_source/parameter/boolean create mode 100644 cdist/conf/type/__ccollect_source/parameter/default/ccollectconf create mode 100644 cdist/conf/type/__ccollect_source/parameter/default/state create mode 100644 cdist/conf/type/__ccollect_source/parameter/optional create mode 100644 cdist/conf/type/__ccollect_source/parameter/optional_multiple create mode 100644 cdist/conf/type/__ccollect_source/parameter/required diff --git a/cdist/conf/type/__ccollect_source/explorer/cksum b/cdist/conf/type/__ccollect_source/explorer/cksum new file mode 100755 index 00000000..335e4e7a --- /dev/null +++ b/cdist/conf/type/__ccollect_source/explorer/cksum @@ -0,0 +1,34 @@ +#!/bin/sh +# +# 2011-2012 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 . +# +# +# Retrieve the md5sum of a file to be created, if it is already existing. +# + +destination="/$__object_id" + +if [ -e "$destination" ]; then + if [ -f "$destination" ]; then + cksum < "$destination" + else + echo "NO REGULAR FILE" + fi +else + echo "NO FILE FOUND, NO CHECKSUM CALCULATED." +fi diff --git a/cdist/conf/type/__ccollect_source/explorer/stat b/cdist/conf/type/__ccollect_source/explorer/stat new file mode 100755 index 00000000..298221b7 --- /dev/null +++ b/cdist/conf/type/__ccollect_source/explorer/stat @@ -0,0 +1,47 @@ +#!/bin/sh +# +# 2013 Steven Armstrong (steven-cdist 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="/$__object_id" + +# nothing to work with, nothing we could do +[ -e "$destination" ] || exit 0 + +os=$("$__explorer/os") +case "$os" in + "freebsd") + # FIXME: should be something like this based on man page, but can not test + stat -f "type: %ST +owner: %Du %Su +group: %Dg %Sg +mode: %Op %Sp +size: %Dz +links: %Dl +" "$destination" + ;; + *) + stat --printf="type: %F +owner: %u %U +group: %g %G +mode: %a %A +size: %s +links: %h +" "$destination" + ;; +esac diff --git a/cdist/conf/type/__ccollect_source/explorer/type b/cdist/conf/type/__ccollect_source/explorer/type new file mode 100755 index 00000000..e723047c --- /dev/null +++ b/cdist/conf/type/__ccollect_source/explorer/type @@ -0,0 +1,33 @@ +#!/bin/sh +# +# 2013 Steven Armstrong (steven-cdist 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="/$__object_id" + +if [ ! -e "$destination" ]; then + echo none +elif [ -h "$destination" ]; then + echo symlink +elif [ -f "$destination" ]; then + echo file +elif [ -d "$destination" ]; then + echo directory +else + echo unknown +fi diff --git a/cdist/conf/type/__ccollect_source/gencode-remote b/cdist/conf/type/__ccollect_source/gencode-remote new file mode 100755 index 00000000..c41b5179 --- /dev/null +++ b/cdist/conf/type/__ccollect_source/gencode-remote @@ -0,0 +1,93 @@ +#!/bin/sh +# +# 2014 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" +state_should="$(cat "$__object/parameter/state")" +type="$(cat "$__object/explorer/type")" +stat_file="$__object/explorer/stat" + + +get_current_value() { + if [ -s "$stat_file" ]; then + _name="$1" + _value="$2" + case "$_value" in + [0-9]*) + _index=2 + ;; + *) + _index=3 + ;; + esac + awk '/'"$_name"':/ { print $'$_index' }' "$stat_file" + unset _name _value _index + fi +} + +set_group() { + echo chgrp \"$1\" \"$destination\" + echo chgrp $1 >> "$__messages_out" +} + +set_owner() { + echo chown \"$1\" \"$destination\" + echo chown $1 >> "$__messages_out" +} + +set_mode() { + echo chmod \"$1\" \"$destination\" + echo chmod $1 >> "$__messages_out" +} + +set_attributes= +case "$state_should" in + present|exists) + # Note: Mode - needs to happen last as a chown/chgrp can alter mode by + # clearing S_ISUID and S_ISGID bits (see chown(2)) + for attribute in group owner mode; do + if [ -f "$__object/parameter/$attribute" ]; then + value_should="$(cat "$__object/parameter/$attribute")" + + # change 0xxx format to xxx format => same as stat returns + if [ "$attribute" = mode ]; then + value_should="$(echo $value_should | sed 's/^0\(...\)/\1/')" + fi + + value_is="$(get_current_value "$attribute" "$value_should")" + if [ -f "$__object/files/set-attributes" -o "$value_should" != "$value_is" ]; then + "set_$attribute" "$value_should" + fi + fi + done + + ;; + + absent) + if [ "$type" = "file" ]; then + echo rm -f \"$destination\" + echo remove >> "$__messages_out" + fi + ;; + + *) + echo "Unknown state: $state_should" >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__ccollect_source/man.text b/cdist/conf/type/__ccollect_source/man.text new file mode 100644 index 00000000..32a7467e --- /dev/null +++ b/cdist/conf/type/__ccollect_source/man.text @@ -0,0 +1,64 @@ +cdist-type__ccollect_source(7) +============================== +Nico Schottelius + + +NAME +---- +cdist-type__ccollect_source - Manage ccollect sources + + +DESCRIPTION +----------- +This cdist type allows you to create or delete ccollect sources. + +REQUIRED PARAMETERS +------------------- +source:: + The source from which to backup +destination:: + The destination directory + + +OPTIONAL PARAMETERS +------------------- +state:: + 'present' or 'absent', defaults to 'present' +ccollectconf:: + The CCOLLECT_CONF directory. Defaults to /etc/ccollect. + + +OPTIONAL MULTIPLE PARAMETERS +---------------------------- +exclude:: + Paths to exclude of backup + +BOOLEAN PARAMETERS +------------------ +verbose:: + Whether to report backup verbosely + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__ccollect_source doc.ungleich.ch \ + --source doc.ungleich.ch:/ \ + --destination /backup/doc.ungleich.ch \ + --exclude '/proc/*' --exclude '/sys/*' \ + --verbose + +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- ccollect(1) +- http://www.nico.schottelius.org/software/ccollect/ + + +COPYING +------- +Copyright \(C) 2014 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/__ccollect_source/manifest b/cdist/conf/type/__ccollect_source/manifest new file mode 100755 index 00000000..89c2ef2b --- /dev/null +++ b/cdist/conf/type/__ccollect_source/manifest @@ -0,0 +1,53 @@ +#!/bin/sh +# +# 2014 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 . +# + +name="$__object_id" +state="$(cat "$__object/parameter/state")" +source="$(cat "$__object/parameter/source")" +destination="$(cat "$__object/parameter/destination")" +ccollectconf="$(cat "$__object/parameter/ccollectconf" | sed 's,/$,,')" + +sourcedir="$ccollectconf/sources" +basedir="$sourcedir/$name" + +destination_file="$basedir/destination" +source_file="$basedir/source" +exclude_file="$basedir/exclude" +verbose_file="$basedir/verbose" + +__directory "$basedir" --state "$state" + +export require="__directory$basedir" +echo "$destination" | __file "$destination_file" --source - --state "$state" +echo "$source" | __file "$source_file" --source - --state "$state" + +################################################################################ +# Booleans +if [ -f "$__object/parameter/verbose" ]; then + verbosestate="present" +else + verbosestate="absent" +fi +__file "$verbose_file" --state "$verbosestate" + +if [ -f "$__object/parameter/exclude" ]; then + __file "$exclude_file" --source - --state "$state" \ + < "$__object/parameter/exclude" +fi diff --git a/cdist/conf/type/__ccollect_source/parameter/boolean b/cdist/conf/type/__ccollect_source/parameter/boolean new file mode 100644 index 00000000..c00ee94a --- /dev/null +++ b/cdist/conf/type/__ccollect_source/parameter/boolean @@ -0,0 +1 @@ +verbose diff --git a/cdist/conf/type/__ccollect_source/parameter/default/ccollectconf b/cdist/conf/type/__ccollect_source/parameter/default/ccollectconf new file mode 100644 index 00000000..a9fda009 --- /dev/null +++ b/cdist/conf/type/__ccollect_source/parameter/default/ccollectconf @@ -0,0 +1 @@ +/etc/ccollect diff --git a/cdist/conf/type/__ccollect_source/parameter/default/state b/cdist/conf/type/__ccollect_source/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__ccollect_source/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__ccollect_source/parameter/optional b/cdist/conf/type/__ccollect_source/parameter/optional new file mode 100644 index 00000000..0249d11e --- /dev/null +++ b/cdist/conf/type/__ccollect_source/parameter/optional @@ -0,0 +1,2 @@ +ccollectconf +state diff --git a/cdist/conf/type/__ccollect_source/parameter/optional_multiple b/cdist/conf/type/__ccollect_source/parameter/optional_multiple new file mode 100644 index 00000000..9ba870ea --- /dev/null +++ b/cdist/conf/type/__ccollect_source/parameter/optional_multiple @@ -0,0 +1 @@ +exclude diff --git a/cdist/conf/type/__ccollect_source/parameter/required b/cdist/conf/type/__ccollect_source/parameter/required new file mode 100644 index 00000000..9239646e --- /dev/null +++ b/cdist/conf/type/__ccollect_source/parameter/required @@ -0,0 +1,2 @@ +source +destination From 4efe8553da4ccf4ec58197bb1422eefa9713e908 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 10 Feb 2014 21:40:11 +0100 Subject: [PATCH 42/76] run apt-get clean before creating preos Signed-off-by: Nico Schottelius --- cdist/preos.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cdist/preos.py b/cdist/preos.py index 347b0cba..ff157f5b 100644 --- a/cdist/preos.py +++ b/cdist/preos.py @@ -162,6 +162,10 @@ cp -L "$src" "$real_dst" fd.write(val) os.chmod(filename, stat.S_IRUSR | stat.S_IXUSR) + def remove_archives(self, base_dir): + cmd = [ "chroot", self.target_dir, "/usr/bin/apt-get", "clean" ] + subprocess.check_call(cmd) + def create_kernel(self): dst = os.path.join(self.out_dir, "kernel") srcglob = glob.glob("%s/boot/vmlinuz-*" % self.target_dir) @@ -270,6 +274,9 @@ cp -L "$src" "$real_dst" if args.config: self.config() + # Cleanup archives before creating any image + self.remove_archives() + # Output pxe files if args.pxe_boot_dir: self.create_pxe(args.pxe_boot_dir) From ac23fa3e1018d80f52bf05686bc6a9e70b23eeeb Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 14 Feb 2014 20:53:43 +0100 Subject: [PATCH 43/76] ++changes Signed-off-by: Nico Schottelius --- docs/changelog | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/changelog b/docs/changelog index 00d2734e..4f6b1064 100644 --- a/docs/changelog +++ b/docs/changelog @@ -4,6 +4,9 @@ Changelog * Changes are always commented with their author in (braces) * Exception: No braces means author == Nico Schottelius +4.0.0pre2: 2014-02-14 + * Core: Remove archives from generated preos (Steven Armstrong) + 4.0.0pre1: 2014-01-20 * Core: Integrate initial install support * Core: Integrate initial preos support From 9ad7e055024c067d6dbb35eab53b49b33a48344c Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 31 Mar 2014 23:58:45 +0200 Subject: [PATCH 44/76] ++;; Signed-off-by: Nico Schottelius --- cdist/conf/type/__dog_vdi/manifest | 1 + 1 file changed, 1 insertion(+) diff --git a/cdist/conf/type/__dog_vdi/manifest b/cdist/conf/type/__dog_vdi/manifest index ab533c4b..be327a3a 100644 --- a/cdist/conf/type/__dog_vdi/manifest +++ b/cdist/conf/type/__dog_vdi/manifest @@ -26,6 +26,7 @@ case "$state_should" in echo "Size is required when state is present" >&2 exit 1 fi + ;; absent) : ;; From 8e060a1d838c38081eda0c8fb796cddaec20593d Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 13 Jun 2014 13:51:03 +0200 Subject: [PATCH 45/76] release 4.0.0pre3 Signed-off-by: Nico Schottelius --- docs/changelog | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/changelog b/docs/changelog index 509394d9..a6e11e08 100644 --- a/docs/changelog +++ b/docs/changelog @@ -4,6 +4,9 @@ Changelog * Changes are always commented with their author in (braces) * Exception: No braces means author == Nico Schottelius +4.0.0pre3: 2014-06-13 + * Update to include changes from cdist 3.1.5 + 4.0.0pre2: 2014-02-14 * Core: Remove archives from generated preos (Steven Armstrong) From 3d82a0d25cda5f3cbbd8e9cb6ac67584f053ed69 Mon Sep 17 00:00:00 2001 From: Markus Koller Date: Fri, 13 Jun 2014 14:56:24 +0200 Subject: [PATCH 46/76] Set hostname in preos --- cdist/preos.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cdist/preos.py b/cdist/preos.py index dc400ba9..0aa7eb6f 100644 --- a/cdist/preos.py +++ b/cdist/preos.py @@ -62,6 +62,8 @@ eof # Steven found this out - coyping it 1:1 # fix the bloody 'stdin: is not a tty' problem __line /root/.profile --line 'mesg n' --state absent + +__hostname preos """ class PreOSExistsError(cdist.Error): From 339167c23c0ccd68841f3f3b36490fce4743aaa6 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 14 Sep 2014 13:51:13 +0200 Subject: [PATCH 47/76] catch some errors Signed-off-by: Nico Schottelius --- cdist/preos.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cdist/preos.py b/cdist/preos.py index 0aa7eb6f..b61318ed 100644 --- a/cdist/preos.py +++ b/cdist/preos.py @@ -148,14 +148,17 @@ cp -L "$src" "$real_dst" log.debug("Bootstrap: %s" % cmd) -# try: - subprocess.check_call(cmd) -# except subprocess.CalledProcessError: -# raise + try: + subprocess.check_call(cmd) + except subprocess.CalledProcessError: + raise cdist.Error("Debootstrap failed (root priviliges required)") # Required to run this - otherwise apt-get install fails cmd = [ "chroot", self.target_dir, "/usr/bin/apt-get", "update" ] - subprocess.check_call(cmd) + try: + subprocess.check_call(cmd) + except subprocess.CalledProcessError: + raise cdist.Error("chrooted apt-get update failed (root priviliges required)") def create_helper_files(self, base_dir): for key, val in self.helper.items(): From 1b1b345263e72f9dfa4a4bd8b8a61892b45f04a3 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 28 Mar 2015 03:20:28 +0900 Subject: [PATCH 48/76] add initial type for building preos Signed-off-by: Nico Schottelius --- cdist/conf/type/__cdist_preos/man.text | 38 ++++++++++++++ cdist/conf/type/__cdist_preos/manifest | 49 +++++++++++++++++++ .../__cdist_preos/parameter/default/branch | 1 + .../__cdist_preos/parameter/default/source | 1 + .../__cdist_preos/parameter/default/username | 1 + .../type/__cdist_preos/parameter/optional | 4 ++ 6 files changed, 94 insertions(+) create mode 100644 cdist/conf/type/__cdist_preos/man.text create mode 100755 cdist/conf/type/__cdist_preos/manifest create mode 100644 cdist/conf/type/__cdist_preos/parameter/default/branch create mode 100644 cdist/conf/type/__cdist_preos/parameter/default/source create mode 100644 cdist/conf/type/__cdist_preos/parameter/default/username create mode 100644 cdist/conf/type/__cdist_preos/parameter/optional 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..8bb2175f --- /dev/null +++ b/cdist/conf/type/__cdist_preos/manifest @@ -0,0 +1,49 @@ +#!/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) + # any linux should work + : + ;; + *) + 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" 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 From 909c58de4e2908afaa2c6f9feaf8ea2810ddf628 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 2 May 2015 12:24:57 +0200 Subject: [PATCH 49/76] add hacking dir for new preos-setup Signed-off-by: Nico Schottelius --- hacking/recursive-ldd.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 hacking/recursive-ldd.sh diff --git a/hacking/recursive-ldd.sh b/hacking/recursive-ldd.sh new file mode 100644 index 00000000..8093145d --- /dev/null +++ b/hacking/recursive-ldd.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# Nico Schottelius +# Fri May 1 17:31:50 CEST 2015 + +# [18:09] wurzel:.cdist-ruag% ldd /usr/bin/ls | sed -e 's/=>//' -e 's/(.*//' | awk '{ if(NF == 2) { print $2 } else { print $1 } }' + +PATH=/bin:/sbin:/usr/bin:/usr/sbin + +bin_list="fdisk + +for command in command_list; + + + +exit 0 + + +bin=$1 + +list="" +new_list=$(objdump -p /usr/bin/ls | awk '$1 ~ /NEEDED/ { print $2 }') + +[18:16] wurzel:.cdist-ruag% ldconfig -p | grep 'libBrokenLocale.so.1$' | sed 's/.* => //' + + +for new_item in $new_list; do + + +done + +ldconfig -p | From a0aba11e772a9e8dbef645f91fb12b1a5844c0b0 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 5 May 2015 13:53:19 +0200 Subject: [PATCH 50/76] +some tools / updates for preos Signed-off-by: Nico Schottelius --- hacking/README | 3 +++ hacking/bin_to_pkg.sh | 4 ++++ hacking/recursive-ldd.sh | 7 +++++-- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 hacking/README create mode 100755 hacking/bin_to_pkg.sh diff --git a/hacking/README b/hacking/README new file mode 100644 index 00000000..f675f106 --- /dev/null +++ b/hacking/README @@ -0,0 +1,3 @@ +- Target: + - get working iso + - have it configured and gathered by cdist? diff --git a/hacking/bin_to_pkg.sh b/hacking/bin_to_pkg.sh new file mode 100755 index 00000000..111b1fa9 --- /dev/null +++ b/hacking/bin_to_pkg.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +abspath=$(command -v "$1") +pacman -Qoq "$abspath" diff --git a/hacking/recursive-ldd.sh b/hacking/recursive-ldd.sh index 8093145d..d66d2b0e 100644 --- a/hacking/recursive-ldd.sh +++ b/hacking/recursive-ldd.sh @@ -6,10 +6,13 @@ PATH=/bin:/sbin:/usr/bin:/usr/sbin -bin_list="fdisk +pkg=" -for command in command_list; +bin_list="fdisk mount" +for bin in command_list; do + +done exit 0 From 56c7431467aa12f12494462277a604f8cc78e60c Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 5 May 2015 13:53:47 +0200 Subject: [PATCH 51/76] __cdist_preos enhancements Signed-off-by: Nico Schottelius --- cdist/conf/type/__cdist_preos/manifest | 50 ++++++++++++++++++++------ 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/cdist/conf/type/__cdist_preos/manifest b/cdist/conf/type/__cdist_preos/manifest index 8bb2175f..78166b38 100755 --- a/cdist/conf/type/__cdist_preos/manifest +++ b/cdist/conf/type/__cdist_preos/manifest @@ -24,15 +24,16 @@ destination="/$__object_id" os=$(cat "$__global/explorer/os") case "$os" in - archlinux) - # any linux should work - : - ;; - *) - 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 - ;; + 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 @@ -44,6 +45,35 @@ for rootdir in boot bin etc lib; do --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 From 8c97ad3d9530423167ce0df768f1977925c9ffac Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 8 May 2015 08:22:22 +0200 Subject: [PATCH 52/76] generate list of files from packages Signed-off-by: Nico Schottelius --- hacking/archlinux/file_list_of_packages.sh | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 hacking/archlinux/file_list_of_packages.sh diff --git a/hacking/archlinux/file_list_of_packages.sh b/hacking/archlinux/file_list_of_packages.sh new file mode 100644 index 00000000..608fdfbc --- /dev/null +++ b/hacking/archlinux/file_list_of_packages.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +pacman -Qlq "$@" From 9f3a8c0956ce97ecd73d8851ec863a4658863616 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 8 May 2015 13:42:13 +0200 Subject: [PATCH 53/76] +tools Signed-off-by: Nico Schottelius --- hacking/README | 9 +++++++++ hacking/recursive-ldd.sh | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/hacking/README b/hacking/README index f675f106..ffd4f6a0 100644 --- a/hacking/README +++ b/hacking/README @@ -1,3 +1,12 @@ - Target: - get working iso - have it configured and gathered by cdist? + +- boot process via ...? + - systemd? + +- packaging via ... + - packages? + - binlist + - bootstrap of os + -> root permissions! diff --git a/hacking/recursive-ldd.sh b/hacking/recursive-ldd.sh index d66d2b0e..600df529 100644 --- a/hacking/recursive-ldd.sh +++ b/hacking/recursive-ldd.sh @@ -8,7 +8,7 @@ PATH=/bin:/sbin:/usr/bin:/usr/sbin pkg=" -bin_list="fdisk mount" +bin_list="bash fdisk mount syslinux umount rm mv" for bin in command_list; do From 75e3f3c90fd471a24aeb48023af93d2b2b16466c Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 13 May 2015 08:13:54 +0200 Subject: [PATCH 54/76] write script to generate outdir from filelist Signed-off-by: Nico Schottelius --- hacking/copy_files_for_iso.sh | 23 +++++++++++++++++++++++ hacking/filelist_from_package.sh | 7 +++++++ hacking/filelist_to_dir.sh | 18 ++++++++++++++++++ hacking/qemu-test.sh | 12 ++++++++++++ hacking/recursive-ldd.sh | 0 5 files changed, 60 insertions(+) create mode 100755 hacking/copy_files_for_iso.sh create mode 100755 hacking/filelist_from_package.sh create mode 100755 hacking/filelist_to_dir.sh create mode 100755 hacking/qemu-test.sh mode change 100644 => 100755 hacking/recursive-ldd.sh diff --git a/hacking/copy_files_for_iso.sh b/hacking/copy_files_for_iso.sh new file mode 100755 index 00000000..0318c072 --- /dev/null +++ b/hacking/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/filelist_from_package.sh b/hacking/filelist_from_package.sh new file mode 100755 index 00000000..58ac48f4 --- /dev/null +++ b/hacking/filelist_from_package.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +# Generate filelist excluding stuff that takes only space +for pkg in bash systemd util-linux; do + pacman -Qlq $pkg | grep -v \ + -e /usr/share/man/ +done diff --git a/hacking/filelist_to_dir.sh b/hacking/filelist_to_dir.sh new file mode 100755 index 00000000..3ce19b9f --- /dev/null +++ b/hacking/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/qemu-test.sh b/hacking/qemu-test.sh new file mode 100755 index 00000000..03695222 --- /dev/null +++ b/hacking/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=$iso,media=cdrom + diff --git a/hacking/recursive-ldd.sh b/hacking/recursive-ldd.sh old mode 100644 new mode 100755 From 1a52df0ddc06660eea4fff7e7f59759415a07401 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 13 May 2015 08:39:22 +0200 Subject: [PATCH 55/76] begin to write down how to create iso Signed-off-by: Nico Schottelius --- hacking/create_iso.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 hacking/create_iso.sh diff --git a/hacking/create_iso.sh b/hacking/create_iso.sh new file mode 100644 index 00000000..23e8a0e3 --- /dev/null +++ b/hacking/create_iso.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +# FIXME: include os explorer to name preos + +indir=./iso + +version=0.3 +out=preos-${version}.iso + +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 $indir From 59d81ddd4b4ba330e920b8e7bb96de1ec1c587ae Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 13 May 2015 09:10:38 +0200 Subject: [PATCH 56/76] create iso works without checksum error Signed-off-by: Nico Schottelius --- hacking/create_iso.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) mode change 100644 => 100755 hacking/create_iso.sh diff --git a/hacking/create_iso.sh b/hacking/create_iso.sh old mode 100644 new mode 100755 index 23e8a0e3..0902bc20 --- a/hacking/create_iso.sh +++ b/hacking/create_iso.sh @@ -2,13 +2,20 @@ # FIXME: include os explorer to name preos -indir=./iso +if [ "$#" -ne 2 ]; then + echo "$0 dir-in iso-out" + exit 1 +fi + +indir=$1; shift +iso=$1; shift version=0.3 + out=preos-${version}.iso -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 $indir + # -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" From a1f003bd9c6fa01906c5d36399564afa605f67ba Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 13 May 2015 09:24:55 +0200 Subject: [PATCH 57/76] get iso to boot into kernel + initramfs Signed-off-by: Nico Schottelius --- hacking/.gitignore | 2 ++ hacking/README | 6 ++++++ hacking/add_kernel_isolinux.sh | 29 +++++++++++++++++++++++++++++ hacking/all.sh | 10 ++++++++++ hacking/qemu-test.sh | 2 +- 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 hacking/.gitignore create mode 100755 hacking/add_kernel_isolinux.sh create mode 100755 hacking/all.sh diff --git a/hacking/.gitignore b/hacking/.gitignore new file mode 100644 index 00000000..e3f3d036 --- /dev/null +++ b/hacking/.gitignore @@ -0,0 +1,2 @@ +iso/ +*.iso diff --git a/hacking/README b/hacking/README index ffd4f6a0..d5aa9423 100644 --- a/hacking/README +++ b/hacking/README @@ -10,3 +10,9 @@ - binlist - bootstrap of os -> root permissions! + +- 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/add_kernel_isolinux.sh b/hacking/add_kernel_isolinux.sh new file mode 100755 index 00000000..ec7b610c --- /dev/null +++ b/hacking/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/all.sh b/hacking/all.sh new file mode 100755 index 00000000..c1b4fb93 --- /dev/null +++ b/hacking/all.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +set -e + +dir=./iso +iso=preos.iso + +./filelist_from_package.sh | ./filelist_to_dir.sh "$dir" +./add_kernel_isolinux.sh "$dir" +./create_iso.sh "$dir" "$iso" diff --git a/hacking/qemu-test.sh b/hacking/qemu-test.sh index 03695222..02afc2e6 100755 --- a/hacking/qemu-test.sh +++ b/hacking/qemu-test.sh @@ -8,5 +8,5 @@ fi iso=$1; shift qemu-system-x86_64 -m 512 -boot order=cd \ - -drive=$iso,media=cdrom + -drive file=$iso,media=cdrom From f5edb02fbd8c3f1b00359bc5f04cb38178393c68 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 13 May 2015 09:30:24 +0200 Subject: [PATCH 58/76] library copy still missing Signed-off-by: Nico Schottelius --- hacking/all.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/hacking/all.sh b/hacking/all.sh index c1b4fb93..fe3d6d11 100755 --- a/hacking/all.sh +++ b/hacking/all.sh @@ -6,5 +6,6 @@ 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" From 648809ff444cd3716d3d8de6a78699dfa0c92ffd Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 13 May 2015 10:25:49 +0200 Subject: [PATCH 59/76] begin ssh integration Signed-off-by: Nico Schottelius --- hacking/README | 10 ++++++++++ hacking/filelist_from_package.sh | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/hacking/README b/hacking/README index d5aa9423..50ba4616 100644 --- a/hacking/README +++ b/hacking/README @@ -1,7 +1,15 @@ +- next step + - rootfs fix + - get working to login + - have sshd enabled + +- everything into initramfs? + - Target: - get working iso - have it configured and gathered by cdist? + - boot process via ...? - systemd? @@ -11,6 +19,8 @@ - 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 diff --git a/hacking/filelist_from_package.sh b/hacking/filelist_from_package.sh index 58ac48f4..1bf24a7c 100755 --- a/hacking/filelist_from_package.sh +++ b/hacking/filelist_from_package.sh @@ -1,7 +1,7 @@ #!/bin/sh # Generate filelist excluding stuff that takes only space -for pkg in bash systemd util-linux; do +for pkg in bash systemd util-linux openssh; do pacman -Qlq $pkg | grep -v \ -e /usr/share/man/ done From b7ed5b7d124d980f3f192a6bca01432be3662f3d Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 19 May 2015 10:02:18 +0200 Subject: [PATCH 60/76] add some scripts to try bootstraping using arch/debian methods Signed-off-by: Nico Schottelius --- hacking/arch_bootstrap.sh | 4 ++++ hacking/debian_bootstrap.sh | 3 +++ 2 files changed, 7 insertions(+) create mode 100644 hacking/arch_bootstrap.sh create mode 100644 hacking/debian_bootstrap.sh diff --git a/hacking/arch_bootstrap.sh b/hacking/arch_bootstrap.sh new file mode 100644 index 00000000..0472bf3c --- /dev/null +++ b/hacking/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/debian_bootstrap.sh b/hacking/debian_bootstrap.sh new file mode 100644 index 00000000..75628116 --- /dev/null +++ b/hacking/debian_bootstrap.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +fakeroot debootstrap jessie ./preos-debootstrap/ From 6ff6604941918f3a36734fa47f817c519ffc2fc6 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 19 May 2015 10:02:53 +0200 Subject: [PATCH 61/76] +logs Signed-off-by: Nico Schottelius --- .../2015-02-10.installation_from_usb_stick | 49 +++++++++++++++++++ docs/dev/logs/2015-03-28.preos-from-os | 32 ++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 docs/dev/logs/2015-02-10.installation_from_usb_stick create mode 100644 docs/dev/logs/2015-03-28.preos-from-os 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 From f51a444012e465847de01d15bc290a8f9f90c9a7 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 19 May 2015 10:19:33 +0200 Subject: [PATCH 62/76] generate sorted / filtered list Signed-off-by: Nico Schottelius --- hacking/filelist_from_package.sh | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/hacking/filelist_from_package.sh b/hacking/filelist_from_package.sh index 1bf24a7c..b5dd8eb7 100755 --- a/hacking/filelist_from_package.sh +++ b/hacking/filelist_from_package.sh @@ -1,7 +1,19 @@ #!/bin/sh # Generate filelist excluding stuff that takes only space -for pkg in bash systemd util-linux openssh; do - pacman -Qlq $pkg | grep -v \ - -e /usr/share/man/ -done +( + 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 perl procps-ng psmisc reiserfsprogs \ + s-nail sed shadow sysfsutils systemd-sysvcompat tar \ + texinfo usbutils util-linux vi which xfsprogs \ + ; do + pacman -Qlq $pkg | grep -v \ + -e /usr/share/man/ \ + -e /usr/share/doc/ + done +) | sort | uniq From 7ba6c0a44a44317993cb032cdf0caefbfa08d055 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 19 May 2015 11:06:54 +0200 Subject: [PATCH 63/76] can generate initramfs from busybox Signed-off-by: Nico Schottelius --- hacking/add_kernel_isolinux.sh | 29 --------- .../arch_bootstrap.sh | 0 .../debian_bootstrap.sh | 0 .../file_list_of_packages.sh | 0 .../filelist_from_package.sh | 0 .../filelist_to_dir.sh | 0 hacking/v3-busybox/add_kernel_isolinux.sh | 24 ++++++++ hacking/v3-busybox/all.sh | 8 +++ hacking/v3-busybox/generate.sh | 27 +++++++++ hacking/v3-busybox/init | 60 +++++++++++++++++++ 10 files changed, 119 insertions(+), 29 deletions(-) delete mode 100755 hacking/add_kernel_isolinux.sh rename hacking/{ => v1-debootstrap-pacstrap}/arch_bootstrap.sh (100%) rename hacking/{ => v1-debootstrap-pacstrap}/debian_bootstrap.sh (100%) rename hacking/{archlinux => v2-initramfs-from-os}/file_list_of_packages.sh (100%) rename hacking/{ => v2-initramfs-from-os}/filelist_from_package.sh (100%) rename hacking/{ => v2-initramfs-from-os}/filelist_to_dir.sh (100%) create mode 100755 hacking/v3-busybox/add_kernel_isolinux.sh create mode 100755 hacking/v3-busybox/all.sh create mode 100755 hacking/v3-busybox/generate.sh create mode 100644 hacking/v3-busybox/init diff --git a/hacking/add_kernel_isolinux.sh b/hacking/add_kernel_isolinux.sh deleted file mode 100755 index ec7b610c..00000000 --- a/hacking/add_kernel_isolinux.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/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/arch_bootstrap.sh b/hacking/v1-debootstrap-pacstrap/arch_bootstrap.sh similarity index 100% rename from hacking/arch_bootstrap.sh rename to hacking/v1-debootstrap-pacstrap/arch_bootstrap.sh diff --git a/hacking/debian_bootstrap.sh b/hacking/v1-debootstrap-pacstrap/debian_bootstrap.sh similarity index 100% rename from hacking/debian_bootstrap.sh rename to hacking/v1-debootstrap-pacstrap/debian_bootstrap.sh diff --git a/hacking/archlinux/file_list_of_packages.sh b/hacking/v2-initramfs-from-os/file_list_of_packages.sh similarity index 100% rename from hacking/archlinux/file_list_of_packages.sh rename to hacking/v2-initramfs-from-os/file_list_of_packages.sh diff --git a/hacking/filelist_from_package.sh b/hacking/v2-initramfs-from-os/filelist_from_package.sh similarity index 100% rename from hacking/filelist_from_package.sh rename to hacking/v2-initramfs-from-os/filelist_from_package.sh diff --git a/hacking/filelist_to_dir.sh b/hacking/v2-initramfs-from-os/filelist_to_dir.sh similarity index 100% rename from hacking/filelist_to_dir.sh rename to hacking/v2-initramfs-from-os/filelist_to_dir.sh 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..51eac9af --- /dev/null +++ b/hacking/v3-busybox/all.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +rm -rf preos +mkdir -p preos/boot + +./generate.sh > preos/boot/initramfs +./add_kernel_isolinux.sh preos + diff --git a/hacking/v3-busybox/generate.sh b/hacking/v3-busybox/generate.sh new file mode 100755 index 00000000..00227a57 --- /dev/null +++ b/hacking/v3-busybox/generate.sh @@ -0,0 +1,27 @@ +#!/bin/sh +set -ex + + +initramfs_dir=$(mktemp -d /tmp/cdist-preos.XXXXXXX) +# initramfs_dir=$1 + +for dir in bin sbin etc proc sys newroot; do + mkdir -p ${initramfs_dir}/$dir +done +touch ${initramfs_dir}/etc/mdev.conf + +cp init "${initramfs_dir}/init" +cp $(which busybox) "${initramfs_dir}/bin" +ln -fs busybox "${initramfs_dir}/bin/sh" + +cd "${initramfs_dir}" +find . | cpio -H newc -o | gzip + +exit 0 + +# TODO: +# - Kernel modules +# - ssh +# - various mkfs +# - libs + diff --git a/hacking/v3-busybox/init b/hacking/v3-busybox/init new file mode 100644 index 00000000..40507339 --- /dev/null +++ b/hacking/v3-busybox/init @@ -0,0 +1,60 @@ +#!/bin/sh + +#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 all the symlinks to /bin/busybox +busybox --install -s + +#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 From 7d7aa60e191a1bfa50ef45814c7e6f398c865edd Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 19 May 2015 11:38:06 +0200 Subject: [PATCH 64/76] create directories required by busybox Signed-off-by: Nico Schottelius --- hacking/{ => v2-initramfs-from-os}/all.sh | 0 hacking/v3-busybox/{generate.sh => create_initramfs.sh} | 7 +++++-- hacking/{ => v3-busybox}/create_iso.sh | 0 hacking/{ => v3-busybox}/qemu-test.sh | 0 4 files changed, 5 insertions(+), 2 deletions(-) rename hacking/{ => v2-initramfs-from-os}/all.sh (100%) rename hacking/v3-busybox/{generate.sh => create_initramfs.sh} (72%) rename hacking/{ => v3-busybox}/create_iso.sh (100%) rename hacking/{ => v3-busybox}/qemu-test.sh (100%) diff --git a/hacking/all.sh b/hacking/v2-initramfs-from-os/all.sh similarity index 100% rename from hacking/all.sh rename to hacking/v2-initramfs-from-os/all.sh diff --git a/hacking/v3-busybox/generate.sh b/hacking/v3-busybox/create_initramfs.sh similarity index 72% rename from hacking/v3-busybox/generate.sh rename to hacking/v3-busybox/create_initramfs.sh index 00227a57..6d57b05c 100755 --- a/hacking/v3-busybox/generate.sh +++ b/hacking/v3-busybox/create_initramfs.sh @@ -5,14 +5,17 @@ set -ex initramfs_dir=$(mktemp -d /tmp/cdist-preos.XXXXXXX) # initramfs_dir=$1 -for dir in bin sbin etc proc sys newroot; do +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" -ln -fs busybox "${initramfs_dir}/bin/sh" + +for link in sh mount; do + ln -fs busybox "${initramfs_dir}/bin/$link" +done cd "${initramfs_dir}" find . | cpio -H newc -o | gzip diff --git a/hacking/create_iso.sh b/hacking/v3-busybox/create_iso.sh similarity index 100% rename from hacking/create_iso.sh rename to hacking/v3-busybox/create_iso.sh diff --git a/hacking/qemu-test.sh b/hacking/v3-busybox/qemu-test.sh similarity index 100% rename from hacking/qemu-test.sh rename to hacking/v3-busybox/qemu-test.sh From 50bca7891f6496dcc732384d249ac386f8de085e Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 19 May 2015 11:39:39 +0200 Subject: [PATCH 65/76] preos 0.4 Signed-off-by: Nico Schottelius --- hacking/v3-busybox/all.sh | 3 ++- hacking/v3-busybox/create_iso.sh | 2 +- hacking/v3-busybox/init | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) mode change 100644 => 100755 hacking/v3-busybox/init diff --git a/hacking/v3-busybox/all.sh b/hacking/v3-busybox/all.sh index 51eac9af..99b0c0ec 100755 --- a/hacking/v3-busybox/all.sh +++ b/hacking/v3-busybox/all.sh @@ -3,6 +3,7 @@ rm -rf preos mkdir -p preos/boot -./generate.sh > preos/boot/initramfs +./create_initramfs.sh > preos/boot/initramfs ./add_kernel_isolinux.sh preos +./create_iso.sh preos preos.iso diff --git a/hacking/v3-busybox/create_iso.sh b/hacking/v3-busybox/create_iso.sh index 0902bc20..c6b39be6 100755 --- a/hacking/v3-busybox/create_iso.sh +++ b/hacking/v3-busybox/create_iso.sh @@ -10,7 +10,7 @@ fi indir=$1; shift iso=$1; shift -version=0.3 +version=0.4 out=preos-${version}.iso diff --git a/hacking/v3-busybox/init b/hacking/v3-busybox/init old mode 100644 new mode 100755 index 40507339..a961526f --- a/hacking/v3-busybox/init +++ b/hacking/v3-busybox/init @@ -1,5 +1,8 @@ #!/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 @@ -7,8 +10,6 @@ mount -t sysfs sysfs /sys #Disable kernel messages from popping onto the screen echo 0 > /proc/sys/kernel/printk -#Create all the symlinks to /bin/busybox -busybox --install -s #Create device nodes mknod /dev/null c 1 3 From bb9d889d158e0082f02815b64f9ecd87afadbc0d Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 19 May 2015 11:52:14 +0200 Subject: [PATCH 66/76] rename & cleanup Signed-off-by: Nico Schottelius --- hacking/.gitignore | 1 + hacking/README | 5 +++++ hacking/{ => v2-initramfs-from-os}/bin_to_pkg.sh | 0 .../{ => v2-initramfs-from-os}/copy_files_for_iso.sh | 0 .../v2-initramfs-from-os/filelist_from_package.sh | 8 +++++--- .../copy_bin_with_libs.sh} | 12 +++++++++--- hacking/v3-busybox/create_initramfs.sh | 2 ++ 7 files changed, 22 insertions(+), 6 deletions(-) rename hacking/{ => v2-initramfs-from-os}/bin_to_pkg.sh (100%) rename hacking/{ => v2-initramfs-from-os}/copy_files_for_iso.sh (100%) rename hacking/{recursive-ldd.sh => v3-busybox/copy_bin_with_libs.sh} (66%) diff --git a/hacking/.gitignore b/hacking/.gitignore index e3f3d036..375edb27 100644 --- a/hacking/.gitignore +++ b/hacking/.gitignore @@ -1,2 +1,3 @@ iso/ *.iso +preos/ diff --git a/hacking/README b/hacking/README index 50ba4616..937564d5 100644 --- a/hacking/README +++ b/hacking/README @@ -2,9 +2,14 @@ - 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? diff --git a/hacking/bin_to_pkg.sh b/hacking/v2-initramfs-from-os/bin_to_pkg.sh similarity index 100% rename from hacking/bin_to_pkg.sh rename to hacking/v2-initramfs-from-os/bin_to_pkg.sh diff --git a/hacking/copy_files_for_iso.sh b/hacking/v2-initramfs-from-os/copy_files_for_iso.sh similarity index 100% rename from hacking/copy_files_for_iso.sh rename to hacking/v2-initramfs-from-os/copy_files_for_iso.sh diff --git a/hacking/v2-initramfs-from-os/filelist_from_package.sh b/hacking/v2-initramfs-from-os/filelist_from_package.sh index b5dd8eb7..5652ba66 100755 --- a/hacking/v2-initramfs-from-os/filelist_from_package.sh +++ b/hacking/v2-initramfs-from-os/filelist_from_package.sh @@ -8,12 +8,14 @@ gettext glibc grep gzip inetutils iproute2 \ iputils jfsutils less licenses linux logrotate lvm2 \ man-db man-pages mdadm nano pacman pciutils \ - pcmciautils perl procps-ng psmisc reiserfsprogs \ + pcmciautils procps-ng psmisc reiserfsprogs \ s-nail sed shadow sysfsutils systemd-sysvcompat tar \ - texinfo usbutils util-linux vi which xfsprogs \ + usbutils util-linux vi which xfsprogs \ ; do pacman -Qlq $pkg | grep -v \ -e /usr/share/man/ \ - -e /usr/share/doc/ + -e /usr/share/doc/ \ + -e /usr/include + done ) | sort | uniq diff --git a/hacking/recursive-ldd.sh b/hacking/v3-busybox/copy_bin_with_libs.sh similarity index 66% rename from hacking/recursive-ldd.sh rename to hacking/v3-busybox/copy_bin_with_libs.sh index 600df529..b3824a78 100755 --- a/hacking/recursive-ldd.sh +++ b/hacking/v3-busybox/copy_bin_with_libs.sh @@ -6,14 +6,20 @@ PATH=/bin:/sbin:/usr/bin:/usr/sbin -pkg=" +#bin_list="udevadm bash fdisk mount syslinux umount rm mv" +bin_list="udevadm fdisk" -bin_list="bash fdisk mount syslinux umount rm mv" +libs=$(mktemp /tmp/cdist-preos-libs.XXXXXXXXXXXXX) + +for bin in bin_list; do -for bin in command_list; do done +rm -f "$libs" + +# lfs +## ldd /bin/$f | sed "s/\t//" | cut -d " " -f1 >> $unsorted exit 0 diff --git a/hacking/v3-busybox/create_initramfs.sh b/hacking/v3-busybox/create_initramfs.sh index 6d57b05c..f87a7ef6 100755 --- a/hacking/v3-busybox/create_initramfs.sh +++ b/hacking/v3-busybox/create_initramfs.sh @@ -20,6 +20,8 @@ done cd "${initramfs_dir}" find . | cpio -H newc -o | gzip +rm -rf "${initramfs_dir}" + exit 0 # TODO: From 48096620267eb20b285c66f705e3d51a19cdcf30 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 19 May 2015 11:52:33 +0200 Subject: [PATCH 67/76] add v2 ideas Signed-off-by: Nico Schottelius --- .../add_kernel_isolinux.sh | 29 +++++++++++++++++++ hacking/v2-initramfs-from-os/packages_arch | 29 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100755 hacking/v2-initramfs-from-os/add_kernel_isolinux.sh create mode 100644 hacking/v2-initramfs-from-os/packages_arch 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/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 From 9dc7160903e3b118020dfad3e2082ca80147fdbf Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 20 May 2015 14:04:34 +0200 Subject: [PATCH 68/76] begin to import bin/libs Signed-off-by: Nico Schottelius --- hacking/v3-busybox/all.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hacking/v3-busybox/all.sh b/hacking/v3-busybox/all.sh index 99b0c0ec..65a3706b 100755 --- a/hacking/v3-busybox/all.sh +++ b/hacking/v3-busybox/all.sh @@ -5,5 +5,5 @@ 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 - From 85c825438ed25b39678a8a69c4bd3423b3709b35 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 28 May 2015 15:37:30 +0200 Subject: [PATCH 69/76] update manpage of __install_generate_fstab (typo) Signed-off-by: Nico Schottelius --- cdist/conf/type/__install_generate_fstab/man.text | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__install_generate_fstab/man.text b/cdist/conf/type/__install_generate_fstab/man.text index d7d747a0..d229f4df 100644 --- a/cdist/conf/type/__install_generate_fstab/man.text +++ b/cdist/conf/type/__install_generate_fstab/man.text @@ -10,7 +10,7 @@ cdist-type__install_generate_fstab - generate /etc/fstab during installation DESCRIPTION ----------- -Generates a /etc/fstab file from information retreived from +Generates a /etc/fstab file from information retrieved from __install_mount definitions. From 348867ff6a84958a2388799fa702396c16c2ae9f Mon Sep 17 00:00:00 2001 From: Markus Koller Date: Wed, 6 Jul 2016 10:15:34 +0200 Subject: [PATCH 70/76] Correctly set hostname in preos --- cdist/preos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/preos.py b/cdist/preos.py index b61318ed..8a17974e 100644 --- a/cdist/preos.py +++ b/cdist/preos.py @@ -63,7 +63,7 @@ eof # fix the bloody 'stdin: is not a tty' problem __line /root/.profile --line 'mesg n' --state absent -__hostname preos +__hostname --name preos """ class PreOSExistsError(cdist.Error): From 78d7d91e42dc7bcbc882eaf735fe48e3714c7f6d Mon Sep 17 00:00:00 2001 From: Markus Koller Date: Wed, 6 Jul 2016 10:30:13 +0200 Subject: [PATCH 71/76] Install lsb-release in preos Several types use the lsb_release command to determine the distribution, if this command is missing unexpected things will happen. --- cdist/preos.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cdist/preos.py b/cdist/preos.py index 8a17974e..df5be1fa 100644 --- a/cdist/preos.py +++ b/cdist/preos.py @@ -38,6 +38,7 @@ DEFAULT_MANIFEST = """ for pkg in \ file \ linux-image-amd64 \ + lsb-release \ openssh-server curl \ syslinux grub2 \ gdisk util-linux lvm2 mdadm \ From 0e114c37ac1756d916a393822a8744eba5d55eb0 Mon Sep 17 00:00:00 2001 From: Markus Koller Date: Wed, 6 Jul 2016 10:47:28 +0200 Subject: [PATCH 72/76] Always use current stable release for preos --- cdist/preos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/preos.py b/cdist/preos.py index df5be1fa..8eced936 100644 --- a/cdist/preos.py +++ b/cdist/preos.py @@ -86,7 +86,7 @@ class PreOS(object): self.arch = arch self.command = "debootstrap" - self.suite = "wheezy" + self.suite = "stable" self.options = [ "--include=openssh-server", "--arch=%s" % self.arch ] From e79610f23c585017da411eea0a5d76b9876eacc4 Mon Sep 17 00:00:00 2001 From: Markus Koller Date: Wed, 6 Jul 2016 11:22:15 +0200 Subject: [PATCH 73/76] Don't try to use hostnamectl when systemd isn't running --- cdist/conf/type/__hostname/explorer/has_hostnamectl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cdist/conf/type/__hostname/explorer/has_hostnamectl b/cdist/conf/type/__hostname/explorer/has_hostnamectl index 9040023d..7e8a57fd 100755 --- a/cdist/conf/type/__hostname/explorer/has_hostnamectl +++ b/cdist/conf/type/__hostname/explorer/has_hostnamectl @@ -18,7 +18,12 @@ # along with cdist. If not, see . # # -# Check whether system has hostnamectl +# Check whether system has hostnamectl and it's usable, i.e. don't +# try to use it when systemd isn't running yet. # -command -v hostnamectl || true +if command -v hostnamectl >/dev/null && hostnamectl status >/dev/null 2>&1; then + echo "yes" +else + true +fi From 16cb3a5ff11bae3f0f99e477bcfe202599a21119 Mon Sep 17 00:00:00 2001 From: Markus Koller Date: Wed, 6 Jul 2016 14:57:59 +0200 Subject: [PATCH 74/76] Update PXE setup for Debian 8 --- cdist/preos.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cdist/preos.py b/cdist/preos.py index 8eced936..c21dc00a 100644 --- a/cdist/preos.py +++ b/cdist/preos.py @@ -40,7 +40,7 @@ for pkg in \ linux-image-amd64 \ lsb-release \ openssh-server curl \ - syslinux grub2 \ + pxelinux syslinux-common grub2 \ gdisk util-linux lvm2 mdadm \ btrfs-tools e2fsprogs jfsutils reiser4progs xfsprogs; do __package $pkg --state present @@ -90,7 +90,7 @@ class PreOS(object): self.options = [ "--include=openssh-server", "--arch=%s" % self.arch ] - self.pxelinux = "/usr/lib/syslinux/pxelinux.0" + self.pxelinux = "/usr/lib/PXELINUX/pxelinux.0" self.pxelinux_cfg = """ DEFAULT preos LABEL preos @@ -178,11 +178,18 @@ cp -L "$src" "$real_dst" def create_pxelinux(self): dst = os.path.join(self.out_dir, "pxelinux.0") - src = "%s/usr/lib/syslinux/pxelinux.0" % self.target_dir + src = "%s/usr/lib/PXELINUX/pxelinux.0" % self.target_dir log.info("Creating pxelinux.0 ...") shutil.copyfile(src, dst, follow_symlinks=True) + def create_ldlinux(self): + dst = os.path.join(self.out_dir, "ldlinux.c32") + src = "%s/usr/lib/syslinux/modules/bios/ldlinux.c32" % self.target_dir + + log.info("Creating ldlinux.c32 ...") + shutil.copyfile(src, dst, follow_symlinks=True) + def create_pxeconfig(self): configdir = os.path.join(self.out_dir, "pxelinux.cfg") configfile = os.path.join(configdir, "default") @@ -219,6 +226,7 @@ cp -L "$src" "$real_dst" self.create_initramfs() self.create_pxeconfig() self.create_pxelinux() + self.create_ldlinux() def setup_initial_manifest(self, user_initial_manifest, replace_manifest): From cd8373fe506cec09944a95d515538f0111a2b349 Mon Sep 17 00:00:00 2001 From: Dominique Roux Date: Tue, 23 Aug 2016 15:55:07 +0200 Subject: [PATCH 75/76] Hotfix: Changed source of consul 0.5.1 --- cdist/conf/type/__consul/files/versions/0.5.1/source | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__consul/files/versions/0.5.1/source b/cdist/conf/type/__consul/files/versions/0.5.1/source index f02a1103..a47eb69c 100644 --- a/cdist/conf/type/__consul/files/versions/0.5.1/source +++ b/cdist/conf/type/__consul/files/versions/0.5.1/source @@ -1 +1 @@ -https://dl.bintray.com/mitchellh/consul/0.5.1_linux_amd64.zip +https://releases.hashicorp.com/consul/0.5.1/consul_0.5.1_linux_amd64.zip From 428c06c8d39ab7777cc1bece34dd0ae23f924d2a Mon Sep 17 00:00:00 2001 From: Dominique Roux Date: Tue, 23 Aug 2016 16:40:13 +0200 Subject: [PATCH 76/76] Hotfix: Changed sources of all consul version + cksum files --- cdist/conf/type/__consul/files/versions/0.4.1/cksum | 2 +- cdist/conf/type/__consul/files/versions/0.4.1/source | 2 +- cdist/conf/type/__consul/files/versions/0.5.0/cksum | 2 +- cdist/conf/type/__consul/files/versions/0.5.0/source | 2 +- cdist/conf/type/__consul/files/versions/0.5.1/cksum | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cdist/conf/type/__consul/files/versions/0.4.1/cksum b/cdist/conf/type/__consul/files/versions/0.4.1/cksum index edba1a68..3e114ece 100644 --- a/cdist/conf/type/__consul/files/versions/0.4.1/cksum +++ b/cdist/conf/type/__consul/files/versions/0.4.1/cksum @@ -1 +1 @@ -428915666 15738724 consul +2024850362 4073679 consul diff --git a/cdist/conf/type/__consul/files/versions/0.4.1/source b/cdist/conf/type/__consul/files/versions/0.4.1/source index b1e9908d..7fb949c8 100644 --- a/cdist/conf/type/__consul/files/versions/0.4.1/source +++ b/cdist/conf/type/__consul/files/versions/0.4.1/source @@ -1 +1 @@ -https://dl.bintray.com/mitchellh/consul/0.4.1_linux_amd64.zip +https://releases.hashicorp.com/consul/0.4.1/consul_0.4.1_linux_amd64.zip diff --git a/cdist/conf/type/__consul/files/versions/0.5.0/cksum b/cdist/conf/type/__consul/files/versions/0.5.0/cksum index fe9888ae..66bb482a 100644 --- a/cdist/conf/type/__consul/files/versions/0.5.0/cksum +++ b/cdist/conf/type/__consul/files/versions/0.5.0/cksum @@ -1 +1 @@ -131560372 17734417 consul +915590436 4669655 consul diff --git a/cdist/conf/type/__consul/files/versions/0.5.0/source b/cdist/conf/type/__consul/files/versions/0.5.0/source index 00a209a5..dc1c33c4 100644 --- a/cdist/conf/type/__consul/files/versions/0.5.0/source +++ b/cdist/conf/type/__consul/files/versions/0.5.0/source @@ -1 +1 @@ -https://dl.bintray.com/mitchellh/consul/0.5.0_linux_amd64.zip +https://releases.hashicorp.com/consul/0.5.0/consul_0.5.0_linux_amd64.zip diff --git a/cdist/conf/type/__consul/files/versions/0.5.1/cksum b/cdist/conf/type/__consul/files/versions/0.5.1/cksum index a176ed43..c1c59011 100644 --- a/cdist/conf/type/__consul/files/versions/0.5.1/cksum +++ b/cdist/conf/type/__consul/files/versions/0.5.1/cksum @@ -1 +1 @@ -2564582176 18232733 consul +190723740 4802625 consul