summaryrefslogtreecommitdiff
path: root/META-INF/com/google/android/update-binary
blob: fc3b94b17b548ff2786fa1478281a9fb69141a85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/sbin/sh
# AnyKernel3 Backend (DO NOT CHANGE)
# osm0sis @ xda-developers

OUTFD=/proc/self/fd/$2;
ZIPFILE="$3";

ps | grep zygote | grep -v grep >/dev/null && BOOTMODE=true || BOOTMODE=false;
$BOOTMODE || ps -A 2>/dev/null | grep zygote | grep -v grep >/dev/null && BOOTMODE=true;

$BOOTMODE && DIR=/sdcard || DIR=$(dirname "$ZIPFILE");

test "$home" || home=/tmp/anykernel;
parent=$(dirname $home);

ui_print() {
  until [ ! "$1" ]; do
    echo -e "ui_print $1\nui_print" > $OUTFD;
    shift;
  done;
}
show_progress() { echo "progress $1 $2" > $OUTFD; }
file_getprop() { $bb grep "^$2=" "$1" | $bb cut -d= -f2-; }
int2ver() {
  if [ "$1" -eq "$1" ] 2>/dev/null; then 
    echo "$1.0.0";
  elif [ ! "$(echo "$1" | $bb cut -d. -f3)" ]; then
    echo "$1.0";
  else
    echo "$1";
  fi;
}
cleanup() {
  cd $parent;
  rm -rf $home;
}
debugging() {
  case $(basename "$ZIPFILE" .zip) in
    *-debugging)
      ui_print " " "Creating debugging archive in $DIR...";
      $bb tar -czvf "$DIR/anykernel3-$(date +%Y-%m-%d_%H%M%S)-debug.tgz" $parent/*;
    ;;
  esac;
}
is_mounted() { $bb mount | $bb grep " $1 "; }
unmount_all() {
  ($bb umount /system;
  if [ -d /system_root -a ! -f /system/build.prop ]; then
    $bb umount /system_root;
  fi;
  $bb umount /system;
  $bb umount /vendor;
  $bb umount /data) 2>/dev/null;
}
abort() {
  ui_print "$*";
  debugging;
  if [ ! -f anykernel.sh -o "$(file_getprop anykernel.sh do.cleanuponabort 2>/dev/null)" == 1 ]; then
    cleanup;
  fi;
  unmount_all;
  exit 1;
}

show_progress 1.34 4;
ui_print " ";
cleanup;
mkdir -p $home/bin;
cd $home;
unzip -o "$ZIPFILE";
if [ $? != 0 -o ! "$(ls tools)" ]; then
  abort "Unzip failed. Aborting...";
fi;
bb=$home/tools/busybox;
chmod 755 $bb;
$bb chmod -R 755 tools bin;
$bb --install -s bin;
if [ $? != 0 -o -z "$(ls bin)" ]; then
  abort "Busybox setup failed. Aborting...";
fi;

if [ -f banner ]; then
  while IFS='' read -r line || $bb [[ -n "$line" ]]; do
    ui_print "$line";
  done < banner;
  ui_print " " " ";
fi;

ui_print "$(file_getprop anykernel.sh kernel.string)";
if [ -f version ]; then
  ui_print " ";
  while IFS='' read -r line || $bb [[ -n "$line" ]]; do
    ui_print "$line";
  done < version;
  ui_print " ";
fi;
ui_print " " "AnyKernel3 by osm0sis @ xda-developers" " " " ";

unmount_all;
if [ ! "$(is_mounted /system)" ]; then
  $bb mount -o ro -t auto /system;
fi;
($bb mount -o ro -t auto /vendor;
$bb mount /data) 2>/dev/null;
if [ -f /system/system/build.prop ]; then
  $bb umount /system;
  ($bb umount /system;
  mkdir /system_root) 2>/dev/null;
  $bb mount -o ro -t auto /dev/block/bootdevice/by-name/system /system_root;
  $bb mount -o bind /system_root/system /system;
fi;
savedpath="$LD_LIBRARY_PATH";
savedpre="$LD_PRELOAD";
unset LD_LIBRARY_PATH;
unset LD_PRELOAD;

if [ ! "$(getprop 2>/dev/null)" ]; then
  getprop() {
    local propval="$(file_getprop /default.prop $1 2>/dev/null)";
    test "$propval" || local propval="$(file_getprop /system/build.prop $1 2>/dev/null)";
    test "$propval" && echo "$propval" || echo "";
  }
elif [ ! "$(getprop ro.product.device 2>/dev/null)" -a ! "$(getprop ro.build.product 2>/dev/null)" ]; then
  getprop() {
    ($(which getprop) | $bb grep "$1" | $bb cut -d[ -f3 | $bb cut -d] -f1) 2>/dev/null;
  }
fi;

if [ "$(file_getprop anykernel.sh do.devicecheck)" == 1 ]; then
  ui_print "Checking device...";
  device="$(getprop ro.product.device)";
  product="$(getprop ro.build.product)";
  for testname in $(file_getprop anykernel.sh 'device.name.*'); do
    if [ "$device" == "$testname" -o "$product" == "$testname" ]; then
      ui_print "$testname";
      match=1;
      break;
    fi;
  done;
  ui_print " ";
  if [ ! "$match" ]; then
    abort "Unsupported device. Aborting...";
  fi;
fi;

supported_ver="$(file_getprop anykernel.sh supported.versions | $bb tr -d '[:space:]')";
if [ "$supported_ver" ]; then
  ui_print "Checking Android version...";
  android_ver="$(file_getprop /system/build.prop ro.build.version.release)";
  if [ "$(echo $supported_ver | $bb grep -)" ]; then
    lo_ver=$(echo $supported_ver | $bb cut -d- -f1);
    hi_ver=$(echo $supported_ver | $bb cut -d- -f2);
    if [ "$(echo -e "$(int2ver $hi_ver)\n$(int2ver $lo_ver)\n$(int2ver $android_ver)" | $bb sort -g | $bb grep -n "$(int2ver $android_ver)" | $bb grep '^2:')" ]; then
      supported=1;
    fi;
  else
    for ver in $(echo $supported_ver | $bb sed 's;,; ;g'); do
      if [ "$(int2ver $ver)" == "$(int2ver $android_ver)" ]; then
        supported=1;
        break;
      fi;
    done;
  fi;
  if [ "$supported" ]; then
    ui_print "$android_ver" " ";
  else
    ui_print " ";
    abort "Unsupported Android version. Aborting...";
  fi;
fi;

ui_print "Installing...";
core=$($bb grep -oE 'ak.*core.sh' anykernel.sh);
test -f tools/$core || $bb ln -s $home/tools/ak*-core.sh $home/tools/$core;
PATH="$home/bin:$PATH" home=$home $bb ash anykernel.sh $2;
if [ $? != 0 ]; then
  abort;
fi;

if [ "$(file_getprop anykernel.sh do.modules)" == 1 ]; then
  ui_print " " "Pushing modules...";
  $bb mount -o rw,remount -t auto /system;
  $bb mount -o rw,remount -t auto /vendor 2>/dev/null;
  cd $home/modules;
  for module in $(find . -name '*.ko'); do
    modtarget=$(echo $module | $bb cut -c2-);
    if [ ! -e $modtarget ]; then
      case $module in
        */vendor/*) modcon=vendor;;
        *) modcon=system;;
      esac;
    fi;
    if [ "$(is_mounted $modtarget)" ]; then
      $bb mount -o rw,remount -t auto $modtarget;
    fi;
    mkdir -p $(dirname $modtarget);
    $bb cp -rLf $module $modtarget;
    $bb chown 0:0 $modtarget;
    $bb chmod 644 $modtarget;
    if [ "$modcon" ]; then
      chcon "u:object_r:${modcon}_file:s0" $modtarget;
    fi;
    if [ "$(is_mounted $modtarget)" ]; then
      $bb mount -o ro,remount -t auto $modtarget;
    fi;
  done;
  cd $home;
  $bb mount -o ro,remount -t auto /system;
  $bb mount -o ro,remount -t auto /vendor 2>/dev/null;
fi;

debugging;

if [ "$(file_getprop anykernel.sh do.cleanup)" == 1 ]; then
  cleanup;
fi;

test "$savedpath" && export LD_LIBRARY_PATH="$savedpath";
test "$savedpre" && export LD_PRELOAD="$savedpre";

unmount_all;

ui_print " " " " "Done!";