external: Allow for a single flag to control all of the fetching

This gives external users the ability to disable all of our fetch flags directly
instead of having to enable each individually every time.

Additionally, this changes our mirror site to the global ftp.debian.org
redirector to reduce the load on the US servers, as well as giving us more
access to proxied connections.

Change-Id: I60eb2cd5bedaee25ff944dccc5bf9836c6099c13
diff --git a/packages.mk b/packages.mk
index a61305c..5bdcfda 100644
--- a/packages.mk
+++ b/packages.mk
@@ -26,7 +26,7 @@
 	mkdir -p $(ROOTDIR)/cache
 	sudo pbuilder create \
 		--basetgz $@ \
-		--mirror http://http.us.debian.org/debian \
+		--mirror http://ftp.debian.org/debian \
 		--distribution stretch \
 		--architecture amd64 \
 		--extrapackages crossbuild-essential-arm64 debhelper
@@ -132,7 +132,10 @@
 $(eval $(call make-pbuilder-package-target,base-files,packages/base-files))
 
 $(eval $(call make-pbuilder-package-target,libedgetpu,libedgetpu))
+
+ifneq ($(IS_EXTERNAL),)
 $(eval $(call make-pbuilder-package-target,edgetpu-api,packages/edgetpu-api,libedgetpu))
+endif
 
 ALL_PACKAGE_TARGETS := $(PBUILDER_TARGETS)
 packages-tarball: $(ROOTDIR)/cache/packages.tgz
diff --git a/pbuilderrc b/pbuilderrc
index 38357ce..261e7be 100644
--- a/pbuilderrc
+++ b/pbuilderrc
@@ -4,7 +4,7 @@
 # the default template
 #
 # read pbuilderrc.5 document for notes on specific options.
-MIRRORSITE=http://http.us.debian.org/debian
+MIRRORSITE=http://ftp.debian.org/debian
 PBUILDERSATISFYDEPENDSCMD=/usr/lib/pbuilder/pbuilder-satisfydepends-apt
 export DEPSBASE=$PRODUCT_OUT/packages
 BINDMOUNTS="$DEPSBASE $ROOTDIR"
diff --git a/preamble.mk b/preamble.mk
index 4f675f5..1748138 100644
--- a/preamble.mk
+++ b/preamble.mk
@@ -15,6 +15,16 @@
 # Preamble. Don't define any targets in this file! This is effectively just a
 # common header where useful global vars go.
 
+ifneq ($(IS_EXTERNAL),)
+    DOCKER_FETCH_TARBALL := false
+    FETCH_PBUILDER_BASE := false
+    ROOTFS_FETCH_TARBALL := false
+    DEBOOTSTRAP_FETCH_TARBALL := false
+    FETCH_PACKAGES := false
+    PACKAGES_FETCH_ROOT_DIRECTORY := $(ROOTDIR)/cache
+    PACKAGES_REVISION := .
+endif
+
 ifneq (,$(wildcard /etc/dpkg/origins/glinux))
 ifneq (,$(wildcard /google))
 	IS_GLINUX = true
diff --git a/rootfs.mk b/rootfs.mk
index 97ed8fe..92064b6 100644
--- a/rootfs.mk
+++ b/rootfs.mk
@@ -35,11 +35,14 @@
 	base-files \
 	bluetooth \
 	bluez \
-	edgetpu-api \
 	libbluetooth3 \
 	libedgetpu \
 	uboot-imx
 
+ifneq ($(IS_EXTERNAL),)
+BASE_PACKAGES += edgetpu-api
+endif
+
 GUI_PACKAGES := \
 	gstreamer1.0-alsa \
 	gstreamer1.0-plugins-bad \
@@ -117,7 +120,9 @@
 	-sudo umount $(ROOTFS_DIR)/boot
 	-sudo umount $(ROOTFS_DIR)
 	sudo mount -o loop $(ROOTFS_PATCHED_IMG).wip $(ROOTFS_DIR)
+	-sudo mkdir -p $(ROOTFS_DIR)/boot
 	sudo mount -o loop $(PRODUCT_OUT)/boot.img $(ROOTFS_DIR)/boot
+	-sudo mkdir -p $(ROOTFS_DIR)/dev
 	sudo mount -o bind /dev $(ROOTFS_DIR)/dev
 	sudo cp /usr/bin/qemu-aarch64-static $(ROOTFS_DIR)/usr/bin