androdeb: reduce number of options

A big rewrite to simplify the options. Now providing a "minimal" FS for
a basic install with just apt, networking tools, etc. And a "full" FS
with BCC included.

Signed-off-by: Joel Fernandes <joel@joelfernandes.org>
diff --git a/BCC.md b/BCC.md
index 9042361..8995747 100644
--- a/BCC.md
+++ b/BCC.md
@@ -65,8 +65,14 @@
 This will make androdeb clone and build the latest version of BCC for the
 target architecture. Note that this is much slower that `--download`.
 ```
-adeb prepare --bcc --kernelsrc /path/to/kernel-source/
+adeb prepare --build --bcc --kernelsrc /path/to/kernel-source/
 ```
+Note that the full androdeb install already contains recent BCC:
+```
+adeb prepare --full
+```
+This downloads and installs a prebuilt FS and is faster than building locally
+using `--build`.
 
 Other Architectures (other than ARM64)
 -----------------------
diff --git a/README.md b/README.md
index 293669b..a4b7d1a 100644
--- a/README.md
+++ b/README.md
@@ -54,10 +54,15 @@
 sudo ln -s $(pwd)/androdeb /usr/bin/androdeb
 ```
 
-* Fastest way of installing adeb onto your device:
+* Installing adeb onto your device:
 ```
 # First make sure device is connected to system
-adeb prepare --download
+# Then run, for the base image:
+adeb prepare
+```
+# The previous command only downloads and installs the base image.
+# Instead if you want to download and install the full image, do:
+adeb prepare --full
 ```
 
 * Now run adeb shell to enter your new environment!:
@@ -87,7 +92,7 @@
 --------------------------------
 ### Install kernel headers in addition to preparing androdeb device:
 ```
-adeb prepare --download --kernelsrc /path/to/kernel-source
+adeb prepare --kernelsrc /path/to/kernel-source
 ```
 
 ### Update kernel headers onto an already prepared device:
@@ -102,31 +107,30 @@
 
 The androdeb fs will be prepared locally by downloading packages as needed:
 ```
-adeb prepare --fullbuild
+adeb prepare --build
 ```
-This is unlike `--download` where the androdeb rootfs is itself pulled from the web.
+This is unlike the default behavior, where the androdeb rootfs is itself pulled from the web.
+
+If you wish to do a full build (that is locally prepare a rootfs with all packages, including bcc, then do):
+```
+adeb prepare --full --build
+```
 
 ### Add kernel headers to device in addition to building locally:
 ```
-adeb prepare --fullbuild --kernelsrc /path/to/kernel-source/
+adeb prepare --build --kernelsrc /path/to/kernel-source/
 ```
 
-### Instead of `--fullbuild`, customize what you install:
+### Build/install a base image with BCC:
 ```
-adeb prepare --editors --compilers
+adeb prepare --build --bcc --kernelsrc /path/to/kernel-source/
 ```
-
-### Install only BCC:
-```
-adeb prepare --bcc --kernelsrc /path/to/kernel-source/
-```
-Note: BCC is built while being installed. Also `--kernelsrc` is
-recommended for tools to function unless device has them
-already.
+Note: BCC is built from source. Also `--kernelsrc` is recommended for tools to
+function unless device has them already.
 
 ### Extract the FS from the device, after its prepared:
 ```
-adeb prepare --fullbuild --buildtar /path/
+adeb prepare --buildtar /path/
 ```
 After device is prepared, it will extract the root fs from it
 and store it as a tar archive at `/path/androdeb-fs.tgz`. This
@@ -149,7 +153,7 @@
 processor architecture. For other architectures, use the --arch option. For
 example for x86_64 architecture, run:
 ```
-adeb prepare --arch amd64 --bcc --kernelsrc /path/to/kernel-source/
+adeb prepare --build --arch amd64 --bcc --kernelsrc /path/to/kernel-source/
 ```
 Note: The --download option ignores the --arch flag. This is because we only
 provide pre-built filesystems for ARM64 at the moment.
diff --git a/androdeb b/androdeb
index 5d9a2ce..6ecfa54 100755
--- a/androdeb
+++ b/androdeb
@@ -13,12 +13,14 @@
 # Set default vars
 DISTRO=buster; ARCH=arm64
 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
 
 # Default packages
-DEFAULT_PACKAGES+="bash
-ca-certificates"
+PACKAGES=""
+DEFAULT_PACKAGES="bash ca-certificates apt net-tools iputils-ping procps vim"
 
 EXTRA_FILES="none"
 
@@ -41,26 +43,22 @@
 fi
 
 case $key in
-    prepare) PREPARE=1;  shift || true;    ;;
     shell) ASHELL=1;     shift || true;     ;;
     remove) REMOVE=1;     shift || true;     ;;
     git-pull) GIT_PULL=1; shift || true; ;;
     pull) PULL=1; shift || true; break	;;
     push) PUSH=1; shift || true; break	;;
+    prepare) PREPARE=1;  shift || true;    ;;
+    --full) FULL=1; config_full_build; shift || true; ;;
     --arch) ARCH=$2; shift || true; shift || true; ;;
     --archive) TARF=$2; shift || true; shift || true; ;;
-    --tracers) source $spath/packages/tracers; shift || true; ;;
-    --compilers) source $spath/packages/compilers; shift || true; ;;
-    --editors) source $spath/packages/editors; shift || true; ;;
-    --scheduler) source $spath/packages/scheduler; shift || true; ;;
-    --fullbuild) config_full_build; shift || true; ;;
-    --download) DOWNLOAD=1; shift || true; ;;
     --bcc) source $spath/packages/bcc; shift || true;     ;;
     --kernelsrc) KERNELSRC="$2"; shift || true;     shift || true;     ;;
     --skip-install) SKIP_INSTALL=1; shift || true; ;;
     --kernel-headers-targz) KERNELHDRS=$2; shift || true;	shift || true;	;;
     --tempdir) TDIR="$2"; shift || true;     shift || true;     ;;
-    --buildtar) BTAR=1; TARDIR="$2"; shift || true;     shift || true;     ;;
+    --build) DOWNLOAD=0;  shift || true;     ;;
+    --buildtar) BTAR=1; DOWNLOAD=0; TARDIR="$2"; shift || true;     shift || true;     ;;
     --device|-s) ADB="$ADB -s $2"; shift || true; shift || true; ;;
     --build-image) BI=1; BUILD_IMAGEF=$2; SKIP_DEVICE=1; shift || true; shift || true; ;;
     --debug) set -x; shift || true; ;;
@@ -70,6 +68,14 @@
 
 [ -z $ASHELL ] && box_out "adeb: $VERSION"
 
+if [ $FULL -eq 1 ]; then
+	FNAME=androdeb-fs.tgz.zip
+	FNAME_UZ=androdeb-fs.tgz
+else
+	FNAME=androdeb-fs-minimal.tgz.zip
+	FNAME_UZ=androdeb-fs-minimal.tgz
+fi
+
 if [ ! -z $BTAR ] && [ -z $TARDIR ]; then
 	TARDIR=$spath
 fi
@@ -112,11 +118,6 @@
 	exit 0
 fi
 
-if [ -z "$ASHELL" ] && [ -z "$REMOVE" ] && [ -z "$PACKAGES" ]; then
-	c_info "No packages specified, so I'm going to build/install all packages (--fullbuild)"
-	config_full_build
-fi
-
 if [[ ! -z ${TARDIR+x} ]] && [[ ! -d $TARDIR ]]; then die 7 "Tar dir specified doesn't exist"; fi
 
 if [ -z $BI ]; then
@@ -198,7 +199,7 @@
 }
 
 function all_done_banner() {
-	c_info "All done! Run \"androdeb shell\" to enter environment"
+	c_info "All done! Run \"adeb shell\" to enter environment"
 }
 
 # Prepare is the last command checked
@@ -218,12 +219,14 @@
 rm -rf $TDIR/*
 TDIR_ABS=$( cd "$TDIR" ; pwd -P )
 
-if [ ! -z "$DOWNLOAD" ]; then
+if [ $DOWNLOAD -eq 1 ]; then
    c_info "Downloading Androdeb from the web..."; c_info ""
+
    # Github dropped tar gz support! ##?#??#! Now we've to zip everything.
-   curl -L https://github.com/joelagnel/androdeb/releases/download/$VERSION/androdeb-fs.tgz.zip --output $TDIR_ABS/androdeb-fs.tgz.zip;
-   unzip -e $TDIR_ABS/androdeb-fs.tgz.zip -d $TDIR_ABS/
-   TARF=$TDIR_ABS/androdeb-fs.tgz; fi
+   curl -L https://github.com/joelagnel/androdeb/releases/download/$VERSION/$FNAME --output $TDIR_ABS/$FNAME
+   unzip -e $TDIR_ABS/$FNAME -d $TDIR_ABS/
+   TARF=$TDIR_ABS/$FNAME_UZ
+fi
 
 OUT_TMP=$TDIR/debian; rm -rf $OUT_TMP; mkdir -p $OUT_TMP
 
@@ -312,13 +315,21 @@
 	$ADB shell /data/androdeb/run-command /bcc-master/build-bcc.sh;
 fi
 
-do_cleanup
-
 # Extract a tar of the built, compiled and installed androdeb env
 if [[ ! -z ${TARDIR+x} ]]; then
-	c_info "Creating and pulling tarball of androdeb env from device"
-	$ADB shell /data/androdeb/build-debian-tar
-	$ADB pull /data/androdeb/androdeb-fs.tgz $TARDIR/
-	$ADB shell rm /data/androdeb/androdeb-fs.tgz; fi
+	c_info "Creating tarball"
+	pushd $TARDIR
+	if [ $INSTALL_BCC -eq 0 ]; then
+		mv $TDIR/deb.tar.gz $FNAME_UZ
+	else
+		$ADB shell /data/androdeb/build-debian-tar
+		$ADB pull /data/androdeb/androdeb-fs.tgz $FNAME_UZ
+		$ADB shell rm /data/androdeb/androdeb-fs.tgz;
+	fi
+	zip -r $FNAME $FNAME_UZ
+	popd
+fi
+
+do_cleanup
 
 all_done_banner
diff --git a/buildstrap b/buildstrap
index b046d20..0aaa635 100755
--- a/buildstrap
+++ b/buildstrap
@@ -12,8 +12,9 @@
 EXTRA_FILES="$(cat $6)"
 INSTALL_BCC=$7
 SKIP_DEVICE=$8		# Skip any device-specific stages
+VARIANT="--variant=minbase"
 
-time qemu-debootstrap --arch $ARCH --include=$PACKAGES \
+time qemu-debootstrap --arch $ARCH --include=$PACKAGES $VARIANT \
 	$DISTRO $OUT_TMP http://deb.debian.org/debian/
 
 # Some reason debootstrap leaves these mounted
diff --git a/utils/banners b/utils/banners
index 491d324..5f975bc 100755
--- a/utils/banners
+++ b/utils/banners
@@ -2,6 +2,11 @@
 
 print_prepare_banner() {
 	c_info "Preparing device..."
+	if [ $FULL -eq 1 ]; then
+		c_info "Doing a full install."
+	else
+		c_info "Doing a base install."
+	fi
 	c_info ""
 }
 
@@ -15,29 +20,39 @@
 	c_info "	push		Copy files to the androdeb filesystem in the device"
 	c_info ""
 	c_info "	prepare		Prepare the device (when running for the first time)"
-	c_info "	--tracers	Enable tracing packages (perf and trace-cmd)"
-	c_info "	--compilers	Enable compilers on the FS (gcc and clang)"
-	c_info "	--editors	Enable vim, emacs and git packages"
-	c_info "	--scheduler	scheduler testing tools (only rt-app for now)"
+	c_info "			By default, this will download and install a base image."
+	c_info "	** Folowing are the prepare options **"
+	c_info "	  --full	Pass this to prepare to download and install the full image which"
+	c_info "			contains compilers, editors, tracers etc."
 	c_info ""
-	c_info "	--fullbuild	Enable all of the above tools (no BCC)"
+	c_info "	  --build	Instead of download, build and install the image onto the device"
 	c_info ""
-	c_info "	--download	Download full FS archive from web (overrides all tools specified)"
-	c_info "	--archive	Use archive for root fs (overrides all other prepare options)"
-	c_info "	--build-image	Build an ext4 .img with the base image and BCC (useful for Qemu)"
+	c_info "	  --archive	Use archive for root fs (overrides all other prepare options)"
 	c_info ""
-	c_info "	--bcc		Build and install BCC from source"
-	c_info "	--kernelsrc	Extract kernel headers for BCC from here"
-	c_info "	--skip-install	Pass this along if only header install is needed"
+	c_info "	  --buildtar	While preparing, also build a tar.gz.zip file of the filesystem,"
+	c_info "				this is how images that are downloaded by prepare are built"
 	c_info ""
-	c_info "	--tempdir	Use a specific temporary directory for build operation"
-	c_info "	--buildtar	Local directory to store tarball of androdeb env from device"
-	c_info "	--distro	Debian distro to base on (default is buster)"
+	c_info "	  --build-image	Build an ext4 .img with the base image and BCC (useful for Qemu)"
+	c_info ""
+	c_info "	** Folowing are misc build options **"
+	c_info "	  --tempdir	Use a specific temporary directory for build operation"
+	c_info "	  --arch		Specify an ARCH to build for (default arm64)"
+	c_info "	  --distro	Debian distro to base on (default is buster)"
+	c_info ""
+	c_info "	** Folowing are the options for BCC **"
+	c_info "	  --bcc		Build and install BCC onto the device, from source"
+	c_info "			BCC is already included in 'prepare --full'"
+	c_info ""
+	c_info "	  --kernelsrc	 Extract kernel headers for BCC from this directory"
+	c_info ""
+	c_info "	  --skip-install Pass this to --kernelsrc if you wish to only extra/install kernel headers"
+	c_info "			 and would like to exit after that (skips build/install of everything else)"
+	c_info ""
+	c_info "	** Folowing are device specific options ** "
 	c_info "	--device	Serial number of adb device."
 	c_info "	      -s	Serial number of adb device."
 	c_info ""
-	c_info "	--debug"
-	c_info "	--arch		Specify an ARCH to build for (default arm64)"
+	c_info "	--debug		Debug all execution."
 	exit 1
 }