@@ -31,6 +31,7 @@ create_directories ()
3131 mkdir -p $BASE_DIR /$DEBOOT_DIR
3232 mkdir -p $BASE_DIR /$ROOT_TARGET
3333 mkdir -p $BASE_DIR /$KERNEL_DIR
34+ mkdir -p $BASE_DIR /$ROOT_TARGET /$KERNEL_DIR
3435}
3536
3637# do path magic
@@ -44,6 +45,24 @@ reset_path ()
4445{
4546 PATH=$ORIGINAL_PATH
4647}
48+ # do the mount magic
49+ do_mount ()
50+ {
51+ mount -o bind $BASE_DIR /$KERNEL_DIR $BASE_DIR /$ROOT_TARGET /$KERNEL_DIR ;
52+ mount -t proc proc $BASE_DIR /$ROOT_TARGET /proc/;
53+ mount -t sysfs sys $BASE_DIR /$ROOT_TARGET /sys/;
54+ mount -o bind /dev $BASE_DIR /$ROOT_TARGET /dev/;
55+ mount -t devpts pts $BASE_DIR /$ROOT_TARGET /dev/pts/;
56+ }
57+ do_unmount ()
58+ {
59+ umount $BASE_DIR /$ROOT_TARGET /dev/pts/;
60+ umount $BASE_DIR /$ROOT_TARGET /dev/;
61+ umount $BASE_DIR /$ROOT_TARGET /sys/;
62+ umount $BASE_DIR /$ROOT_TARGET /proc/;
63+ umount $BASE_DIR /$ROOT_TARGET /$KERNEL_DIR ;
64+ }
65+
4766# this function gets the debootstrap package and unpacks it into the appropriate directory, all ready to be used
4867get_deboot ()
4968{
@@ -55,6 +74,38 @@ get_deboot ()
5574}
5675
5776# this function just creates the chroot environment
77+ deboot_stage_one ()
78+ {
79+ # do the bootstrap
80+ DEBOOTSTRAP_DIR=$BASE_DIR /$DEBOOT_DIR /usr/share/debootstrap $BASE_DIR /$DEBOOT_DIR /usr/sbin/debootstrap --foreign --arch=$ROOT_ARCH --variant=buildd --no-check-gpg $ROOT_SUITE $BASE_DIR /$ROOT_TARGET $ROOT_SOURCE ;
81+ }
82+ deboot_stage_two ()
83+ {
84+ # do the second stage bootstrap
85+ chroot $BASE_DIR /$ROOT_TARGET /debootstrap/debootstrap --second-stage;
86+ }
87+ deboot_setup ()
88+ {
89+ # stop dpkg from running daemons
90+ cat > $BASE_DIR /$ROOT_TARGET /usr/sbin/policy-rc.d << EOF
91+ #!/bin/sh
92+ exit 101
93+ EOF
94+ chmod a+x $BASE_DIR /$ROOT_TARGET /usr/sbin/policy-rc.d;
95+
96+ # update the chroot's sources.list
97+ printf ' %s' " $ROOT_SOURCES_LIST " > $BASE_DIR /$ROOT_TARGET /etc/apt/sources.list;
98+
99+ # update the locale
100+ printf ' %s' " $ROOT_LOCALE " > $BASE_DIR /$ROOT_TARGET /etc/locale.gen;
101+ chroot $BASE_DIR /$ROOT_TARGET /usr/sbin/locale-gen
102+
103+ # divert ischroot
104+ # note that this throws error, my need to be fixed, not sure
105+ chroot $BASE_DIR /$ROOT_TARGET dpkg-divert --divert /usr/bin/ischroot.debianutils --rename /usr/bin/ischroot;
106+ chroot $BASE_DIR /$ROOT_TARGET /bin/ln -s /bin/true /usr/bin/ischroot;
107+
108+ }
58109deboot_chroot ()
59110{
60111 # do the bootstrap
72123 chmod a+x $BASE_DIR /$ROOT_TARGET /usr/sbin/policy-rc.d;
73124
74125# update the chroot's sources.list
75- cat > $BASE_DIR /$ROOT_TARGET /etc/apt/sources.list << EOF
76- deb http://archive.ubuntu.com/ubuntu $ROOT_SUITE main restricted universe multiverse
77- deb http://archive.ubuntu.com/ubuntu $ROOT_SUITE -updates main restricted universe multiverse
78- deb http://archive.ubuntu.com/ubuntu $ROOT_SUITE -security main restricted universe multiverse
79- EOF
126+ # cat > $BASE_DIR/$ROOT_TARGET/etc/apt/sources.list <<EOF
127+ # deb http://archive.ubuntu.com/ubuntu $ROOT_SUITE main restricted universe multiverse
128+ # deb http://archive.ubuntu.com/ubuntu $ROOT_SUITE-updates main restricted universe multiverse
129+ # deb http://archive.ubuntu.com/ubuntu $ROOT_SUITE-security main restricted universe multiverse
130+ # EOF
131+ printf ' %s' " $ROOT_SOURCES_LIST "
132+ > $BASE_DIR /$ROOT_TARGET /etc/apt/sources.list;
80133
81134 # divert ischroot
82135 # note that this throws error, my need to be fixed, not sure
88141# bring the chroot current
89142upgrade_chroot ()
90143{
91- chroot $BASE_DIR /$ROOT_TARGET apt-get update;
92- chroot $BASE_DIR /$ROOT_TARGET apt-get dist-upgrade;
144+ chroot $BASE_DIR /$ROOT_TARGET apt-get -qy update;
145+ chroot $BASE_DIR /$ROOT_TARGET apt-get -qy dist-upgrade;
93146}
94147
95148# install required packages in the chroot
96149install_build_tools ()
97150{
98- chroot $BASE_DIR /$ROOT_TARGET apt-get install $REQUIRED_PACKAGES ;
151+ chroot $BASE_DIR /$ROOT_TARGET apt-get -qy install $REQUIRED_PACKAGES ;
99152}
100153
101154# this function gets the architecture for our chroot
@@ -117,6 +170,8 @@ get_architecture ()
117170 esac ;
118171}
119172
173+ # this patch was attempting to fix a problem that was actually a path
174+ # problem, so it's currently not used, but left in case it's needed later
120175# deboot comes out of the box with an offensive mount command.
121176# this patches it to fix the error when mounting the proc file system
122177# this patch from http://blog.tsunanet.net/2013/01/using-debootstrap-with-grsec.html?m=1
0 commit comments