Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 1 | function __print_lineage_functions_help() { |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 2 | cat <<EOF |
Dan Pasanen | 0344771 | 2016-12-19 11:22:55 -0600 | [diff] [blame] | 3 | Additional LineageOS functions: |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 4 | - cout: Changes directory to out. |
| 5 | - mmp: Builds all of the modules in the current directory and pushes them to the device. |
| 6 | - mmap: Builds all of the modules in the current directory and its dependencies, then pushes the package to the device. |
| 7 | - mmmp: Builds all of the modules in the supplied directories and pushes them to the device. |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 8 | - lineagegerrit: A Git wrapper that fetches/pushes patch from/to LineageOS Gerrit Review. |
| 9 | - lineagerebase: Rebase a Gerrit change and push it again. |
| 10 | - lineageremote: Add git remote for LineageOS Gerrit Review. |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 11 | - aospremote: Add git remote for matching AOSP repository. |
| 12 | - cafremote: Add git remote for matching CodeAurora repository. |
| 13 | - mka: Builds using SCHED_BATCH on all processors. |
| 14 | - mkap: Builds the module(s) using mka and pushes them to the device. |
| 15 | - cmka: Cleans and builds using mka. |
| 16 | - repodiff: Diff 2 different branches or tags within the same repo |
| 17 | - repolastsync: Prints date and time of last repo sync. |
| 18 | - reposync: Parallel repo sync using ionice and SCHED_BATCH. |
| 19 | - repopick: Utility to fetch changes from Gerrit. |
| 20 | - installboot: Installs a boot.img to the connected device. |
| 21 | - installrecovery: Installs a recovery.img to the connected device. |
| 22 | EOF |
| 23 | } |
| 24 | |
Luca Stefani | 076c27b | 2017-08-17 20:30:00 +0200 | [diff] [blame] | 25 | function mk_timer() |
| 26 | { |
| 27 | local start_time=$(date +"%s") |
| 28 | $@ |
| 29 | local ret=$? |
| 30 | local end_time=$(date +"%s") |
| 31 | local tdiff=$(($end_time-$start_time)) |
| 32 | local hours=$(($tdiff / 3600 )) |
| 33 | local mins=$((($tdiff % 3600) / 60)) |
| 34 | local secs=$(($tdiff % 60)) |
| 35 | local ncolors=$(tput colors 2>/dev/null) |
| 36 | echo |
| 37 | if [ $ret -eq 0 ] ; then |
| 38 | echo -n "#### make completed successfully " |
| 39 | else |
| 40 | echo -n "#### make failed to build some targets " |
| 41 | fi |
| 42 | if [ $hours -gt 0 ] ; then |
| 43 | printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs |
| 44 | elif [ $mins -gt 0 ] ; then |
| 45 | printf "(%02g:%02g (mm:ss))" $mins $secs |
| 46 | elif [ $secs -gt 0 ] ; then |
| 47 | printf "(%s seconds)" $secs |
| 48 | fi |
| 49 | echo " ####" |
| 50 | echo |
| 51 | return $ret |
| 52 | } |
| 53 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 54 | function brunch() |
| 55 | { |
| 56 | breakfast $* |
| 57 | if [ $? -eq 0 ]; then |
| 58 | mka bacon |
| 59 | else |
| 60 | echo "No such item in brunch menu. Try 'breakfast'" |
| 61 | return 1 |
| 62 | fi |
| 63 | return $? |
| 64 | } |
| 65 | |
| 66 | function breakfast() |
| 67 | { |
| 68 | target=$1 |
| 69 | local variant=$2 |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 70 | LINEAGE_DEVICES_ONLY="true" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 71 | unset LUNCH_MENU_CHOICES |
| 72 | add_lunch_combo full-eng |
Dan Pasanen | 91f7620 | 2017-07-06 08:21:30 -0500 | [diff] [blame] | 73 | for f in `/bin/ls vendor/lineage/vendorsetup.sh 2> /dev/null` |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 74 | do |
| 75 | echo "including $f" |
| 76 | . $f |
| 77 | done |
| 78 | unset f |
| 79 | |
| 80 | if [ $# -eq 0 ]; then |
| 81 | # No arguments, so let's have the full menu |
| 82 | lunch |
| 83 | else |
| 84 | echo "z$target" | grep -q "-" |
| 85 | if [ $? -eq 0 ]; then |
| 86 | # A buildtype was specified, assume a full device name |
| 87 | lunch $target |
| 88 | else |
Simon Shields | 63ce74b | 2016-12-28 11:33:29 +1100 | [diff] [blame] | 89 | # This is probably just the Lineage model name |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 90 | if [ -z "$variant" ]; then |
| 91 | variant="userdebug" |
| 92 | fi |
Matt Mower | ed8c248 | 2017-01-02 02:26:01 -0600 | [diff] [blame] | 93 | |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 94 | lunch lineage_$target-$variant |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 95 | fi |
| 96 | fi |
| 97 | return $? |
| 98 | } |
| 99 | |
| 100 | alias bib=breakfast |
| 101 | |
| 102 | function eat() |
| 103 | { |
| 104 | if [ "$OUT" ] ; then |
Zhao Wei Liew | 321dde5 | 2017-01-01 15:24:38 +0800 | [diff] [blame] | 105 | MODVERSION=$(get_build_var LINEAGE_VERSION) |
Dan Pasanen | 0344771 | 2016-12-19 11:22:55 -0600 | [diff] [blame] | 106 | ZIPFILE=lineage-$MODVERSION.zip |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 107 | ZIPPATH=$OUT/$ZIPFILE |
| 108 | if [ ! -f $ZIPPATH ] ; then |
| 109 | echo "Nothing to eat" |
| 110 | return 1 |
| 111 | fi |
| 112 | adb start-server # Prevent unexpected starting server message from adb get-state in the next line |
| 113 | if [ $(adb get-state) != device -a $(adb shell test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then |
| 114 | echo "No device is online. Waiting for one..." |
| 115 | echo "Please connect USB and/or enable USB debugging" |
| 116 | until [ $(adb get-state) = device -o $(adb shell test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do |
| 117 | sleep 1 |
| 118 | done |
| 119 | echo "Device Found.." |
| 120 | fi |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 121 | if (adb shell getprop ro.lineage.device | grep -q "$LINEAGE_BUILD"); then |
Ethan Chen | b69c2ff | 2016-12-31 13:23:56 -0800 | [diff] [blame] | 122 | # if adbd isn't root we can't write to /cache/recovery/ |
| 123 | adb root |
| 124 | sleep 1 |
| 125 | adb wait-for-device |
| 126 | cat << EOF > /tmp/command |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 127 | --sideload_auto_reboot |
| 128 | EOF |
Ethan Chen | b69c2ff | 2016-12-31 13:23:56 -0800 | [diff] [blame] | 129 | if adb push /tmp/command /cache/recovery/ ; then |
| 130 | echo "Rebooting into recovery for sideload installation" |
| 131 | adb reboot recovery |
| 132 | adb wait-for-sideload |
| 133 | adb sideload $ZIPPATH |
| 134 | fi |
| 135 | rm /tmp/command |
| 136 | else |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 137 | echo "The connected device does not appear to be $LINEAGE_BUILD, run away!" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 138 | fi |
Ethan Chen | b69c2ff | 2016-12-31 13:23:56 -0800 | [diff] [blame] | 139 | return $? |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 140 | else |
| 141 | echo "Nothing to eat" |
| 142 | return 1 |
| 143 | fi |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | function omnom() |
| 147 | { |
| 148 | brunch $* |
| 149 | eat |
| 150 | } |
| 151 | |
| 152 | function cout() |
| 153 | { |
| 154 | if [ "$OUT" ]; then |
| 155 | cd $OUT |
| 156 | else |
| 157 | echo "Couldn't locate out directory. Try setting OUT." |
| 158 | fi |
| 159 | } |
| 160 | |
| 161 | function dddclient() |
| 162 | { |
| 163 | local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT) |
| 164 | local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED) |
| 165 | local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED) |
| 166 | local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED) |
| 167 | local OUT_EXE_SYMBOLS=$(get_symbols_directory) |
| 168 | local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS) |
| 169 | local ARCH=$(get_build_var TARGET_ARCH) |
| 170 | local GDB |
| 171 | case "$ARCH" in |
| 172 | arm) GDB=arm-linux-androideabi-gdb;; |
| 173 | arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;; |
| 174 | mips|mips64) GDB=mips64el-linux-android-gdb;; |
| 175 | x86) GDB=x86_64-linux-android-gdb;; |
| 176 | x86_64) GDB=x86_64-linux-android-gdb;; |
| 177 | *) echo "Unknown arch $ARCH"; return 1;; |
| 178 | esac |
| 179 | |
| 180 | if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then |
| 181 | local EXE="$1" |
| 182 | if [ "$EXE" ] ; then |
| 183 | EXE=$1 |
| 184 | if [[ $EXE =~ ^[^/].* ]] ; then |
| 185 | EXE="system/bin/"$EXE |
| 186 | fi |
| 187 | else |
| 188 | EXE="app_process" |
| 189 | fi |
| 190 | |
| 191 | local PORT="$2" |
| 192 | if [ "$PORT" ] ; then |
| 193 | PORT=$2 |
| 194 | else |
| 195 | PORT=":5039" |
| 196 | fi |
| 197 | |
| 198 | local PID="$3" |
| 199 | if [ "$PID" ] ; then |
| 200 | if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then |
| 201 | PID=`pid $3` |
| 202 | if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then |
| 203 | # that likely didn't work because of returning multiple processes |
| 204 | # try again, filtering by root processes (don't contain colon) |
| 205 | PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'` |
| 206 | if [[ ! "$PID" =~ ^[0-9]+$ ]] |
| 207 | then |
| 208 | echo "Couldn't resolve '$3' to single PID" |
| 209 | return 1 |
| 210 | else |
| 211 | echo "" |
| 212 | echo "WARNING: multiple processes matching '$3' observed, using root process" |
| 213 | echo "" |
| 214 | fi |
| 215 | fi |
| 216 | fi |
| 217 | adb forward "tcp$PORT" "tcp$PORT" |
| 218 | local USE64BIT="$(is64bit $PID)" |
| 219 | adb shell gdbserver$USE64BIT $PORT --attach $PID & |
| 220 | sleep 2 |
| 221 | else |
| 222 | echo "" |
| 223 | echo "If you haven't done so already, do this first on the device:" |
| 224 | echo " gdbserver $PORT /system/bin/$EXE" |
| 225 | echo " or" |
| 226 | echo " gdbserver $PORT --attach <PID>" |
| 227 | echo "" |
| 228 | fi |
| 229 | |
| 230 | OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT |
| 231 | OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT |
| 232 | |
| 233 | echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS" |
| 234 | echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS:$OUT_SO_SYMBOLS/hw:$OUT_SO_SYMBOLS/ssl/engines:$OUT_SO_SYMBOLS/drm:$OUT_SO_SYMBOLS/egl:$OUT_SO_SYMBOLS/soundfx:$OUT_VENDOR_SO_SYMBOLS:$OUT_VENDOR_SO_SYMBOLS/hw:$OUT_VENDOR_SO_SYMBOLS/egl" |
| 235 | echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb" |
| 236 | echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT" |
| 237 | # Enable special debugging for ART processes. |
| 238 | if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then |
| 239 | echo >> "$OUT_ROOT/gdbclient.cmds" "art-on" |
| 240 | fi |
| 241 | echo >>"$OUT_ROOT/gdbclient.cmds" "" |
| 242 | |
| 243 | local WHICH_GDB= |
| 244 | # 64-bit exe found |
| 245 | if [ "$USE64BIT" != "" ] ; then |
| 246 | WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64 |
| 247 | # 32-bit exe / 32-bit platform |
| 248 | elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then |
| 249 | WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB |
| 250 | # 32-bit exe / 64-bit platform |
| 251 | else |
| 252 | WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB |
| 253 | fi |
| 254 | |
| 255 | ddd --debugger $WHICH_GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE" |
| 256 | else |
| 257 | echo "Unable to determine build system output dir." |
| 258 | fi |
| 259 | } |
| 260 | |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 261 | function lineageremote() |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 262 | { |
| 263 | if ! git rev-parse --git-dir &> /dev/null |
| 264 | then |
| 265 | echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up." |
| 266 | return 1 |
| 267 | fi |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 268 | git remote rm lineage 2> /dev/null |
Michael Bestas | ad3a570 | 2017-08-24 00:00:48 +0300 | [diff] [blame] | 269 | local GERRIT_REMOTE=$(git config --get remote.github.projectname) |
Michael Bestas | af3532b | 2017-08-23 17:40:40 +0300 | [diff] [blame] | 270 | if [ -z "$GERRIT_REMOTE" ] |
| 271 | then |
Michael Bestas | ad3a570 | 2017-08-24 00:00:48 +0300 | [diff] [blame] | 272 | local GERRIT_REMOTE=$(git config --get remote.aosp.projectname | sed s#platform/#android/#g | sed s#/#_#g) |
| 273 | local PFX="LineageOS/" |
Michael Bestas | af3532b | 2017-08-23 17:40:40 +0300 | [diff] [blame] | 274 | fi |
Michael Bestas | ad3a570 | 2017-08-24 00:00:48 +0300 | [diff] [blame] | 275 | local LINEAGE_USER=$(git config --get review.review.lineageos.org.username) |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 276 | if [ -z "$LINEAGE_USER" ] |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 277 | then |
Michael Bestas | af3532b | 2017-08-23 17:40:40 +0300 | [diff] [blame] | 278 | git remote add lineage ssh://review.lineageos.org:29418/$PFX$GERRIT_REMOTE |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 279 | else |
Michael Bestas | af3532b | 2017-08-23 17:40:40 +0300 | [diff] [blame] | 280 | git remote add lineage ssh://$LINEAGE_USER@review.lineageos.org:29418/$PFX$GERRIT_REMOTE |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 281 | fi |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 282 | echo "Remote 'lineage' created" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | function aospremote() |
| 286 | { |
| 287 | if ! git rev-parse --git-dir &> /dev/null |
| 288 | then |
| 289 | echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up." |
| 290 | return 1 |
| 291 | fi |
| 292 | git remote rm aosp 2> /dev/null |
Michael Bestas | ad3a570 | 2017-08-24 00:00:48 +0300 | [diff] [blame] | 293 | local PROJECT=$(pwd -P | sed -e "s#$ANDROID_BUILD_TOP\/##; s#-caf.*##; s#\/default##") |
Rashed Abdel-Tawab | fd8b829 | 2017-10-24 21:55:52 -0400 | [diff] [blame] | 294 | # Google moved the repo location in Oreo |
| 295 | if [ $PROJECT = "build/make" ] |
| 296 | then |
| 297 | PROJECT="build" |
| 298 | fi |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 299 | if (echo $PROJECT | grep -qv "^device") |
| 300 | then |
Michael Bestas | ad3a570 | 2017-08-24 00:00:48 +0300 | [diff] [blame] | 301 | local PFX="platform/" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 302 | fi |
| 303 | git remote add aosp https://android.googlesource.com/$PFX$PROJECT |
| 304 | echo "Remote 'aosp' created" |
| 305 | } |
| 306 | |
| 307 | function cafremote() |
| 308 | { |
| 309 | if ! git rev-parse --git-dir &> /dev/null |
| 310 | then |
| 311 | echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up." |
| 312 | return 1 |
| 313 | fi |
| 314 | git remote rm caf 2> /dev/null |
Michael Bestas | ad3a570 | 2017-08-24 00:00:48 +0300 | [diff] [blame] | 315 | local PROJECT=$(pwd -P | sed -e "s#$ANDROID_BUILD_TOP\/##; s#-caf.*##; s#\/default##") |
Rashed Abdel-Tawab | fd8b829 | 2017-10-24 21:55:52 -0400 | [diff] [blame] | 316 | # Google moved the repo location in Oreo |
| 317 | if [ $PROJECT = "build/make" ] |
| 318 | then |
| 319 | PROJECT="build" |
| 320 | fi |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 321 | if (echo $PROJECT | grep -qv "^device") |
| 322 | then |
Michael Bestas | ad3a570 | 2017-08-24 00:00:48 +0300 | [diff] [blame] | 323 | local PFX="platform/" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 324 | fi |
Zhao Wei Liew | fb4b8c5 | 2017-01-08 09:03:01 +0800 | [diff] [blame] | 325 | git remote add caf https://source.codeaurora.org/quic/la/$PFX$PROJECT |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 326 | echo "Remote 'caf' created" |
| 327 | } |
| 328 | |
| 329 | function installboot() |
| 330 | { |
| 331 | if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ]; |
| 332 | then |
| 333 | echo "No recovery.fstab found. Build recovery first." |
| 334 | return 1 |
| 335 | fi |
| 336 | if [ ! -e "$OUT/boot.img" ]; |
| 337 | then |
| 338 | echo "No boot.img found. Run make bootimage first." |
| 339 | return 1 |
| 340 | fi |
| 341 | PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}` |
| 342 | if [ -z "$PARTITION" ]; |
| 343 | then |
| 344 | # Try for RECOVERY_FSTAB_VERSION = 2 |
| 345 | PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}` |
| 346 | PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}` |
| 347 | if [ -z "$PARTITION" ]; |
| 348 | then |
| 349 | echo "Unable to determine boot partition." |
| 350 | return 1 |
| 351 | fi |
| 352 | fi |
| 353 | adb start-server |
| 354 | adb wait-for-online |
| 355 | adb root |
| 356 | sleep 1 |
| 357 | adb wait-for-online shell mount /system 2>&1 > /dev/null |
| 358 | adb wait-for-online remount |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 359 | if (adb shell getprop ro.lineage.device | grep -q "$LINEAGE_BUILD"); |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 360 | then |
| 361 | adb push $OUT/boot.img /cache/ |
Ashwin Ramesh | b0ea62a | 2017-08-13 12:00:15 +0530 | [diff] [blame] | 362 | if [ -e "$OUT/system/lib/modules/*" ]; |
| 363 | then |
| 364 | for i in $OUT/system/lib/modules/*; |
| 365 | do |
| 366 | adb push $i /system/lib/modules/ |
| 367 | done |
| 368 | adb shell chmod 644 /system/lib/modules/* |
| 369 | fi |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 370 | adb shell dd if=/cache/boot.img of=$PARTITION |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 371 | echo "Installation complete." |
| 372 | else |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 373 | echo "The connected device does not appear to be $LINEAGE_BUILD, run away!" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 374 | fi |
| 375 | } |
| 376 | |
| 377 | function installrecovery() |
| 378 | { |
| 379 | if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ]; |
| 380 | then |
| 381 | echo "No recovery.fstab found. Build recovery first." |
| 382 | return 1 |
| 383 | fi |
| 384 | if [ ! -e "$OUT/recovery.img" ]; |
| 385 | then |
| 386 | echo "No recovery.img found. Run make recoveryimage first." |
| 387 | return 1 |
| 388 | fi |
| 389 | PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}` |
| 390 | if [ -z "$PARTITION" ]; |
| 391 | then |
| 392 | # Try for RECOVERY_FSTAB_VERSION = 2 |
| 393 | PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}` |
| 394 | PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}` |
| 395 | if [ -z "$PARTITION" ]; |
| 396 | then |
| 397 | echo "Unable to determine recovery partition." |
| 398 | return 1 |
| 399 | fi |
| 400 | fi |
| 401 | adb start-server |
| 402 | adb wait-for-online |
| 403 | adb root |
| 404 | sleep 1 |
| 405 | adb wait-for-online shell mount /system 2>&1 >> /dev/null |
| 406 | adb wait-for-online remount |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 407 | if (adb shell getprop ro.lineage.device | grep -q "$LINEAGE_BUILD"); |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 408 | then |
| 409 | adb push $OUT/recovery.img /cache/ |
| 410 | adb shell dd if=/cache/recovery.img of=$PARTITION |
| 411 | echo "Installation complete." |
| 412 | else |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 413 | echo "The connected device does not appear to be $LINEAGE_BUILD, run away!" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 414 | fi |
| 415 | } |
| 416 | |
| 417 | function makerecipe() { |
| 418 | if [ -z "$1" ] |
| 419 | then |
| 420 | echo "No branch name provided." |
| 421 | return 1 |
| 422 | fi |
| 423 | cd android |
| 424 | sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml |
| 425 | git commit -a -m "$1" |
| 426 | cd .. |
| 427 | |
| 428 | repo forall -c ' |
| 429 | |
| 430 | if [ "$REPO_REMOTE" = "github" ] |
| 431 | then |
| 432 | pwd |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 433 | lineageremote |
| 434 | git push lineage HEAD:refs/heads/'$1' |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 435 | fi |
| 436 | ' |
| 437 | } |
| 438 | |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 439 | function lineagegerrit() { |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 440 | if [ "$(__detect_shell)" = "zsh" ]; then |
| 441 | # zsh does not define FUNCNAME, derive from funcstack |
| 442 | local FUNCNAME=$funcstack[1] |
| 443 | fi |
| 444 | |
| 445 | if [ $# -eq 0 ]; then |
| 446 | $FUNCNAME help |
| 447 | return 1 |
| 448 | fi |
Dan Pasanen | 0344771 | 2016-12-19 11:22:55 -0600 | [diff] [blame] | 449 | local user=`git config --get review.review.lineageos.org.username` |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 450 | local review=`git config --get remote.github.review` |
| 451 | local project=`git config --get remote.github.projectname` |
| 452 | local command=$1 |
| 453 | shift |
| 454 | case $command in |
| 455 | help) |
| 456 | if [ $# -eq 0 ]; then |
| 457 | cat <<EOF |
| 458 | Usage: |
| 459 | $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS] |
| 460 | |
| 461 | Commands: |
| 462 | fetch Just fetch the change as FETCH_HEAD |
| 463 | help Show this help, or for a specific command |
| 464 | pull Pull a change into current branch |
| 465 | push Push HEAD or a local branch to Gerrit for a specific branch |
| 466 | |
| 467 | Any other Git commands that support refname would work as: |
| 468 | git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS |
| 469 | |
| 470 | See '$FUNCNAME help COMMAND' for more information on a specific command. |
| 471 | |
| 472 | Example: |
| 473 | $FUNCNAME checkout -b topic 1234/5 |
| 474 | works as: |
| 475 | git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\ |
| 476 | && git checkout -b topic FETCH_HEAD |
| 477 | will checkout a new branch 'topic' base on patch-set 5 of change 1234. |
| 478 | Patch-set 1 will be fetched if omitted. |
| 479 | EOF |
| 480 | return |
| 481 | fi |
| 482 | case $1 in |
| 483 | __cmg_*) echo "For internal use only." ;; |
| 484 | changes|for) |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 485 | if [ "$FUNCNAME" = "lineagegerrit" ]; then |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 486 | echo "'$FUNCNAME $1' is deprecated." |
| 487 | fi |
| 488 | ;; |
| 489 | help) $FUNCNAME help ;; |
| 490 | fetch|pull) cat <<EOF |
| 491 | usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET] |
| 492 | |
| 493 | works as: |
| 494 | git $1 OPTIONS http://DOMAIN/p/PROJECT \\ |
| 495 | refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} |
| 496 | |
| 497 | Example: |
| 498 | $FUNCNAME $1 1234 |
| 499 | will $1 patch-set 1 of change 1234 |
| 500 | EOF |
| 501 | ;; |
| 502 | push) cat <<EOF |
| 503 | usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH |
| 504 | |
| 505 | works as: |
| 506 | git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\ |
| 507 | {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH |
| 508 | |
| 509 | Example: |
| 510 | $FUNCNAME push fix6789:gingerbread |
| 511 | will push local branch 'fix6789' to Gerrit for branch 'gingerbread'. |
| 512 | HEAD will be pushed from local if omitted. |
| 513 | EOF |
| 514 | ;; |
| 515 | *) |
| 516 | $FUNCNAME __cmg_err_not_supported $1 && return |
| 517 | cat <<EOF |
| 518 | usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS] |
| 519 | |
| 520 | works as: |
| 521 | git fetch http://DOMAIN/p/PROJECT \\ |
| 522 | refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\ |
| 523 | && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS |
| 524 | EOF |
| 525 | ;; |
| 526 | esac |
| 527 | ;; |
| 528 | __cmg_get_ref) |
| 529 | $FUNCNAME __cmg_err_no_arg $command $# && return 1 |
| 530 | local change_id patchset_id hash |
| 531 | case $1 in |
| 532 | */*) |
| 533 | change_id=${1%%/*} |
| 534 | patchset_id=${1#*/} |
| 535 | ;; |
| 536 | *) |
| 537 | change_id=$1 |
| 538 | patchset_id=1 |
| 539 | ;; |
| 540 | esac |
| 541 | hash=$(($change_id % 100)) |
| 542 | case $hash in |
| 543 | [0-9]) hash="0$hash" ;; |
| 544 | esac |
| 545 | echo "refs/changes/$hash/$change_id/$patchset_id" |
| 546 | ;; |
| 547 | fetch|pull) |
| 548 | $FUNCNAME __cmg_err_no_arg $command $# help && return 1 |
| 549 | $FUNCNAME __cmg_err_not_repo && return 1 |
| 550 | local change=$1 |
| 551 | shift |
| 552 | git $command $@ http://$review/p/$project \ |
| 553 | $($FUNCNAME __cmg_get_ref $change) || return 1 |
| 554 | ;; |
| 555 | push) |
| 556 | $FUNCNAME __cmg_err_no_arg $command $# help && return 1 |
| 557 | $FUNCNAME __cmg_err_not_repo && return 1 |
| 558 | if [ -z "$user" ]; then |
| 559 | echo >&2 "Gerrit username not found." |
| 560 | return 1 |
| 561 | fi |
| 562 | local local_branch remote_branch |
| 563 | case $1 in |
| 564 | *:*) |
| 565 | local_branch=${1%:*} |
| 566 | remote_branch=${1##*:} |
| 567 | ;; |
| 568 | *) |
| 569 | local_branch=HEAD |
| 570 | remote_branch=$1 |
| 571 | ;; |
| 572 | esac |
| 573 | shift |
| 574 | git push $@ ssh://$user@$review:29418/$project \ |
| 575 | $local_branch:refs/for/$remote_branch || return 1 |
| 576 | ;; |
| 577 | changes|for) |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 578 | if [ "$FUNCNAME" = "lineagegerrit" ]; then |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 579 | echo >&2 "'$FUNCNAME $command' is deprecated." |
| 580 | fi |
| 581 | ;; |
| 582 | __cmg_err_no_arg) |
| 583 | if [ $# -lt 2 ]; then |
| 584 | echo >&2 "'$FUNCNAME $command' missing argument." |
| 585 | elif [ $2 -eq 0 ]; then |
| 586 | if [ -n "$3" ]; then |
| 587 | $FUNCNAME help $1 |
| 588 | else |
| 589 | echo >&2 "'$FUNCNAME $1' missing argument." |
| 590 | fi |
| 591 | else |
| 592 | return 1 |
| 593 | fi |
| 594 | ;; |
| 595 | __cmg_err_not_repo) |
| 596 | if [ -z "$review" -o -z "$project" ]; then |
| 597 | echo >&2 "Not currently in any reviewable repository." |
| 598 | else |
| 599 | return 1 |
| 600 | fi |
| 601 | ;; |
| 602 | __cmg_err_not_supported) |
| 603 | $FUNCNAME __cmg_err_no_arg $command $# && return |
| 604 | case $1 in |
| 605 | #TODO: filter more git commands that don't use refname |
| 606 | init|add|rm|mv|status|clone|remote|bisect|config|stash) |
| 607 | echo >&2 "'$FUNCNAME $1' is not supported." |
| 608 | ;; |
| 609 | *) return 1 ;; |
| 610 | esac |
| 611 | ;; |
| 612 | #TODO: other special cases? |
| 613 | *) |
| 614 | $FUNCNAME __cmg_err_not_supported $command && return 1 |
| 615 | $FUNCNAME __cmg_err_no_arg $command $# help && return 1 |
| 616 | $FUNCNAME __cmg_err_not_repo && return 1 |
| 617 | local args="$@" |
| 618 | local change pre_args refs_arg post_args |
| 619 | case "$args" in |
| 620 | *--\ *) |
| 621 | pre_args=${args%%-- *} |
| 622 | post_args="-- ${args#*-- }" |
| 623 | ;; |
| 624 | *) pre_args="$args" ;; |
| 625 | esac |
| 626 | args=($pre_args) |
| 627 | pre_args= |
| 628 | if [ ${#args[@]} -gt 0 ]; then |
| 629 | change=${args[${#args[@]}-1]} |
| 630 | fi |
| 631 | if [ ${#args[@]} -gt 1 ]; then |
| 632 | pre_args=${args[0]} |
| 633 | for ((i=1; i<${#args[@]}-1; i++)); do |
| 634 | pre_args="$pre_args ${args[$i]}" |
| 635 | done |
| 636 | fi |
| 637 | while ((1)); do |
| 638 | case $change in |
| 639 | ""|--) |
| 640 | $FUNCNAME help $command |
| 641 | return 1 |
| 642 | ;; |
| 643 | *@*) |
| 644 | if [ -z "$refs_arg" ]; then |
| 645 | refs_arg="@${change#*@}" |
| 646 | change=${change%%@*} |
| 647 | fi |
| 648 | ;; |
| 649 | *~*) |
| 650 | if [ -z "$refs_arg" ]; then |
| 651 | refs_arg="~${change#*~}" |
| 652 | change=${change%%~*} |
| 653 | fi |
| 654 | ;; |
| 655 | *^*) |
| 656 | if [ -z "$refs_arg" ]; then |
| 657 | refs_arg="^${change#*^}" |
| 658 | change=${change%%^*} |
| 659 | fi |
| 660 | ;; |
| 661 | *:*) |
| 662 | if [ -z "$refs_arg" ]; then |
| 663 | refs_arg=":${change#*:}" |
| 664 | change=${change%%:*} |
| 665 | fi |
| 666 | ;; |
| 667 | *) break ;; |
| 668 | esac |
| 669 | done |
| 670 | $FUNCNAME fetch $change \ |
| 671 | && git $command $pre_args FETCH_HEAD$refs_arg $post_args \ |
| 672 | || return 1 |
| 673 | ;; |
| 674 | esac |
| 675 | } |
| 676 | |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 677 | function lineagerebase() { |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 678 | local repo=$1 |
| 679 | local refs=$2 |
| 680 | local pwd="$(pwd)" |
| 681 | local dir="$(gettop)/$repo" |
| 682 | |
| 683 | if [ -z $repo ] || [ -z $refs ]; then |
Dan Pasanen | 0344771 | 2016-12-19 11:22:55 -0600 | [diff] [blame] | 684 | echo "LineageOS Gerrit Rebase Usage: " |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 685 | echo " lineagerebase <path to project> <patch IDs on Gerrit>" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 686 | echo " The patch IDs appear on the Gerrit commands that are offered." |
| 687 | echo " They consist on a series of numbers and slashes, after the text" |
| 688 | echo " refs/changes. For example, the ID in the following command is 26/8126/2" |
| 689 | echo "" |
| 690 | echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD" |
| 691 | echo "" |
| 692 | return |
| 693 | fi |
| 694 | |
| 695 | if [ ! -d $dir ]; then |
| 696 | echo "Directory $dir doesn't exist in tree." |
| 697 | return |
| 698 | fi |
| 699 | cd $dir |
| 700 | repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g) |
| 701 | echo "Starting branch..." |
| 702 | repo start tmprebase . |
| 703 | echo "Bringing it up to date..." |
| 704 | repo sync . |
| 705 | echo "Fetching change..." |
Dan Pasanen | 0344771 | 2016-12-19 11:22:55 -0600 | [diff] [blame] | 706 | git fetch "http://review.lineageos.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 707 | if [ "$?" != "0" ]; then |
| 708 | echo "Error cherry-picking. Not uploading!" |
| 709 | return |
| 710 | fi |
| 711 | echo "Uploading..." |
| 712 | repo upload . |
| 713 | echo "Cleaning up..." |
| 714 | repo abandon tmprebase . |
| 715 | cd $pwd |
| 716 | } |
| 717 | |
| 718 | function mka() { |
Luca Stefani | 085af72 | 2017-08-17 20:34:44 +0200 | [diff] [blame] | 719 | m -j "$@" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | function cmka() { |
| 723 | if [ ! -z "$1" ]; then |
| 724 | for i in "$@"; do |
| 725 | case $i in |
| 726 | bacon|otapackage|systemimage) |
| 727 | mka installclean |
| 728 | mka $i |
| 729 | ;; |
| 730 | *) |
| 731 | mka clean-$i |
| 732 | mka $i |
| 733 | ;; |
| 734 | esac |
| 735 | done |
| 736 | else |
| 737 | mka clean |
| 738 | mka |
| 739 | fi |
| 740 | } |
| 741 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 742 | function repolastsync() { |
| 743 | RLSPATH="$ANDROID_BUILD_TOP/.repo/.repo_fetchtimes.json" |
| 744 | RLSLOCAL=$(date -d "$(stat -c %z $RLSPATH)" +"%e %b %Y, %T %Z") |
| 745 | RLSUTC=$(date -d "$(stat -c %z $RLSPATH)" -u +"%e %b %Y, %T %Z") |
| 746 | echo "Last repo sync: $RLSLOCAL / $RLSUTC" |
| 747 | } |
| 748 | |
| 749 | function reposync() { |
Luca Stefani | 085af72 | 2017-08-17 20:34:44 +0200 | [diff] [blame] | 750 | repo sync -j 4 "$@" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | function repodiff() { |
| 754 | if [ -z "$*" ]; then |
| 755 | echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]" |
| 756 | return |
| 757 | fi |
| 758 | diffopts=$* repo forall -c \ |
| 759 | 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;' |
| 760 | } |
| 761 | |
| 762 | # Return success if adb is up and not in recovery |
| 763 | function _adb_connected { |
| 764 | { |
| 765 | if [[ "$(adb get-state)" == device && |
Marc K | 299137f | 2016-10-20 10:27:10 +0200 | [diff] [blame] | 766 | "$(adb shell test -e /sbin/recovery; echo $?)" != 0 ]] |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 767 | then |
| 768 | return 0 |
| 769 | fi |
| 770 | } 2>/dev/null |
| 771 | |
| 772 | return 1 |
| 773 | }; |
| 774 | |
| 775 | # Credit for color strip sed: http://goo.gl/BoIcm |
| 776 | function dopush() |
| 777 | { |
| 778 | local func=$1 |
| 779 | shift |
| 780 | |
| 781 | adb start-server # Prevent unexpected starting server message from adb get-state in the next line |
| 782 | if ! _adb_connected; then |
| 783 | echo "No device is online. Waiting for one..." |
| 784 | echo "Please connect USB and/or enable USB debugging" |
| 785 | until _adb_connected; do |
| 786 | sleep 1 |
| 787 | done |
| 788 | echo "Device Found." |
| 789 | fi |
| 790 | |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 791 | if (adb shell getprop ro.lineage.device | grep -q "$LINEAGE_BUILD") || [ "$FORCE_PUSH" = "true" ]; |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 792 | then |
| 793 | # retrieve IP and PORT info if we're using a TCP connection |
Marc K | 2be9cac | 2016-10-20 10:27:35 +0200 | [diff] [blame] | 794 | TCPIPPORT=$(adb devices \ |
| 795 | | egrep '^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9]):[0-9]+[^0-9]+' \ |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 796 | | head -1 | awk '{print $1}') |
| 797 | adb root &> /dev/null |
| 798 | sleep 0.3 |
| 799 | if [ -n "$TCPIPPORT" ] |
| 800 | then |
| 801 | # adb root just killed our connection |
| 802 | # so reconnect... |
| 803 | adb connect "$TCPIPPORT" |
| 804 | fi |
| 805 | adb wait-for-device &> /dev/null |
| 806 | sleep 0.3 |
| 807 | adb remount &> /dev/null |
| 808 | |
| 809 | mkdir -p $OUT |
| 810 | ($func $*|tee $OUT/.log;return ${PIPESTATUS[0]}) |
| 811 | ret=$?; |
| 812 | if [ $ret -ne 0 ]; then |
| 813 | rm -f $OUT/.log;return $ret |
| 814 | fi |
| 815 | |
Rashed Abdel-Tawab | 0180664 | 2017-01-19 15:52:13 -0500 | [diff] [blame] | 816 | is_gnu_sed=`sed --version | head -1 | grep -c GNU` |
| 817 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 818 | # Install: <file> |
Rashed Abdel-Tawab | 0180664 | 2017-01-19 15:52:13 -0500 | [diff] [blame] | 819 | if [ $is_gnu_sed -gt 0 ]; then |
Marc K | 97b035d | 2016-10-20 10:27:44 +0200 | [diff] [blame] | 820 | LOC="$(cat $OUT/.log | sed -r -e 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' -e 's/^\[ {0,2}[0-9]{1,3}% [0-9]{1,6}\/[0-9]{1,6}\] +//' \ |
| 821 | | grep '^Install: ' | cut -d ':' -f 2)" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 822 | else |
Marc K | 97b035d | 2016-10-20 10:27:44 +0200 | [diff] [blame] | 823 | LOC="$(cat $OUT/.log | sed -E "s/"$'\E'"\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g" -E "s/^\[ {0,2}[0-9]{1,3}% [0-9]{1,6}\/[0-9]{1,6}\] +//" \ |
| 824 | | grep '^Install: ' | cut -d ':' -f 2)" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 825 | fi |
| 826 | |
| 827 | # Copy: <file> |
Rashed Abdel-Tawab | 0180664 | 2017-01-19 15:52:13 -0500 | [diff] [blame] | 828 | if [ $is_gnu_sed -gt 0 ]; then |
Marc K | 97b035d | 2016-10-20 10:27:44 +0200 | [diff] [blame] | 829 | LOC="$LOC $(cat $OUT/.log | sed -r -e 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' -e 's/^\[ {0,2}[0-9]{1,3}% [0-9]{1,6}\/[0-9]{1,6}\] +//' \ |
| 830 | | grep '^Copy: ' | cut -d ':' -f 2)" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 831 | else |
Marc K | 97b035d | 2016-10-20 10:27:44 +0200 | [diff] [blame] | 832 | LOC="$LOC $(cat $OUT/.log | sed -E "s/"$'\E'"\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g" -E 's/^\[ {0,2}[0-9]{1,3}% [0-9]{1,6}\/[0-9]{1,6}\] +//' \ |
| 833 | | grep '^Copy: ' | cut -d ':' -f 2)" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 834 | fi |
| 835 | |
| 836 | # If any files are going to /data, push an octal file permissions reader to device |
| 837 | if [ -n "$(echo $LOC | egrep '(^|\s)/data')" ]; then |
| 838 | CHKPERM="/data/local/tmp/chkfileperm.sh" |
| 839 | ( |
| 840 | cat <<'EOF' |
| 841 | #!/system/xbin/sh |
| 842 | FILE=$@ |
| 843 | if [ -e $FILE ]; then |
| 844 | ls -l $FILE | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}' | cut -d ' ' -f1 |
| 845 | fi |
| 846 | EOF |
| 847 | ) > $OUT/.chkfileperm.sh |
| 848 | echo "Pushing file permissions checker to device" |
| 849 | adb push $OUT/.chkfileperm.sh $CHKPERM |
| 850 | adb shell chmod 755 $CHKPERM |
| 851 | rm -f $OUT/.chkfileperm.sh |
| 852 | fi |
| 853 | |
| 854 | stop_n_start=false |
| 855 | for FILE in $(echo $LOC | tr " " "\n"); do |
| 856 | # Make sure file is in $OUT/system or $OUT/data |
| 857 | case $FILE in |
| 858 | $OUT/system/*|$OUT/data/*) |
| 859 | # Get target file name (i.e. /system/bin/adb) |
| 860 | TARGET=$(echo $FILE | sed "s#$OUT##") |
| 861 | ;; |
| 862 | *) continue ;; |
| 863 | esac |
| 864 | |
| 865 | case $TARGET in |
| 866 | /data/*) |
| 867 | # fs_config only sets permissions and se labels for files pushed to /system |
| 868 | if [ -n "$CHKPERM" ]; then |
| 869 | OLDPERM=$(adb shell $CHKPERM $TARGET) |
| 870 | OLDPERM=$(echo $OLDPERM | tr -d '\r' | tr -d '\n') |
| 871 | OLDOWN=$(adb shell ls -al $TARGET | awk '{print $2}') |
| 872 | OLDGRP=$(adb shell ls -al $TARGET | awk '{print $3}') |
| 873 | fi |
| 874 | echo "Pushing: $TARGET" |
| 875 | adb push $FILE $TARGET |
| 876 | if [ -n "$OLDPERM" ]; then |
| 877 | echo "Setting file permissions: $OLDPERM, $OLDOWN":"$OLDGRP" |
| 878 | adb shell chown "$OLDOWN":"$OLDGRP" $TARGET |
| 879 | adb shell chmod "$OLDPERM" $TARGET |
| 880 | else |
| 881 | echo "$TARGET did not exist previously, you should set file permissions manually" |
| 882 | fi |
| 883 | adb shell restorecon "$TARGET" |
| 884 | ;; |
| 885 | /system/priv-app/SystemUI/SystemUI.apk|/system/framework/*) |
| 886 | # Only need to stop services once |
| 887 | if ! $stop_n_start; then |
| 888 | adb shell stop |
| 889 | stop_n_start=true |
| 890 | fi |
| 891 | echo "Pushing: $TARGET" |
| 892 | adb push $FILE $TARGET |
| 893 | ;; |
| 894 | *) |
| 895 | echo "Pushing: $TARGET" |
| 896 | adb push $FILE $TARGET |
| 897 | ;; |
| 898 | esac |
| 899 | done |
| 900 | if [ -n "$CHKPERM" ]; then |
| 901 | adb shell rm $CHKPERM |
| 902 | fi |
| 903 | if $stop_n_start; then |
| 904 | adb shell start |
| 905 | fi |
| 906 | rm -f $OUT/.log |
| 907 | return 0 |
| 908 | else |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 909 | echo "The connected device does not appear to be $LINEAGE_BUILD, run away!" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 910 | fi |
| 911 | } |
| 912 | |
| 913 | alias mmp='dopush mm' |
| 914 | alias mmmp='dopush mmm' |
| 915 | alias mmap='dopush mma' |
Zhao Wei Liew | 64fc5ae | 2016-12-10 16:48:27 +0800 | [diff] [blame] | 916 | alias mmmap='dopush mmma' |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 917 | alias mkap='dopush mka' |
| 918 | alias cmkap='dopush cmka' |
| 919 | |
| 920 | function repopick() { |
| 921 | T=$(gettop) |
Dan Pasanen | 91f7620 | 2017-07-06 08:21:30 -0500 | [diff] [blame] | 922 | $T/vendor/lineage/build/tools/repopick.py $@ |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | function fixup_common_out_dir() { |
| 926 | common_out_dir=$(get_build_var OUT_DIR)/target/common |
| 927 | target_device=$(get_build_var TARGET_DEVICE) |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 928 | if [ ! -z $LINEAGE_FIXUP_COMMON_OUT ]; then |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 929 | if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then |
| 930 | mv ${common_out_dir} ${common_out_dir}-${target_device} |
| 931 | ln -s ${common_out_dir}-${target_device} ${common_out_dir} |
| 932 | else |
| 933 | [ -L ${common_out_dir} ] && rm ${common_out_dir} |
| 934 | mkdir -p ${common_out_dir}-${target_device} |
| 935 | ln -s ${common_out_dir}-${target_device} ${common_out_dir} |
| 936 | fi |
| 937 | else |
| 938 | [ -L ${common_out_dir} ] && rm ${common_out_dir} |
| 939 | mkdir -p ${common_out_dir} |
| 940 | fi |
| 941 | } |
Steve Kondik | 26e669b | 2016-11-04 12:05:19 -0700 | [diff] [blame] | 942 | |
| 943 | # Enable SD-LLVM if available |
| 944 | if [ -d $(gettop)/prebuilts/snapdragon-llvm/toolchains ]; then |
Alexander Martinz | 1bbf3e9 | 2016-11-05 15:27:43 +0100 | [diff] [blame] | 945 | case `uname -s` in |
| 946 | Darwin) |
| 947 | # Darwin is not supported yet |
| 948 | ;; |
| 949 | *) |
| 950 | export SDCLANG=true |
| 951 | export SDCLANG_PATH=$(gettop)/prebuilts/snapdragon-llvm/toolchains/llvm-Snapdragon_LLVM_for_Android_3.8/prebuilt/linux-x86_64/bin |
| 952 | export SDCLANG_LTO_DEFS=$(gettop)/device/qcom/common/sdllvm-lto-defs.mk |
| 953 | ;; |
| 954 | esac |
Steve Kondik | 26e669b | 2016-11-04 12:05:19 -0700 | [diff] [blame] | 955 | fi |
Luca Stefani | 84fda60 | 2016-11-24 14:16:33 +0100 | [diff] [blame] | 956 | |
| 957 | # Android specific JACK args |
| 958 | if [ -n "$JACK_SERVER_VM_ARGUMENTS" ] && [ -z "$ANDROID_JACK_VM_ARGS" ]; then |
| 959 | export ANDROID_JACK_VM_ARGS=$JACK_SERVER_VM_ARGUMENTS |
| 960 | fi |