some new scripts, functions,....
authorMichael Prokop <mika@grml.org>
Mon, 12 Feb 2007 23:17:04 +0000 (00:17 +0100)
committerMichael Prokop <mika@grml.org>
Mon, 12 Feb 2007 23:17:04 +0000 (00:17 +0100)
config/grml-live.conf [new file with mode: 0644]
info/dpkg.get-selections.debootstrap [new file with mode: 0644]
scripts/01_bootstrap.sh [new file with mode: 0644]
scripts/02_chroot.sh [new file with mode: 0644]
scripts/10_finalize_chroot.sh [new file with mode: 0644]
scripts/functions.sh
scripts/grml-live

diff --git a/config/grml-live.conf b/config/grml-live.conf
new file mode 100644 (file)
index 0000000..9ad84cc
--- /dev/null
@@ -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 <mika@grml.org>
+# 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 (file)
index 0000000..889af11
--- /dev/null
@@ -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 (file)
index 0000000..027f5bd
--- /dev/null
@@ -0,0 +1,28 @@
+# Filename:      01_bootstrap.sh
+# Purpose:       build script for creating grml live-cd
+# Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
+# 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 (file)
index 0000000..fe2f84a
--- /dev/null
@@ -0,0 +1,62 @@
+# Filename:      02_chroot.sh
+# Purpose:       build script for creating grml live-cd
+# Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
+# 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 <<EOF
+#!/bin/sh
+echo
+echo "Information: policy-rc.d in action."
+exit 101
+EOF
+          chmod 755 "${TARGET}"/usr/sbin/policy-rc.d
+          ;;
+
+       deapply)
+          debug "executing patch_chroot in deapply mode"
+          rm -f "${TARGET}"/etc/debian_chroot
+
+          if [ -f "${TARGET}"/etc/hosts.orig ] ; then
+             mv "${TARGET}"/etc/hosts.orig "$TARGET"/etc/hosts
+          else
+             rm -f "$TARGET"/etc/hosts
+          fi
+
+          # TODO: adjust for grml-policy.rc.d
+          if [ -f "${TARGET}"/etc/resolv.conf.orig ] ; then
+             mv "${TARGET}"/etc/resolv.conf.orig "$TARGET"/etc/resolv.conf
+          else
+             rm -f "$TARGET"/etc/resolv.conf
+          fi
+
+          rm -f "${TARGET}"/usr/sbin/policy-rc.d
+          ;;
+  esac
+}
+
+## END OF FILE #################################################################
+# vim: ai tw=80 ft=sh expandtab
diff --git a/scripts/10_finalize_chroot.sh b/scripts/10_finalize_chroot.sh
new file mode 100644 (file)
index 0000000..7da8dce
--- /dev/null
@@ -0,0 +1,17 @@
+# Filename:      10_finalize_chroot.sh
+# Purpose:       build script for creating grml live-cd
+# Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
+# 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
index 1f1dd2b..76ba78a 100644 (file)
@@ -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 <command>"
+  chroot "$TARGET" "$1"
 }
 
 ## END OF FILE #################################################################
index ee7fbdd..d085932 100755 (executable)
@@ -4,26 +4,80 @@
 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
 # 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