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