2020-08-08 11:39:31 +00:00
|
|
|
#!/ventoy/busybox/ash
|
2020-04-04 16:07:50 +00:00
|
|
|
#************************************************************************************
|
|
|
|
# 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/>.
|
|
|
|
#
|
|
|
|
#************************************************************************************
|
|
|
|
|
|
|
|
####################################################################
|
|
|
|
# #
|
2021-02-27 01:27:31 +00:00
|
|
|
# Step 1 : extract busybox & set busybox environment #
|
2020-04-04 16:07:50 +00:00
|
|
|
# #
|
|
|
|
####################################################################
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-03-05 15:03:34 +00:00
|
|
|
if [ -e $BUSYBOX_PATH/busyboxaa64.xz ]; then
|
|
|
|
export VTOY_ARCH=aarch64
|
|
|
|
elif [ -e $BUSYBOX_PATH/busyboxm64e.xz ]; then
|
|
|
|
export VTOY_ARCH=mips64el
|
|
|
|
else
|
|
|
|
if [ -e $BUSYBOX_PATH/32h ]; then
|
|
|
|
export VTOY_ARCH=x86_64
|
|
|
|
else
|
|
|
|
export VTOY_ARCH=i386
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2022-01-08 15:07:04 +00:00
|
|
|
if [ "$VTOY_ARCH" = "i386" ]; then
|
|
|
|
if $BUSYBOX_PATH/vtchmod32 -6; then
|
|
|
|
export VTOY_ARCH=x86_64
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-03-05 15:03:34 +00:00
|
|
|
echo $VTOY_ARCH > $VTOY_PATH/ventoy_arch
|
|
|
|
|
|
|
|
|
|
|
|
if [ "$VTOY_ARCH" = "aarch64" ]; then
|
|
|
|
$BUSYBOX_PATH/xzminidecaa64 < $BUSYBOX_PATH/busyboxaa64.xz > $BUSYBOX_PATH/busybox
|
|
|
|
$BUSYBOX_PATH/vtchmodaa64 $BUSYBOX_PATH/busybox
|
|
|
|
elif [ "$VTOY_ARCH" = "mips64el" ]; then
|
|
|
|
$BUSYBOX_PATH/xzminidecm64e < $BUSYBOX_PATH/busyboxm64e.xz > $BUSYBOX_PATH/busybox
|
|
|
|
$BUSYBOX_PATH/vtchmodm64e $BUSYBOX_PATH/busybox
|
|
|
|
elif [ "$VTOY_ARCH" = "x86_64" ]; then
|
|
|
|
$BUSYBOX_PATH/xzminidec64 < $BUSYBOX_PATH/busybox64.xz > $BUSYBOX_PATH/busybox
|
|
|
|
if [ -s $BUSYBOX_PATH/busybox ]; then
|
|
|
|
$BUSYBOX_PATH/vtchmod64 $BUSYBOX_PATH/busybox
|
2020-08-29 05:12:36 +00:00
|
|
|
else
|
2021-03-05 15:03:34 +00:00
|
|
|
$BUSYBOX_PATH/xzminidec64_musl < $BUSYBOX_PATH/busybox64.xz > $BUSYBOX_PATH/busybox
|
|
|
|
$BUSYBOX_PATH/vtchmod64_musl $BUSYBOX_PATH/busybox
|
2020-08-29 05:12:36 +00:00
|
|
|
fi
|
2020-12-11 23:56:52 +00:00
|
|
|
else
|
|
|
|
$BUSYBOX_PATH/xzminidec32 < $BUSYBOX_PATH/busybox32.xz > $BUSYBOX_PATH/busybox
|
|
|
|
$BUSYBOX_PATH/vtchmod32 $BUSYBOX_PATH/busybox
|
2020-08-08 11:39:31 +00:00
|
|
|
fi
|
|
|
|
|
2020-08-29 05:12:36 +00:00
|
|
|
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
|
2020-04-04 16:07:50 +00:00
|
|
|
|
|
|
|
export PATH=$BUSYBOX_PATH/:$VTOY_PATH/tool
|
|
|
|
|
2020-04-08 14:44:14 +00:00
|
|
|
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)
|
2022-01-08 15:07:04 +00:00
|
|
|
export VTOY_LINUX_REMOUNT=$(hexdump -n 1 -s 454 -e '1/1 "%02x"' $VTOY_PATH/ventoy_os_param)
|
2020-04-04 16:07:50 +00:00
|
|
|
|
|
|
|
#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
|
2020-08-07 14:23:27 +00:00
|
|
|
xz -d ventoy_chain.sh.xz
|
|
|
|
xz -d ventoy_loop.sh.xz
|
2020-04-04 16:07:50 +00:00
|
|
|
|
|
|
|
if [ -n "$VTOY_REDT_BUG" ]; then
|
|
|
|
xz -d -c hook.cpio.xz | cpio -idm
|
|
|
|
xz -d -c tool.cpio.xz | cpio -idm
|
2020-08-08 11:39:31 +00:00
|
|
|
xz -d -c loop.cpio.xz | cpio -idm
|
2020-04-04 16:07:50 +00:00
|
|
|
else
|
|
|
|
xz -d -c hook.cpio.xz | cpio -idm 2>>$VTLOG
|
|
|
|
xz -d -c tool.cpio.xz | cpio -idm 2>>$VTLOG
|
2020-08-08 11:39:31 +00:00
|
|
|
xz -d -c loop.cpio.xz | cpio -idm 2>>$VTLOG
|
|
|
|
fi
|
|
|
|
|
2021-03-05 15:03:34 +00:00
|
|
|
|
|
|
|
if [ "$VTOY_ARCH" = "x86_64" ]; then
|
|
|
|
echo "Use x86_64 busybox toolkit ..." >>$VTLOG
|
2022-02-14 04:31:06 +00:00
|
|
|
$BUSYBOX_PATH/xzcat $BUSYBOX_PATH/xzcat64_musl.xz > $BUSYBOX_PATH/xzcat_musl
|
|
|
|
$BUSYBOX_PATH/chmod +x $BUSYBOX_PATH/xzcat_musl
|
2021-03-05 15:03:34 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
rm -f $VTOY_PATH/tool/lz4cat $VTOY_PATH/tool/zstdcat
|
|
|
|
ln -s $VTOY_PATH/tool/lz4cat64 $VTOY_PATH/tool/lz4cat
|
|
|
|
ln -s $VTOY_PATH/tool/zstdcat64 $VTOY_PATH/tool/zstdcat
|
|
|
|
elif [ "$VTOY_ARCH" = "i386" ]; then
|
2020-12-11 23:56:52 +00:00
|
|
|
echo "Use i386 busybox toolkit ..." >>$VTLOG
|
2022-02-14 04:31:06 +00:00
|
|
|
$BUSYBOX_PATH/xzcat $BUSYBOX_PATH/xzcat32_musl.xz > $BUSYBOX_PATH/xzcat_musl
|
|
|
|
$BUSYBOX_PATH/chmod +x $BUSYBOX_PATH/xzcat_musl
|
2020-08-08 11:39:31 +00:00
|
|
|
ln -s $BUSYBOX_PATH/xzminidec32 $BUSYBOX_PATH/xzminidec
|
|
|
|
ln -s $VTOY_PATH/tool/dmsetup32 $VTOY_PATH/tool/dmsetup
|
2020-08-29 05:12:36 +00:00
|
|
|
ln -s $VTOY_PATH/tool/lunzip32 $VTOY_PATH/tool/lunzip
|
2021-03-05 15:03:34 +00:00
|
|
|
|
2021-08-01 13:50:36 +00:00
|
|
|
if uname -a | egrep -q 'x86_64|amd64'; then
|
|
|
|
echo "zstdcat use 64bit ..." >>$VTLOG
|
|
|
|
rm -f $VTOY_PATH/tool/zstdcat
|
|
|
|
ln -s $VTOY_PATH/tool/zstdcat64 $VTOY_PATH/tool/zstdcat
|
|
|
|
fi
|
2021-03-05 15:03:34 +00:00
|
|
|
elif [ "$VTOY_ARCH" = "mips64el" ]; then
|
|
|
|
echo "Use MIPS64 busybox toolkit ..." >>$VTLOG
|
|
|
|
ln -s $BUSYBOX_PATH/xzminidecm64e $BUSYBOX_PATH/xzminidec
|
|
|
|
ln -s $VTOY_PATH/tool/dmsetupm64e $VTOY_PATH/tool/dmsetup
|
|
|
|
|
|
|
|
# TBD
|
|
|
|
#ln -s $VTOY_PATH/tool/lunzipm64e $VTOY_PATH/tool/lunzip
|
|
|
|
|
|
|
|
rm -f $VTOY_PATH/tool/lz4cat $VTOY_PATH/tool/zstdcat
|
|
|
|
ln -s $VTOY_PATH/tool/lz4catm64e $VTOY_PATH/tool/lz4cat
|
|
|
|
|
|
|
|
# TBD
|
|
|
|
#ln -s $VTOY_PATH/tool/zstdcataa64 $VTOY_PATH/tool/zstdcat
|
|
|
|
|
|
|
|
elif [ "$VTOY_ARCH" = "aarch64" ]; then
|
|
|
|
echo "Use ARM64 busybox toolkit ..." >>$VTLOG
|
|
|
|
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
|
|
|
|
|
|
|
|
rm -f $VTOY_PATH/tool/lz4cat $VTOY_PATH/tool/zstdcat
|
|
|
|
ln -s $VTOY_PATH/tool/lz4cataa64 $VTOY_PATH/tool/lz4cat
|
|
|
|
ln -s $VTOY_PATH/tool/zstdcataa64 $VTOY_PATH/tool/zstdcat
|
|
|
|
else
|
|
|
|
echo "Unknown busybox toolkit ..." >>$VTLOG
|
2020-04-04 16:07:50 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
rm -f *.xz
|
|
|
|
cd /
|
|
|
|
|
|
|
|
####################################################################
|
|
|
|
# #
|
|
|
|
# Step 2 : Hand over to ventoy init #
|
|
|
|
# #
|
|
|
|
####################################################################
|
|
|
|
exec $BUSYBOX_PATH/sh $VTOY_PATH/init
|