some new scripts, functions,....
[grml-live.git] / scripts / 02_chroot.sh
1 # Filename:      02_chroot.sh
2 # Purpose:       build script for creating grml live-cd
3 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
4 # Bug-Reports:   see http://grml.org/bugs/
5 # License:       This file is licensed under the GPL v2.
6 # Latest change: Tue Feb 13 00:16:27 CET 2007
7 ################################################################################
8
9 chroot_shell() {
10   chroot "$TARGET" /bin/bash
11 }
12
13 chroot_exec() {
14   chroot "$TARGET" /usr/bin/env -i HOME="/root" PATH="/usr/sbin:/usr/bin:/sbin:/bin" TERM="${TERM}" \
15   DEBIAN_FRONTEND="${DEBCONF_FRONTEND}" DEBIAN_PRIORITY="${DEBCONF_PRIORITY}" ${1}
16   return $?
17 }
18
19 patch_chroot() {
20   case "${1}" in
21
22        apply)
23           debug "executing patch_chroot in apply mode"
24           echo "grml-live" > "${TARGET}"/etc/debian_chroot
25           [ -f "${TARGET}"/etc/hosts ] && cp "${TARGET}"/etc/hosts "$TARGET"/etc/hosts.orig
26           [ -f /etc/hosts ]            && cp /etc/hosts "$TARGET"/etc/hosts
27           [ -f "${TARGET}"/etc/resolv.conf ] && cp "${TARGET}"/etc/resolv.conf "$TARGET"/etc/resolv.conf.orig
28           [ -f /etc/resolv.conf ]            && cp /etc/resolv.conf "$TARGET"/etc/resolv.conf
29           # TODO: make sure to fix setup of grml-policy.rc.d
30           cat > "${TARGET}"/usr/sbin/policy-rc.d <<EOF
31 #!/bin/sh
32 echo
33 echo "Information: policy-rc.d in action."
34 exit 101
35 EOF
36           chmod 755 "${TARGET}"/usr/sbin/policy-rc.d
37           ;;
38
39        deapply)
40           debug "executing patch_chroot in deapply mode"
41           rm -f "${TARGET}"/etc/debian_chroot
42
43           if [ -f "${TARGET}"/etc/hosts.orig ] ; then
44              mv "${TARGET}"/etc/hosts.orig "$TARGET"/etc/hosts
45           else
46              rm -f "$TARGET"/etc/hosts
47           fi
48
49           # TODO: adjust for grml-policy.rc.d
50           if [ -f "${TARGET}"/etc/resolv.conf.orig ] ; then
51              mv "${TARGET}"/etc/resolv.conf.orig "$TARGET"/etc/resolv.conf
52           else
53              rm -f "$TARGET"/etc/resolv.conf
54           fi
55
56           rm -f "${TARGET}"/usr/sbin/policy-rc.d
57           ;;
58   esac
59 }
60
61 ## END OF FILE #################################################################
62 # vim: ai tw=80 ft=sh expandtab