1
0
mirror of https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks.git synced 2025-09-03 13:12:44 +02:00

Allow custom firmware repositories (#1651)

* Add repo option to autoupdate.sh

* Fix repo option in autoupdate.sh

* Use local repo when checking for updates

* Use default repo if non given in VERSION file in autoupdates.sh

* Pass custom repo to web ui and update cgi

* Add custom firmware update to web ui

* Fix update messages

* Fix update start arguments

* Fix update input labels

* Add custom upgrade button when on custom firmware
This commit is contained in:
Greg Thornton
2020-12-22 00:48:59 -06:00
committed by GitHub
parent 4f304046fa
commit 43d73c3c77
4 changed files with 125 additions and 68 deletions

View File

@@ -48,6 +48,7 @@ usage()
echo "Usage this script to update the ${REPO} github repo from ${BRANCH} (default) branch"
echo "Options:"
echo "-b (--backup) backup erased file (add extension ${BACKUPEXT} to the local file before ovewrite it) "
echo "-x (--repo) to set the repo"
echo "-r (--branch) to set the branch"
echo "-f (--force) force update"
echo "-d (--dest) set the destination folder (default is ${DESTFOLDER})"
@@ -169,7 +170,7 @@ countdownreboot()
# Generate VERSION file
generateVersionFile ()
{
echo "{\"date\":\"${REMOTECOMMITDATE}\",\"branch\":\"${BRANCH}\",\"commit\":\"${REMOTECOMMITID}\"}" > $VERSION_FILE
echo "{\"date\":\"${REMOTECOMMITDATE}\",\"repo\":\"${REPO}\",\"branch\":\"${BRANCH}\",\"commit\":\"${REMOTECOMMITID}\"}" > $VERSION_FILE
}
##########################################################################
# Curl with optional authentication
@@ -228,6 +229,11 @@ do
_PROGRESS=1;
shift
;;
-x | --repo)
REPO=$2;
shift
shift
;;
-r | --branch)
BRANCH=$2
shift
@@ -264,14 +270,21 @@ action "rm -rf ${DESTOVERRIDE} 2>/dev/null"
if [ -f "$VERSION_FILE" ]; then
LOCALCOMMITID=$(${JQ} -r .commit ${VERSION_FILE})
if [ ${LOCALCOMMITID} = ${REMOTECOMMITID} ]; then
LOCALREPO=$(${JQ} -r .repo ${VERSION_FILE})
if [ -z "$LOCALREPO" ]; then LOCALREPO="$REPO"; fi
if [ ${LOCALREPO} = ${REPO} ] && [ ${LOCALCOMMITID} = ${REMOTECOMMITID} ]; then
logerror "You are currently on the latest version"
echo "You are currently on the latest version"
exit 1
else
elif [ ${LOCALREPO} = ${REPO} ]; then
echo "Need to upgrade from ${LOCALCOMMITID} to ${REMOTECOMMITID}"
log "Getting list of remote files."
FILES=$(curl -s ${GITHUBURL}/${REPO}/compare/${LOCALCOMMITID}...${REMOTECOMMITID} | ${JQ} -r '.files[].raw_url' | grep ${REMOTEFOLDER})
else
echo "Repo has changed. Upgrade to last commit ${REMOTECOMMITID}"
log "Getting list of remote files."
FIRST=$(curl -s ${GITHUBURL}/${REPO}/contents/${REMOTEFOLDER}?ref=${BRANCH})
FILES=$(getfiles "${FIRST}")
fi
else
echo "Version file missing. Upgrade to last commit ${REMOTECOMMITID}"

View File

@@ -803,13 +803,15 @@ github_curl() {
# Check commit between VERSION file and github
check_commit() {
if [ -s /system/sdcard/VERSION ]; then
localrepo=$(/system/sdcard/bin/jq -r .repo /system/sdcard/VERSION)
if [ -z "$localrepo" ]; then localrepo="EliasKotlyar"; fi
localcommit=$(/system/sdcard/bin/jq -r .commit /system/sdcard/VERSION)
localbranch=$(/system/sdcard/bin/jq -r .branch /system/sdcard/VERSION)
remotecommit=$(github_curl -s https://api.github.com/repos/EliasKotlyar/Xiaomi-Dafang-Hacks/commits/${localbranch} | /system/sdcard/bin/jq -r '.sha[0:7]')
remotecommit=$(github_curl -s https://api.github.com/repos/${localrepo}/commits/${localbranch} | /system/sdcard/bin/jq -r '.sha[0:7]')
if [ ${localcommit} = ${remotecommit} ]; then
echo "${localcommit} ( No update available)"
else
commitbehind=$(github_curl -s https://api.github.com/repos/EliasKotlyar/Xiaomi-Dafang-Hacks/compare/${remotecommit}...${localcommit} | /system/sdcard/bin/jq -r '.behind_by')
commitbehind=$(github_curl -s https://api.github.com/repos/${localrepo}/compare/${remotecommit}...${localcommit} | /system/sdcard/bin/jq -r '.behind_by')
echo "${localcommit} ( ${commitbehind} commits behind Github)"
fi
else

View File

@@ -533,10 +533,14 @@ auto_night_mode_status)
update)
processId=$(ps | grep autoupdate.sh | grep -v grep)
release=""
if [ $F_release == "beta" ]; then
release="-r beta"
fi
repo=$(printf '%b' "${F_repo//%/\\x}")
if [ -n "$repo" ]; then
repo="-x $repo"
fi
release=$(printf '%b' "${F_release//%/\\x}")
if [ -n "$release" ]; then
release="-r $release"
fi
if [ $F_mode == "full" ]; then
mv /system/sdcard/VERSION /system/sdcard/VERSION.old
fi
@@ -545,9 +549,9 @@ auto_night_mode_status)
date >> /var/log/update.log
github_token=$(get_config /system/sdcard/config/updates.conf github_token)
if [ "$github_token" != "" ]; then
/system/sdcard/bin/busybox nohup /system/sdcard/autoupdate.sh -s -v -f ${release} -t "$github_token" >> "/system/sdcard/log/update.log" &
/system/sdcard/bin/busybox nohup /system/sdcard/autoupdate.sh -s -v -f ${repo} ${release} -t "$github_token" >> "/system/sdcard/log/update.log" &
else
/system/sdcard/bin/busybox nohup /system/sdcard/autoupdate.sh -s -v -f ${release} >> "/system/sdcard/log/update.log" &
/system/sdcard/bin/busybox nohup /system/sdcard/autoupdate.sh -s -v -f ${repo} ${release} >> "/system/sdcard/log/update.log" &
fi
processId=$(ps | grep autoupdate.sh | grep -v grep)
fi
@@ -695,17 +699,19 @@ motion_detection_mqtt_snapshot_status)
;;
check_update)
if [ -s /system/sdcard/VERSION ]; then
localrepo=$(/system/sdcard/bin/jq -r .repo /system/sdcard/VERSION)
if [ -z "$localrepo" ]; then localrepo="EliasKotlyar"; fi
localcommit=$(/system/sdcard/bin/jq -r .commit /system/sdcard/VERSION)
localbranch=$(/system/sdcard/bin/jq -r .branch /system/sdcard/VERSION)
remotecommit=$(github_curl -s https://api.github.com/repos/EliasKotlyar/Xiaomi-Dafang-Hacks/commits/${localbranch} | /system/sdcard/bin/jq -r '.sha[0:7]')
commitbehind=$(github_curl -s https://api.github.com/repos/EliasKotlyar/Xiaomi-Dafang-Hacks/compare/${remotecommit}...${localcommit} | /system/sdcard/bin/jq -r '.behind_by')
remotecommit=$(github_curl -s https://api.github.com/repos/${localrepo}/commits/${localbranch} | /system/sdcard/bin/jq -r '.sha[0:7]')
commitbehind=$(github_curl -s https://api.github.com/repos/${localrepo}/compare/${remotecommit}...${localcommit} | /system/sdcard/bin/jq -r '.behind_by')
if [ ${localcommit} = ${remotecommit} ]; then
echo "${localbranch}:0"
echo "${localrepo}:${localbranch}:0"
else
echo "${localbranch}:${commitbehind}"
echo "${localrepo}:${localbranch}:${commitbehind}"
fi
else
echo "null:-1"
echo "null:null:-1"
fi
return
;;

View File

@@ -47,62 +47,100 @@ function accordionUpdate(param) {
}
}
function startCustom(el) {
var repo = $('#custom_repo').val();
var branch = $('#custom_branch').val();
var mode = $('#custom_full').is(":checked") ? 'full' : 'cumul';
start(repo, branch, mode);
}
function showupdatepage(result) {
$('#update').html('<h2 id="updatemsg">Seaching for updates ...</h2>');
$.ajax({
'url': 'cgi-bin/action.cgi?cmd=check_update'
}).done(function(result){
var update = result.split(":")
var update_status = parseInt(update[1],10);
var repo = update[0];
var branch = update[1];
var update_status = parseInt(update[2],10);
var custom = '<div class="w3-panel w3-border w3-round"> \
<h2>Custom Firmware</h2> \
<label for="custom_repo">Repository</label> \
<input id="custom_repo" class="w3-input w3-block w3-theme" type="text" value="' + repo + '" /><br /> \
<label for="custom_branch">Branch</label> \
<input id="custom_branch" class="w3-input w3-block w3-theme" type="text" value="' + branch + '" /><br /> \
<input id="custom_full" class="w3-check w3-theme" type="checkbox" checked="checked" /> \
<label for="custom_full">Force full update</label><br /><br /> \
<button class="w3-btn w3-block w3-theme" onclick="startCustom();">Update custom firmware</Button><br /> \
</div>';
if (update_status == 0) {
$('#updatemsg').html("You have already the latest version from the " + update[0] + " branch")
if (update[0] == "master") {
$('#updatemsg').append('<button class="accordion" type="button" onclick="accordionUpdate(this);">Other Update Options</button> \
$('#updatemsg').html("You have already the latest version from the " + branch + " branch of the " + repo + " repo.")
if (branch == "master") {
$('#update').append('<button class="accordion" type="button" onclick="accordionUpdate(this);">Other Update Options</button> \
<div class="panel"> <p></p>\
<input id="switchBeta" class="w3-btn w3-block w3-theme" type="text" value="Switch to BETA firmware" onclick="start(\'beta\',\'full\')"/><br /> \
<input id="fullStable" class="w3-btn w3-block w3-theme" type="text" value="Force full update to STABLE (remove version file + update)" onclick="start(\'master\',\'full\')"/><br /> \
</div>');
<input id="switchBeta" class="w3-btn w3-block w3-theme" type="text" value="Switch to BETA firmware" onclick="start(\'' + repo + '\',\'beta\',\'full\')"/><br /> \
<input id="fullStable" class="w3-btn w3-block w3-theme" type="text" value="Force full update to STABLE (remove version file + update)" onclick="start(\'' + repo + '\',\'master\',\'full\')"/><br /> \
' + custom + '</div>');
}
else {
$('#updatemsg').append('<button class="accordion" type="button" onclick="accordionUpdate(this);">Other Update Options</button> \
else if (branch == "beta") {
$('#update').append('<button class="accordion" type="button" onclick="accordionUpdate(this);">Other Update Options</button> \
<div class="panel"> <p></p>\
<input id="switchStable" class="w3-btn w3-block w3-theme" type="text" value="Switch to STABLE firmware" onclick="start(\'master\',\'full\')"/><br /> \
<input id="fullBeta" class="w3-btn w3-block w3-theme" type="text" value="Force full update to BETA (remove version file + update)" onclick="start(\'beta\',\'full\')"/><br /> \
</div>');
<input id="switchStable" class="w3-btn w3-block w3-theme" type="text" value="Switch to STABLE firmware" onclick="start(\'' + repo + '\',\'master\',\'full\')"/><br /> \
<input id="fullBeta" class="w3-btn w3-block w3-theme" type="text" value="Force full update to BETA (remove version file + update)" onclick="start(\'' + repo + '\',\'beta\',\'full\')"/><br /> \
' + custom + '</div>');
}
else {
$('#update').append('<button class="accordion" type="button" onclick="accordionUpdate(this);">Other Update Options</button> \
<div class="panel"> <p></p>\
<input id="fullCustom" class="w3-btn w3-block w3-theme" type="text" value="Force full update to CUSTOM (remove version file + update)" onclick="start(\'' + repo + '\',\'' + branch + '\',\'full\')"/><br /> \
<input id="switchStable" class="w3-btn w3-block w3-theme" type="text" value="Switch to STABLE firmware" onclick="start(\'' + repo + '\',\'master\',\'full\')"/><br /> \
<input id="fullBeta" class="w3-btn w3-block w3-theme" type="text" value="Force full update to BETA (remove version file + update)" onclick="start(\'' + repo + '\',\'beta\',\'full\')"/><br /> \
' + custom + '</div>');
}
}
else if (update_status == -1) {
$('#updatemsg').html("No version file found. <br /> You can update the firmware on this camera to the latest version from <a target='_blank' href='https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks'>Github repository</a>. <br />Settings will be retained after update.")
$('#updatemsg').append('\
<input id="updateStable" class="w3-btn w3-block w3-theme" type="text" value="Update firmware (STABLE)" onclick="start(\'master\',\'cumul\')"/><br /> \
<input id="updateBeta" class="w3-btn w3-block w3-theme" type="text" value="Update firmware (BETA)" onclick="start(\'beta\',\'cumul\')"/><br />');
$('#update').append('\
<input id="updateStable" class="w3-btn w3-block w3-theme" type="text" value="Update firmware (STABLE)" onclick="start(\'EliasKotlyar\',\'master\',\'cumul\')"/><br /> \
<input id="updateBeta" class="w3-btn w3-block w3-theme" type="text" value="Update firmware (BETA)" onclick="start(\'EliasKotlyar\',\'beta\',\'cumul\')"/><br />' + custom);
}
else if (update_status > 0) {
$('#updatemsg').html("You are "+ update_status +" commits behind "+ update[0] + " branch");
if (update[0] == "master") {
$('#updatemsg').append('<input id="updateStable" class="w3-btn w3-block w3-theme" type="text" value="Update firmware (STABLE)" onclick="start(\'master\',\'cumul\')"/><br />');
$('#updatemsg').append('<button class="accordion" type="button" onclick="accordionUpdate(this);">Other Update Options</button> \
$('#updatemsg').html("You are "+ update_status +" commits behind the " + branch + " branch of the " + repo + " repo.")
if (branch == "master") {
$('#update').append('<input id="updateStable" class="w3-btn w3-block w3-theme" type="text" value="Update firmware (STABLE)" onclick="start(\'' + repo + '\',\'master\',\'cumul\')"/><br />');
$('#update').append('<button class="accordion" type="button" onclick="accordionUpdate(this);">Other Update Options</button> \
<div class="panel"><p></p> \
<input id="switchBeta" class="w3-btn w3-block w3-theme" type="text" value="Switch to BETA firmware" onclick="start(\'beta\',\'full\')"/><br /> \
<input id="fullStable" class="w3-btn w3-block w3-theme" type="text" value="Force full update to STABLE (remove version file + update)" onclick="start(\'master\',\'full\')"/><br /> \
</div>');
<input id="switchBeta" class="w3-btn w3-block w3-theme" type="text" value="Switch to BETA firmware" onclick="start(\'' + repo + '\',\'beta\',\'full\')"/><br /> \
<input id="fullStable" class="w3-btn w3-block w3-theme" type="text" value="Force full update to STABLE (remove version file + update)" onclick="start(\'' + repo + '\',\'master\',\'full\')"/><br /> \
' + custom + '</div>');
}
else if (branch == "beta") {
$('#update').append('<input id="updateBeta" class="w3-btn w3-block w3-theme" type="text" value="Update firmware (BETA)" onclick="start(\'' + repo + '\',\'beta\',\'cumul\')"/><br />');
$('#update').append('<button class="accordion" type="button" onclick="accordionUpdate(this);">Other Update Options</button> \
<div class="panel"> <p></p>\
<input id="switchStable" class="w3-btn w3-block w3-theme" type="text" value="Switch to STABLE firmware" onclick="start(\'' + repo + '\',\'master\',\'full\')"/><br /> \
<input id="fullBeta" class="w3-btn w3-block w3-theme" type="text" value="Force full update to BETA (remove version file + update)" onclick="start(\'' + repo + '\',\'beta\',\'full\')"/><br /> \
' + custom + '</div>');
}
else {
$('#updatemsg').append('<input id="updateBeta" class="w3-btn w3-block w3-theme" type="text" value="Update firmware (BETA)" onclick="start(\'beta\',\'cumul\')"/><br />');
$('#updatemsg').append('<button class="accordion" type="button" onclick="accordionUpdate(this);">Other Update Options</button> \
$('#update').append('<input id="updateCustom" class="w3-btn w3-block w3-theme" type="text" value="Update firmware (CUSTOM)" onclick="start(\'' + repo + '\',\'' + branch + '\',\'cumul\')"/><br />');
$('#update').append('<button class="accordion" type="button" onclick="accordionUpdate(this);">Other Update Options</button> \
<div class="panel"> <p></p>\
<input id="switchStable" class="w3-btn w3-block w3-theme" type="text" value="Switch to STABLE firmware" onclick="start(\'master\',\'full\')"/><br /> \
<input id="fullBeta" class="w3-btn w3-block w3-theme" type="text" value="Force full update to BETA (remove version file + update)" onclick="start(\'beta\',\'full\')"/><br /> \
</div>');
<input id="switchStable" class="w3-btn w3-block w3-theme" type="text" value="Switch to STABLE firmware" onclick="start(\'' + repo + '\',\'master\',\'full\')"/><br /> \
<input id="fullBeta" class="w3-btn w3-block w3-theme" type="text" value="Force full update to BETA (remove version file + update)" onclick="start(\'' + repo + '\',\'beta\',\'full\')"/><br /> \
' + custom + '</div>');
}
}
else {
$('#updatemsg').text("There is a problem with your VERSION file. Please do a full update to create a valid VERSION file.");
$('#updatemsg').append('\
<input id="updateStable" class="w3-btn w3-block w3-theme" type="text" value="Update firmware (STABLE)" onclick="start(\'master\',\'cumul\')"/><br /> \
<input id="updateBeta" class="w3-btn w3-block w3-theme" type="text" value="Update firmware (BETA)" onclick="start(\'beta\',\'cumul\')"/><br />');
$('#update').append('\
<input id="updateStable" class="w3-btn w3-block w3-theme" type="text" value="Update firmware (STABLE)" onclick="start(\'EliasKotlyar\',\'master\',\'cumul\')"/><br /> \
<input id="updateBeta" class="w3-btn w3-block w3-theme" type="text" value="Update firmware (BETA)" onclick="start(\'EliasKotlyar\',\'beta\',\'cumul\')"/><br />' + custom);
}
});
}
@@ -177,7 +215,7 @@ function getFiles(dir) {
}
function start(branch,mode) {
function start(repo,branch,mode) {
var login = "";
// if ($('#login').val().length > 0) {
// login = "login=" + $('#login').val() + ":" + $('#password').val();
@@ -188,7 +226,7 @@ function start(branch,mode) {
$('#modal_content').html('<h4>Please note: at the end of this process the camera will reboot without notice!</h4> \
<div class="w3-light-grey"><div id="progress" class="w3-container w3-theme" style="width:0%"><span id="progressValue">0%</span></div></div><br><h4 id=message></h4>');
var url = 'cgi-bin/action.cgi?cmd=update&release='+branch+'&mode='+mode;
var url = 'cgi-bin/action.cgi?cmd=update&repo='+repo+'&release='+branch+'&mode='+mode;
$.ajax({
'url': url,
'type': 'POST',
@@ -290,5 +328,3 @@ function onLoad() {
}
onLoad();