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