mirror of
https://github.com/remittor/zapret-openwrt.git
synced 2026-02-01 23:30:38 +03:00
luci: Fix func execAndRead
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
#!/bin/sh
|
||||
# Copyright (c) 2024 remittor
|
||||
awk -V
|
||||
PID_FILE=/tmp/zapret-script-exec.pid
|
||||
[ -f $PID_FILE ] && exit 70
|
||||
if [ -f $PID_FILE ]; then
|
||||
echo "ERROR: file $PID_FILE already exists!" | awk 'NR==1'
|
||||
exit 70
|
||||
fi
|
||||
LOG_FILE=$1
|
||||
RC_FILE=$1.rc
|
||||
SH_FILE=$2
|
||||
shift 2
|
||||
[ ! -f $SH_FILE ] && exit 71
|
||||
if [ ! -f $SH_FILE ]; then
|
||||
echo "ERROR: script $SH_FILE not found!" | awk 'NR==1'
|
||||
exit 71
|
||||
fi
|
||||
: > $LOG_FILE
|
||||
: > $RC_FILE
|
||||
start-stop-daemon -S -b -p $PID_FILE -x /bin/sh -- -c '
|
||||
@@ -17,7 +22,13 @@ start-stop-daemon -S -b -p $PID_FILE -x /bin/sh -- -c '
|
||||
shift 3
|
||||
sh $SH_FILE "$@" > $LOG_FILE 2>&1
|
||||
RET_CODE=$?
|
||||
sleep 1
|
||||
wc -l $LOG_FILE >/dev/null
|
||||
echo $RET_CODE > $RC_FILE
|
||||
' sh $LOG_FILE $RC_FILE $SH_FILE "$@"
|
||||
RET_CODE=$?
|
||||
if [ $RET_CODE != 0 ]; then
|
||||
echo "ERROR: script $SH_FILE not executed! ret_code = $RET_CODE" | awk 'NR==1'
|
||||
exit $RET_CODE
|
||||
fi
|
||||
echo "Script $SH_FILE running..." | awk 'NR==1'
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user