]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - INSTALL/VentoyWeb.sh
add vtoytool 01
[Ventoy.git] / INSTALL / VentoyWeb.sh
1 #!/bin/sh
2
3 print_usage() {
4 echo 'Usage: VentoyWeb.sh [ OPTION ]'
5 echo ' OPTION: (optional)'
6 echo ' -H x.x.x.x http server IP address (default is 127.0.0.1)'
7 echo ' -p PORT http server PORT (default is 24680)'
8 echo ' -h print this help'
9 echo ''
10 }
11
12 print_err() {
13 echo ""
14 echo "$*"
15 echo ""
16 }
17
18 uid=$(id -u)
19 if [ $uid -ne 0 ]; then
20 print_err "Please use sudo or run the script as root."
21 exit 1
22 fi
23
24 OLDDIR=$(pwd)
25
26 if uname -m | egrep -q 'aarch64|arm64'; then
27 TOOLDIR=aarch64
28 elif uname -m | egrep -q 'x86_64|amd64'; then
29 TOOLDIR=x86_64
30 elif uname -m | egrep -q 'mips64'; then
31 TOOLDIR=mips64el
32 else
33 TOOLDIR=i386
34 fi
35
36 if [ ! -f ./tool/$TOOLDIR/V2DServer ]; then
37 if [ -f ${0%VentoyWeb.sh}/tool/$TOOLDIR/V2DServer ]; then
38 cd ${0%VentoyWeb.sh}
39 fi
40 fi
41
42 PATH=./tool/$TOOLDIR:$PATH
43
44 if [ ! -f ./boot/boot.img ]; then
45 if [ -d ./grub ]; then
46 echo "Don't run VentoyWeb.sh here, please download the released install package, and run the script in it."
47 else
48 echo "Please run under the correct directory!"
49 fi
50 exit 1
51 fi
52
53 HOST="127.0.0.1"
54 PORT=24680
55
56 while [ -n "$1" ]; do
57 if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
58 print_usage
59 exit 0
60 elif [ "$1" = "-H" ]; then
61 shift
62 if echo $1 | grep -q '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*'; then
63 HOST="$1"
64 else
65 print_err "Invalid host $1"
66 exit 1
67 fi
68 elif [ "$1" = "-p" ]; then
69 shift
70 if [ $1 -gt 0 -a $1 -le 65535 ]; then
71 PORT="$1"
72 else
73 print_err "Invalid port $1"
74 exit 1
75 fi
76 fi
77
78 shift
79 done
80
81
82 if ps -ef | grep "V2DServer.*$HOST.*$PORT" | grep -q -v grep; then
83 print_err "Another ventoy server is running now, please close it first."
84 exit 1
85 fi
86
87 LOGFILE=log.txt
88 #delete the log.txt if it's more than 8MB
89 if [ -f $LOGFILE ]; then
90 logsize=$(stat -c '%s' $LOGFILE)
91 if [ $logsize -gt 8388608 ]; then
92 rm -f $LOGFILE
93 fi
94 fi
95
96
97 if [ -f ./tool/$TOOLDIR/V2DServer.xz ]; then
98 xz -d ./tool/$TOOLDIR/V2DServer.xz
99 chmod +x ./tool/$TOOLDIR/V2DServer
100 fi
101
102
103 V2DServer "$HOST" "$PORT" &
104 wID=$!
105 sleep 1
106
107 vtVer=$(cat ventoy/version)
108 echo ""
109 echo "==============================================================="
110 if [ "$LANG" = "zh_CN.UTF-8" ]; then
111 echo " Ventoy Server $vtVer 已经启动 ..."
112 echo " 请打开浏览器,访问 http://${HOST}:${PORT}"
113 else
114 echo " Ventoy Server $vtVer is running ..."
115 echo " Please open your browser and visit http://${HOST}:${PORT}"
116 fi
117 echo "==============================================================="
118 echo ""
119 echo "################## Press Ctrl + C to exit #####################"
120 echo ""
121
122 wait $wID
123
124 if [ -n "$OLDDIR" ]; then
125 CURDIR=$(pwd)
126 if [ "$CURDIR" != "$OLDDIR" ]; then
127 cd "$OLDDIR"
128 fi
129 fi