]> glassweightruler.freedombox.rocks Git - Ventoy.git/blobdiff - INSTALL/VentoyWeb.sh
1.1.07 release
[Ventoy.git] / INSTALL / VentoyWeb.sh
index 3bc9469ee69d253181ce3a2f468182b5df60b683..537348aac5862b0d6b306628730b5dec977695d3 100644 (file)
@@ -1,11 +1,10 @@
-#!/bin/sh
+#!/bin/bash
 
 print_usage() {    
     echo 'Usage:  VentoyWeb.sh [ OPTION ]'   
     echo '  OPTION: (optional)'
     echo '   -H x.x.x.x  http server IP address (default is 127.0.0.1)'
     echo '   -p PORT     http server PORT (default is 24680)'
-    echo "   -n          don't start web browser"
     echo '   -h          print this help'
     echo ''
 }
@@ -16,37 +15,6 @@ print_err() {
     echo ""
 }
 
-check_option() {
-    app="$1"
-    $app --help 2>&1 | grep -q "$2"
-}
-
-get_user() {
-    name=$(logname)
-    if [ -n "$name" -a "$name" != "root" ]; then
-        echo $name; return
-    fi
-    
-    name=${HOME#/home/}
-    if [ -n "$name" -a "$name" != "root" ]; then
-        echo $name; return
-    fi
-}
-
-chromium_proc() {
-    app="$1"
-    
-    url="http://${HOST}:${PORT}/index.html"
-    
-    if check_option "$app" '[-][-]app='; then
-        su $VUSER -c "$app --app=$url >> $LOGFILE 2>&1"
-    elif check_option "$app" '[-][-]new[-]window='; then
-        su $VUSER -c "$app --new-window $url >> $LOGFILE 2>&1"
-    else
-        su $VUSER -c "$app $url >> $LOGFILE 2>&1"
-    fi
-}
-
 uid=$(id -u)
 if [ $uid -ne 0 ]; then
     print_err "Please use sudo or run the script as root."
@@ -55,10 +23,12 @@ fi
 
 OLDDIR=$(pwd)
 
-if uname -a | egrep -q 'aarch64|arm64'; then
+if uname -m | grep -E -q 'aarch64|arm64'; then
     TOOLDIR=aarch64
-elif uname -a | egrep -q 'x86_64|amd64'; then
+elif uname -m | grep -E -q 'x86_64|amd64'; then
     TOOLDIR=x86_64
+elif uname -m | grep -E -q 'mips64'; then
+    TOOLDIR=mips64el
 else
     TOOLDIR=i386
 fi
@@ -75,6 +45,7 @@ if [ ! -f ./boot/boot.img ]; then
     if [ -d ./grub ]; then
         echo "Don't run VentoyWeb.sh here, please download the released install package, and run the script in it."
     else
+        echo "Current directory is $PWD"
         echo "Please run under the correct directory!" 
     fi
     exit 1
@@ -87,8 +58,6 @@ while [ -n "$1" ]; do
     if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
         print_usage
         exit 0
-    elif [ "$1" = "-n" ]; then
-        NOWEB=1
     elif [ "$1" = "-H" ]; then
         shift
         if echo $1 | grep -q '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*'; then
@@ -116,63 +85,42 @@ if ps -ef | grep "V2DServer.*$HOST.*$PORT" | grep -q -v grep; then
     exit 1
 fi
 
-VUSER=$(get_user)
 LOGFILE=log.txt
 #delete the log.txt if it's more than 8MB
 if [ -f $LOGFILE ]; then
     logsize=$(stat -c '%s' $LOGFILE)
     if [ $logsize -gt 8388608 ]; then
         rm -f $LOGFILE
-        su $VUSER -c "touch $LOGFILE"
     fi
-else
-    su $VUSER -c "touch $LOGFILE"
 fi
 
 
-
 if [ -f ./tool/$TOOLDIR/V2DServer.xz ]; then
     xz -d ./tool/$TOOLDIR/V2DServer.xz
     chmod +x ./tool/$TOOLDIR/V2DServer
 fi
 
+
 V2DServer "$HOST" "$PORT" &
+wID=$!
+sleep 1
 
 vtVer=$(cat ventoy/version)
 echo ""
-echo "=================================================================="
-echo "  Ventoy Server $vtVer is running at http://${HOST}:${PORT} ..."
-echo "=================================================================="
-echo ""
-echo "################ Press Ctrl + C to exit ######################"
-echo ""
-
-if [ "$NOWEB" = "1" ]; then
-    echo "Please open your web browser and visit http://${HOST}:${PORT}"
-else
-    if which -a google-chrome-stable >> $LOGFILE 2>&1; then    
-        chromium_proc google-chrome-stable
-    elif which -a google-chrome >> $LOGFILE 2>&1; then    
-        chromium_proc google-chrome
-    elif which -a chrome >> $LOGFILE 2>&1; then    
-        chromium_proc chrome
-    elif which -a browser >> $LOGFILE 2>&1; then        
-        chromium_proc browser        
-    elif which -a firefox >> $LOGFILE 2>&1; then
-        su $VUSER -c "firefox --no-remote \"http://${HOST}:${PORT}/index.html\""
-    else
-        echo "Please open your web browser and visit http://${HOST}:${PORT}"
-    fi
-fi
-
-if ps -ef | grep "V2DServer.*$HOST.*$PORT" | grep -q -v grep; then
-    echo ""
+echo "==============================================================="
+if [ "$LANG" = "zh_CN.UTF-8" ]; then
+    echo "  Ventoy Server $vtVer 已经启动 ..."
+    echo "  请打开浏览器,访问 http://${HOST}:${PORT}"
 else
-    print_err "Ventoy Server Error! Please check log.txt."
+    echo "  Ventoy Server $vtVer is running ..."
+    echo "  Please open your browser and visit http://${HOST}:${PORT}"
 fi
+echo "==============================================================="
+echo ""
+echo "################## Press Ctrl + C to exit #####################"
+echo ""
 
-wait $!
-
+wait $wID
 
 if [ -n "$OLDDIR" ]; then 
     CURDIR=$(pwd)