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