summaryrefslogtreecommitdiff
path: root/META-INF/com/google/android/update-binary
blob: 0b466a0797df546f64931b1b0e250969c4322bda (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
#!/sbin/sh
# AnyKernel2 Backend
# osm0sis @ xda-developers

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

ui_print() {
  until [ ! "$1" ]; do
    echo -e "ui_print $1\nui_print" > $OUTFD;
    shift;
  done;
}
show_progress() { echo "progress $1 $2" > $OUTFD; }
file_getprop() { grep "^$2=" "$1" | cut -d= -f2; }
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 "";
  }
fi;
cleanup() { rm -rf /tmp/anykernel; }
debugging() {
  case $(basename "$ZIPFILE" .zip) in
    *-debugging)
      ui_print " ";
      ui_print "Creating debugging archive in zip directory...";
      $bb tar -czvf "$DIR/anykernel2-$(date +%Y-%m-%d_%H%M%S)-debug.tgz" /tmp/*;
    ;;
  esac;
}
abort() {
  ui_print "$*";
  debugging;
  if [ ! -f /tmp/anykernel/anykernel.sh -o "$(file_getprop /tmp/anykernel/anykernel.sh do.cleanuponabort 2>/dev/null)" == 1 ]; then
    cleanup;
  fi;
  umount /system;
  umount /vendor 2>/dev/null;
  umount /data 2>/dev/null;
  exit 1;
}

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

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

ui_print "$(file_getprop /tmp/anykernel/anykernel.sh kernel.string)";
if [ -f /tmp/anykernel/version ]; then
  ui_print " ";
  ui_print "$(cat /tmp/anykernel/version)";
  ui_print " ";
fi;
ui_print " ";
ui_print "AnyKernel2 by osm0sis @ xda-developers";
ui_print " ";
ui_print " ";

umount /system 2>/dev/null;
umount /vendor 2>/dev/null;
mount -o ro -t auto /system;
mount -o ro -t auto /vendor 2>/dev/null;
mount /data 2>/dev/null;
test -f /system/system/build.prop && root=/system;

if [ "$(file_getprop /tmp/anykernel/anykernel.sh do.devicecheck)" == 1 ]; then
  ui_print "Checking device...";
  for i in 1 2 3 4 5; do
    testname="$(file_getprop /tmp/anykernel/anykernel.sh device.name$i)";
    if [ "$(getprop ro.product.device)" == "$testname" -o "$(getprop ro.build.product)" == "$testname" ]; then
      ui_print "$testname";
      match=1;
    fi;
  done;
  ui_print " ";
  if [ "$match" != 1 ]; then
    abort "Unsupported device. Aborting...";
  fi;
fi;

ui_print "Installing kernel...";
for i in $($bb --list); do
  $bb ln -s $bb /tmp/anykernel/bin/$i;
done;
if [ $? != 0 -o -z "$(ls /tmp/anykernel/bin)" ]; then
  abort "Recovery busybox setup failed. Aborting...";
fi;
PATH="/tmp/anykernel/bin:$PATH" $bb ash /tmp/anykernel/anykernel.sh $2;
if [ $? != "0" ]; then
  abort;
fi;

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

debugging;

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

umount /system;
umount /vendor 2>/dev/null;
umount /data 2>/dev/null;
ui_print " ";
ui_print " ";
ui_print "Done!";