init 4.65 KB
Newer Older
longpanda's avatar
update  
longpanda committed
1
#!/ventoy/busybox/ash
longpanda's avatar
longpanda committed
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
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
# 
#************************************************************************************

####################################################################
#                                                                  #
# Step 1 : extract busybox & set busybox enviroment                #
#                                                                  #
####################################################################

export VTOY_ORG_PATH=$PATH
export VTOY_PATH=/ventoy
export BUSYBOX_PATH=$VTOY_PATH/busybox
export VTLOG=$VTOY_PATH/log
export FIND=$BUSYBOX_PATH/find
export GREP=$BUSYBOX_PATH/grep
export EGREP=$BUSYBOX_PATH/egrep
export CAT=$BUSYBOX_PATH/cat
export AWK=$BUSYBOX_PATH/awk
export SED=$BUSYBOX_PATH/sed
export SLEEP=$BUSYBOX_PATH/sleep
export HEAD=$BUSYBOX_PATH/head

longpanda's avatar
longpanda committed
39
40
41
42
43
if [ -e $BUSYBOX_PATH/32h ]; then
    if [ -e $BUSYBOX_PATH/64h ]; then
        #this is arm64
        $BUSYBOX_PATH/xzminidecaa64 < $BUSYBOX_PATH/busyboxaa64.xz > $BUSYBOX_PATH/busybox
        $BUSYBOX_PATH/vtchmodaa64 $BUSYBOX_PATH/busybox
longpanda's avatar
longpanda committed
44
    else
longpanda's avatar
longpanda committed
45
46
47
48
49
        #this is x86_64
        $BUSYBOX_PATH/xzminidec64 < $BUSYBOX_PATH/busybox64.xz > $BUSYBOX_PATH/busybox
        if [ -s $BUSYBOX_PATH/busybox ]; then
            $BUSYBOX_PATH/vtchmod64 $BUSYBOX_PATH/busybox
        else
50
51
            $BUSYBOX_PATH/xzminidec64_musl < $BUSYBOX_PATH/busybox64.xz > $BUSYBOX_PATH/busybox 
            $BUSYBOX_PATH/vtchmod64_musl $BUSYBOX_PATH/busybox
longpanda's avatar
longpanda committed
52
        fi
longpanda's avatar
longpanda committed
53
    fi
longpanda's avatar
longpanda committed
54
55
56
else
    $BUSYBOX_PATH/xzminidec32 < $BUSYBOX_PATH/busybox32.xz > $BUSYBOX_PATH/busybox
    $BUSYBOX_PATH/vtchmod32 $BUSYBOX_PATH/busybox
longpanda's avatar
update  
longpanda committed
57
58
fi

longpanda's avatar
longpanda committed
59
60
61
62
63
64
if [ -e $BUSYBOX_PATH/busybox ]; then
    $BUSYBOX_PATH/busybox --install $BUSYBOX_PATH
else
    $BUSYBOX_PATH/tmpxz -d $BUSYBOX_PATH/busybox32.xz
    $BUSYBOX_PATH/busybox32 --install $BUSYBOX_PATH
fi
longpanda's avatar
longpanda committed
65
66
67

export PATH=$BUSYBOX_PATH/:$VTOY_PATH/tool

longpanda's avatar
bug fix  
longpanda committed
68
69
export VTOY_BREAK_LEVEL=$(hexdump -n 1 -s 449 -e '1/1 "%02x"' $VTOY_PATH/ventoy_os_param)
export VTOY_DEBUG_LEVEL=$(hexdump -n 1 -s 450 -e '1/1 "%02x"' $VTOY_PATH/ventoy_os_param)
longpanda's avatar
longpanda committed
70
71
72
73
74
75
76
77
78
79
80

#Fixme: busybox shell output redirect seems to have some bug in rhel5
if uname -a | grep -q el5; then
    VTOY_REDT_BUG=YES
fi

if [ -z "$VTOY_REDT_BUG" ]; then
    echo "============== VENTOY =================" >>$VTLOG
fi

cd $VTOY_PATH
longpanda's avatar
longpanda committed
81
82
xz -d ventoy_chain.sh.xz
xz -d ventoy_loop.sh.xz
longpanda's avatar
longpanda committed
83
84
85
86

if [ -n "$VTOY_REDT_BUG" ]; then
    xz -d -c hook.cpio.xz | cpio -idm
    xz -d -c tool.cpio.xz | cpio -idm
longpanda's avatar
update  
longpanda committed
87
    xz -d -c loop.cpio.xz | cpio -idm
longpanda's avatar
longpanda committed
88
89
90
else
    xz -d -c hook.cpio.xz | cpio -idm 2>>$VTLOG
    xz -d -c tool.cpio.xz | cpio -idm 2>>$VTLOG
longpanda's avatar
update  
longpanda committed
91
92
93
    xz -d -c loop.cpio.xz | cpio -idm 2>>$VTLOG
fi

longpanda's avatar
longpanda committed
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
if [ -e $BUSYBOX_PATH/32h ]; then
    if [ -e $BUSYBOX_PATH/64h ]; then
        echo "Use ARM64 busybox toolkit ..." >>$VTLOG
        echo aarch64 > $VTOY_PATH/ventoy_arch
        ln -s $BUSYBOX_PATH/xzminidecaa64 $BUSYBOX_PATH/xzminidec
        ln -s $VTOY_PATH/tool/dmsetupaa64 $VTOY_PATH/tool/dmsetup
        ln -s $VTOY_PATH/tool/lunzipaa64 $VTOY_PATH/tool/lunzip
    else
        echo "Use x86_64 busybox toolkit ..." >>$VTLOG
        echo x86_64 > $VTOY_PATH/ventoy_arch
        ln -s $BUSYBOX_PATH/xzminidec64 $BUSYBOX_PATH/xzminidec
        ln -s $VTOY_PATH/tool/dmsetup64 $VTOY_PATH/tool/dmsetup
        ln -s $VTOY_PATH/tool/lunzip64 $VTOY_PATH/tool/lunzip
    fi
else
    echo "Use i386 busybox toolkit ..." >>$VTLOG
    echo i386 > $VTOY_PATH/ventoy_arch
longpanda's avatar
update  
longpanda committed
111
112
    ln -s $BUSYBOX_PATH/xzminidec32 $BUSYBOX_PATH/xzminidec
    ln -s $VTOY_PATH/tool/dmsetup32 $VTOY_PATH/tool/dmsetup
longpanda's avatar
longpanda committed
113
    ln -s $VTOY_PATH/tool/lunzip32 $VTOY_PATH/tool/lunzip
longpanda's avatar
longpanda committed
114
115
116
117
118
119
120
121
122
123
124
fi

rm -f *.xz
cd /

####################################################################
#                                                                  #
# Step 2 : Hand over to ventoy init                                #
#                                                                  #
####################################################################
exec $BUSYBOX_PATH/sh $VTOY_PATH/init