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