• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3spath="$(dirname "$(readlink -f "$0")")"
4source $spath/utils/support
5source $spath/utils/banners
6
7ARCH=$1
8DISTRO=$2
9TDIR=$3
10OUT_TMP=$4
11PACKAGES=$5
12EXTRA_FILES="$(cat $6)"
13INSTALL_BCC=$7
14SKIP_DEVICE=$8		# Skip any device-specific stages
15VARIANT="--variant=minbase"
16
17time qemu-debootstrap --arch $ARCH --include=$PACKAGES $VARIANT \
18	$DISTRO $OUT_TMP http://deb.debian.org/debian/
19
20# Some reason debootstrap leaves these mounted
21umount $OUT_TMP/proc/sys/fs/binfmt_misc || true
22umount $OUT_TMP/proc || true
23
24# Make bash the default shell
25chroot $OUT_TMP rm /bin/sh || true
26chroot $OUT_TMP ln -s /bin/bash /bin/sh || true
27cp $spath/addons/bashrc $OUT_TMP/.bashrc
28cp $spath/addons/bashrc.common $OUT_TMP/.bashrc.common
29cp $spath/addons/bashrc.silent $OUT_TMP/.bashrc.silent
30cp $spath/addons/get_kvers.sh $OUT_TMP/
31
32for f in $EXTRA_FILES; do
33	if [ $f == "none" ]; then continue; fi
34	cp $f $OUT_TMP/
35done
36
37# Cleanup
38rm -rf $OUT_TMP/lib/udev/*
39rm -rf $OUT_TMP/var/lib/apt/lists/*
40rm -rf $OUT_TMP/var/cache/apt/archives/*deb
41rm -rf $OUT_TMP/usr/share/locale/*
42rm -rf $OUT_TMP/usr/lib/share/locale/*
43rm -rf $OUT_TMP/usr/share/doc/*
44rm -rf $OUT_TMP/usr/lib/share/doc/*
45rm -rf $OUT_TMP/usr/share/ieee-data/*
46rm -rf $OUT_TMP/usr/lib/share/ieee-data/*
47rm -rf $OUT_TMP/usr/share/man/*
48rm -rf $OUT_TMP/usr/lib/share/man/*
49
50# Fix apt-get issue: Android requires _apt user to be in the
51# AID_INET group which is also android specific.
52grep -ri _apt:x:100:65534 $OUT_TMP/etc/passwd > /dev/null 2>&1
53if [ $? -ne 0 ]; then
54	c_warning "_apt user cannot be added to AID_INET group"
55else
56	sed -i -e 's/_apt:x:100:65534/_apt:x:100:3003/' $OUT_TMP/etc/passwd
57fi
58
59# Add a default DNS server
60echo "nameserver 4.2.2.2" > $OUT_TMP/etc/resolv.conf
61
62# Clone BCC if needed
63if [ $INSTALL_BCC -eq 1 ]; then
64	git clone https://github.com/iovisor/bcc.git $TDIR/debian/bcc-master
65	cp $spath/bcc/build-bcc.sh $TDIR/debian/bcc-master/;
66fi
67
68# Should be really do this?
69chmod -R 0777 $TDIR/
70
71[ $SKIP_DEVICE -eq 0 ] || exit 0
72
73c_info "Compressing new filesystem to prepare to push to Android /data/androdeb/"
74tar -zcf $TDIR/deb.tar.gz -C $TDIR debian
75
76chmod 0777 $TDIR/deb.tar.gz
77