diff --git a/firmware_mod/autoupdate.sh b/firmware_mod/autoupdate.sh index 0f5b82b..39b3cf9 100755 --- a/firmware_mod/autoupdate.sh +++ b/firmware_mod/autoupdate.sh @@ -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 @@ -263,15 +269,22 @@ fi action "rm -rf ${DESTOVERRIDE} 2>/dev/null" if [ -f "$VERSION_FILE" ]; then - LOCALCOMMITID=$(${JQ} -r .commit ${VERSION_FILE}) - if [ ${LOCALCOMMITID} = ${REMOTECOMMITID} ]; then + LOCALCOMMITID=$(${JQ} -r .commit ${VERSION_FILE}) + 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}" @@ -306,10 +319,10 @@ do fi # sometimes zero byte files are received, which overwrite the local files, we ignore those files # exception: files that are hidden i.e. start with dot. Ex: files like ".gitkeep" - if [[ ! -s ${TMPFILE} ]] && [[ $(basename ${LOCALFILE} | cut -c1-1) != "." ]]; then - echo "Received zero byte file $i, exiting." - exit 1 - fi + if [[ ! -s ${TMPFILE} ]] && [[ $(basename ${LOCALFILE} | cut -c1-1) != "." ]]; then + echo "Received zero byte file $i, exiting." + exit 1 + fi # Check the file exists in local if [ -f "${DESTFOLDER}/${LOCALFILE}" ]; then REMOTESHA=$(${SHA} ${TMPFILE} 2>/dev/null | cut -d "=" -f 2) diff --git a/firmware_mod/scripts/common_functions.sh b/firmware_mod/scripts/common_functions.sh index a741428..6511d4d 100755 --- a/firmware_mod/scripts/common_functions.sh +++ b/firmware_mod/scripts/common_functions.sh @@ -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 diff --git a/firmware_mod/www/cgi-bin/action.cgi b/firmware_mod/www/cgi-bin/action.cgi index fc9256c..e7fe8a6 100755 --- a/firmware_mod/www/cgi-bin/action.cgi +++ b/firmware_mod/www/cgi-bin/action.cgi @@ -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 ;; diff --git a/firmware_mod/www/js/control.js b/firmware_mod/www/js/control.js index 8995b16..df45e6d 100755 --- a/firmware_mod/www/js/control.js +++ b/firmware_mod/www/js/control.js @@ -14,7 +14,7 @@ function timedRefresh(timeoutPeriod) { function update(onStart) { $.ajax({ 'url': 'cgi-bin/action.cgi?cmd=show_updateProgress' - }).done(function(log) { + }).done(function(log) { if (log < 0) { if (onStart != true) { @@ -44,65 +44,103 @@ function accordionUpdate(param) { panel.style.maxHeight = null; } else { panel.style.maxHeight = panel.scrollHeight + "px"; - } + } +} + +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('