]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - INSTALL/VentoyPlugson.sh
Fix the issue (introduced in 1.1.06) that the Ventoy ISO partition cannot be mounted...
[Ventoy.git] / INSTALL / VentoyPlugson.sh
1 #!/bin/bash
2
3 . ./tool/ventoy_lib.sh
4
5 print_usage() {
6 echo 'Usage: sudo bash VentoyPlugson.sh [OPTION] /dev/sdX'
7 echo ' OPTION: (optional)'
8 echo ' -H x.x.x.x http server IP address (default is 127.0.0.1)'
9 echo ' -P PORT http server PORT (default is 24681)'
10 echo ' -h print this help'
11 echo ''
12 }
13
14 uid=$(id -u)
15 if [ $uid -ne 0 ]; then
16 echo "Please use sudo or run the script as root."
17 exit 1
18 fi
19
20 if [ "$1" = "__vbash__" ]; then
21 shift
22 else
23 if readlink /bin/sh | grep -q bash; then
24 :
25 else
26 exec /bin/bash $0 "__vbash__" "$@"
27 fi
28 fi
29
30 OLDDIR=$(pwd)
31
32 machine=$(uname -m)
33 if echo $machine | grep -E -q 'aarch64|arm64'; then
34 TOOLDIR=aarch64
35 elif echo $machine | grep -E -q 'x86_64|amd64'; then
36 TOOLDIR=x86_64
37 elif echo $machine | grep -E -q 'mips64'; then
38 TOOLDIR=mips64el
39 elif echo $machine | grep -E -q 'i[3-6]86'; then
40 TOOLDIR=i386
41 else
42 echo "Unsupported machine type $machine"
43 exit 1
44 fi
45
46
47 if ! [ -f "$OLDDIR/tool/plugson.tar.xz" ]; then
48 echo "Please run under the correct directory!"
49 exit 1
50 fi
51
52 echo "############# VentoyPlugson $* [$TOOLDIR] ################" >> ./VentoyPlugson.log
53 date >> ./VentoyPlugson.log
54
55 echo "decompress tools" >> ./VentoyPlugson.log
56 cd ./tool/$TOOLDIR
57
58 ls *.xz > /dev/null 2>&1
59 if [ $? -eq 0 ]; then
60 [ -f ./xzcat ] && chmod +x ./xzcat
61
62 for file in $(ls *.xz); do
63 echo "decompress $file" >> ./VentoyPlugson.log
64 xzcat $file > ${file%.xz}
65 [ -f ./${file%.xz} ] && chmod +x ./${file%.xz}
66 [ -f ./$file ] && rm -f ./$file
67 done
68 fi
69
70 cd ../../
71 chmod +x -R ./tool/$TOOLDIR
72
73 if ! [ -f "$OLDDIR/tool/$TOOLDIR/Plugson" ]; then
74 echo "$OLDDIR/tool/$TOOLDIR/Plugson does not exist!"
75 exit 1
76 fi
77
78
79 PATH=./tool/$TOOLDIR:$PATH
80
81 HOST="127.0.0.1"
82 PORT=24681
83
84 while [ -n "$1" ]; do
85 if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
86 print_usage
87 exit 0
88 elif [ "$1" = "-H" ]; then
89 shift
90 if echo $1 | grep -q '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*'; then
91 HOST="$1"
92 else
93 echo "Invalid host $1"
94 exit 1
95 fi
96 elif [ "$1" = "-P" ]; then
97 shift
98 if [ $1 -gt 0 -a $1 -le 65535 ]; then
99 PORT="$1"
100 else
101 echo "Invalid port $1"
102 exit 1
103 fi
104 else
105 DISK=$1
106 fi
107
108 shift
109 done
110
111 if [ -z "$DISK" ]; then
112 print_usage
113 exit 0
114 fi
115
116 if ps -ef | grep "tool/$TOOLDIR/Plugson.*$HOST.*$PORT" | grep -q -v grep; then
117 echo "Another ventoy server is running now, please close it first."
118 exit 1
119 fi
120
121 if echo $DISK | grep -q "[a-z]d[a-z][1-9]"; then
122 DISK=${DISK:0:-1}
123 fi
124
125 if echo $DISK | grep -E -q "/dev/nvme|/dev/mmcblk/dev/nbd"; then
126 if echo $DISK | grep -q "p[1-9]$"; then
127 DISK=${DISK:0:-2}
128 fi
129 fi
130
131
132 if [ ! -b "$DISK" ]; then
133 echo "$DISK does NOT exist."
134 exit 1
135 fi
136
137
138 version=$(get_disk_ventoy_version $DISK)
139 if [ $? -eq 0 ]; then
140 echo "Ventoy version in Disk: $version"
141
142 vtPart1Type=$(dd if=$DISK bs=1 count=1 skip=450 status=none | hexdump -n1 -e '1/1 "%02X"')
143 if [ "$vtPart1Type" = "EE" ]; then
144 echo "Disk Partition Style : GPT"
145 partstyle=1
146 else
147 echo "Disk Partition Style : MBR"
148 partstyle=0
149 fi
150
151 if check_disk_secure_boot $DISK; then
152 echo "Secure Boot Support : YES"
153 secureboot=1
154 else
155 echo "Secure Boot Support : NO"
156 secureboot=0
157 fi
158 else
159 echo "$DISK is NOT Ventoy disk."
160 exit 1
161 fi
162
163 PART1=$(get_disk_part_name $DISK 1)
164
165 if grep -q "^$PART1 " /proc/mounts; then
166 mtpnt=$(grep "^$PART1 " /proc/mounts | awk '{print $2}' | sed 's/\\040/ /g')
167 fstype=$(grep "^$PART1 " /proc/mounts | awk '{print $3}')
168
169 if echo $fstype | grep -q -i 'fuse'; then
170 if hexdump -C -n 16 $PART1 | grep -q -i "EXFAT"; then
171 fstype="exFAT"
172 elif hexdump -C -n 16 $PART1 | grep -q -i "NTFS"; then
173 fstype="NTFS"
174 fi
175 fi
176
177 echo "$PART1 is mounted at $mtpnt $fstype"
178 else
179 echo "$PART1 is NOT mounted, please mount it first!"
180 exit 1
181 fi
182
183 if [ -d "$mtpnt/ventoy" ]; then
184 echo "ventoy directory exist OK"
185 else
186 echo "create ventoy directory"
187 mkdir -p "$mtpnt/ventoy"
188 if [ -d "$mtpnt/ventoy" ]; then
189 chmod -R 0755 "$mtpnt/ventoy"
190 else
191 echo "Failed to create directory $mtpnt/ventoy"
192 exit 1
193 fi
194 fi
195
196
197 #change current directory to Ventoy disk
198 cd "$mtpnt"
199 "$OLDDIR/tool/$TOOLDIR/Plugson" "$HOST" "$PORT" "$OLDDIR" "$DISK" $version "$fstype" $partstyle $secureboot &
200 wID=$!
201 sleep 1
202
203 if [ -f /proc/$wID/maps ]; then
204 echo ""
205 echo "==============================================================="
206 if [ "$LANG" = "zh_CN.UTF-8" ]; then
207 echo " Ventoy Plugson Server 已经启动 ..."
208 echo " 请打开浏览器,访问 http://${HOST}:${PORT}"
209 else
210 echo " Ventoy Plugson Server is running ..."
211 echo " Please open your browser and visit http://${HOST}:${PORT}"
212 fi
213 echo "==============================================================="
214 echo ""
215 echo "################## Press Ctrl + C to exit #####################"
216 echo ""
217
218 wait $wID
219 fi
220
221
222 if [ -n "$OLDDIR" ]; then
223 CURDIR=$(pwd)
224 if [ "$CURDIR" != "$OLDDIR" ]; then
225 cd "$OLDDIR"
226 fi
227 fi