]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - INSTALL/VentoyWeb.sh
1.1.07 release
[Ventoy.git] / INSTALL / VentoyWeb.sh
1 #!/bin/bash
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 | grep -E -q 'aarch64|arm64'; then
27 TOOLDIR=aarch64
28 elif uname -m | grep -E -q 'x86_64|amd64'; then
29 TOOLDIR=x86_64
30 elif uname -m | grep -E -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 "Current directory is $PWD"
49 echo "Please run under the correct directory!"
50 fi
51 exit 1
52 fi
53
54 HOST="127.0.0.1"
55 PORT=24680
56
57 while [ -n "$1" ]; do
58 if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
59 print_usage
60 exit 0
61 elif [ "$1" = "-H" ]; then
62 shift
63 if echo $1 | grep -q '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*'; then
64 HOST="$1"
65 else
66 print_err "Invalid host $1"
67 exit 1
68 fi
69 elif [ "$1" = "-p" ]; then
70 shift
71 if [ $1 -gt 0 -a $1 -le 65535 ]; then
72 PORT="$1"
73 else
74 print_err "Invalid port $1"
75 exit 1
76 fi
77 fi
78
79 shift
80 done
81
82
83 if ps -ef | grep "V2DServer.*$HOST.*$PORT" | grep -q -v grep; then
84 print_err "Another ventoy server is running now, please close it first."
85 exit 1
86 fi
87
88 LOGFILE=log.txt
89 #delete the log.txt if it's more than 8MB
90 if [ -f $LOGFILE ]; then
91 logsize=$(stat -c '%s' $LOGFILE)
92 if [ $logsize -gt 8388608 ]; then
93 rm -f $LOGFILE
94 fi
95 fi
96
97
98 if [ -f ./tool/$TOOLDIR/V2DServer.xz ]; then
99 xz -d ./tool/$TOOLDIR/V2DServer.xz
100 chmod +x ./tool/$TOOLDIR/V2DServer
101 fi
102
103
104 V2DServer "$HOST" "$PORT" &
105 wID=$!
106 sleep 1
107
108 vtVer=$(cat ventoy/version)
109 echo ""
110 echo "==============================================================="
111 if [ "$LANG" = "zh_CN.UTF-8" ]; then
112 echo " Ventoy Server $vtVer 已经启动 ..."
113 echo " 请打开浏览器,访问 http://${HOST}:${PORT}"
114 else
115 echo " Ventoy Server $vtVer is running ..."
116 echo " Please open your browser and visit http://${HOST}:${PORT}"
117 fi
118 echo "==============================================================="
119 echo ""
120 echo "################## Press Ctrl + C to exit #####################"
121 echo ""
122
123 wait $wID
124
125 if [ -n "$OLDDIR" ]; then
126 CURDIR=$(pwd)
127 if [ "$CURDIR" != "$OLDDIR" ]; then
128 cd "$OLDDIR"
129 fi
130 fi