forked from osm0sis/AnyKernel3
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanykernel.sh
More file actions
executable file
·199 lines (175 loc) · 5.75 KB
/
anykernel.sh
File metadata and controls
executable file
·199 lines (175 loc) · 5.75 KB
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
### AnyKernel3 Ramdisk Mod Script
## osm0sis @ xda-developers
### AnyKernel setup
# global properties
properties() { '
kernel.string=Spiteful Kernel by @vbajs
do.devicecheck=1
do.modules=0
do.systemless=1
do.cleanup=1
do.cleanuponabort=0
device.name1=sweet
device.name2=sweetin
supported.versions=
supported.patchlevels=
supported.vendorpatchlevels=
'; }
### AnyKernel install
# boot shell variables
block=/dev/block/bootdevice/by-name/boot
is_slot_device=0
ramdisk_compression=auto
patch_vbmeta_flag=auto
# import functions/variables and setup patching
. tools/ak3-core.sh
# Archive and kernel image definitions
ARCHIVE="$AKHOME/Image.7z"
EXTRACT_DIR="$AKHOME/tmp_kernel"
KERNEL_NONKSU="Image"
KERNEL_RKSU="rksu-Image"
KERNEL_KSUN="ksun-Image"
# Dummy files
DUMMY_NONKSU="$AKHOME/NONKSU"
DUMMY_RKSU="$AKHOME/RKSU"
DUMMY_KSUN="$AKHOME/KSUN"
SELECTED_KERNEL=""
# ================================================
# Step 1: Extract Archive
# ================================================
ui_print "==============================================="
ui_print " EXTRACTING KERNEL ARCHIVE"
ui_print "==============================================="
mkdir -p "$EXTRACT_DIR"
chmod 755 "$AKHOME/tools/7za"
ui_print "[========== ] 33%..."
"$AKHOME/tools/7za" x "$ARCHIVE" -o"$EXTRACT_DIR"
ui_print "[================== ] 66%..."
sleep 0.5
ui_print "[====================] 100%"
ui_print "DONE: Extraction complete"
# ================================================
# Force NONKSU when Magisk is detected
# ================================================
if [ -f /data/adb/magisk/magisk ]; then
ui_print "WARNING: Magisk found! Creating NONKSU trigger"
ui_print "IT IS NOT RECOMMENDED TO HAVE KSU AND MAGISK AT THE SAME TIME!!"
ui_print "If you want KSU, please uninstall Magisk completely, and then reflash kernel zip."
touch $AKHOME/NONKSU
fi
# ================================================
# Step 2: Dummy File Detection
# ================================================
ui_print "==============================================="
ui_print " DETECTING KERNEL TYPE"
ui_print "==============================================="
count=0
[ -f "$DUMMY_NONKSU" ] && count=$((count + 1))
[ -f "$DUMMY_KSU" ] && count=$((count + 1))
[ -f "$DUMMY_SUSFS" ] && count=$((count + 1))
if [ "$count" -gt 1 ]; then
ui_print "ERROR: More than one dummy trigger found!"
rm -rf "$EXTRACT_DIR"
exit 1
elif [ "$count" -eq 1 ]; then
if [ -f "$DUMMY_RKSU" ]; then
ui_print "TRIGGER DETECTED: RKSU -> RissuKSU"
SELECTED_KERNEL="$EXTRACT_DIR/$KERNEL_RKSU"
elif [ -f "$DUMMY_KSUN" ]; then
ui_print "TRIGGER DETECTED: KSUN -> KernelSU-Next + SUSFS 1.5.12"
SELECTED_KERNEL="$EXTRACT_DIR/$KERNEL_KSUN"
else
ui_print "TRIGGER DETECTED: NONKSU -> Non-root"
SELECTED_KERNEL="$EXTRACT_DIR/$KERNEL_NONKSU"
fi
else
# ================================================
# Step 3: Volume Key Selector
# ================================================
ui_print "==============================================="
ui_print " VOLUME KEY SELECTION MODE"
ui_print "==============================================="
selection=1
ui_print " "
ui_print "Select Image to flash"
ui_print "USE VOLUME + TO CYCLE, VOLUME - TO SELECT"
ui_print "TIMEOUT: 10 SECONDS"
ui_print " "
ui_print "1. Non-root (DEFAULT)"
ui_print "2. RissuKSU"
ui_print "3. KenelSU-Next + SUSFS 1.5.12"
ui_print " "
ui_print "CURRENT SELECTION: Non-root"
start_time=$(date +%s)
timeout=10
while true; do
keyevent=$(getevent -lc 1 2>/dev/null | grep "KEY_" | head -n 1 | awk '{print $3}')
now=$(date +%s)
elapsed=$((now - start_time))
if [ "$elapsed" -ge "$timeout" ]; then
ui_print "TIMEOUT REACHED. ABORTING!"
rm -rf "$EXTRACT_DIR"
exit 1
fi
case "$keyevent" in
KEY_VOLUMEUP)
selection=$(((selection % 3) + 1))
case $selection in
1) ui_print "CURRENT SELECTION: Non-root" ;;
2) ui_print "CURRENT SELECTION: RissuKSU" ;;
3) ui_print "CURRENT SELECTION: KernelSU-Next + SUSFS 1.5.12" ;;
esac
start_time=$(date +%s)
sleep 0.5
;;
KEY_VOLUMEDOWN)
case $selection in
1)
ui_print "SELECTED: Non-root"
SELECTED_KERNEL="$EXTRACT_DIR/$KERNEL_NONKSU"
;;
2)
ui_print "SELECTED: RissuKSU"
SELECTED_KERNEL="$EXTRACT_DIR/$KERNEL_RKSU"
;;
3)
ui_print "SELECTED: KernelSU-Next + SUSFS 1.5.12"
SELECTED_KERNEL="$EXTRACT_DIR/$KERNEL_KSUN"
;;
esac
break
;;
esac
done
fi
# ================================================
# Step 4: Compress Selected Kernel
# ================================================
ui_print "==============================================="
ui_print " COMPRESSING SELECTED KERNEL"
ui_print "==============================================="
if [ -f "$SELECTED_KERNEL" ]; then
ui_print "GZIPPING IMAGE..."
gzip -c "$SELECTED_KERNEL" > "$AKHOME/Image.gz"
ui_print "SUCCESS: IMAGE SAVED AS Image.gz"
else
ui_print "ERROR: SELECTED KERNEL IMAGE NOT FOUND"
rm -rf "$EXTRACT_DIR"
exit 1
fi
# ================================================
# Step 6: Clean Temporary Files
# ================================================
ui_print "==============================================="
ui_print " CLEANING TEMPORARY FILES"
ui_print "==============================================="
rm -rf "$EXTRACT_DIR"
## boot files attributes
boot_attributes() {
set_perm_recursive 0 0 755 644 $ramdisk/*
set_perm_recursive 0 0 750 750 $ramdisk/init* $ramdisk/sbin
}
# boot install
dump_boot; # use split_boot to skip ramdisk unpack, e.g. for devices with init_boot ramdisk
write_boot; # use flash_boot to skip ramdisk repack, e.g. for devices with init_boot ramdisk
## end boot install