Skip to content

Commit

Permalink
script optimization for UOS
Browse files Browse the repository at this point in the history
  • Loading branch information
ventoy committed Mar 9, 2021
1 parent dce5d1b commit 67e839b
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 103 deletions.
106 changes: 3 additions & 103 deletions INSTALL/VentoyWebDeepin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ print_err() {
echo ""
}


get_user() {
name=$(logname)
if [ -n "$name" -a "$name" != "root" ]; then
Expand All @@ -28,14 +27,6 @@ get_user() {
fi
}

get_browser_cmd() {
if uos-browser --version > /dev/null 2>&1; then
echo "uos-browser"; return
else
echo "browser"
fi
}

uid=$(id -u)
if [ $uid -ne 0 ]; then
exec sudo sh $0 $*
Expand Down Expand Up @@ -104,99 +95,8 @@ if ps -ef | grep "V2DServer.*$HOST.*$PORT" | grep -q -v grep; then
exit 1
fi

VUSER=$(get_user)

LOGFILE=log.txt
if [ -e $LOGFILE ]; then
LogGroup=$(stat -c '%G' $LOGFILE)
if [ "$LogGroup" = "root" ]; then
rm -f $LOGFILE
su $VUSER -c "touch $LOGFILE"
fi
if grep -q -i uos /etc/os-release; then
. ./tool/WebUos.sh
else
su $VUSER -c "touch $LOGFILE"
fi

#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
fi
fi


if [ -f ./tool/$TOOLDIR/V2DServer.xz ]; then
xz -d ./tool/$TOOLDIR/V2DServer.xz
chmod +x ./tool/$TOOLDIR/V2DServer
fi

rm -rf ./*_VTMPDIR
vtWebTmpDir=$(su $VUSER -c "mktemp -d -p ./ --suffix=_VTMPDIR")

V2DServer "$HOST" "$PORT" &
V2DPid=$!
sleep 1

browsercmd=$(get_browser_cmd)
su $VUSER -c "$browsercmd --window-size=550,400 --app=\"http://${HOST}:${PORT}/index.html?chrome-app\" --user-data-dir=$vtWebTmpDir >> $LOGFILE 2>&1" &
WebPid=$!


vtoy_trap_exit() {

[ -d /proc/$V2DPid ] && kill -2 $V2DPid
[ -d /proc/$WebPid ] && kill -9 $WebPid

while [ -n "1" ]; do
curPid=$(ps -ef | grep -m1 "$vtWebTmpDir" | egrep -v '\sgrep\s' | awk '{print $2}')
if [ -z "$curPid" ]; then
break
fi

if [ -d /proc/$curPid ]; then
kill -9 $curPid
fi
done

[ -d $vtWebTmpDir ] && rm -rf $vtWebTmpDir

if [ -n "$OLDDIR" ]; then
CURDIR=$(pwd)
if [ "$CURDIR" != "$OLDDIR" ]; then
cd "$OLDDIR"
fi
fi

exit 1
}

trap vtoy_trap_exit HUP INT QUIT TSTP
sleep 1


vtVer=$(cat ventoy/version)
echo ""
echo "=================================================="
if [ "$LANG" = "zh_CN.UTF-8" ]; then
echo " Ventoy Server $vtVer 已经启动 ..."
else
echo " Ventoy Server $vtVer is running ..."
fi
echo "=================================================="
echo ""
echo "########### Press Ctrl + C to exit ###############"
echo ""

wait $WebPid

[ -d /proc/$V2DPid ] && kill -2 $V2DPid

[ -d $vtWebTmpDir ] && rm -rf $vtWebTmpDir

if [ -n "$OLDDIR" ]; then
CURDIR=$(pwd)
if [ "$CURDIR" != "$OLDDIR" ]; then
cd "$OLDDIR"
fi
. ./tool/WebDeepin.sh
fi
95 changes: 95 additions & 0 deletions INSTALL/tool/WebDeepin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/sh

LOGFILE=log.txt
VUSER=$(get_user)

if [ -e $LOGFILE ]; then
chown $VUSER $LOGFILE
else
su $VUSER -c "touch $LOGFILE"
fi

#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
fi
fi


if [ -f ./tool/$TOOLDIR/V2DServer.xz ]; then
xz -d ./tool/$TOOLDIR/V2DServer.xz
chmod +x ./tool/$TOOLDIR/V2DServer
fi

rm -rf ./*_VTMPDIR
vtWebTmpDir=$(mktemp -d -p ./ --suffix=_VTMPDIR)
chown $VUSER $vtWebTmpDir


V2DServer "$HOST" "$PORT" &
V2DPid=$!
sleep 1

su $VUSER -c "browser --window-size=550,400 --app=\"http://${HOST}:${PORT}/index.html?chrome-app\" --user-data-dir=$vtWebTmpDir >> $LOGFILE 2>&1" &
WebPid=$!


vtoy_trap_exit() {

[ -d /proc/$V2DPid ] && kill -2 $V2DPid
[ -d /proc/$WebPid ] && kill -9 $WebPid

while [ -n "1" ]; do
curPid=$(ps -ef | grep -m1 "$vtWebTmpDir" | egrep -v '\sgrep\s' | awk '{print $2}')
if [ -z "$curPid" ]; then
break
fi

if [ -d /proc/$curPid ]; then
kill -9 $curPid
fi
done

[ -d $vtWebTmpDir ] && rm -rf $vtWebTmpDir

if [ -n "$OLDDIR" ]; then
CURDIR=$(pwd)
if [ "$CURDIR" != "$OLDDIR" ]; then
cd "$OLDDIR"
fi
fi

exit 1
}

trap vtoy_trap_exit HUP INT QUIT TSTP
sleep 1


vtVer=$(cat ventoy/version)
echo ""
echo "=================================================="
if [ "$LANG" = "zh_CN.UTF-8" ]; then
echo " Ventoy Server $vtVer 已经启动 ..."
else
echo " Ventoy Server $vtVer is running ..."
fi
echo "=================================================="
echo ""
echo "########### Press Ctrl + C to exit ###############"
echo ""

wait $WebPid

[ -d /proc/$V2DPid ] && kill -2 $V2DPid

[ -d $vtWebTmpDir ] && rm -rf $vtWebTmpDir

if [ -n "$OLDDIR" ]; then
CURDIR=$(pwd)
if [ "$CURDIR" != "$OLDDIR" ]; then
cd "$OLDDIR"
fi
fi
51 changes: 51 additions & 0 deletions INSTALL/tool/WebUos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/sh

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
fi
fi


if [ -f ./tool/$TOOLDIR/V2DServer.xz ]; then
xz -d ./tool/$TOOLDIR/V2DServer.xz
chmod +x ./tool/$TOOLDIR/V2DServer
fi

rm -rf ./*_VTMPDIR
vtWebTmpDir=$(mktemp -d -p ./ --suffix=_VTMPDIR)

V2DServer "$HOST" "$PORT" &
V2DPid=$!
sleep 1


vtVer=$(cat ventoy/version)
echo ""
echo "=================================================="
if [ "$LANG" = "zh_CN.UTF-8" ]; then
echo " Ventoy Server $vtVer 已经启动 ..."
else
echo " Ventoy Server $vtVer is running ..."
fi
echo "=================================================="
echo ""
echo "########### Press Ctrl + C to exit ###############"
echo ""


uos-browser --window-size=550,400 --app="http://${HOST}:${PORT}/index.html?chrome-app" --user-data-dir=$vtWebTmpDir >> $LOGFILE 2>&1

[ -d /proc/$V2DPid ] && kill -2 $V2DPid
[ -d $vtWebTmpDir ] && rm -rf $vtWebTmpDir

if [ -n "$OLDDIR" ]; then
CURDIR=$(pwd)
if [ "$CURDIR" != "$OLDDIR" ]; then
cd "$OLDDIR"
fi
fi
2 changes: 2 additions & 0 deletions INSTALL/ventoy_pack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ fi

dos2unix -q ./tool/ventoy_lib.sh
dos2unix -q ./tool/VentoyWorker.sh
dos2unix -q ./tool/WebDeepin.sh
dos2unix -q ./tool/WebUos.sh

. ./tool/ventoy_lib.sh

Expand Down

0 comments on commit 67e839b

Please sign in to comment.