-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunctions
217 lines (203 loc) · 7.03 KB
/
functions
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/bin/bash
# vim: noai:ts=4:sw=4:syn=sh
# Copyright 2013 Jon Allen ([email protected])
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# functions
# this is the script that builder.sh sources to do all the dirty work
# this function simply deletes everything
clean_directories ()
{
rm -rf $BASE_DIR/$ROOT_TARGET;
rm -rf $BASE_DIR/$DEBOOT_DIR;
rm -rf $BASE_DIR/$KERNEL_DIR;
}
# just make the directories we'll need
create_directories ()
{
mkdir -p $BASE_DIR/$DEBOOT_DIR;
mkdir -p $BASE_DIR/$ROOT_TARGET;
mkdir -p $BASE_DIR/$KERNEL_DIR;
mkdir -p $BASE_DIR/$ROOT_TARGET/$KERNEL_DIR;
mkdir -p $BASE_DIR/$KERNEL_OUT_DIR;
}
#do path magic
ORIGINAL_PATH=$PATH
set_path ()
{
ORIGINAL_PATH=$PATH;
PATH=$DUAL_PATH;
}
reset_path ()
{
PATH=$ORIGINAL_PATH;
}
#do the mount magic
do_mount ()
{
sleep 1;
mount -o bind $BASE_DIR/$KERNEL_DIR $BASE_DIR/$ROOT_TARGET/$KERNEL_DIR;
mount -t proc proc $BASE_DIR/$ROOT_TARGET/proc/;
mount -t sysfs sys $BASE_DIR/$ROOT_TARGET/sys/;
mount -o bind /dev $BASE_DIR/$ROOT_TARGET/dev/;
mount -t devpts devpts -o mode=620,gid=5 $BASE_DIR/$ROOT_TARGET/dev/pts/;
}
do_unmount ()
{
sleep 1;
umount $BASE_DIR/$ROOT_TARGET/dev/pts/;
umount $BASE_DIR/$ROOT_TARGET/dev/;
umount $BASE_DIR/$ROOT_TARGET/sys/;
umount $BASE_DIR/$ROOT_TARGET/proc/;
umount $BASE_DIR/$ROOT_TARGET/$KERNEL_DIR;
}
enter_chroot ()
{
chroot $BASE_DIR/$ROOT_TARGET /bin/bash;
}
# this function gets the debootstrap package and unpacks it into the appropriate directory, all ready to be used
get_deboot ()
{
cd $BASE_DIR/$DEBOOT_DIR;
wget -c $DEBOOT_SRC/$DEBOOT_DEB;
ar -x $DEBOOT_DEB;
tar -xf data.tar.xz;
cd $BASE_DIR;
}
# this function just creates the chroot environment
deboot_stage_one ()
{
# do the bootstrap
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;
}
deboot_stage_two ()
{
#do the second stage bootstrap
chroot $BASE_DIR/$ROOT_TARGET /debootstrap/debootstrap --second-stage;
}
deboot_setup ()
{
#stop dpkg from running daemons
cat > $BASE_DIR/$ROOT_TARGET/usr/sbin/policy-rc.d <<EOF
#!/bin/sh
exit 101
EOF
chmod a+x $BASE_DIR/$ROOT_TARGET/usr/sbin/policy-rc.d;
# update the chroot's sources.list
printf '%s' "$ROOT_SOURCES_LIST" >$BASE_DIR/$ROOT_TARGET/etc/apt/sources.list;
#update the locale
printf '%s' "$ROOT_LOCALE" >$BASE_DIR/$ROOT_TARGET/etc/locale.gen;
chroot $BASE_DIR/$ROOT_TARGET /usr/sbin/locale-gen
#divert ischroot
#note that this throws error, my need to be fixed, not sure
chroot $BASE_DIR/$ROOT_TARGET dpkg-divert --divert /usr/bin/ischroot.debianutils --rename /usr/bin/ischroot;
chroot $BASE_DIR/$ROOT_TARGET /bin/ln -s /bin/true /usr/bin/ischroot;
}
# bring the chroot current
upgrade_chroot ()
{
chroot $BASE_DIR/$ROOT_TARGET apt-get -qy update;
chroot $BASE_DIR/$ROOT_TARGET apt-get -qy dist-upgrade;
}
# install required packages in the chroot
install_build_tools ()
{
chroot $BASE_DIR/$ROOT_TARGET apt-get -qy install $REQUIRED_PACKAGES;
}
# this function gets the architecture for our chroot
# currently only ix86 32 and 64 bit targets are supported
# but I'll eventually get around to adding more
get_architecture ()
{
case `uname -m` in
i?86)
ROOT_ARCH=i386
;;
x86_64)
ROOT_ARCH=amd64
;;
*)
echo "I don't know what kind of architecture the chroot needs to be"
exit 1
;;
esac;
}
#functions for managing the kernel source
kernel_get ()
{
git clone $KERNEL_REPO $BASE_DIR/$KERNEL_DIR;
}
kernel_pull ()
{
git -C $BASE_DIR/$KERNEL_DIR pull;
}
#see https://wiki.ubuntu.com/Nexus7/Kernel for more information
kernel_build ()
{
set_path;
do_mount;
cd $BASE_DIR/$ROOT_TARGET/$KERNEL_DIR;
git clean -xdf;
export ARCH=arm;
export SUBARCH=arm;
export CROSS_COMPILE="ccache arm-linux-gnueabihf-"
chroot $BASE_DIR/$ROOT_TARGET su - -c "cd /"$KERNEL_DIR"; make ARCH=arm SUBARCH=arm CROSS_COMPILE="'"ccache arm-linux-gnueabihf-"'" mrproper";
chroot $BASE_DIR/$ROOT_TARGET su - -c "cd /"$KERNEL_DIR"; make ARCH=arm SUBARCH=arm CROSS_COMPILE="'"ccache arm-linux-gnueabihf-"'" grouper_ubuntu_defconfig";
chroot $BASE_DIR/$ROOT_TARGET su - -c "cd /"$KERNEL_DIR"; make -j$BUILD_PROCESSES ARCH=arm SUBARCH=arm CROSS_COMPILE="'"ccache arm-linux-gnueabihf-"';
cp $BASE_DIR/$KERNEL_DIR/arch/arm/boot/zImage $BASE_DIR/$KERNEL_OUT_DIR/
# sed -i '/do_tools/ s/true/false/' debian.nexus7/rules.d/armhf.mk;
# chroot $BASE_DIR/$ROOT_TARGET su - -c "cd /"$KERNEL_DIR"; fakeroot debian/rules clean";
# chroot $BASE_DIR/$ROOT_TARGET su - -c 'cd /'$KERNEL_DIR'; debuild -eDEB_BUILD_OPTIONS="parallel='$BUILD_PROCESSES'" -eCROSS_COMPILE="ccache arm-linux-gnueabihf-" -b -aarmhf -us -uc -nc';
cd $BASE_DIR;
do_unmount;
reset_path;
}
kernel_boot ()
{
echo 'Creating test.img';
echo "cmdline=$KERNEL_CMD_LINE">$BASE_DIR/$KERNEL_OUT_DIR/cmd.txt
abootimg --create $BASE_DIR/$KERNEL_OUT_DIR/test.img -f $BASE_DIR/$KERNEL_OUT_DIR/cmd.txt -k $BASE_DIR/$KERNEL_OUT_DIR/$KERNEL_TARGET -r $BASE_DIR/$KERNEL_OUT_DIR/$RAMDISK_TARGET;
# fastboot boot $BASE_DIR/$KERNEL_OUT_DIR/$KERNEL_TARGET $BASE_DIR/$KERNEL_OUT_DIR/$RAMDISK_TARGET -c "$KERNEL_CMD_LINE";
echo 'Booting test.img';
fastboot boot $BASE_DIR/$KERNEL_OUT_DIR/test.img;
}
# this patch was attempting to fix a problem that was actually a path
# problem, so it's currently not used, but left in case it's needed later
# deboot comes out of the box with an offensive mount command.
# this patches it to fix the error when mounting the proc file system
# this patch from http://blog.tsunanet.net/2013/01/using-debootstrap-with-grsec.html?m=1
patch_deboot ()
{
local MOUNT_PATCH="--- usr/share/debootstrap/functions.orig 2013-11-26 07:15:53.909242727 -0600
+++ usr/share/debootstrap/functions 2013-11-26 07:17:39.464665969 -0600
@@ -998,12 +998,14 @@
umount_on_exit /proc/bus/usb
umount_on_exit /proc
umount "'"'"\$TARGET/proc"'"'" 2>/dev/null || true
- in_target mount -t proc proc /proc
+# in_target mount -t proc proc /proc
+ sudo mount -o bind /proc "'"'"\$TARGET/proc"'"'"
if [ -d "'"'"\$TARGET/sys"'"'" ] && \\
grep -q '[[:space:]]sysfs' /proc/filesystems 2>/dev/null; then
umount_on_exit /sys
umount "'"'"\$TARGET/sys"'"'" 2>/dev/null || true
- in_target mount -t sysfs sysfs /sys
+# in_target mount -t sysfs sysfs /sys
+ sudo mount -o bin /sys "'"'"\$TARGET/sys"'"'"
fi
on_exit clear_mtab
;;
";
printf '%s' "$MOUNT_PATCH"|patch --ignore-whitespace --verbose $BASE_DIR/$DEBOOT_DIR/usr/share/debootstrap/functions;
}