From 46e3a2d278bc75b91f6a5eae3fbdedae02441d64 Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Tue, 13 Feb 2007 00:17:04 +0100 Subject: [PATCH] some new scripts, functions,.... --- config/grml-live.conf | 30 ++++++++ info/dpkg.get-selections.debootstrap | 128 +++++++++++++++++++++++++++++++++++ scripts/01_bootstrap.sh | 28 ++++++++ scripts/02_chroot.sh | 62 +++++++++++++++++ scripts/10_finalize_chroot.sh | 17 +++++ scripts/functions.sh | 39 ++++++----- scripts/grml-live | 76 ++++++++++++++++++--- 7 files changed, 353 insertions(+), 27 deletions(-) create mode 100644 config/grml-live.conf create mode 100644 info/dpkg.get-selections.debootstrap create mode 100644 scripts/01_bootstrap.sh create mode 100644 scripts/02_chroot.sh create mode 100644 scripts/10_finalize_chroot.sh diff --git a/config/grml-live.conf b/config/grml-live.conf new file mode 100644 index 0000000..9ad84cc --- /dev/null +++ b/config/grml-live.conf @@ -0,0 +1,30 @@ +# Filename: /etc/grml-live/grml-live.conf +# Purpose: configuration file for creating grml live-cd +# Authors: grml-team (grml.org), (c) Michael Prokop +# Bug-Reports: see http://grml.org/bugs/ +# License: This file is licensed under the GPL v2. +# Latest change: Mon Feb 12 22:56:59 CET 2007 +################################################################################ + +DEBUG=1 # be more verbose on stdout? +DEBUG_SYSLOG=1 # log actions to syslog? + +ARCH='i386' # see 'dpkg-architecture' and 'dpkg-architecture -L' +TARGET='/home/mika/chroot' # + +DEBCONF_PRIORITY="critical" +DEBCONF_FRONTEND="noninteractive" +RECOMMENDS="no" + +# PACKAGE_LIST='' + +SOURCES_LIST=' + deb http://deb.grml.org/ grml-stable main + deb http://ftp.tu-graz.ac.at/mirror/debian unstable main contrib non-free + +# deb-src http://deb.grml.org/ grml-stable main +# deb-src http://ftp.de.debian.org/debian/ unstable main contrib non-free +' + +## END OF FILE ################################################################# +# vim: ai tw=80 ft=zsh expandtab diff --git a/info/dpkg.get-selections.debootstrap b/info/dpkg.get-selections.debootstrap new file mode 100644 index 0000000..889af11 --- /dev/null +++ b/info/dpkg.get-selections.debootstrap @@ -0,0 +1,128 @@ +adduser install +apt install +apt-utils install +aptitude install +base-files install +base-passwd install +bash install +bsdmainutils install +bsdutils install +coreutils install +cpio install +cron install +cyrus-sasl2-doc install +debconf install +debconf-i18n install +debian-archive-keyring install +debianutils install +dhcp3-client install +dhcp3-common install +diff install +dmidecode install +dpkg install +dselect install +e2fslibs install +e2fsprogs install +ed install +findutils install +gcc-4.1-base install +gnupg install +gpgv install +grep install +groff-base install +gzip install +hostname install +ifupdown install +info install +initscripts install +iptables install +iputils-ping install +klogd install +laptop-detect install +libacl1 install +libattr1 install +libblkid1 install +libbz2-1.0 install +libc6 install +libcap1 install +libcomerr2 install +libconsole install +libdb4.2 install +libdb4.3 install +libdb4.4 install +libdevmapper1.02 install +libgcc1 install +libgcrypt11 install +libgdbm3 install +libgnutls13 install +libgpg-error0 install +libldap-2.3-0 install +libldap2 install +liblocale-gettext-perl install +liblzo1 install +liblzo2-2 install +libncurses5 install +libncursesw5 install +libnewt0.52 install +libopencdk8 install +libpam-modules install +libpam-runtime install +libpam0g install +libpopt0 install +libreadline5 install +libsasl2 install +libsasl2-2 install +libselinux1 install +libsepol1 install +libsigc++-1.2-5c2 install +libsigc++-2.0-0c2a install +libslang2 install +libss2 install +libssl0.9.8 install +libstdc++6 install +libtasn1-3 install +libtext-charwidth-perl install +libtext-iconv-perl install +libtext-wrapi18n-perl install +libusb-0.1-4 install +libuuid1 install +libwrap0 install +login install +logrotate install +lsb-base install +makedev install +man-db install +manpages install +mawk install +mktemp install +module-init-tools install +mount install +nano install +ncurses-base install +ncurses-bin install +net-tools install +netbase install +netcat install +openbsd-inetd install +passwd install +perl-base install +procps install +readline-common install +sed install +sysklogd install +sysv-rc install +sysvinit install +sysvinit-utils install +tar install +tasksel install +tasksel-data install +tcpd install +traceroute install +tzdata install +update-inetd install +util-linux install +vim-common install +vim-tiny install +wget install +whiptail install +zlib1g install diff --git a/scripts/01_bootstrap.sh b/scripts/01_bootstrap.sh new file mode 100644 index 0000000..027f5bd --- /dev/null +++ b/scripts/01_bootstrap.sh @@ -0,0 +1,28 @@ +# Filename: 01_bootstrap.sh +# Purpose: build script for creating grml live-cd +# Authors: grml-team (grml.org), (c) Michael Prokop +# Bug-Reports: see http://grml.org/bugs/ +# License: This file is licensed under the GPL v2. +# Latest change: Tue Feb 13 00:13:24 CET 2007 +################################################################################ + +# main execution +bootstrap() { + debug "executing bootstrap" ; + + # create main grml-live directory within chroot + if ! [ -d "${TARGET}/grml-live/" ] ; then + debug "bootstrap: creating ${TARGET}/grml-live/" + mkdir "${TARGET}/grml-live/" + fi + + # check whether chroot exists already + if [ -f "${TARGET}/grml-live/bootstrap" ] ; then + debug_warn "chroot exists already, skipping execution of $DEBOOTSTRAP and continuing" + else + $DEBOOTSTRAP --arch $ARCH $RELEASE $TARGET $MIRROR && touch "${TARGET}/grml-live/bootstrap" + fi +} + +## END OF FILE ################################################################# +# vim: ai tw=80 ft=sh expandtab diff --git a/scripts/02_chroot.sh b/scripts/02_chroot.sh new file mode 100644 index 0000000..fe2f84a --- /dev/null +++ b/scripts/02_chroot.sh @@ -0,0 +1,62 @@ +# Filename: 02_chroot.sh +# Purpose: build script for creating grml live-cd +# Authors: grml-team (grml.org), (c) Michael Prokop +# Bug-Reports: see http://grml.org/bugs/ +# License: This file is licensed under the GPL v2. +# Latest change: Tue Feb 13 00:16:27 CET 2007 +################################################################################ + +chroot_shell() { + chroot "$TARGET" /bin/bash +} + +chroot_exec() { + chroot "$TARGET" /usr/bin/env -i HOME="/root" PATH="/usr/sbin:/usr/bin:/sbin:/bin" TERM="${TERM}" \ + DEBIAN_FRONTEND="${DEBCONF_FRONTEND}" DEBIAN_PRIORITY="${DEBCONF_PRIORITY}" ${1} + return $? +} + +patch_chroot() { + case "${1}" in + + apply) + debug "executing patch_chroot in apply mode" + echo "grml-live" > "${TARGET}"/etc/debian_chroot + [ -f "${TARGET}"/etc/hosts ] && cp "${TARGET}"/etc/hosts "$TARGET"/etc/hosts.orig + [ -f /etc/hosts ] && cp /etc/hosts "$TARGET"/etc/hosts + [ -f "${TARGET}"/etc/resolv.conf ] && cp "${TARGET}"/etc/resolv.conf "$TARGET"/etc/resolv.conf.orig + [ -f /etc/resolv.conf ] && cp /etc/resolv.conf "$TARGET"/etc/resolv.conf + # TODO: make sure to fix setup of grml-policy.rc.d + cat > "${TARGET}"/usr/sbin/policy-rc.d < +# Bug-Reports: see http://grml.org/bugs/ +# License: This file is licensed under the GPL v2. +# Latest change: Mon Feb 12 23:24:17 CET 2007 +################################################################################ + +# main execution +chroot_finalize() { + if [ -f "${TARGET}/etc/apt/sources.list.grml" ] ; then + chroot_exec "( cd /etc/apt/ ; ln -s sources.list.grml sources.list )" + fi +} + +## END OF FILE ################################################################# +# vim: ai tw=80 ft=sh expandtab diff --git a/scripts/functions.sh b/scripts/functions.sh index 1f1dd2b..76ba78a 100644 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -8,6 +8,7 @@ bailout(){ [ -n "$1" ] && EXIT="$1" || EXIT="1" + [ -n "$2" ] && echo "$2">&2 exit "$EXIT" } @@ -19,30 +20,36 @@ usage() { debug() { if [[ -n "$DEBUG" ]] ; then - print "grml-live: $*" - [[ -n "$DEBUG_SYSLOG" ]] && [ -x /usr/bin/logger ] && logger -t grml-live "$*" + einfo "grml-live: $*" + [[ -n "$DEBUG_SYSLOG" ]] && [ -x /usr/bin/logger ] && logger -t grml-live-info "$*" else return 0 # do nothing fi } -cmdline_options () { - while true - do - case "${1}" in - (-r|--root) LIVE_ROOT="${2}" - shift 2 ;; - (-v|--version) usage - exit 1 ;; - (--) shift - break ;; - (*) exit 0 ;; - esac - done +debug_warn() { + if [[ -n "$DEBUG" ]] ; then + ewarn "grml-live: $*" + [[ -n "$DEBUG_SYSLOG" ]] && [ -x /usr/bin/logger ] && logger -t grml-live-warn "$*" + else + return 0 # do nothing + fi } + +debug_error() { + if [[ -n "$DEBUG" ]] ; then + eerror "grml-live: $*" + [[ -n "$DEBUG_SYSLOG" ]] && [ -x /usr/bin/logger ] && logger -t grml-live-error "$*" + else + return 0 # do nothing + fi +} + chroot_exec() { -; + [ -n "$TARGET" ] || bailout 1 "\$TARGET unset, can not chroot_exec" + [ -n "$1" ] || bailout 1 "Error executing chroot_exec. Usage: chroot_exec " + chroot "$TARGET" "$1" } ## END OF FILE ################################################################# diff --git a/scripts/grml-live b/scripts/grml-live index ee7fbdd..d085932 100755 --- a/scripts/grml-live +++ b/scripts/grml-live @@ -4,26 +4,80 @@ # Authors: grml-team (grml.org), (c) Michael Prokop # Bug-Reports: see http://grml.org/bugs/ # License: This file is licensed under the GPL v2. -# Latest change: Thu Feb 08 22:35:43 CET 2007 +# Latest change: Tue Feb 13 00:16:11 CET 2007 ################################################################################ -LANG=C -LC_ALL=C - -DEBUG=1 # be more verbose on stdout? -DEBUG_SYSLOG=1 # log actions to syslog? +LANG=C ; LC_ALL=C +set -e # fail on any error # functions -FUNCTIONSFILE='functions.sh' - +FUNCTIONSFILE='functions.sh' # TODO: fix location for file in $FUNCTIONSFILE /etc/grml/lsb-functions /etc/grml/script-functions ; do - [[ -r $FUNCTIONSFILE ]] && source $file || { print "Reading $file failed, fatal error, exiting." ; exit 1 } + [ -r "$file" ] && source "$file" || { print "Reading $file failed. Fatal error, exiting." ; exit 1 } done +# Clean exit trap bailout 1 2 3 15 -# main execution -debug "executing cmdline_options" ; cmdline_options +# We need root permissions to execute all the chroot stuff +check4root || bailout 1 + +# default variables +[ -n "$DEBOOTSTRAP" ] || DEBOOTSTRAP='debootstrap' +[ -n "$ARCH" ] || ARCH="$(dpkg --print-architecture)" +[ -n "$RELEASE" ] || RELEASE='sid' +[ -n "$MIRROR" ] || MIRROR='ftp://ftp.tugraz.at/mirror/debian' +[ -n "$TARGET" ] || TARGET="$(pwd)/grml-live/chroot/" + +# cmdline parsing, allow overwriting of variables +while true ; do + case "${1}" in + (-c|--config) CONFIG="${2}" + shift 2 ;; + (-r|--root) TARGET="${2}" + shift 2 ;; + (-h|--hook) HOOK="${2}" + shift 2 ;; + (-v|--version) usage + exit 1 ;; + (--) shift + break ;; + (*) break ;; + esac +done + +# configuration file +if [ -n "$CONFIG" ] ; then + [ -r "$CONFIG" ] || bailout 1 "Sorry, configuration file $CONFIG could not be read. Fatal error, exiting" + debug "sourcing $CONFIG" + source "$CONFIG" +else + source ../config/grml-live.conf # TODO: fix location +fi + +# make sure we have some variables, directories,... available before main execution +[ -d "$TARGET" ] || mkdir "$TARGET" +[ -n "$ARCH" ] && ARCH="$DEB_HOST_ARCH" || bailout 1 "\$ARCH not set, exiting." + +# TODO: fix location +source 01_bootstrap.sh +source 02_chroot.sh + +if [ -n "$HOOK" ] ; then + debug "executing given hook $HOOK" + $HOOK + exit 0 +fi + +## main execution + +# 01_bootstrap.sh +bootstrap + +# 02_chroot.sh +patch_chroot apply +chroot_shell +patch_chroot deapply ## END OF FILE ################################################################# # vim: ai tw=80 ft=zsh expandtab -- 2.1.4