]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - IMG/cpio/ventoy/ventoy_loop.sh
Fix the drive letter case check issue for VentoyPlugson in Windows. (#2078)
[Ventoy.git] / IMG / cpio / ventoy / ventoy_loop.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 : Process ko #
43 # #
44 ####################################################################
45 $BUSYBOX_PATH/mkdir -p /ventoy/modules
46 $BUSYBOX_PATH/ls -1a / | $EGREP '\.ko$|\.ko.[gx]z$' | while read vtline; do
47 if [ "${vtline:0:1}" = "." ]; then
48 $BUSYBOX_PATH/mv /${vtline} /ventoy/modules/${vtline:1}
49 else
50 $BUSYBOX_PATH/mv /${vtline} /ventoy/modules/
51 fi
52 done
53
54 if [ -e /vtloopex.tar.xz ]; then
55 echo "extract vtloopex ..." >> $VTLOG
56 $BUSYBOX_PATH/tar -xJf /vtloopex.tar.xz -C $VTOY_PATH/
57 $BUSYBOX_PATH/rm -f /vtloopex.tar.xz
58 fi
59
60
61 ####################################################################
62 # #
63 # Step 3 : Do OS specific hook #
64 # #
65 ####################################################################
66 ventoy_get_os_type() {
67 echo "kernel version" >> $VTLOG
68 $CAT /proc/version >> $VTLOG
69
70 if $GREP -q 'endless' /proc/version; then
71 echo 'endless'; return
72 fi
73
74 if $GREP -q 'OpenWrt' /proc/version; then
75 echo 'openwrt'; return
76 fi
77
78 if $GREP -q 'easyos' /proc/cmdline; then
79 echo 'easyos'; return
80 fi
81
82 if [ -e /BOOT_SPECS ]; then
83 if $GREP -q 'easyos' /BOOT_SPECS; then
84 echo 'easyos'; return
85 fi
86 fi
87
88 if [ -e /etc/os-release ]; then
89 if $GREP -q 'volumio' /etc/os-release; then
90 echo 'volumio'; return
91 fi
92 fi
93
94 if $GREP -q 'ventoyos=' /proc/cmdline; then
95 $SED "s/.*ventoyos=\([a-zA-Z0-9_-]*\).*/\1/" /proc/cmdline; return
96 fi
97
98 if [ -d /twres ]; then
99 if $GREP -q 'Phoenix' /init; then
100 echo 'phoenixos'; return
101 fi
102 fi
103
104 # rhel5/CentOS5 and all other distributions based on them
105 if $GREP -q 'el5' /proc/version; then
106 echo 'rhel5'; return
107
108 # rhel6/CentOS6 and all other distributions based on them
109 elif $GREP -q 'el6' /proc/version; then
110 echo 'rhel6'; return
111
112 # rhel7/CentOS7/rhel8/CentOS8 and all other distributions based on them
113 elif $GREP -q 'el[78]' /proc/version; then
114 echo 'rhel7'; return
115
116 # Maybe rhel9 rhel1x use the same way? Who knows!
117 elif $EGREP -q 'el9|el1[0-9]' /proc/version; then
118 echo 'rhel7'; return
119
120 # Fedora : do the same process with rhel7
121 elif $GREP -q '\.fc[0-9][0-9]\.' /proc/version; then
122 echo 'rhel7'; return
123
124 # Debian :
125 elif $GREP -q '[Dd]ebian' /proc/version; then
126 echo 'debian'; return
127
128 # Ubuntu : do the same process with debian
129 elif $GREP -q '[Uu]buntu' /proc/version; then
130 echo 'debian'; return
131
132 # Deepin : do the same process with debian
133 elif $GREP -q '[Dd]eepin' /proc/version; then
134 echo 'debian'; return
135
136 # SUSE
137 elif $GREP -q 'SUSE' /proc/version; then
138 echo 'suse'; return
139
140 # ArchLinux
141 elif $EGREP -q 'archlinux|ARCH' /proc/version; then
142 echo 'arch'; return
143
144 # kiosk
145 elif $EGREP -q 'kiosk' /proc/version; then
146 echo 'kiosk'; return
147
148 # gentoo
149 elif $EGREP -q '[Gg]entoo' /proc/version; then
150 if $GREP -q 'daphile' /proc/version; then
151 echo 'daphile'; return
152 fi
153
154 echo 'gentoo'; return
155
156 # TinyCore
157 elif $EGREP -q 'tinycore' /proc/version; then
158 echo 'tinycore'; return
159
160 # manjaro
161 elif $EGREP -q 'manjaro|MANJARO' /proc/version; then
162 echo 'manjaro'; return
163
164 # mageia
165 elif $EGREP -q 'mageia' /proc/version; then
166 echo 'mageia'; return
167
168 # pclinux OS
169 elif $GREP -i -q 'PCLinuxOS' /proc/version; then
170 echo 'pclos'; return
171
172 # KaOS
173 elif $GREP -i -q 'kaos' /proc/version; then
174 echo 'kaos'; return
175
176 # Alpine
177 elif $GREP -q 'Alpine' /proc/version; then
178 echo 'alpine'; return
179
180 elif $GREP -i -q 'PhoenixOS' /proc/version; then
181 echo 'phoenixos'; return
182
183 # NixOS
184 elif $GREP -i -q 'NixOS' /proc/version; then
185 echo 'nixos'; return
186
187
188 fi
189
190 if [ -e /lib/debian-installer ]; then
191 echo 'debian'; return
192 fi
193
194 if [ -e /etc/os-release ]; then
195 if $GREP -q 'XenServer' /etc/os-release; then
196 echo 'xen'; return
197 elif $GREP -q 'SUSE ' /etc/os-release; then
198 echo 'suse'; return
199 elif $GREP -q 'uruk' /etc/os-release; then
200 echo 'debian'; return
201 elif $GREP -q 'Solus' /etc/os-release; then
202 echo 'rhel7'; return
203 elif $GREP -q 'openEuler' /etc/os-release; then
204 echo 'openEuler'; return
205 elif $GREP -q 'fuyu' /etc/os-release; then
206 echo 'openEuler'; return
207 elif $GREP -q 'deepin' /etc/os-release; then
208 echo 'debian'; return
209 elif $GREP -q 'chinauos' /etc/os-release; then
210 echo 'debian'; return
211 fi
212 fi
213
214 if $BUSYBOX_PATH/dmesg | $GREP -q -m1 "Xen:"; then
215 echo 'xen'; return
216 fi
217
218
219 if [ -e /etc/HOSTNAME ] && $GREP -i -q 'slackware' /etc/HOSTNAME; then
220 echo 'slackware'; return
221 fi
222
223 if [ -e /init ]; then
224 if $GREP -i -q zeroshell /init; then
225 echo 'zeroshell'; return
226 fi
227 fi
228
229 if $EGREP -q 'ALT ' /proc/version; then
230 echo 'alt'; return
231 fi
232
233 if $EGREP -q 'porteus' /proc/version; then
234 echo 'debian'; return
235 fi
236
237 if $GREP -q 'Clear Linux ' /proc/version; then
238 echo 'clear'; return
239 fi
240
241 if $GREP -q 'artix' /proc/version; then
242 echo 'arch'; return
243 fi
244
245 if $GREP -q 'berry ' /proc/version; then
246 echo 'berry'; return
247 fi
248
249 if $GREP -q 'Gobo ' /proc/version; then
250 echo 'gobo'; return
251 fi
252
253 if $GREP -q 'NuTyX' /proc/version; then
254 echo 'nutyx'; return
255 fi
256
257 if [ -d /gnu ]; then
258 vtLineNum=$($FIND /gnu/ -name guix | $BUSYBOX_PATH/wc -l)
259 if [ $vtLineNum -gt 0 ]; then
260 echo 'guix'; return
261 fi
262 fi
263
264 if $GREP -q 'android.x86' /proc/version; then
265 echo 'android'; return
266 fi
267
268 if $GREP -q 'adelielinux' /proc/version; then
269 echo 'adelie'; return
270 fi
271
272 if $GREP -q 'pmagic' /proc/version; then
273 echo 'pmagic'; return
274 fi
275
276 if $GREP -q 'CDlinux' /proc/cmdline; then
277 echo 'cdlinux'; return
278 fi
279
280 if $GREP -q 'parabola' /proc/version; then
281 echo 'parabola'; return
282 fi
283
284 if $GREP -q 'cucumber' /proc/version; then
285 echo 'cucumber'; return
286 fi
287
288 if $GREP -q 'fatdog' /proc/version; then
289 echo 'fatdog'; return
290 fi
291
292 if $GREP -q 'KWORT' /proc/version; then
293 echo 'kwort'; return
294 fi
295
296 if $GREP -q 'iwamoto' /proc/version; then
297 echo 'vine'; return
298 fi
299
300 if $GREP -q 'hyperbola' /proc/cmdline; then
301 echo 'hyperbola'; return
302 fi
303
304 if $GREP -q 'CRUX' /proc/version; then
305 echo 'crux'; return
306 fi
307
308 if [ -f /init ]; then
309 if $GREP -q 'AryaLinux' /init; then
310 echo 'aryalinux'; return
311 elif $GREP -q 'Dragora' /init; then
312 echo 'dragora'; return
313
314 fi
315 fi
316
317 if $GREP -q 'slackware' /proc/version; then
318 echo 'slackware'; return
319 fi
320
321 if $BUSYBOX_PATH/hostname | $GREP -q 'smoothwall'; then
322 echo 'smoothwall'; return
323 fi
324
325 if $GREP -q 'photon' /proc/version; then
326 echo 'photon'; return
327 fi
328
329 if $GREP -q 'ploplinux' /proc/version; then
330 echo 'ploplinux'; return
331 fi
332
333 if $GREP -q 'lunar' /proc/version; then
334 echo 'lunar'; return
335 fi
336
337 if $GREP -q 'SMGL-' /proc/version; then
338 echo 'smgl'; return
339 fi
340
341 if $GREP -q 'rancher' /proc/version; then
342 echo 'rancher'; return
343 fi
344
345
346 if [ -e /init ]; then
347 if $GREP -q -m1 'T2 SDE' /init; then
348 echo 't2'; return
349 fi
350 fi
351
352 if $GREP -q 'wifislax' /proc/version; then
353 echo 'wifislax'; return
354 fi
355
356 if $GREP -q 'pisilinux' /proc/version; then
357 echo 'pisilinux'; return
358 fi
359
360 if $GREP -q 'blackPanther' /proc/version; then
361 echo 'blackPanther'; return
362 fi
363
364 if $GREP -q 'primeos' /proc/version; then
365 echo 'primeos'; return
366 fi
367
368 if $GREP -q 'austrumi' /proc/version; then
369 echo 'austrumi'; return
370 fi
371
372 if [ -f /DISTRO_SPECS ]; then
373 if $GREP -q '[Pp]uppy' /DISTRO_SPECS; then
374 echo 'debian'; return
375 elif $GREP -q 'veket' /DISTRO_SPECS; then
376 echo 'debian'; return
377 fi
378 fi
379
380 if [ -f /etc/openEuler-release ]; then
381 echo "openEuler"; return
382 fi
383
384 echo "default"
385 }
386
387 VTOS=$(ventoy_get_os_type)
388 echo "OS=###${VTOS}###" >>$VTLOG
389 if [ -e "$VTOY_PATH/loop/$VTOS/ventoy-hook.sh" ]; then
390 $BUSYBOX_PATH/sh "$VTOY_PATH/loop/$VTOS/ventoy-hook.sh"
391 elif [ -e "$VTOY_PATH/hook/$VTOS/ventoy-hook.sh" ]; then
392 $BUSYBOX_PATH/sh "$VTOY_PATH/hook/$VTOS/ventoy-hook.sh"
393 fi
394
395
396 ####################################################################
397 # #
398 # Step 4 : Check for debug break #
399 # #
400 ####################################################################
401 if [ "$VTOY_BREAK_LEVEL" = "03" ] || [ "$VTOY_BREAK_LEVEL" = "13" ]; then
402 $SLEEP 5
403 echo -e "\n\n\033[32m ################################################# \033[0m"
404 echo -e "\033[32m ################ VENTOY DEBUG ################### \033[0m"
405 echo -e "\033[32m ################################################# \033[0m \n"
406 if [ "$VTOY_BREAK_LEVEL" = "13" ]; then
407 $CAT $VTOY_PATH/log
408 fi
409 exec $BUSYBOX_PATH/sh
410 fi
411
412
413 ####################################################################
414 # #
415 # Step 5 : Hand over to real init #
416 # #
417 ####################################################################
418 $BUSYBOX_PATH/umount /proc
419 if [ "$rmproc" = "Y" ]; then
420 $BUSYBOX_PATH/rm -rf /proc
421 fi
422
423 if [ -f $VTOY_PATH/ventoy_persistent_map ]; then
424 export PERSISTENT='YES'
425 export PERSISTENCE='true'
426 fi
427
428 cd /
429
430 unset VTLOG FIND GREP EGREP CAT AWK SED SLEEP HEAD vtcmdline
431
432 for vtinit in $user_rdinit /init /sbin/init /linuxrc; do
433 if [ -d /ventoy_rdroot ]; then
434 if [ -e "/ventoy_rdroot$vtinit" ]; then
435 # switch_root will check /init file, this is a cheat code
436 echo 'switch_root' > /init
437 exec $BUSYBOX_PATH/switch_root /ventoy_rdroot "$vtinit"
438 fi
439 else
440 if [ -e "$vtinit" ];then
441 if [ -f "$VTOY_PATH/hook/$VTOS/ventoy-before-init.sh" ]; then
442 $BUSYBOX_PATH/sh "$VTOY_PATH/hook/$VTOS/ventoy-before-init.sh"
443 fi
444 exec "$vtinit"
445 fi
446 fi
447 done
448
449 # Should never reach here
450 echo -e "\n\n\033[31m ############ INIT NOT FOUND ############### \033[0m \n"
451 exec $BUSYBOX_PATH/sh