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