blob: 031f2b674c0eb594e276c46f987265ab73e6701f [file] [log] [blame]
Joel Fernandes6c1ca312018-03-30 17:13:15 -07001#!/bin/bash -e
Joel Fernandesefe6c4c2018-04-01 21:24:02 -07002#
Joel Fernandes1ed30d72018-05-18 14:08:20 -07003# (c) Joel Fernandes <joel@joelfernandes.org>
Joel Fernandesefe6c4c2018-04-01 21:24:02 -07004
Erick Reyesdd195c02018-08-16 14:50:47 -07005VERSION=v0.99g
Joel Fernandesa67be0b2018-04-01 13:40:34 -07006
Joel Fernandes464193e2018-04-02 23:54:49 -07007spath="$(dirname "$(readlink -f "$0")")"
8# spath=$( cd "$(dirname "$0")" ; pwd -P )
Joel Fernandes4fb97ea2018-03-31 11:15:19 -07009curdir=$( pwd -P )
Joel Fernandes4e19ccd2018-07-08 17:23:07 -070010source $spath/utils/support
Joel Fernandesca8fb552018-04-01 13:48:16 -070011source $spath/utils/banners
Joel Fernandes83676b12018-03-30 23:33:47 -070012
Joel Fernandes6c1ca312018-03-30 17:13:15 -070013# Set default vars
Joel Fernandesf0c54092018-04-01 19:05:10 -070014DISTRO=buster; ARCH=arm64
Joel Fernandes02939a32018-04-02 22:18:10 -070015ADB="adb"
Joel Fernandes6975db22018-07-11 20:53:16 -070016FULL=0 # Default to a minimal install
17DOWNLOAD=1 # Default to downloading from web
Joel Fernandesfdc52002018-07-08 18:49:20 -070018SKIP_DEVICE=0 # Skip device preparation
Joel Fernandesffcbfe42018-07-08 19:08:02 -070019INSTALL_BCC=0 # Decide if BCC is to be installed
Joel Fernandesf0c54092018-04-01 19:05:10 -070020
21# Default packages
Joel Fernandes6975db22018-07-11 20:53:16 -070022PACKAGES=""
23DEFAULT_PACKAGES="bash ca-certificates apt net-tools iputils-ping procps vim"
Joel Fernandes (Google)4f711082018-05-29 16:23:15 -070024
Joel Fernandes (Google)4b216fd2018-05-29 12:33:27 -070025EXTRA_FILES="none"
Joel Fernandes6c1ca312018-03-30 17:13:15 -070026
Joel Fernandesab5f9282018-04-05 22:53:23 -070027config_full_build() {
Joel Fernandes (Google)d7f21f12018-05-27 20:19:51 -070028 for f in $(ls $spath/packages); do source $spath/packages/$f; done;
Joel Fernandesab5f9282018-04-05 22:53:23 -070029}
30
Joel Fernandes6c1ca312018-03-30 17:13:15 -070031# Parse command line parameters
Joel Fernandes5b4be9c2018-03-30 23:58:27 -070032if [ $# -lt 1 ]; then usage; fi; POSITIONAL=()
Joel Fernandes4fb97ea2018-03-31 11:15:19 -070033while [[ $# -gt 0 ]]; do key="$1";
Joel Fernandesccb993f2018-07-02 19:59:04 -070034
35# If its shell mode, any future args become shell's args
36if [ "x$ASHELL" == "x1" ]; then
37 if [ -z "$SHELL_ARGS" ]; then
38 SHELL_ARGS=$key
39 else
40 SHELL_ARGS="$SHELL_ARGS $key"
41 fi
42 shift || true; continue
43fi
44
Erick Reyesde9be052018-08-02 20:08:28 -070045KERNEL_HEADERS_NEEDED=0
46
Joel Fernandes6c1ca312018-03-30 17:13:15 -070047case $key in
Joel Fernandese2a04662018-03-31 19:33:23 -070048 shell) ASHELL=1; shift || true; ;;
Joel Fernandesb4c80a62018-04-02 22:37:22 -070049 remove) REMOVE=1; shift || true; ;;
Erick Reyese25caea2018-06-19 15:42:59 -070050 git-pull) GIT_PULL=1; shift || true; ;;
51 pull) PULL=1; shift || true; break ;;
Erick Reyes5104a6c2018-06-27 15:31:58 -070052 push) PUSH=1; shift || true; break ;;
Joel Fernandes6975db22018-07-11 20:53:16 -070053 prepare) PREPARE=1; shift || true; ;;
54 --full) FULL=1; config_full_build; shift || true; ;;
Joel Fernandes (Google)08d1a072018-05-28 13:29:03 -070055 --arch) ARCH=$2; shift || true; shift || true; ;;
Joel Fernandes (Google)387c8952018-07-25 16:27:49 -070056 --archive) DOWNLOAD=0; TARF=$2; shift || true; shift || true; ;;
Erick Reyesde9be052018-08-02 20:08:28 -070057 --bcc) source $spath/packages/bcc; KERNEL_HEADERS_NEEDED=1; shift || true; ;;
Joel Fernandes5b4be9c2018-03-30 23:58:27 -070058 --kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;;
Joel Fernandes (Google)1171d2d2018-05-30 17:22:09 -070059 --skip-install) SKIP_INSTALL=1; shift || true; ;;
Joel Fernandes1ed30d72018-05-18 14:08:20 -070060 --kernel-headers-targz) KERNELHDRS=$2; shift || true; shift || true; ;;
Joel Fernandese2a04662018-03-31 19:33:23 -070061 --tempdir) TDIR="$2"; shift || true; shift || true; ;;
Joel Fernandes6975db22018-07-11 20:53:16 -070062 --build) DOWNLOAD=0; shift || true; ;;
63 --buildtar) BTAR=1; DOWNLOAD=0; TARDIR="$2"; shift || true; shift || true; ;;
Joel Fernandes02939a32018-04-02 22:18:10 -070064 --device|-s) ADB="$ADB -s $2"; shift || true; shift || true; ;;
Joel Fernandesfdc52002018-07-08 18:49:20 -070065 --build-image) BI=1; BUILD_IMAGEF=$2; SKIP_DEVICE=1; shift || true; shift || true; ;;
Joel Fernandesca8fb552018-04-01 13:48:16 -070066 --debug) set -x; shift || true; ;;
Joel Fernandes112243b2018-07-08 17:42:48 -070067 *) c_error "Unknown option ($1)"; usage; ;;
Joel Fernandes6c1ca312018-03-30 17:13:15 -070068esac
69done
70
Joel Fernandesc7551962018-07-10 14:12:19 -070071[ -z $ASHELL ] && box_out "adeb: $VERSION"
Joel Fernandesdd102af2018-07-08 19:38:42 -070072
Joel Fernandes6975db22018-07-11 20:53:16 -070073if [ $FULL -eq 1 ]; then
74 FNAME=androdeb-fs.tgz.zip
75 FNAME_UZ=androdeb-fs.tgz
Erick Reyesde9be052018-08-02 20:08:28 -070076 KERNEL_HEADERS_NEEDED=1
Joel Fernandes6975db22018-07-11 20:53:16 -070077else
78 FNAME=androdeb-fs-minimal.tgz.zip
79 FNAME_UZ=androdeb-fs-minimal.tgz
80fi
81
Joel Fernandesddd28032018-07-08 23:13:17 -070082if [ ! -z $BTAR ] && [ -z $TARDIR ]; then
83 TARDIR=$spath
84fi
85
Erick Reyese25caea2018-06-19 15:42:59 -070086if [ ! -z "$GIT_PULL" ]; then
Joel Fernandes112243b2018-07-08 17:42:48 -070087 c_info "Updating androdeb by git pull"
Joel Fernandes16371152018-04-05 22:50:36 -070088 cd $spath
89 git pull
Joel Fernandes112243b2018-07-08 17:42:48 -070090 c_info "Done."
Joel Fernandes16371152018-04-05 22:50:36 -070091 exit 0
92fi
93
Erick Reyese25caea2018-06-19 15:42:59 -070094if [ ! -z "$PULL" ]; then
95 if [ $1 == "-a" ]; then
96 PRESERVE="-a"
Joel Fernandes112243b2018-07-08 17:42:48 -070097 c_info "Preserving filestamps and mode"
Erick Reyese25caea2018-06-19 15:42:59 -070098 shift || true
99 fi
Erick Reyes5104a6c2018-06-27 15:31:58 -0700100 file_count=`count_sources $@`
Erick Reyese25caea2018-06-19 15:42:59 -0700101 i=0
102 while [ $i -lt $file_count ]; do
103 files["$i"]=/data/androdeb/debian/$1
104 shift || true
105 i=$((i + 1))
106 done
107 $ADB pull $PRESERVE "${files[@]}" "$@"
108 exit 0
109fi
110
Erick Reyes5104a6c2018-06-27 15:31:58 -0700111if [ ! -z "$PUSH" ]; then
Erick Reyes5104a6c2018-06-27 15:31:58 -0700112 file_count=`count_sources $@`
113 i=0
114 while [ $i -lt $file_count ]; do
115 files["$i"]=$1
116 shift || true
117 i=$((i + 1))
118 done
119 dest=/data/androdeb/debian/$1
120 $ADB push $sync "${files[@]}" $dest
121 exit 0
122fi
123
Joel Fernandes97958e12018-03-31 23:51:44 -0700124if [[ ! -z ${TARDIR+x} ]] && [[ ! -d $TARDIR ]]; then die 7 "Tar dir specified doesn't exist"; fi
Joel Fernandes92057762018-03-31 23:38:43 -0700125
Joel Fernandesfdc52002018-07-08 18:49:20 -0700126if [ -z $BI ]; then
Joel Fernandesdd102af2018-07-08 19:38:42 -0700127 [ -z $ASHELL ] && c_info "Looking for device.."
Joel Fernandes (Google)9ed573a2018-07-25 16:07:55 -0700128 set +e
Joel Fernandesc26696d2018-07-08 18:28:12 -0700129 do_adb_root "$ADB"
Joel Fernandesaf07ec72018-04-02 22:01:19 -0700130
Joel Fernandesc26696d2018-07-08 18:28:12 -0700131 if [ $? -ne 0 ]; then
132 c_error "adb root failed, make sure:"
133 c_error " * If multiple devices connected, provide --device <serialno> (or -s <serialno>)"
134 c_error " * Try to run \"adb root\" manually and see if it works. Typically this needs a userdebug build."
135 c_error ""
136 c_error "Note: adb can be typically obtained using the android-tools-adb or the adb"
137 c_error "packages on your distro, or by installing the Android SDK."
138 die 3 "Exiting."
139 fi
Joel Fernandes (Google)9ed573a2018-07-25 16:07:55 -0700140 set -e
Joel Fernandesfdc52002018-07-08 18:49:20 -0700141else
142 [ ! -z $BUILD_IMAGEF ] || die 8 "--build-image passed but no image file provided"
Joel Fernandes (Google)9c3ae932018-05-28 14:34:48 -0700143fi
Joel Fernandes72656c52018-03-31 20:35:33 -0700144
Joel Fernandesb4c80a62018-04-02 22:37:22 -0700145if [ ! -z "$REMOVE" ]; then
146 die_if_no_androdeb "Nothing to remove."
Joel Fernandes (Google)7c8b1082018-06-25 12:29:10 -0700147 $ADB shell /data/androdeb/device-umount-all || true;
Joel Fernandesb4c80a62018-04-02 22:37:22 -0700148 $ADB shell rm -rf /data/androdeb; exit 0; fi
149
Joel Fernandes83676b12018-03-30 23:33:47 -0700150##########################################################
Joel Fernandese2a04662018-03-31 19:33:23 -0700151# SHELL
Joel Fernandes83676b12018-03-30 23:33:47 -0700152##########################################################
Joel Fernandese381ac72018-03-31 21:46:36 -0700153if [ ! -z ${ASHELL+x} ]; then
Joel Fernandes02939a32018-04-02 22:18:10 -0700154 set +e; $ADB shell ls /data/androdeb/debian/.bashrc > /dev/null 2>&1
Joel Fernandesc9646812018-03-31 19:45:46 -0700155 if [ $? -ne 0 ]; then
156 die 2 "Device doesn't have an androdeb environment, run \"./androdeb prepare\" first";
157 fi; set -e
158
Joel Fernandesccb993f2018-07-02 19:59:04 -0700159 if [ ! -z ${SHELL_ARGS+x} ]; then
160 # Explanation of quotes:
161 # Outer quote is so that androdeb's bash passes the SHELL_ARGS as a single
162 # argument to $ADB shell. Inner quotes is so that run-command can receive all
163 # the args even though they may be separated by spaces. \m/
164 $ADB shell -t /data/androdeb/run-command "\"$SHELL_ARGS\""
165 else
166 $ADB shell -t /data/androdeb/run
167 fi
168
Joel Fernandese2a04662018-03-31 19:33:23 -0700169 exit 0
170fi
171
172##########################################################
173# PREPARE
174##########################################################
Joel Fernandesf0c54092018-04-01 19:05:10 -0700175
176function do_cleanup() {
177 rm -rf $TDIR/*; if [ $MKTEMP -eq 1 ]; then rm -rf $TDIR; fi
178}
179
180function push_unpack_headers() {
Joel Fernandesb4c80a62018-04-02 22:37:22 -0700181 die_if_no_androdeb "Couldn't update headers."
Joel Fernandesf0c54092018-04-01 19:05:10 -0700182
Joel Fernandesf95f2b22018-07-08 17:54:47 -0700183 c_info "Storing kernel headers into androdeb /kernel-headers/"
Joel Fernandes02939a32018-04-02 22:18:10 -0700184 $ADB shell rm -rf /data/androdeb/debian/kernel-headers/
185 $ADB shell mkdir /data/androdeb/debian/kernel-headers/
Joel Fernandesf95f2b22018-07-08 17:54:47 -0700186 run_quiet $ADB push $TDIR_ABS/kh.tgz /data/androdeb/
Joel Fernandes02939a32018-04-02 22:18:10 -0700187 $ADB shell tar -xvf /data/androdeb/kh.tgz -C /data/androdeb/debian/kernel-headers/ > /dev/null
188 $ADB shell rm /data/androdeb/kh.tgz
Joel Fernandesf0c54092018-04-01 19:05:10 -0700189}
190
Joel Fernandes1ed30d72018-05-18 14:08:20 -0700191function push_unpack_tarred_headers() {
192 die_if_no_androdeb "Couldn't update headers."
193
194 $ADB shell rm -rf /data/androdeb/debian/kernel-headers/
195 $ADB shell mkdir /data/androdeb/debian/kernel-headers/
Joel Fernandesf95f2b22018-07-08 17:54:47 -0700196
197 c_info "Pushing headers tar onto device"
198 run_quiet $ADB push $1 /data/androdeb/
199
Joel Fernandes112243b2018-07-08 17:42:48 -0700200 c_info "Storing kernel headers into androdeb root directory"
Joel Fernandes1ed30d72018-05-18 14:08:20 -0700201 $ADB shell tar -xvf /data/androdeb/$(basename $1) -C /data/androdeb/debian/ > /dev/null
202
203 $ADB shell rm /data/androdeb/$(basename $1)
204}
205
Joel Fernandes72065112018-04-01 20:02:53 -0700206function all_done_banner() {
Joel Fernandes6975db22018-07-11 20:53:16 -0700207 c_info "All done! Run \"adeb shell\" to enter environment"
Joel Fernandes72065112018-04-01 20:02:53 -0700208}
209
Erick Reyesde9be052018-08-02 20:08:28 -0700210function check_repo_url () {
211 if [ -z $ADEB_REPO_URL ]; then
212 c_warning "Automatic download is disabled. To enable it, please set the \$ADEB_REPO_URL"
213 c_warning "environment variable as recommended in the setup instructions in the README.md"
214 do_cleanup
215 exit 0
216 fi
217}
218
219function download_headers() {
220 KERNEL_MAJOR=`$ADB shell uname -r | cut -d - -f 1 | cut -d . -f 1`
221 KERNEL_MINOR=`$ADB shell uname -r | cut -d - -f 1 | cut -d . -f 2`
222 KERNEL_VERSION="$KERNEL_MAJOR.$KERNEL_MINOR"
Erick Reyesdd195c02018-08-16 14:50:47 -0700223 PREBUILT_HEADERS_FILE=headers-$ARCH-$KERNEL_VERSION.tar.gz.zip
Erick Reyesde9be052018-08-02 20:08:28 -0700224
225 check_repo_url
226
Erick Reyesdd195c02018-08-16 14:50:47 -0700227 curl -L https://$ADEB_REPO_URL/releases/download/$VERSION/$PREBUILT_HEADERS_FILE --output $TDIR_ABS/$PREBUILT_HEADERS_FILE ||
228 die 9 "Failed to download kernel headers. Please check your internet connection and repository URL"
Erick Reyesde9be052018-08-02 20:08:28 -0700229
230 unzip -e $TDIR_ABS/$PREBUILT_HEADERS_FILE -d $TDIR_ABS/ ||
Erick Reyesdd195c02018-08-16 14:50:47 -0700231 die 10 "Failed to download kernel headers. Kernel $KERNEL_VERSION for $ARCH may not be supported or ADEB_REPO_URL is incorrect."
Erick Reyesde9be052018-08-02 20:08:28 -0700232 KERNELHDRS=$TDIR_ABS/`echo "$PREBUILT_HEADERS_FILE" | sed "s/.zip//"`
233}
234
Joel Fernandes72656c52018-03-31 20:35:33 -0700235# Prepare is the last command checked
Joel Fernandes9f00bf42018-04-01 10:36:33 -0700236if [ -z "$PREPARE" ]; then usage; fi
Joel Fernandes72656c52018-03-31 20:35:33 -0700237
Joel Fernandes1ed30d72018-05-18 14:08:20 -0700238if [ ! -z "$TARF" ] && [ ! -f $TARF ] && [ -z "$DOWNLOAD" ]; then die 5 "archive provided doesn't exist"; fi
Joel Fernandes9f00bf42018-04-01 10:36:33 -0700239
Joel Fernandes1ed30d72018-05-18 14:08:20 -0700240if [ ! -z "$KERNELSRC" ] && [ ! -d $KERNELSRC ]; then die 6 "Kernel source directory provided doesn't exist"; fi
241
242if [ ! -z "$KERNELHDRS" ] && [ ! -f $KERNELHDRS ]; then die 7 "Kernel headers tar.gz doesn't exist"; fi
Joel Fernandese2a04662018-03-31 19:33:23 -0700243
Joel Fernandesca8fb552018-04-01 13:48:16 -0700244print_prepare_banner
245
Joel Fernandes6c1ca312018-03-30 17:13:15 -0700246# Where do we want to store temporary files
Joel Fernandese2a04662018-03-31 19:33:23 -0700247MKTEMP=0; if [[ -z ${TDIR+x} ]] || [[ ! -d "${TDIR}" ]]; then
248 TDIR=`mktemp -d`; MKTEMP=1; fi
Joel Fernandese381ac72018-03-31 21:46:36 -0700249rm -rf $TDIR/*
250TDIR_ABS=$( cd "$TDIR" ; pwd -P )
Joel Fernandes6c1ca312018-03-30 17:13:15 -0700251
Joel Fernandes6975db22018-07-11 20:53:16 -0700252if [ $DOWNLOAD -eq 1 ]; then
Joel Fernandes112243b2018-07-08 17:42:48 -0700253 c_info "Downloading Androdeb from the web..."; c_info ""
Joel Fernandes6975db22018-07-11 20:53:16 -0700254
Joel Fernandes (Google)9e670aa2018-06-25 13:39:34 -0700255 # Github dropped tar gz support! ##?#??#! Now we've to zip everything.
Erick Reyesde9be052018-08-02 20:08:28 -0700256 check_repo_url
Joel Fernandes (Google)db9005f2018-07-25 16:44:12 -0700257
Erick Reyesdd195c02018-08-16 14:50:47 -0700258 curl -L https://$ADEB_REPO_URL/releases/download/$VERSION/$FNAME --output $TDIR_ABS/$FNAME ||
Joel Fernandes (Google)db9005f2018-07-25 16:44:12 -0700259 die 9 "Failed to download adeb release."
260
261 unzip -e $TDIR_ABS/$FNAME -d $TDIR_ABS/ ||
262 die 10 "Failed to download adeb release. Double check the ADEB_REPO_URL value."
Joel Fernandes6975db22018-07-11 20:53:16 -0700263 TARF=$TDIR_ABS/$FNAME_UZ
264fi
Joel Fernandesa67be0b2018-04-01 13:40:34 -0700265
Erick Reyesdd195c02018-08-16 14:50:47 -0700266if [ ! -z "$KERNEL_HEADERS_NEEDED" ] && [ -z "$KERNELSRC" ] && [ -z "$KERNELHDRS" ]; then
Erick Reyesde9be052018-08-02 20:08:28 -0700267 c_info "Kernel headers are needed but none were provided. Downloading pre-built headers"
268 download_headers
269fi
270
Joel Fernandese2a04662018-03-31 19:33:23 -0700271OUT_TMP=$TDIR/debian; rm -rf $OUT_TMP; mkdir -p $OUT_TMP
Joel Fernandesf0c54092018-04-01 19:05:10 -0700272
Joel Fernandes1ed30d72018-05-18 14:08:20 -0700273# Unpack the supplied kernel headers tar.gz directly into androdeb root
274if [ ! -z "$KERNELHDRS" ]; then
Joel Fernandes112243b2018-07-08 17:42:48 -0700275 c_info "Building updating kernel headers from supplied tar.gz ($KERNELHDRS)"
Joel Fernandes1ed30d72018-05-18 14:08:20 -0700276
277 # Is header tar gz update the only thing left to do?
Joel Fernandes (Google)1171d2d2018-05-30 17:22:09 -0700278 if [[ ! -z "$SKIP_INSTALL" ]]; then
Joel Fernandes112243b2018-07-08 17:42:48 -0700279 c_info "Skipping install"
Joel Fernandes1ed30d72018-05-18 14:08:20 -0700280 push_unpack_tarred_headers $KERNELHDRS; do_cleanup; all_done_banner; exit 0; fi
281
282 tar -xvf $KERNELHDRS -C $OUT_TMP/ > /dev/null
283fi
284
Joel Fernandesf0c54092018-04-01 19:05:10 -0700285# Package kernel headers
286if [ ! -z "$KERNELSRC" ]; then
Joel Fernandes112243b2018-07-08 17:42:48 -0700287 c_info "Building and updating kernel headers from kernel source dir ($KERNELSRC)"
Joel Fernandes72065112018-04-01 20:02:53 -0700288 $spath/bcc/build-kheaders-targz.sh ${KERNELSRC} $TDIR_ABS/kh.tgz > /dev/null
289
Joel Fernandesf0c54092018-04-01 19:05:10 -0700290 # Is header update the only thing left to do?
Joel Fernandes (Google)1171d2d2018-05-30 17:22:09 -0700291 if [[ ! -z "$SKIP_INSTALL" ]]; then
Joel Fernandes112243b2018-07-08 17:42:48 -0700292 c_info "Skipping install"
Joel Fernandes72065112018-04-01 20:02:53 -0700293 push_unpack_headers; do_cleanup; all_done_banner; exit 0; fi
Joel Fernandesf0c54092018-04-01 19:05:10 -0700294
Joel Fernandese381ac72018-03-31 21:46:36 -0700295 mkdir $OUT_TMP/kernel-headers
Joel Fernandes72065112018-04-01 20:02:53 -0700296 tar -xvf $TDIR_ABS/kh.tgz -C $OUT_TMP/kernel-headers/ > /dev/null
Joel Fernandese381ac72018-03-31 21:46:36 -0700297fi
Joel Fernandes4fb97ea2018-03-31 11:15:19 -0700298
Joel Fernandesf0c54092018-04-01 19:05:10 -0700299# Build FS from existing tar, very simple.
Joel Fernandes9f00bf42018-04-01 10:36:33 -0700300if [ ! -z "$TARF" ]; then
Joel Fernandes112243b2018-07-08 17:42:48 -0700301 c_info "Using archive at $TARF for filesystem preparation"
Joel Fernandes02939a32018-04-02 22:18:10 -0700302 $ADB shell mkdir -p /data/androdeb/
Joel Fernandesf95f2b22018-07-08 17:54:47 -0700303
304 c_info "Pushing filesystem to device.."
305 run_quiet $ADB push $TARF /data/androdeb/deb.tar.gz
306
307 c_info "Pushing addons to device.."
308 run_quiet $ADB push $spath/addons/* /data/androdeb/
309
310 c_info "Unpacking filesystem in device.."
311 run_quiet $ADB shell /data/androdeb/device-unpack
Joel Fernandes9f00bf42018-04-01 10:36:33 -0700312
Joel Fernandes1ed30d72018-05-18 14:08:20 -0700313 if [ ! -z "$KERNELHDRS" ]; then push_unpack_tarred_headers $KERNELHDRS; fi
Joel Fernandesf0c54092018-04-01 19:05:10 -0700314 if [ ! -z "$KERNELSRC" ]; then push_unpack_headers; fi
315
Joel Fernandes72065112018-04-01 20:02:53 -0700316 do_cleanup; all_done_banner; exit 0
Joel Fernandesf0c54092018-04-01 19:05:10 -0700317fi
318
319PACKAGES+="$DEFAULT_PACKAGES"
Joel Fernandes112243b2018-07-08 17:42:48 -0700320c_info "Using temporary directory: $TDIR"
Joel Fernandes4fb97ea2018-03-31 11:15:19 -0700321
Joel Fernandes112243b2018-07-08 17:42:48 -0700322if [[ $EUID -ne 0 ]]; then c_info "The next stage runs as sudo, please enter password if asked."; fi
Joel Fernandes4fb97ea2018-03-31 11:15:19 -0700323
Joel Fernandes (Google)57b3fd22018-05-29 16:27:03 -0700324ex_files=$(mktemp); echo $EXTRA_FILES > $ex_files
325
Joel Fernandes (Google)4f711082018-05-29 16:23:15 -0700326sudo $spath/buildstrap $ARCH $DISTRO $TDIR $OUT_TMP \
327 "$(make_csv "$PACKAGES")"\
Joel Fernandesfdc52002018-07-08 18:49:20 -0700328 $ex_files $INSTALL_BCC $SKIP_DEVICE
Joel Fernandes (Google)57b3fd22018-05-29 16:27:03 -0700329rm $ex_files
Joel Fernandes (Google)9c3ae932018-05-28 14:34:48 -0700330
331# If we only wanted to prepare a rootfs and don't have
332# a device connected, then just echo that and skip cleanup
Joel Fernandesfdc52002018-07-08 18:49:20 -0700333if [ $SKIP_DEVICE -eq 1 ]; then
334 c_info "Device preparation is being skipped for the selected options"
Joel Fernandesba7214e2018-07-08 18:15:49 -0700335 c_info "any builds that need to happen on device may be cloned but not built."
Joel Fernandes47ef2152018-07-08 19:13:51 -0700336
337 if [ ! -z $BI ]; then
338 sudo $spath/buildimage $OUT_TMP $(dirname $BUILD_IMAGEF)/$(basename $BUILD_IMAGEF)
339 sudo chmod a+rw $(dirname $BUILD_IMAGEF)/$(basename $BUILD_IMAGEF)
Joel Fernandes9a38e602018-07-08 19:26:32 -0700340 c_info "Your .img has been built! Enjoy!"
Joel Fernandes47ef2152018-07-08 19:13:51 -0700341 fi
Joel Fernandesba7214e2018-07-08 18:15:49 -0700342
343 do_cleanup
Joel Fernandes9a38e602018-07-08 19:26:32 -0700344 exit 0
Joel Fernandes (Google)9c3ae932018-05-28 14:34:48 -0700345fi
Joel Fernandes4dd60862018-03-31 13:27:16 -0700346
347# Push tar to device and start unpack
Joel Fernandes02939a32018-04-02 22:18:10 -0700348$ADB shell mkdir -p /data/androdeb/
349$ADB push $TDIR/deb.tar.gz /data/androdeb/
350$ADB push $spath/addons/* /data/androdeb/
351$ADB shell /data/androdeb/device-unpack
Joel Fernandesb61d27d2018-03-31 11:59:45 -0700352
Joel Fernandes6f1c70f2018-03-31 20:26:26 -0700353# Build BCC and install bcc on device if needed
Joel Fernandes241160e2018-07-08 23:36:11 -0700354if [ $INSTALL_BCC -eq 1 ]; then
Joel Fernandesffcbfe42018-07-08 19:08:02 -0700355 $ADB shell /data/androdeb/run-command /bcc-master/build-bcc.sh;
356fi
Joel Fernandes4fb97ea2018-03-31 11:15:19 -0700357
Joel Fernandes97958e12018-03-31 23:51:44 -0700358# Extract a tar of the built, compiled and installed androdeb env
359if [[ ! -z ${TARDIR+x} ]]; then
Joel Fernandes6975db22018-07-11 20:53:16 -0700360 c_info "Creating tarball"
361 pushd $TARDIR
362 if [ $INSTALL_BCC -eq 0 ]; then
363 mv $TDIR/deb.tar.gz $FNAME_UZ
364 else
365 $ADB shell /data/androdeb/build-debian-tar
366 $ADB pull /data/androdeb/androdeb-fs.tgz $FNAME_UZ
367 $ADB shell rm /data/androdeb/androdeb-fs.tgz;
368 fi
369 zip -r $FNAME $FNAME_UZ
370 popd
371fi
372
373do_cleanup
Joel Fernandes97958e12018-03-31 23:51:44 -0700374
Joel Fernandes72065112018-04-01 20:02:53 -0700375all_done_banner