Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ on device without having to cripple it.
Requirements for running
------------------------
Target:
An ARM64 android N or later device which has "adb root" supported. Typically
this is a build in a userdebug configuration. Device should have atleast 2 GB
free space in the data partition. If you would like to use other architectures,
see the [Other Architectures](https://github.com/joelagnel/adeb/blob/master/README.md#how-to-use-adeb-for-other-architectures-other-than-arm64) section.
An armhf, arm64, i386 or amd64 Android N or later device which has "adb root"
supported. Typically this is a build in a userdebug configuration. Device should
have at least 2 GB free space in the data partition. If you would like to use an
architecture other than the default of arm64, see the
[Other Architectures](https://github.com/joelagnel/adeb/blob/master/README.md#how-to-use-adeb-for-other-architectures-other-than-arm64)
section.

Host:
A machine running recent Ubuntu or Debian, with 4GB of memory and 4GB free space.
Host needs debootstrap and qemu-debootstrap packages.
To install it, run `sudo apt-get install qemu-user-static debootstrap`.
Host needs the debootstrap, fakeroot and qemu-user-static packages. To install
these, run `sudo apt-get install debootstrap fakeroot qemu-user-static`.
Other distributions may work but they are not tested.

Quick Start Instructions
Expand Down Expand Up @@ -155,5 +157,9 @@ example for x86_64 architecture, run:
```
adeb prepare --build --arch amd64 --bcc --kernelsrc /path/to/kernel-source/
```
Normally you want to use --foreign too, especially if your distro's glibc
version does not match the --distro option. This mode eliminates the need
for root (chroot) or qemu-debootstrap, but it does cause more setup to be
done on the device side the first time you enter adeb.
Note: The --download option ignores the --arch flag. This is because we only
provide pre-built filesystems for ARM64 at the moment.
30 changes: 24 additions & 6 deletions androdeb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ source $spath/utils/support
source $spath/utils/banners

# Set default vars
DISTRO=buster; ARCH=arm64
DISTRO=buster; ARCH=arm64; MIRROR=http://deb.debian.org/debian/
ADB="adb"
FULL=0 # Default to a minimal install
DOWNLOAD=1 # Default to downloading from web
SKIP_DEVICE=0 # Skip device preparation
INSTALL_BCC=0 # Decide if BCC is to be installed
FOREIGN=0 # Use debootstrap --foreign mode

# Default packages
PACKAGES=""
Expand Down Expand Up @@ -51,6 +52,8 @@ case $key in
prepare) PREPARE=1; shift || true; ;;
--full) FULL=1; config_full_build; shift || true; ;;
--arch) ARCH=$2; shift || true; shift || true; ;;
--distro) DISTRO="$2"; shift || true; shift || true; ;;
--foreign) FOREIGN=1; shift || true; ;;
--archive) TARF=$2; shift || true; shift || true; ;;
--bcc) source $spath/packages/bcc; shift || true; ;;
--kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;;
Expand Down Expand Up @@ -80,6 +83,24 @@ if [ ! -z $BTAR ] && [ -z $TARDIR ]; then
TARDIR=$spath
fi

case $ARCH in
i386) ;;
amd64) ;;
arm64) ;;
armhf) ;;
*) echo "Unsupported arch ($ARCH)"; ;;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change to "Warning: untested arch ($ARCH)" ?

esac

case $DISTRO in
buster) ;;
bionic)
if [ "$ARCH" == "i386" -o "$ARCH" == "amd64" ]; then
MIRROR=http://archive.ubuntu.com/ubuntu/
else
MIRROR=http://ports.ubuntu.com/; fi ;;
*) echo "Unusupported distro ($DISTRO)"; ;;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change to "Warning: Untested distro ($DISTRO)" ?

esac

if [ ! -z "$GIT_PULL" ]; then
c_info "Updating androdeb by git pull"
cd $spath
Expand Down Expand Up @@ -279,13 +300,10 @@ fi
PACKAGES+="$DEFAULT_PACKAGES"
c_info "Using temporary directory: $TDIR"

if [[ $EUID -ne 0 ]]; then c_info "The next stage runs as sudo, please enter password if asked."; fi

ex_files=$(mktemp); echo $EXTRA_FILES > $ex_files

sudo $spath/buildstrap $ARCH $DISTRO $TDIR $OUT_TMP \
"$(make_csv "$PACKAGES")"\
$ex_files $INSTALL_BCC $SKIP_DEVICE
$spath/buildstrap $ARCH $DISTRO $TDIR $OUT_TMP "$PACKAGES" \
$ex_files $INSTALL_BCC $SKIP_DEVICE $MIRROR $FOREIGN
rm $ex_files

# If we only wanted to prepare a rootfs and don't have
Expand Down
72 changes: 42 additions & 30 deletions buildstrap
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,70 @@ ARCH=$1
DISTRO=$2
TDIR=$3
OUT_TMP=$4
PACKAGES=$5
PACKAGES="$(make_csv "$5")"
EXTRA_FILES="$(cat $6)"
INSTALL_BCC=$7
SKIP_DEVICE=$8 # Skip any device-specific stages
MIRROR=$9
shift
FOREIGN=$9
VARIANT="--variant=minbase"

time qemu-debootstrap --arch $ARCH --include=$PACKAGES $VARIANT \
$DISTRO $OUT_TMP http://deb.debian.org/debian/
if [ $FOREIGN -eq 1 ]; then
debootstrap="debootstrap --foreign"
root=fakeroot
else
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these if/else blocks are so huge, I suggest split them into 2 different functions. Maybe do_debian and do_ubuntu and then call them from the if/else.

if [ $EUID -ne 0 ]; then echo "The next stage runs as sudo, please enter password if asked."; fi
debootstrap=qemu-debootstrap
root=sudo
fi

time $root $debootstrap --arch $ARCH --include=$PACKAGES $VARIANT \
$DISTRO $OUT_TMP $MIRROR

# Some reason debootstrap leaves these mounted
umount $OUT_TMP/proc/sys/fs/binfmt_misc || true
umount $OUT_TMP/proc || true
$root umount $OUT_TMP/proc/sys/fs/binfmt_misc || true
$root umount $OUT_TMP/proc || true

# Make bash the default shell
chroot $OUT_TMP rm /bin/sh || true
chroot $OUT_TMP ln -s /bin/bash /bin/sh || true
cp $spath/addons/bashrc $OUT_TMP/.bashrc
cp $spath/addons/bashrc.common $OUT_TMP/.bashrc.common
cp $spath/addons/bashrc.silent $OUT_TMP/.bashrc.silent
cp $spath/addons/get_kvers.sh $OUT_TMP/
$root ln -sf /bin/bash $OUT_TMP/bin/sh || true
$root cp $spath/addons/bashrc $OUT_TMP/.bashrc
$root cp $spath/addons/bashrc.common $OUT_TMP/.bashrc.common
$root cp $spath/addons/bashrc.silent $OUT_TMP/.bashrc.silent
$root cp $spath/addons/get_kvers.sh $OUT_TMP/

for f in $EXTRA_FILES; do
if [ $f == "none" ]; then continue; fi
cp $f $OUT_TMP/
$root cp $f $OUT_TMP/
done

# Cleanup
rm -rf $OUT_TMP/lib/udev/*
rm -rf $OUT_TMP/var/lib/apt/lists/*
rm -rf $OUT_TMP/var/cache/apt/archives/*deb
rm -rf $OUT_TMP/usr/share/locale/*
rm -rf $OUT_TMP/usr/lib/share/locale/*
rm -rf $OUT_TMP/usr/share/doc/*
rm -rf $OUT_TMP/usr/lib/share/doc/*
rm -rf $OUT_TMP/usr/share/ieee-data/*
rm -rf $OUT_TMP/usr/lib/share/ieee-data/*
rm -rf $OUT_TMP/usr/share/man/*
rm -rf $OUT_TMP/usr/lib/share/man/*
$root rm -rf $OUT_TMP/lib/udev/*
$root rm -rf $OUT_TMP/var/lib/apt/lists/*
$root rm -rf $OUT_TMP/var/cache/apt/archives/*deb
$root rm -rf $OUT_TMP/usr/share/locale/*
$root rm -rf $OUT_TMP/usr/lib/share/locale/*
$root rm -rf $OUT_TMP/usr/share/doc/*
$root rm -rf $OUT_TMP/usr/lib/share/doc/*
$root rm -rf $OUT_TMP/usr/share/ieee-data/*
$root rm -rf $OUT_TMP/usr/lib/share/ieee-data/*
$root rm -rf $OUT_TMP/usr/share/man/*
$root rm -rf $OUT_TMP/usr/lib/share/man/*

# Fix apt-get issue: Android requires _apt user to be in the
# AID_INET group which is also android specific.
grep -ri _apt:x:100:65534 $OUT_TMP/etc/passwd > /dev/null 2>&1
if [ $? -ne 0 ]; then
c_warning "_apt user cannot be added to AID_INET group"
else
sed -i -e 's/_apt:x:100:65534/_apt:x:100:3003/' $OUT_TMP/etc/passwd
$root sed -i -e 's/_apt:x:100:65534/_apt:x:100:3003/' \
$OUT_TMP/etc/passwd
fi

# Add a default DNS server
echo "nameserver 4.2.2.2" > $OUT_TMP/etc/resolv.conf
$root tee $OUT_TMP/etc/resolv.conf >/dev/null <<EOF
nameserver 4.2.2.2
EOF

# Clone BCC if needed
if [ $INSTALL_BCC -eq 1 ]; then
Expand All @@ -70,12 +84,10 @@ if [ $INSTALL_BCC -eq 1 ]; then
popd
fi

# Should be really do this?
chmod -R 0777 $TDIR/

[ $SKIP_DEVICE -eq 0 ] || exit 0

c_info "Compressing new filesystem to prepare to push to Android /data/androdeb/"
tar -zcf $TDIR/deb.tar.gz -C $TDIR debian

chmod 0777 $TDIR/deb.tar.gz
$root tar -zpcf $TDIR/deb.tar.gz -C $TDIR debian

$root chown --reference=$TDIR $TDIR/deb.tar.gz