Joel Fernandes | 6c1ca31 | 2018-03-30 17:13:15 -0700 | [diff] [blame] | 1 | #!/bin/bash -e |
Joel Fernandes | efe6c4c | 2018-04-01 21:24:02 -0700 | [diff] [blame] | 2 | # |
Joel Fernandes | 1ed30d7 | 2018-05-18 14:08:20 -0700 | [diff] [blame] | 3 | # (c) Joel Fernandes <joel@joelfernandes.org> |
Joel Fernandes | efe6c4c | 2018-04-01 21:24:02 -0700 | [diff] [blame] | 4 | |
Joel Fernandes | 5ac823f | 2018-07-08 14:04:31 -0700 | [diff] [blame] | 5 | VERSION=v0.99e |
Joel Fernandes | a67be0b | 2018-04-01 13:40:34 -0700 | [diff] [blame] | 6 | |
Joel Fernandes | 464193e | 2018-04-02 23:54:49 -0700 | [diff] [blame] | 7 | spath="$(dirname "$(readlink -f "$0")")" |
| 8 | # spath=$( cd "$(dirname "$0")" ; pwd -P ) |
Joel Fernandes | 4fb97ea | 2018-03-31 11:15:19 -0700 | [diff] [blame] | 9 | curdir=$( pwd -P ) |
Joel Fernandes | 4e19ccd | 2018-07-08 17:23:07 -0700 | [diff] [blame] | 10 | source $spath/utils/support |
Joel Fernandes | ca8fb55 | 2018-04-01 13:48:16 -0700 | [diff] [blame] | 11 | source $spath/utils/banners |
Joel Fernandes | 83676b1 | 2018-03-30 23:33:47 -0700 | [diff] [blame] | 12 | |
Joel Fernandes | 6c1ca31 | 2018-03-30 17:13:15 -0700 | [diff] [blame] | 13 | # Set default vars |
Joel Fernandes | f0c5409 | 2018-04-01 19:05:10 -0700 | [diff] [blame] | 14 | DISTRO=buster; ARCH=arm64 |
Joel Fernandes | 02939a3 | 2018-04-02 22:18:10 -0700 | [diff] [blame] | 15 | ADB="adb" |
Joel Fernandes | fdc5200 | 2018-07-08 18:49:20 -0700 | [diff] [blame] | 16 | SKIP_DEVICE=0 # Skip device preparation |
Joel Fernandes | ffcbfe4 | 2018-07-08 19:08:02 -0700 | [diff] [blame] | 17 | INSTALL_BCC=0 # Decide if BCC is to be installed |
Joel Fernandes | f0c5409 | 2018-04-01 19:05:10 -0700 | [diff] [blame] | 18 | |
| 19 | # Default packages |
Joel Fernandes (Google) | 4f71108 | 2018-05-29 16:23:15 -0700 | [diff] [blame] | 20 | DEFAULT_PACKAGES+="bash |
| 21 | ca-certificates" |
| 22 | |
Joel Fernandes (Google) | 4b216fd | 2018-05-29 12:33:27 -0700 | [diff] [blame] | 23 | EXTRA_FILES="none" |
Joel Fernandes | 6c1ca31 | 2018-03-30 17:13:15 -0700 | [diff] [blame] | 24 | |
Joel Fernandes | ab5f928 | 2018-04-05 22:53:23 -0700 | [diff] [blame] | 25 | config_full_build() { |
Joel Fernandes (Google) | d7f21f1 | 2018-05-27 20:19:51 -0700 | [diff] [blame] | 26 | for f in $(ls $spath/packages); do source $spath/packages/$f; done; |
Joel Fernandes | ab5f928 | 2018-04-05 22:53:23 -0700 | [diff] [blame] | 27 | } |
| 28 | |
Joel Fernandes | 6c1ca31 | 2018-03-30 17:13:15 -0700 | [diff] [blame] | 29 | # Parse command line parameters |
Joel Fernandes | 5b4be9c | 2018-03-30 23:58:27 -0700 | [diff] [blame] | 30 | if [ $# -lt 1 ]; then usage; fi; POSITIONAL=() |
Joel Fernandes | 4fb97ea | 2018-03-31 11:15:19 -0700 | [diff] [blame] | 31 | while [[ $# -gt 0 ]]; do key="$1"; |
Joel Fernandes | ccb993f | 2018-07-02 19:59:04 -0700 | [diff] [blame] | 32 | |
| 33 | # If its shell mode, any future args become shell's args |
| 34 | if [ "x$ASHELL" == "x1" ]; then |
| 35 | if [ -z "$SHELL_ARGS" ]; then |
| 36 | SHELL_ARGS=$key |
| 37 | else |
| 38 | SHELL_ARGS="$SHELL_ARGS $key" |
| 39 | fi |
| 40 | shift || true; continue |
| 41 | fi |
| 42 | |
Joel Fernandes | 6c1ca31 | 2018-03-30 17:13:15 -0700 | [diff] [blame] | 43 | case $key in |
Joel Fernandes (Google) | 448a174 | 2018-05-29 12:23:18 -0700 | [diff] [blame] | 44 | prepare) PREPARE=1; shift || true; ;; |
Joel Fernandes | e2a0466 | 2018-03-31 19:33:23 -0700 | [diff] [blame] | 45 | shell) ASHELL=1; shift || true; ;; |
Joel Fernandes | b4c80a6 | 2018-04-02 22:37:22 -0700 | [diff] [blame] | 46 | remove) REMOVE=1; shift || true; ;; |
Erick Reyes | e25caea | 2018-06-19 15:42:59 -0700 | [diff] [blame] | 47 | git-pull) GIT_PULL=1; shift || true; ;; |
| 48 | pull) PULL=1; shift || true; break ;; |
Erick Reyes | 5104a6c | 2018-06-27 15:31:58 -0700 | [diff] [blame] | 49 | push) PUSH=1; shift || true; break ;; |
Joel Fernandes (Google) | 08d1a07 | 2018-05-28 13:29:03 -0700 | [diff] [blame] | 50 | --arch) ARCH=$2; shift || true; shift || true; ;; |
Joel Fernandes | 9f00bf4 | 2018-04-01 10:36:33 -0700 | [diff] [blame] | 51 | --archive) TARF=$2; shift || true; shift || true; ;; |
Joel Fernandes | 4fb97ea | 2018-03-31 11:15:19 -0700 | [diff] [blame] | 52 | --tracers) source $spath/packages/tracers; shift || true; ;; |
| 53 | --compilers) source $spath/packages/compilers; shift || true; ;; |
| 54 | --editors) source $spath/packages/editors; shift || true; ;; |
| 55 | --scheduler) source $spath/packages/scheduler; shift || true; ;; |
Joel Fernandes | ab5f928 | 2018-04-05 22:53:23 -0700 | [diff] [blame] | 56 | --fullbuild) config_full_build; shift || true; ;; |
Joel Fernandes | a67be0b | 2018-04-01 13:40:34 -0700 | [diff] [blame] | 57 | --download) DOWNLOAD=1; shift || true; ;; |
Joel Fernandes | 100c468 | 2018-04-01 20:09:57 -0700 | [diff] [blame] | 58 | --bcc) source $spath/packages/bcc; shift || true; ;; |
Joel Fernandes | 5b4be9c | 2018-03-30 23:58:27 -0700 | [diff] [blame] | 59 | --kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;; |
Joel Fernandes (Google) | 1171d2d | 2018-05-30 17:22:09 -0700 | [diff] [blame] | 60 | --skip-install) SKIP_INSTALL=1; shift || true; ;; |
Joel Fernandes | 1ed30d7 | 2018-05-18 14:08:20 -0700 | [diff] [blame] | 61 | --kernel-headers-targz) KERNELHDRS=$2; shift || true; shift || true; ;; |
Joel Fernandes | e2a0466 | 2018-03-31 19:33:23 -0700 | [diff] [blame] | 62 | --tempdir) TDIR="$2"; shift || true; shift || true; ;; |
Joel Fernandes | ddd2803 | 2018-07-08 23:13:17 -0700 | [diff] [blame^] | 63 | --buildtar) BTAR=1; TARDIR="$2"; shift || true; shift || true; ;; |
Joel Fernandes | 02939a3 | 2018-04-02 22:18:10 -0700 | [diff] [blame] | 64 | --device|-s) ADB="$ADB -s $2"; shift || true; shift || true; ;; |
Joel Fernandes | fdc5200 | 2018-07-08 18:49:20 -0700 | [diff] [blame] | 65 | --build-image) BI=1; BUILD_IMAGEF=$2; SKIP_DEVICE=1; shift || true; shift || true; ;; |
Joel Fernandes | ca8fb55 | 2018-04-01 13:48:16 -0700 | [diff] [blame] | 66 | --debug) set -x; shift || true; ;; |
Joel Fernandes | 112243b | 2018-07-08 17:42:48 -0700 | [diff] [blame] | 67 | *) c_error "Unknown option ($1)"; usage; ;; |
Joel Fernandes | 6c1ca31 | 2018-03-30 17:13:15 -0700 | [diff] [blame] | 68 | esac |
| 69 | done |
| 70 | |
Joel Fernandes | dd102af | 2018-07-08 19:38:42 -0700 | [diff] [blame] | 71 | [ -z $ASHELL ] && box_out "androdeb: $VERSION" |
| 72 | |
Joel Fernandes | ddd2803 | 2018-07-08 23:13:17 -0700 | [diff] [blame^] | 73 | if [ ! -z $BTAR ] && [ -z $TARDIR ]; then |
| 74 | TARDIR=$spath |
| 75 | fi |
| 76 | |
Erick Reyes | e25caea | 2018-06-19 15:42:59 -0700 | [diff] [blame] | 77 | if [ ! -z "$GIT_PULL" ]; then |
Joel Fernandes | 112243b | 2018-07-08 17:42:48 -0700 | [diff] [blame] | 78 | c_info "Updating androdeb by git pull" |
Joel Fernandes | 1637115 | 2018-04-05 22:50:36 -0700 | [diff] [blame] | 79 | cd $spath |
| 80 | git pull |
Joel Fernandes | 112243b | 2018-07-08 17:42:48 -0700 | [diff] [blame] | 81 | c_info "Done." |
Joel Fernandes | 1637115 | 2018-04-05 22:50:36 -0700 | [diff] [blame] | 82 | exit 0 |
| 83 | fi |
| 84 | |
Erick Reyes | e25caea | 2018-06-19 15:42:59 -0700 | [diff] [blame] | 85 | if [ ! -z "$PULL" ]; then |
| 86 | if [ $1 == "-a" ]; then |
| 87 | PRESERVE="-a" |
Joel Fernandes | 112243b | 2018-07-08 17:42:48 -0700 | [diff] [blame] | 88 | c_info "Preserving filestamps and mode" |
Erick Reyes | e25caea | 2018-06-19 15:42:59 -0700 | [diff] [blame] | 89 | shift || true |
| 90 | fi |
Erick Reyes | 5104a6c | 2018-06-27 15:31:58 -0700 | [diff] [blame] | 91 | file_count=`count_sources $@` |
Erick Reyes | e25caea | 2018-06-19 15:42:59 -0700 | [diff] [blame] | 92 | i=0 |
| 93 | while [ $i -lt $file_count ]; do |
| 94 | files["$i"]=/data/androdeb/debian/$1 |
| 95 | shift || true |
| 96 | i=$((i + 1)) |
| 97 | done |
| 98 | $ADB pull $PRESERVE "${files[@]}" "$@" |
| 99 | exit 0 |
| 100 | fi |
| 101 | |
Erick Reyes | 5104a6c | 2018-06-27 15:31:58 -0700 | [diff] [blame] | 102 | if [ ! -z "$PUSH" ]; then |
Erick Reyes | 5104a6c | 2018-06-27 15:31:58 -0700 | [diff] [blame] | 103 | file_count=`count_sources $@` |
| 104 | i=0 |
| 105 | while [ $i -lt $file_count ]; do |
| 106 | files["$i"]=$1 |
| 107 | shift || true |
| 108 | i=$((i + 1)) |
| 109 | done |
| 110 | dest=/data/androdeb/debian/$1 |
| 111 | $ADB push $sync "${files[@]}" $dest |
| 112 | exit 0 |
| 113 | fi |
| 114 | |
Joel Fernandes | 9649a26 | 2018-07-02 20:49:41 -0700 | [diff] [blame] | 115 | if [ -z "$ASHELL" ] && [ -z "$REMOVE" ] && [ -z "$PACKAGES" ]; then |
Joel Fernandes | 112243b | 2018-07-08 17:42:48 -0700 | [diff] [blame] | 116 | c_info "No packages specified, so I'm going to build/install all packages (--fullbuild)" |
Joel Fernandes (Google) | 9c3ae93 | 2018-05-28 14:34:48 -0700 | [diff] [blame] | 117 | config_full_build |
| 118 | fi |
| 119 | |
Joel Fernandes | 97958e1 | 2018-03-31 23:51:44 -0700 | [diff] [blame] | 120 | if [[ ! -z ${TARDIR+x} ]] && [[ ! -d $TARDIR ]]; then die 7 "Tar dir specified doesn't exist"; fi |
Joel Fernandes | 9205776 | 2018-03-31 23:38:43 -0700 | [diff] [blame] | 121 | |
Joel Fernandes | fdc5200 | 2018-07-08 18:49:20 -0700 | [diff] [blame] | 122 | if [ -z $BI ]; then |
Joel Fernandes | dd102af | 2018-07-08 19:38:42 -0700 | [diff] [blame] | 123 | [ -z $ASHELL ] && c_info "Looking for device.." |
Joel Fernandes | c26696d | 2018-07-08 18:28:12 -0700 | [diff] [blame] | 124 | do_adb_root "$ADB" |
Joel Fernandes | af07ec7 | 2018-04-02 22:01:19 -0700 | [diff] [blame] | 125 | |
Joel Fernandes | c26696d | 2018-07-08 18:28:12 -0700 | [diff] [blame] | 126 | if [ $? -ne 0 ]; then |
| 127 | c_error "adb root failed, make sure:" |
| 128 | c_error " * If multiple devices connected, provide --device <serialno> (or -s <serialno>)" |
| 129 | c_error " * Try to run \"adb root\" manually and see if it works. Typically this needs a userdebug build." |
| 130 | c_error "" |
| 131 | c_error "Note: adb can be typically obtained using the android-tools-adb or the adb" |
| 132 | c_error "packages on your distro, or by installing the Android SDK." |
| 133 | die 3 "Exiting." |
| 134 | fi |
Joel Fernandes | fdc5200 | 2018-07-08 18:49:20 -0700 | [diff] [blame] | 135 | else |
| 136 | [ ! -z $BUILD_IMAGEF ] || die 8 "--build-image passed but no image file provided" |
Joel Fernandes (Google) | 9c3ae93 | 2018-05-28 14:34:48 -0700 | [diff] [blame] | 137 | fi |
Joel Fernandes | 72656c5 | 2018-03-31 20:35:33 -0700 | [diff] [blame] | 138 | |
Joel Fernandes | b4c80a6 | 2018-04-02 22:37:22 -0700 | [diff] [blame] | 139 | if [ ! -z "$REMOVE" ]; then |
| 140 | die_if_no_androdeb "Nothing to remove." |
Joel Fernandes (Google) | 7c8b108 | 2018-06-25 12:29:10 -0700 | [diff] [blame] | 141 | $ADB shell /data/androdeb/device-umount-all || true; |
Joel Fernandes | b4c80a6 | 2018-04-02 22:37:22 -0700 | [diff] [blame] | 142 | $ADB shell rm -rf /data/androdeb; exit 0; fi |
| 143 | |
Joel Fernandes | 83676b1 | 2018-03-30 23:33:47 -0700 | [diff] [blame] | 144 | ########################################################## |
Joel Fernandes | e2a0466 | 2018-03-31 19:33:23 -0700 | [diff] [blame] | 145 | # SHELL |
Joel Fernandes | 83676b1 | 2018-03-30 23:33:47 -0700 | [diff] [blame] | 146 | ########################################################## |
Joel Fernandes | e381ac7 | 2018-03-31 21:46:36 -0700 | [diff] [blame] | 147 | if [ ! -z ${ASHELL+x} ]; then |
Joel Fernandes | 02939a3 | 2018-04-02 22:18:10 -0700 | [diff] [blame] | 148 | set +e; $ADB shell ls /data/androdeb/debian/.bashrc > /dev/null 2>&1 |
Joel Fernandes | c964681 | 2018-03-31 19:45:46 -0700 | [diff] [blame] | 149 | if [ $? -ne 0 ]; then |
| 150 | die 2 "Device doesn't have an androdeb environment, run \"./androdeb prepare\" first"; |
| 151 | fi; set -e |
| 152 | |
Joel Fernandes | ccb993f | 2018-07-02 19:59:04 -0700 | [diff] [blame] | 153 | if [ ! -z ${SHELL_ARGS+x} ]; then |
| 154 | # Explanation of quotes: |
| 155 | # Outer quote is so that androdeb's bash passes the SHELL_ARGS as a single |
| 156 | # argument to $ADB shell. Inner quotes is so that run-command can receive all |
| 157 | # the args even though they may be separated by spaces. \m/ |
| 158 | $ADB shell -t /data/androdeb/run-command "\"$SHELL_ARGS\"" |
| 159 | else |
| 160 | $ADB shell -t /data/androdeb/run |
| 161 | fi |
| 162 | |
Joel Fernandes | e2a0466 | 2018-03-31 19:33:23 -0700 | [diff] [blame] | 163 | exit 0 |
| 164 | fi |
| 165 | |
| 166 | ########################################################## |
| 167 | # PREPARE |
| 168 | ########################################################## |
Joel Fernandes | f0c5409 | 2018-04-01 19:05:10 -0700 | [diff] [blame] | 169 | |
| 170 | function do_cleanup() { |
| 171 | rm -rf $TDIR/*; if [ $MKTEMP -eq 1 ]; then rm -rf $TDIR; fi |
| 172 | } |
| 173 | |
| 174 | function push_unpack_headers() { |
Joel Fernandes | b4c80a6 | 2018-04-02 22:37:22 -0700 | [diff] [blame] | 175 | die_if_no_androdeb "Couldn't update headers." |
Joel Fernandes | f0c5409 | 2018-04-01 19:05:10 -0700 | [diff] [blame] | 176 | |
Joel Fernandes | f95f2b2 | 2018-07-08 17:54:47 -0700 | [diff] [blame] | 177 | c_info "Storing kernel headers into androdeb /kernel-headers/" |
Joel Fernandes | 02939a3 | 2018-04-02 22:18:10 -0700 | [diff] [blame] | 178 | $ADB shell rm -rf /data/androdeb/debian/kernel-headers/ |
| 179 | $ADB shell mkdir /data/androdeb/debian/kernel-headers/ |
Joel Fernandes | f95f2b2 | 2018-07-08 17:54:47 -0700 | [diff] [blame] | 180 | run_quiet $ADB push $TDIR_ABS/kh.tgz /data/androdeb/ |
Joel Fernandes | 02939a3 | 2018-04-02 22:18:10 -0700 | [diff] [blame] | 181 | $ADB shell tar -xvf /data/androdeb/kh.tgz -C /data/androdeb/debian/kernel-headers/ > /dev/null |
| 182 | $ADB shell rm /data/androdeb/kh.tgz |
Joel Fernandes | f0c5409 | 2018-04-01 19:05:10 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Joel Fernandes | 1ed30d7 | 2018-05-18 14:08:20 -0700 | [diff] [blame] | 185 | function push_unpack_tarred_headers() { |
| 186 | die_if_no_androdeb "Couldn't update headers." |
| 187 | |
| 188 | $ADB shell rm -rf /data/androdeb/debian/kernel-headers/ |
| 189 | $ADB shell mkdir /data/androdeb/debian/kernel-headers/ |
Joel Fernandes | f95f2b2 | 2018-07-08 17:54:47 -0700 | [diff] [blame] | 190 | |
| 191 | c_info "Pushing headers tar onto device" |
| 192 | run_quiet $ADB push $1 /data/androdeb/ |
| 193 | |
Joel Fernandes | 112243b | 2018-07-08 17:42:48 -0700 | [diff] [blame] | 194 | c_info "Storing kernel headers into androdeb root directory" |
Joel Fernandes | 1ed30d7 | 2018-05-18 14:08:20 -0700 | [diff] [blame] | 195 | $ADB shell tar -xvf /data/androdeb/$(basename $1) -C /data/androdeb/debian/ > /dev/null |
| 196 | |
| 197 | $ADB shell rm /data/androdeb/$(basename $1) |
| 198 | } |
| 199 | |
Joel Fernandes | 7206511 | 2018-04-01 20:02:53 -0700 | [diff] [blame] | 200 | function all_done_banner() { |
Joel Fernandes | 112243b | 2018-07-08 17:42:48 -0700 | [diff] [blame] | 201 | c_info "All done! Run \"androdeb shell\" to enter environment" |
Joel Fernandes | 7206511 | 2018-04-01 20:02:53 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Joel Fernandes | 72656c5 | 2018-03-31 20:35:33 -0700 | [diff] [blame] | 204 | # Prepare is the last command checked |
Joel Fernandes | 9f00bf4 | 2018-04-01 10:36:33 -0700 | [diff] [blame] | 205 | if [ -z "$PREPARE" ]; then usage; fi |
Joel Fernandes | 72656c5 | 2018-03-31 20:35:33 -0700 | [diff] [blame] | 206 | |
Joel Fernandes | 1ed30d7 | 2018-05-18 14:08:20 -0700 | [diff] [blame] | 207 | if [ ! -z "$TARF" ] && [ ! -f $TARF ] && [ -z "$DOWNLOAD" ]; then die 5 "archive provided doesn't exist"; fi |
Joel Fernandes | 9f00bf4 | 2018-04-01 10:36:33 -0700 | [diff] [blame] | 208 | |
Joel Fernandes | 1ed30d7 | 2018-05-18 14:08:20 -0700 | [diff] [blame] | 209 | if [ ! -z "$KERNELSRC" ] && [ ! -d $KERNELSRC ]; then die 6 "Kernel source directory provided doesn't exist"; fi |
| 210 | |
| 211 | if [ ! -z "$KERNELHDRS" ] && [ ! -f $KERNELHDRS ]; then die 7 "Kernel headers tar.gz doesn't exist"; fi |
Joel Fernandes | e2a0466 | 2018-03-31 19:33:23 -0700 | [diff] [blame] | 212 | |
Joel Fernandes | ca8fb55 | 2018-04-01 13:48:16 -0700 | [diff] [blame] | 213 | print_prepare_banner |
| 214 | |
Joel Fernandes | 6c1ca31 | 2018-03-30 17:13:15 -0700 | [diff] [blame] | 215 | # Where do we want to store temporary files |
Joel Fernandes | e2a0466 | 2018-03-31 19:33:23 -0700 | [diff] [blame] | 216 | MKTEMP=0; if [[ -z ${TDIR+x} ]] || [[ ! -d "${TDIR}" ]]; then |
| 217 | TDIR=`mktemp -d`; MKTEMP=1; fi |
Joel Fernandes | e381ac7 | 2018-03-31 21:46:36 -0700 | [diff] [blame] | 218 | rm -rf $TDIR/* |
| 219 | TDIR_ABS=$( cd "$TDIR" ; pwd -P ) |
Joel Fernandes | 6c1ca31 | 2018-03-30 17:13:15 -0700 | [diff] [blame] | 220 | |
Joel Fernandes | a67be0b | 2018-04-01 13:40:34 -0700 | [diff] [blame] | 221 | if [ ! -z "$DOWNLOAD" ]; then |
Joel Fernandes | 112243b | 2018-07-08 17:42:48 -0700 | [diff] [blame] | 222 | c_info "Downloading Androdeb from the web..."; c_info "" |
Joel Fernandes (Google) | 9e670aa | 2018-06-25 13:39:34 -0700 | [diff] [blame] | 223 | # Github dropped tar gz support! ##?#??#! Now we've to zip everything. |
| 224 | curl -L https://github.com/joelagnel/androdeb/releases/download/$VERSION/androdeb-fs.tgz.zip --output $TDIR_ABS/androdeb-fs.tgz.zip; |
| 225 | unzip -e $TDIR_ABS/androdeb-fs.tgz.zip -d $TDIR_ABS/ |
Joel Fernandes | a67be0b | 2018-04-01 13:40:34 -0700 | [diff] [blame] | 226 | TARF=$TDIR_ABS/androdeb-fs.tgz; fi |
| 227 | |
Joel Fernandes | e2a0466 | 2018-03-31 19:33:23 -0700 | [diff] [blame] | 228 | OUT_TMP=$TDIR/debian; rm -rf $OUT_TMP; mkdir -p $OUT_TMP |
Joel Fernandes | f0c5409 | 2018-04-01 19:05:10 -0700 | [diff] [blame] | 229 | |
Joel Fernandes | 1ed30d7 | 2018-05-18 14:08:20 -0700 | [diff] [blame] | 230 | # Unpack the supplied kernel headers tar.gz directly into androdeb root |
| 231 | if [ ! -z "$KERNELHDRS" ]; then |
Joel Fernandes | 112243b | 2018-07-08 17:42:48 -0700 | [diff] [blame] | 232 | c_info "Building updating kernel headers from supplied tar.gz ($KERNELHDRS)" |
Joel Fernandes | 1ed30d7 | 2018-05-18 14:08:20 -0700 | [diff] [blame] | 233 | |
| 234 | # Is header tar gz update the only thing left to do? |
Joel Fernandes (Google) | 1171d2d | 2018-05-30 17:22:09 -0700 | [diff] [blame] | 235 | if [[ ! -z "$SKIP_INSTALL" ]]; then |
Joel Fernandes | 112243b | 2018-07-08 17:42:48 -0700 | [diff] [blame] | 236 | c_info "Skipping install" |
Joel Fernandes | 1ed30d7 | 2018-05-18 14:08:20 -0700 | [diff] [blame] | 237 | push_unpack_tarred_headers $KERNELHDRS; do_cleanup; all_done_banner; exit 0; fi |
| 238 | |
| 239 | tar -xvf $KERNELHDRS -C $OUT_TMP/ > /dev/null |
| 240 | fi |
| 241 | |
Joel Fernandes | f0c5409 | 2018-04-01 19:05:10 -0700 | [diff] [blame] | 242 | # Package kernel headers |
| 243 | if [ ! -z "$KERNELSRC" ]; then |
Joel Fernandes | 112243b | 2018-07-08 17:42:48 -0700 | [diff] [blame] | 244 | c_info "Building and updating kernel headers from kernel source dir ($KERNELSRC)" |
Joel Fernandes | 7206511 | 2018-04-01 20:02:53 -0700 | [diff] [blame] | 245 | $spath/bcc/build-kheaders-targz.sh ${KERNELSRC} $TDIR_ABS/kh.tgz > /dev/null |
| 246 | |
Joel Fernandes | f0c5409 | 2018-04-01 19:05:10 -0700 | [diff] [blame] | 247 | # Is header update the only thing left to do? |
Joel Fernandes (Google) | 1171d2d | 2018-05-30 17:22:09 -0700 | [diff] [blame] | 248 | if [[ ! -z "$SKIP_INSTALL" ]]; then |
Joel Fernandes | 112243b | 2018-07-08 17:42:48 -0700 | [diff] [blame] | 249 | c_info "Skipping install" |
Joel Fernandes | 7206511 | 2018-04-01 20:02:53 -0700 | [diff] [blame] | 250 | push_unpack_headers; do_cleanup; all_done_banner; exit 0; fi |
Joel Fernandes | f0c5409 | 2018-04-01 19:05:10 -0700 | [diff] [blame] | 251 | |
Joel Fernandes | e381ac7 | 2018-03-31 21:46:36 -0700 | [diff] [blame] | 252 | mkdir $OUT_TMP/kernel-headers |
Joel Fernandes | 7206511 | 2018-04-01 20:02:53 -0700 | [diff] [blame] | 253 | tar -xvf $TDIR_ABS/kh.tgz -C $OUT_TMP/kernel-headers/ > /dev/null |
Joel Fernandes | e381ac7 | 2018-03-31 21:46:36 -0700 | [diff] [blame] | 254 | fi |
Joel Fernandes | 4fb97ea | 2018-03-31 11:15:19 -0700 | [diff] [blame] | 255 | |
Joel Fernandes | f0c5409 | 2018-04-01 19:05:10 -0700 | [diff] [blame] | 256 | # Build FS from existing tar, very simple. |
Joel Fernandes | 9f00bf4 | 2018-04-01 10:36:33 -0700 | [diff] [blame] | 257 | if [ ! -z "$TARF" ]; then |
Joel Fernandes | 112243b | 2018-07-08 17:42:48 -0700 | [diff] [blame] | 258 | c_info "Using archive at $TARF for filesystem preparation" |
Joel Fernandes | 02939a3 | 2018-04-02 22:18:10 -0700 | [diff] [blame] | 259 | $ADB shell mkdir -p /data/androdeb/ |
Joel Fernandes | f95f2b2 | 2018-07-08 17:54:47 -0700 | [diff] [blame] | 260 | |
| 261 | c_info "Pushing filesystem to device.." |
| 262 | run_quiet $ADB push $TARF /data/androdeb/deb.tar.gz |
| 263 | |
| 264 | c_info "Pushing addons to device.." |
| 265 | run_quiet $ADB push $spath/addons/* /data/androdeb/ |
| 266 | |
| 267 | c_info "Unpacking filesystem in device.." |
| 268 | run_quiet $ADB shell /data/androdeb/device-unpack |
Joel Fernandes | 9f00bf4 | 2018-04-01 10:36:33 -0700 | [diff] [blame] | 269 | |
Joel Fernandes | 1ed30d7 | 2018-05-18 14:08:20 -0700 | [diff] [blame] | 270 | if [ ! -z "$KERNELHDRS" ]; then push_unpack_tarred_headers $KERNELHDRS; fi |
Joel Fernandes | f0c5409 | 2018-04-01 19:05:10 -0700 | [diff] [blame] | 271 | if [ ! -z "$KERNELSRC" ]; then push_unpack_headers; fi |
| 272 | |
Joel Fernandes | 7206511 | 2018-04-01 20:02:53 -0700 | [diff] [blame] | 273 | do_cleanup; all_done_banner; exit 0 |
Joel Fernandes | f0c5409 | 2018-04-01 19:05:10 -0700 | [diff] [blame] | 274 | fi |
| 275 | |
| 276 | PACKAGES+="$DEFAULT_PACKAGES" |
Joel Fernandes | 112243b | 2018-07-08 17:42:48 -0700 | [diff] [blame] | 277 | c_info "Using temporary directory: $TDIR" |
Joel Fernandes | 4fb97ea | 2018-03-31 11:15:19 -0700 | [diff] [blame] | 278 | |
Joel Fernandes | 112243b | 2018-07-08 17:42:48 -0700 | [diff] [blame] | 279 | if [[ $EUID -ne 0 ]]; then c_info "The next stage runs as sudo, please enter password if asked."; fi |
Joel Fernandes | 4fb97ea | 2018-03-31 11:15:19 -0700 | [diff] [blame] | 280 | |
Joel Fernandes (Google) | 57b3fd2 | 2018-05-29 16:27:03 -0700 | [diff] [blame] | 281 | ex_files=$(mktemp); echo $EXTRA_FILES > $ex_files |
| 282 | |
Joel Fernandes (Google) | 4f71108 | 2018-05-29 16:23:15 -0700 | [diff] [blame] | 283 | sudo $spath/buildstrap $ARCH $DISTRO $TDIR $OUT_TMP \ |
| 284 | "$(make_csv "$PACKAGES")"\ |
Joel Fernandes | fdc5200 | 2018-07-08 18:49:20 -0700 | [diff] [blame] | 285 | $ex_files $INSTALL_BCC $SKIP_DEVICE |
Joel Fernandes (Google) | 57b3fd2 | 2018-05-29 16:27:03 -0700 | [diff] [blame] | 286 | rm $ex_files |
Joel Fernandes (Google) | 9c3ae93 | 2018-05-28 14:34:48 -0700 | [diff] [blame] | 287 | |
| 288 | # If we only wanted to prepare a rootfs and don't have |
| 289 | # a device connected, then just echo that and skip cleanup |
Joel Fernandes | fdc5200 | 2018-07-08 18:49:20 -0700 | [diff] [blame] | 290 | if [ $SKIP_DEVICE -eq 1 ]; then |
| 291 | c_info "Device preparation is being skipped for the selected options" |
Joel Fernandes | ba7214e | 2018-07-08 18:15:49 -0700 | [diff] [blame] | 292 | c_info "any builds that need to happen on device may be cloned but not built." |
Joel Fernandes | 47ef215 | 2018-07-08 19:13:51 -0700 | [diff] [blame] | 293 | |
| 294 | if [ ! -z $BI ]; then |
| 295 | sudo $spath/buildimage $OUT_TMP $(dirname $BUILD_IMAGEF)/$(basename $BUILD_IMAGEF) |
| 296 | sudo chmod a+rw $(dirname $BUILD_IMAGEF)/$(basename $BUILD_IMAGEF) |
Joel Fernandes | 9a38e60 | 2018-07-08 19:26:32 -0700 | [diff] [blame] | 297 | c_info "Your .img has been built! Enjoy!" |
Joel Fernandes | 47ef215 | 2018-07-08 19:13:51 -0700 | [diff] [blame] | 298 | fi |
Joel Fernandes | ba7214e | 2018-07-08 18:15:49 -0700 | [diff] [blame] | 299 | |
| 300 | do_cleanup |
Joel Fernandes | 9a38e60 | 2018-07-08 19:26:32 -0700 | [diff] [blame] | 301 | exit 0 |
Joel Fernandes (Google) | 9c3ae93 | 2018-05-28 14:34:48 -0700 | [diff] [blame] | 302 | fi |
Joel Fernandes | 4dd6086 | 2018-03-31 13:27:16 -0700 | [diff] [blame] | 303 | |
| 304 | # Push tar to device and start unpack |
Joel Fernandes | 02939a3 | 2018-04-02 22:18:10 -0700 | [diff] [blame] | 305 | $ADB shell mkdir -p /data/androdeb/ |
| 306 | $ADB push $TDIR/deb.tar.gz /data/androdeb/ |
| 307 | $ADB push $spath/addons/* /data/androdeb/ |
| 308 | $ADB shell /data/androdeb/device-unpack |
Joel Fernandes | b61d27d | 2018-03-31 11:59:45 -0700 | [diff] [blame] | 309 | |
Joel Fernandes | 6f1c70f | 2018-03-31 20:26:26 -0700 | [diff] [blame] | 310 | # Build BCC and install bcc on device if needed |
Joel Fernandes | ffcbfe4 | 2018-07-08 19:08:02 -0700 | [diff] [blame] | 311 | if [ $INSTALL_BCC -eq 0 ]; then |
| 312 | $ADB shell /data/androdeb/run-command /bcc-master/build-bcc.sh; |
| 313 | fi |
Joel Fernandes | 4fb97ea | 2018-03-31 11:15:19 -0700 | [diff] [blame] | 314 | |
Joel Fernandes | f0c5409 | 2018-04-01 19:05:10 -0700 | [diff] [blame] | 315 | do_cleanup |
Joel Fernandes | e381ac7 | 2018-03-31 21:46:36 -0700 | [diff] [blame] | 316 | |
Joel Fernandes | 97958e1 | 2018-03-31 23:51:44 -0700 | [diff] [blame] | 317 | # Extract a tar of the built, compiled and installed androdeb env |
| 318 | if [[ ! -z ${TARDIR+x} ]]; then |
Joel Fernandes | 112243b | 2018-07-08 17:42:48 -0700 | [diff] [blame] | 319 | c_info "Creating and pulling tarball of androdeb env from device" |
Joel Fernandes | 02939a3 | 2018-04-02 22:18:10 -0700 | [diff] [blame] | 320 | $ADB shell /data/androdeb/build-debian-tar |
| 321 | $ADB pull /data/androdeb/androdeb-fs.tgz $TARDIR/ |
| 322 | $ADB shell rm /data/androdeb/androdeb-fs.tgz; fi |
Joel Fernandes | 97958e1 | 2018-03-31 23:51:44 -0700 | [diff] [blame] | 323 | |
Joel Fernandes | 7206511 | 2018-04-01 20:02:53 -0700 | [diff] [blame] | 324 | all_done_banner |