]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - IMG/cpio/ventoy/ventoy_chain.sh
Support Lenovo EasyStartup
[Ventoy.git] / IMG / cpio / ventoy / ventoy_chain.sh
1 #!/ventoy/busybox/sh
2 #************************************************************************************
3 # Copyright (c) 2020, longpanda <admin@ventoy.net>
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; either version 3 of the
8 # License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, see <http://www.gnu.org/licenses/>.
17 #
18 #************************************************************************************
19
20 ####################################################################
21 # #
22 # Step 1 : Parse kernel parameter #
23 # #
24 ####################################################################
25 if ! [ -e /proc ]; then
26 $BUSYBOX_PATH/mkdir /proc
27 rmproc='Y'
28 fi
29 $BUSYBOX_PATH/mount -t proc proc /proc
30
31 # vtinit=xxx to replace rdinit=xxx
32 vtcmdline=$($CAT /proc/cmdline)
33 for i in $vtcmdline; do
34 if echo $i | $GREP -q vtinit; then
35 user_rdinit=${i#vtinit=}
36 echo "user set user_rdinit=${user_rdinit}" >>$VTLOG
37 fi
38 done
39
40 ####################################################################
41 # #
42 # Step 2 : Do OS specific hook #
43 # #
44 ####################################################################
45 ventoy_get_os_type() {
46 echo "kernel version" >> $VTLOG
47 $CAT /proc/version >> $VTLOG
48
49 if [ -d /twres ]; then
50 if $GREP -q 'Phoenix' /init; then
51 echo 'phoenixos'; return
52 fi
53 fi
54
55 # rhel5/CentOS5 and all other distributions based on them
56 if $GREP -q 'el5' /proc/version; then
57 echo 'rhel5'; return
58
59 # rhel6/CentOS6 and all other distributions based on them
60 elif $GREP -q 'el6' /proc/version; then
61 if [ -f /sbin/detectcd ]; then
62 if $GREP -q -i 'LENOVO-EasyStartup' /sbin/detectcd; then
63 echo 'easystartup'; return
64 fi
65 fi
66
67 echo 'rhel6'; return
68
69 # rhel7/CentOS7/rhel8/CentOS8 and all other distributions based on them
70 elif $GREP -q 'el[78]' /proc/version; then
71 echo 'rhel7'; return
72
73 # Maybe rhel9 rhel1x use the same way? Who knows!
74 elif $EGREP -q 'el9|el1[0-9]' /proc/version; then
75 echo 'rhel7'; return
76
77 # Fedora : do the same process with rhel7
78 elif $GREP -q '\.fc[0-9][0-9]\.' /proc/version; then
79 echo 'rhel7'; return
80
81 # Debian :
82 elif $GREP -q '[Dd]ebian' /proc/version; then
83 echo 'debian'; return
84
85 # Ubuntu : do the same process with debian
86 elif $GREP -q '[Uu]buntu' /proc/version; then
87 echo 'debian'; return
88
89 # Deepin : do the same process with debian
90 elif $GREP -q '[Dd]eepin' /proc/version; then
91 echo 'debian'; return
92
93 # SUSE
94 elif $GREP -q 'SUSE' /proc/version; then
95 echo 'suse'; return
96
97 # ArchLinux
98 elif $EGREP -q 'archlinux|ARCH' /proc/version; then
99 echo 'arch'; return
100
101 # kiosk
102 elif $EGREP -q 'kiosk' /proc/version; then
103 echo 'kiosk'; return
104
105 # gentoo
106 elif $EGREP -q '[Gg]entoo' /proc/version; then
107 if $GREP -q 'daphile' /proc/version; then
108 echo 'daphile'; return
109 fi
110
111 echo 'gentoo'; return
112
113 # TinyCore
114 elif $EGREP -q 'tinycore' /proc/version; then
115 echo 'tinycore'; return
116
117 # manjaro
118 elif $EGREP -q 'manjaro|MANJARO' /proc/version; then
119 echo 'manjaro'; return
120
121 # mageia
122 elif $EGREP -q 'mageia' /proc/version; then
123 echo 'mageia'; return
124
125 # pclinux OS
126 elif $GREP -i -q 'PCLinuxOS' /proc/version; then
127 echo 'pclos'; return
128
129 # KaOS
130 elif $GREP -i -q 'kaos' /proc/version; then
131 echo 'kaos'; return
132
133 # Alpine
134 elif $GREP -q 'Alpine' /proc/version; then
135 echo 'alpine'; return
136
137 elif $GREP -i -q 'PhoenixOS' /proc/version; then
138 echo 'phoenixos'; return
139
140 # NixOS
141 elif $GREP -i -q 'NixOS' /proc/version; then
142 echo 'nixos'; return
143
144
145 fi
146
147 if [ -e /lib/debian-installer ]; then
148 echo 'debian'; return
149 fi
150
151 if [ -e /etc/os-release ]; then
152 if $GREP -q 'XenServer' /etc/os-release; then
153 echo 'xen'; return
154 elif $GREP -q 'SUSE ' /etc/os-release; then
155 echo 'suse'; return
156 elif $GREP -q 'uruk' /etc/os-release; then
157 echo 'debian'; return
158 elif $GREP -q 'Solus' /etc/os-release; then
159 echo 'rhel7'; return
160 elif $GREP -q 'openEuler' /etc/os-release; then
161 echo 'openEuler'; return
162 elif $GREP -q 'fuyu' /etc/os-release; then
163 echo 'openEuler'; return
164 fi
165 fi
166
167 if $BUSYBOX_PATH/dmesg | $GREP -q -m1 "Xen:"; then
168 echo 'xen'; return
169 fi
170
171
172 if [ -e /etc/HOSTNAME ] && $GREP -i -q 'slackware' /etc/HOSTNAME; then
173 echo 'slackware'; return
174 fi
175
176 if [ -e /init ]; then
177 if $GREP -i -q zeroshell /init; then
178 echo 'zeroshell'; return
179 fi
180 fi
181
182 if $EGREP -q 'ALT ' /proc/version; then
183 echo 'alt'; return
184 fi
185
186 if $EGREP -q 'porteus' /proc/version; then
187 echo 'debian'; return
188 fi
189
190 if $GREP -q 'Clear Linux ' /proc/version; then
191 echo 'clear'; return
192 fi
193
194 if $GREP -q 'artix' /proc/version; then
195 echo 'arch'; return
196 fi
197
198 if $GREP -q 'berry ' /proc/version; then
199 echo 'berry'; return
200 fi
201
202 if $GREP -q 'Gobo ' /proc/version; then
203 echo 'gobo'; return
204 fi
205
206 if $GREP -q 'NuTyX' /proc/version; then
207 echo 'nutyx'; return
208 fi
209
210 if [ -d /gnu ]; then
211 vtLineNum=$($FIND /gnu/ -name guix | $BUSYBOX_PATH/wc -l)
212 if [ $vtLineNum -gt 0 ]; then
213 echo 'guix'; return
214 fi
215 fi
216
217 if $GREP -q 'android.x86' /proc/version; then
218 echo 'android'; return
219 fi
220
221 if $GREP -q 'adelielinux' /proc/version; then
222 echo 'adelie'; return
223 fi
224
225 if $GREP -q 'pmagic' /proc/version; then
226 echo 'pmagic'; return
227 fi
228
229 if $GREP -q 'CDlinux' /proc/cmdline; then
230 echo 'cdlinux'; return
231 fi
232
233 if $GREP -q 'parabola' /proc/version; then
234 echo 'parabola'; return
235 fi
236
237 if $GREP -q 'cucumber' /proc/version; then
238 echo 'cucumber'; return
239 fi
240
241 if $GREP -q 'fatdog' /proc/version; then
242 echo 'fatdog'; return
243 fi
244
245 if $GREP -q 'KWORT' /proc/version; then
246 echo 'kwort'; return
247 fi
248
249 if $GREP -q 'iwamoto' /proc/version; then
250 echo 'vine'; return
251 fi
252
253 if $GREP -q 'hyperbola' /proc/cmdline; then
254 echo 'hyperbola'; return
255 fi
256
257 if $GREP -q 'CRUX' /proc/version; then
258 echo 'crux'; return
259 fi
260
261 if [ -f /init ]; then
262 if $GREP -q 'AryaLinux' /init; then
263 echo 'aryalinux'; return
264 elif $GREP -q 'Dragora' /init; then
265 echo 'dragora'; return
266
267 fi
268 fi
269
270 if $GREP -q 'slackware' /proc/version; then
271 echo 'slackware'; return
272 fi
273
274 if $BUSYBOX_PATH/hostname | $GREP -q 'smoothwall'; then
275 echo 'smoothwall'; return
276 fi
277
278 if $GREP -q 'photon' /proc/version; then
279 echo 'photon'; return
280 fi
281
282 if $GREP -q 'ploplinux' /proc/version; then
283 echo 'ploplinux'; return
284 fi
285
286 if $GREP -q 'lunar' /proc/version; then
287 echo 'lunar'; return
288 fi
289
290 if $GREP -q 'SMGL-' /proc/version; then
291 echo 'smgl'; return
292 fi
293
294 if $GREP -q 'rancher' /proc/version; then
295 echo 'rancher'; return
296 fi
297
298
299 if [ -e /init ]; then
300 if $GREP -q -m1 'T2 SDE' /init; then
301 echo 't2'; return
302 fi
303 fi
304
305 if $GREP -q 'wifislax' /proc/version; then
306 echo 'wifislax'; return
307 fi
308
309 if $GREP -q 'pisilinux' /proc/version; then
310 echo 'pisilinux'; return
311 fi
312
313 if $GREP -q 'blackPanther' /proc/version; then
314 echo 'blackPanther'; return
315 fi
316
317 if $GREP -q 'primeos' /proc/version; then
318 echo 'primeos'; return
319 fi
320
321 if $GREP -q 'austrumi' /proc/version; then
322 echo 'austrumi'; return
323 fi
324
325 if [ -f /DISTRO_SPECS ]; then
326 if $GREP -q '[Pp]uppy' /DISTRO_SPECS; then
327 echo 'debian'; return
328 elif $GREP -q 'veket' /DISTRO_SPECS; then
329 echo 'debian'; return
330 fi
331 fi
332
333 if [ -f /etc/openEuler-release ]; then
334 echo "openEuler"; return
335 fi
336
337 echo "default"
338 }
339
340 VTOS=$(ventoy_get_os_type)
341 echo "OS=###${VTOS}###" >>$VTLOG
342 if [ -e "$VTOY_PATH/hook/$VTOS/ventoy-hook.sh" ]; then
343 $BUSYBOX_PATH/sh "$VTOY_PATH/hook/$VTOS/ventoy-hook.sh"
344 fi
345
346
347 ####################################################################
348 # #
349 # Step 3 : Check for debug break #
350 # #
351 ####################################################################
352 if [ "$VTOY_BREAK_LEVEL" = "03" ] || [ "$VTOY_BREAK_LEVEL" = "13" ]; then
353 $SLEEP 5
354 echo -e "\n\n\033[32m ################################################# \033[0m"
355 echo -e "\033[32m ################ VENTOY DEBUG ################### \033[0m"
356 echo -e "\033[32m ################################################# \033[0m \n"
357 if [ "$VTOY_BREAK_LEVEL" = "13" ]; then
358 $CAT $VTOY_PATH/log
359 fi
360 exec $BUSYBOX_PATH/sh
361 fi
362
363
364 ####################################################################
365 # #
366 # Step 4 : Hand over to real init #
367 # #
368 ####################################################################
369 $BUSYBOX_PATH/umount /proc
370 if [ "$rmproc" = "Y" ]; then
371 $BUSYBOX_PATH/rm -rf /proc
372 fi
373
374 if [ -f $VTOY_PATH/ventoy_persistent_map ]; then
375 export PERSISTENT='YES'
376 export PERSISTENCE='true'
377 fi
378
379 cd /
380
381 unset VTLOG FIND GREP EGREP CAT AWK SED SLEEP HEAD vtcmdline
382
383 for vtinit in $user_rdinit /init /sbin/init /linuxrc; do
384 if [ -d /ventoy_rdroot ]; then
385 if [ -e "/ventoy_rdroot$vtinit" ]; then
386 # switch_root will check /init file, this is a cheat code
387 echo 'switch_root' > /init
388 exec $BUSYBOX_PATH/switch_root /ventoy_rdroot "$vtinit"
389 fi
390 else
391 if [ -e "$vtinit" ];then
392 if [ -f "$VTOY_PATH/hook/$VTOS/ventoy-before-init.sh" ]; then
393 $BUSYBOX_PATH/sh "$VTOY_PATH/hook/$VTOS/ventoy-before-init.sh"
394 fi
395 exec "$vtinit"
396 fi
397 fi
398 done
399
400 # Should never reach here
401 echo -e "\n\n\033[31m ############ INIT NOT FOUND ############### \033[0m \n"
402 exec $BUSYBOX_PATH/sh