]>
glassweightruler.freedombox.rocks Git - Ventoy.git/blob - Vlnk/VentoyVlnk.sh
4 echo 'Usage: sudo sh VentoyVlnk.sh CMD FILE'
6 echo ' -c FILE create vlnk for FILE'
7 echo ' -l VLNK parse vlnk file'
8 echo ' -v print verbose info'
9 echo ' -h print this help'
16 if [ $verbose_flag -eq 1 ]; then
22 echo $1 | grep -E -q '.*(.vlnk.iso|.vlnk.img|.vlnk.wim|.vlnk.vhd|.vlnk.vhdx|.vlnk.efi|.vlnk.vtoy|.vlnk.dat)$'
27 if [ $uid -ne 0 ]; then
28 echo "Please use sudo or run the script as root."
32 #check system tools used bellow
33 for t
in 'mountpoint' 'readlink' 'xzcat'; do
34 if ! which "$t" > /dev
/null
2>&1; then
35 echo "$t command not found in current system!"
41 if echo $machine | grep -E -q 'aarch64|arm64'; then
43 elif echo $machine | grep -E -q 'x86_64|amd64'; then
45 elif echo $machine | grep -E -q 'mips64'; then
47 elif echo $machine | grep -E -q 'i[3-6]86'; then
50 echo "Unsupported machine type $machine"
54 fullsh
=$(readlink -f "$0")
57 if [ -f "$vtoydir/tool/$TOOLDIR/vlnk.xz" ]; then
58 xzcat
"$vtoydir/tool/$TOOLDIR/vlnk.xz" > "$vtoydir/tool/$TOOLDIR/vlnk"
59 rm -f "$vtoydir/tool/$TOOLDIR/vlnk.xz"
62 if [ -f "$vtoydir/tool/$TOOLDIR/vlnk" ]; then
63 chmod +x
"$vtoydir/tool/$TOOLDIR/vlnk"
65 echo "$vtoydir/tool/$TOOLDIR/vlnk does not exist! "
69 PATH
="$vtoydir/tool/$TOOLDIR":$PATH
73 if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
76 elif [ "$1" = "-c" ]; then
80 elif [ "$1" = "-o" ]; then
83 elif [ "$1" = "-l" ]; then
87 elif [ "$1" = "-v" ]; then
91 echo "invalid option $1"
98 if [ "$CMD" = "c" ]; then
99 vlog
"Create vlnk for $IMG"
101 if [ ! -f "$IMG" ]; then
102 echo "$IMG does not exist!"
106 if echo $IMG | grep -E -q -i '.*(.iso|.img|.wim|.vhd|.vhdx|.efi|.vtoy|.dat)$'; then
109 echo "This file is not supported for vlnk!"
113 if vlnk_suffix
"$IMG"; then
114 echo "This is already a vlnk file!"
118 if $VLNKCMD -t "$IMG"; then
119 echo "This is already a vlnk file!"
123 FULLIMG
=$(readlink -f "$IMG")
124 if [ ! -f "$FULLIMG" ]; then
125 echo "$FULLIMG does not exist!"
128 vlog
"Full file path is $FULLIMG"
131 #check img file position is a valid mountpoint
132 FULLDIR
=${FULLIMG%/*}
133 while [ -n "${FULLDIR}" ]; do
134 if mountpoint
-q "${FULLDIR}"; then
137 FULLDIR
="${FULLDIR%/*}"
140 if [ -z "${FULLDIR}" ]; then
144 IMGPATH
="${FULLIMG#$FULLDIR}"
147 IMGFILE
=$(basename "$IMGPATH")
148 vlog
"IMGPATH=$IMGPATH IMGFILE=$IMGFILE"
151 mntdev
=$(mountpoint -d "${FULLDIR}")
152 vlog
"mountpoint is ${FULLDIR} dev $mntdev"
155 if grep -q " ${FULLDIR} " /proc
/mounts
; then
156 DEV
=$(grep " ${FULLDIR} " /proc/mounts | awk '{print $1}')
157 FS
=$(grep " ${FULLDIR} " /proc/mounts | awk '{print $3}')
158 vlog
"File system of $DEV is $FS"
160 if echo $FS | grep -E -q "ext2|ext3|ext4|exfat|vfat|fat32|fat16|fat12|ntfs|xfs|udf"; then
162 elif [ "$FS" = "fuseblk" ]; then
163 vlog
"$DEV is fuseblk"
164 if hexdump -C -n 8 $DEV | grep -q "NTFS"; then
165 vlog
"$DEV is NTFS OK"
166 elif hexdump -C -n 8 $DEV | grep -q "EXFAT"; then
167 vlog
"$DEV is exFAT OK"
169 echo "$DEV is not supported!"
174 echo "$FS is not supported!"
178 echo "${FULLDIR} not found in /proc/mounts"
183 Major
=$(echo $mntdev | awk -F: '{print $1}')
184 Minor
=$(echo $mntdev | awk -F: '{print $2}')
185 vlog
"Major=$Major Minor=$Minor"
189 M1
=$(echo $line | awk '{print $1}')
190 M2
=$(echo $line | awk '{print $2}')
191 if [ "$Major" = "$M1" -a "$Minor" = "$M2" ]; then
192 IMGPARTITION
=$(echo $line | awk '{print $4}')
193 vlog
"disk partition is $IMGPARTITION"
196 done < /proc
/partitions
198 if [ -z "$IMGPARTITION" ]; then
199 echo "Disk partition not found for $FULLDIR"
200 grep " $FULLDIR " /proc
/mounts
204 if [ -f "/sys/class/block/$IMGPARTITION/start" ]; then
205 PARTSTART
=$(cat "/sys/class/block/$IMGPARTITION/start")
206 if echo $IMGPARTITION | grep -E -q 'mmc|nbd|nvme'; then
207 DISK
=$(echo /dev/$IMGPARTITION | sed "s/^\(.*\)p
[0-9][0-9]*$
/\
1/")
209 DISK=$(echo /dev/$IMGPARTITION | sed "s/^\(.*[^0-9]\)[0-9][0-9]*$/\1/")
212 if [ ! -b $DISK ]; then
213 echo "Device $DISK not exist!"
217 vlog
"PARTSTART=$PARTSTART DISK=$DISK"
219 if echo $IMGPARTITION | grep -q '^dm-[0-9][0-9]*'; then
220 echo "LVM/DM is not supported!"
222 echo "/sys/class/block/$IMGPARTITION/start not exist!"
227 if [ -n "$OUT" ]; then
228 lowersuffix
=$(echo ${IMG##*.} | tr 'A-Z' 'a-z')
229 OUT
="${OUT}.vlnk.${lowersuffix}"
232 lowersuffix
=$(echo ${IMGFILE##*.} | tr 'A-Z' 'a-z')
233 OUT
="${name}.vlnk.${lowersuffix}"
236 echo "Output VLNK file is $OUT"
237 [ -f "${OUT}" ] && rm -f "${OUT}"
240 if [ -f "${OUT}" ]; then
243 echo "Failed to create ${OUT}"
247 if $VLNKCMD -c "$IMGPATH" -d $DISK -p $PARTSTART -o "${OUT}"; then
248 echo "====== Vlnk file create success ========="
251 echo "====== Vlnk file create failed ========="
255 elif [ "$CMD" = "l" ]; then
256 vlog
"Parse vlnk for $VLNK"
258 if [ ! -f "$VLNK" ]; then
259 echo "$VLNK does not exist!"
263 if vlnk_suffix
"$VLNK"; then
266 echo "Invalid vlnk file suffix!"
270 if $VLNKCMD -t "$VLNK"; then
271 vlog
"Vlnk data check OK"
273 echo "This is not a valid vlnk file!"