summaryrefslogtreecommitdiff
path: root/src/scripts/12patch.sh
blob: 873865c36d257af3b6d6979e379eedb44b2019ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/sh

# make-live - utility to build Debian Live systems
#
# Copyright (C) 2006 Daniel Baumann <daniel@debian.org>
# Copyright (C) 2006 Marco Amadori <marco.amadori@gmail.com>
#
# make-live comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
# This is free software, and you are welcome to redistribute it
# under certain conditions; see COPYING for details.

Patch_chroot ()
{
	# Some maintainer scripts can detect if they are in a chrooted system.
	# Therefore, we create the needed file.

	case "${1}" in
		apply)
			# Create chroot file
			echo "debian-live" > "${LIVE_CHROOT}"/etc/debian_chroot
			;;

		deapply)
			# Remove chroot file
			rm -f "${LIVE_CHROOT}"/etc/debian_chroot
			;;
	esac
}

Patch_runlevel ()
{
	# Disabling all init scripts with a blocking policy as in
	# /usr/share/doc/sysv-rc/README.policy-rc.d.gz.

	case "${1}" in
		apply)
			# Create init policy
			echo > "${LIVE_CHROOT}"/usr/sbin/policy-rc.d <<EOF
#!/bin/sh

exit 101
EOF

			chmod 0755 "${LIVE_CHROOT}"/usr/sbin/policy-rc.d
			;;

		deapply)
			# Removing init policy
			rm -f "${LIVE_CHROOT}"/usr/sbin/policy-rc.d
			;;
	esac
}

Patch_network ()
{
	# Packages which are manually installed inside the chroot are installed
	# from the network. Therefore, we need to be able to resolv hosts.

	case "${1}" in
		apply)
			# Save host lookup table
			if [ -f "${LIVE_CHROOT}"/etc/hosts ]
			then
				cp "${LIVE_CHROOT}"/etc/hosts "${LIVE_CHROOT}"/etc/hosts.orig
			fi

			# Save resolver configuration
			if [ -f "${LIVE_CHROOT}"/etc/resolv.conf ]
			then
				cp "${LIVE_CHROOT}"/etc/resolv.conf "${LIVE_CHROOT}"/etc/resolv.conf.orig
			fi

			# Copy host lookup table
			if [ -f /etc/hosts ]
			then
				cp /etc/hosts "${LIVE_CHROOT}"/etc/hosts
			fi

			# Copy resolver configuration
			if [ -f /etc/resolv.conf ]
			then
				cp /etc/resolv.conf "${LIVE_CHROOT}"/etc/resolv.conf
			fi
			;;

		deapply)
			# Restore host lookup table
			if [ -f "${LIVE_CHROOT}"/etc/hosts.orig ]
			then
				mv "${LIVE_CHROOT}"/etc/hosts.orig "${LIVE_CHROOT}"/etc/hosts
			fi

			# Restore resolver configuration
			if [ -f "${LIVE_CHROOT}"/etc/resolv.conf.orig ]
			then
				mv "${LIVE_CHROOT}"/etc/resolv.conf.orig "${LIVE_CHROOT}"/etc/resolv.conf
			fi
			;;
	esac
}

Patch_linux ()
{
	# The linux-image package asks interactively for initial ramdisk
	# creation. Therefore, we preconfigure /etc/kernel-img.conf.
	# FIXME: preseeding?

	case "${1}" in
		apply)
			# Write configuration option
			echo "do_initrd = Yes"  >> "${LIVE_CHROOT}"/etc/kernel-img.conf
			;;

		deapply)
			# Remove configuration file
			rm -f "${LIVE_CHROOT}"/etc/kernel-img.conf
			;;
	esac
}