1
0
mirror of https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks.git synced 2025-09-09 07:30:57 +02:00

New auto updatepage (#428)

* Update update.html

* New autoupdate page
- Autoupdate with progress bar (approximative as based on files already on card)
- associated log tab
- version in settings

* New autoupdate page
- Autoupdate with progress bar (approximative as based on files already on card)
- associated log tab
- version in settings
This commit is contained in:
nik0
2018-06-07 20:40:55 +02:00
committed by jmtatsch
parent c3f9b9d66c
commit 282e04e911
7 changed files with 216 additions and 31 deletions

View File

@@ -12,7 +12,7 @@ BRANCH="master"
# Initial remote folder
REMOTEFOLDER="firmware_mod"
# Default destination foler
DESTFOLDER="./"
DESTFOLDER="/system/sdcard/"
DESTOVERRIDE="/tmp/Update"
# The list of exclude, can have multple filter with "*.conf|*.sh"
EXCLUDEFILTER="*.conf|*.user"
@@ -22,6 +22,7 @@ CURL="/system/sdcard/bin/curl -k"
JQ="/system/sdcard/bin/jq"
SHA="/system/sdcard/bin/openssl dgst -sha256"
BASENAME="/system/sdcard/bin/busybox basename"
FIND="/system/sdcard/bin/busybox find"
TMPFILE=/tmp/udpate.tmp
BACKUPEXT=.backup
@@ -30,6 +31,10 @@ _V=0
_FORCE=0
_FORCEREBOOT=0
_BACKUP=0
_PROGRESS=0
_NBFILES=0
_NBTOTALFILES=0
##########################################################################
usage()
@@ -42,6 +47,7 @@ usage()
echo "-f (--force) force update"
echo "-d (--dest) set the destination folder (default is ${DESTFOLDER})"
echo "-p (--print) print action only, do nothing"
echo "-s (--steps) add progress in file /tmp/progress"
echo "-v (--verbose) for verbose"
echo "-u (--user) githup login/password (not mandatory, but sometime anonymous account get banned)"
@@ -80,6 +86,17 @@ logerror ()
echo "$@" 1>&2
}
##########################################################################
# Log string on std error
progress()
{
if [ ${_PROGRESS} -eq 1 ]; then
_NBFILES=$((${_NBFILES} + 1))
echo -n $((${_NBFILES} *100 / ${_NBTOTALFILES} )) > /tmp/progress
# echo "file = ${_NBFILES}, total=${_NBTOTALFILES} = $((${_NBFILES} *100 / ${_NBTOTALFILES} ))"
fi
}
##########################################################################
# If "printonly" action is selected print the action to do (but don't do it
# If not execute it
@@ -107,6 +124,13 @@ ismatch()
echo notmatch
}
##########################################################################
# Return the current (last) commit from the specified repo and branch
getCurrentCommitDateFromRemote()
{
LASTCOMMITDATE=$(${CURL} -s ${GITHUBURL}/${REPO}/commits/${BRANCH} | grep date | head -1 | cut -d'"' -f 4)
echo ${LASTCOMMITDATE}
}
##########################################################################
# Print the files from repo of the folder $1
@@ -140,6 +164,8 @@ countdownreboot()
i=$((${i} - 1))
sleep 1;
done
action sync
action sync
action reboot
}
##########################################################################
@@ -178,6 +204,10 @@ do
shift
shift
;;
-s | --steps)
_PROGRESS=1;
shift
;;
*|-h |\? | --help)
usage $0
exit 1
@@ -201,12 +231,22 @@ fi
action "rm -rf ${DESTOVERRIDE} 2>/dev/null"
log "Getting list of remote files."
FIRST=$(${CURL} -s ${GITHUBURL}/${REPO}/contents/${REMOTEFOLDER}?ref=${BRANCH})
FILES=$(getfiles "${FIRST}")
if [ $_PROGRESS = 1 ]; then
_NBTOTALFILES=$(echo $FILES | wc -w)
log Number of file to update $_NBTOTALFILES
echo -n 0 > /tmp/progress
fi
# For all the repository files
for i in ${FILES}
do
progress
# String to remove to get the local path
REMOVE="${GITHUBURLRAW}/${REPO}/${BRANCH}/${REMOTEFOLDER}/"
LOCALFILE="${DESTFOLDER}${i#$REMOVE}"
@@ -242,7 +282,7 @@ do
action mv ${TMPFILE} ${DESTOVERRIDE}/${LOCALFILE}
else
echo "${LOCALFILE} needs to be updated. Overwrite?"
echo "[Y]es or [N]o or [A]ll?"
echo "[Y]es or [N]o or [A]ll?"
rep=$(ask_yes_or_no )
if [ "${rep}" = "no" ]; then
echo "${LOCALFILE} not updated"
@@ -283,6 +323,11 @@ do
fi
done
if [ $_PROGRESS = 1 ]; then
echo -n 100 > /tmp/progress
fi
if [ -d ${DESTOVERRIDE} ] && [ $(ls -l ${DESTOVERRIDE}/* | wc -l 2>/dev/null) > 1 ]; then
echo "--------------- Stopping services ---------"
for i in /system/sdcard/controlscripts/*; do
@@ -296,6 +341,8 @@ if [ -d ${DESTOVERRIDE} ] && [ $(ls -l ${DESTOVERRIDE}/* | wc -l 2>/dev/null) >
action "cp -Rf ${DESTOVERRIDE}/* ${DESTFOLDER} 2>/dev/null"
action "rm -Rf ${DESTOVERRIDE}/* 2>/dev/null"
# Everythings was OK, save the date
echo $(getCurrentCommitDateFromRemote) > /system/sdcard/.lastCommitDate
echo "--------------- Reboot ------------"
if [ ${_FORCEREBOOT} = 1 ]; then
countdownreboot
@@ -308,5 +355,6 @@ if [ -d ${DESTOVERRIDE} ] && [ $(ls -l ${DESTOVERRIDE}/* | wc -l 2>/dev/null) >
fi
fi
else
echo $(getCurrentCommitDateFromRemote) > /system/sdcard/.lastCommitDate
echo "No files to update."
fi

View File

@@ -35,6 +35,10 @@ if [ -n "$F_cmd" ]; then
echo "Contents of v4l2rtspserver-master.log<br/>"
cat /system/sdcard/log/v4l2rtspserver-master.log
;;
5)
echo "Contents of update.log <br/>"
cat /var/log/update.log
;;
esac
echo "</pre>"
@@ -62,6 +66,10 @@ if [ -n "$F_cmd" ]; then
echo "Contents of v4l2rtspserver-master.log cleared<br/>"
echo -n "" > /system/sdcard/log/v4l2rtspserver-master.log
;;
5)
echo "Contents of update.log cleared <br/>"
echo -n "" > /var/log/update.log
;;
esac
echo "</pre>"
return
@@ -387,10 +395,6 @@ if [ -n "$F_cmd" ]; then
/system/sdcard/bin/setconf -k t -v on
fi
# echo "region_of_interest=${F_x0},${F_y0},${F_x1},${F_y1}" > /system/sdcard/config/motion.conf
# echo "motion_sensitivity=${F_motion_sensitivity}" >> /system/sdcard/config/motion.conf
# echo "motion_indicator_color=${F_motion_indicator_color}" >> /system/sdcard/config/motion.conf
/system/sdcard/bin/setconf -k r -v ${F_x0},${F_y0},${F_x1},${F_y1}
/system/sdcard/bin/setconf -k m -v ${F_motion_sensitivity}
/system/sdcard/bin/setconf -k z -v ${F_motion_indicator_color}
@@ -399,26 +403,13 @@ if [ -n "$F_cmd" ]; then
# Changed the detection region, need to restart the server
if [ ${F_restart_server} == "1" ]
then
processName="v4l2rtspserver-master"
#get the process pid
processId=`ps | grep ${processName} | grep -v grep | awk '{ printf $1 }'`
if [ "${processId}X" != "X" ]
then
#found the process, now get the full path and the parameters in order to restart it
executable=`ls -l /proc/${processId}/exe | awk '{print $NF}'`
cmdLine=`tr '\0' ' ' < /proc/${processId}/cmdline | awk '{$1=""}1'`
kill ${processId} 2>/dev/null
# Set the socket option in order to restart easily the server (socket in use)
echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
sleep 2
cmdLine="/system/sdcard/bin/busybox nohup "${executable}${cmdLine} 2>/dev/null
${cmdLine} 2>/dev/null >/dev/null &
else
echo "<p>process v4l2rtspserver-master was not found</p>"
if [ "$(rtsp_h264_server status)" = "ON" ]; then
rtsp_h264_server off
rtsp_h264_server on
fi
if [ "$(rtsp_mjpeg_server status)" = "ON" ]; then
rtsp_mjpeg_server off
rtsp_mjpeg_server on
fi
fi
@@ -480,7 +471,37 @@ if [ -n "$F_cmd" ]; then
/system/sdcard/bin/setconf -k l -v "$F_HFEnabled" 2>/dev/null
/system/sdcard/bin/setconf -k h -v "$F_audioinVol" 2>/dev/null
return
;;
;;
update)
processId=$(ps | grep autoupdate.sh | grep -v grep)
if [ "$processId" == "" ]
then
echo "===============" >> /var/log/update.log
date >> /var/log/update.log
if [ "$F_login" != "" ]; then
/system/sdcard/bin/busybox nohup /system/sdcard/autoupdate.sh -s -v -f -u $F_login >> "/var/log/update.log" &
else
/system/sdcard/bin/busybox nohup /system/sdcard/autoupdate.sh -s -v -f >> "/var/log/update.log" &
fi
processId=$(ps | grep autoupdate.sh | grep -v grep)
fi
echo $processId
return
;;
show_updateProgress)
processId=$(ps | grep autoupdate.sh | grep -v grep)
if [ "$processId" == "" ]
then
echo -n -1
else
if [ -f /tmp/progress ] ; then
cat /tmp/progress
else
echo -n 0
fi
fi
return
;;
*)
echo "Unsupported command '$F_cmd'"
;;

View File

@@ -100,9 +100,9 @@ cat << EOF
<!-- Version -->
<div class='card status_card'>
<header class='card-header'><p class='card-header-title'>Version</p></header>
<header class='card-header'><p class='card-header-title'>Version (last commit date from GitHub/autoupdate script)</p></header>
<div class='card-content'>
<p>$(cut -d'=' -f2 /etc/os-release)</p>
<p>$(cat /system/sdcard/.lastCommitDate)</p>
</div>
</div>

View File

@@ -173,7 +173,7 @@
<a id="configmotion" class="navbar-item onpage" href="javascript: void(0)" data-target="configmotion.html">Motion Detection</a>
<a id="network" class="navbar-item onpage" href="javascript: void(0)" data-target="cgi-bin/network.cgi">Network Information</a>
<a id="logs" class="navbar-item onpage" href="javascript: void(0)" data-target="logs.html">Logs</a>
<a class="navbar-item prompt" href="javascript: void(0)" data-message="Are you sure you wish to update? Warning: This will take some minutes ... without any status indication." data-target="cgi-bin/update.cgi">Update</a>
<a id="update" class="navbar-item onpage" href="javascript: void(0)" data-target="update.html">Update</a>
<a class="navbar-item prompt" href="javascript: void(0)" data-message="Are you sure you wish to reboot?" data-target="cgi-bin/action.cgi?cmd=reboot">Reboot</a>
<a class="navbar-item prompt" href="javascript: void(0)" data-message="Are you sure you wish to shutdown?" data-target="cgi-bin/action.cgi?cmd=shutdown">Shutdown</a>
</div>

View File

@@ -35,6 +35,12 @@
<span>video server</span>
</a>
</li>
<li data-tab="5">
<a>
<span class="icon is-small"><i class="fa fa-file-text-o"></i></span>
<span>Last update</span>
</a>
</li>
</ul>
</div>
<div id="tab-content">
@@ -48,7 +54,8 @@
</p>
<p data-content="4" id="tab4">
</p>
<p data-content="5" id="tab5">
</p>
</div>
<script type="text/javascript">

View File

@@ -0,0 +1,109 @@
<script type="text/javascript">
$(document).ready(function() {
update(true)
});
function timedRefresh(timeoutPeriod) {
timeoutPeriod -= 1;
$('#message').text("Rebooting ... wait..." + timeoutPeriod);
if (timeoutPeriod == 0) {
window.location.href = window.location.href;
} else {
setTimeout(function() {
timedRefresh(timeoutPeriod)
}, 1000);
}
};
function update(onStart) {
$.ajax({
'url': 'cgi-bin/action.cgi?cmd=show_updateProgress'
}).done(function(log) {
if (log < 0) {
if (onStart != true)
{
$('#message').text("Error starting update progress");
$('#message').text("Error starting update process");
}
$('#start').removeAttr('disabled');
} else {
$('#start').attr("disabled", "disabled");
$('#message').text("Update in progress");
$('#progress').val(log);
// This is the end, start the reboot count down
if (log >= 100) {
timedRefresh(45);
} else {
setTimeout(update, 500);
}
}
});
}
function start() {
var login = ""
if ($('#login').val().length > 0) {
login = "login=" + $('#login').val() + ":" + $('#password').val();
}
$.ajax({
'url': 'cgi-bin/action.cgi?cmd=update',
'type': 'POST',
'data': login
}).done(function(result) {
if (result.length > 0) {
$('#start').attr("disabled", "disabled");
update(false);
} else {
$('#message').text("Error starting update progress");
$('#start').removeAttr('disabled');
}
});
}
</script>
<div class='card status_card'>
<header class='card-header'>
<p class='card-header-title'>GitHub login and password (not mandatory)</p>
</header>
<div class='card-content'>
<div class="field is-horizontal">
<div class="field-body">
<div class="field">
<div class="control">
<input class="input" id="login" name="login" type="text" size="12" value="" />
</div>
</div>
</div>
<div class="field-body">
<div class="field">
<div class="control">
<input class="input" id="password" name="password" type="password" size="12" value="" />
</div>
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-label is-normal">
</div>
<div class="field-body">
<div class="field">
<div class="control">
<input id="start" class="button is-primary" type="submit" value="Start" onclick="start()" />
</div>
</div>
</div>
</div>
</div>
</div>
<pre>
<h4 class="title is-4">Please note that at the end of the process the camera will reboot without notice</h4>
<progress id=progress name=progress class="progress is-danger" value=0 max="100"></progress>
<h1 id=message class="title is-1 has-text-centered"></h1>
</pre>