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