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

Merge branch 'master' of https://github.com/nik0/Xiaomi-Dafang-Hacks into AutoUpdate

This commit is contained in:
nik0
2018-04-18 07:25:39 -07:00

View File

@@ -1,5 +1,4 @@
#!/bin/sh
##########################################################################
# Github autodownload script
# See usage for help
@@ -14,7 +13,8 @@ BRANCH="master"
REMOTEFOLDER="firmware_mod"
# Default destination foler
DESTFOLDER="./"
# The list of exclude, can have multple filter with "*\.conf|*\.sh"
EXCLUDEFILTER="*\.conf|run\.sh"
# Somme URL
GITHUBURL="https://api.github.com/repos"
GITHUBURLRAW="https://raw.githubusercontent.com"
@@ -28,14 +28,14 @@ SHA="/system/sdcard/bin/openssl dgst -sha256"
#SHA="openssl dgst -sha256"
TMPFILE=/tmp/udpate.tmp
BACKUPEXT=.backup
LASTGLOBALCOMMIT=""
_PRINTONLY=0
_V=0
_FORCE=0
_CHECK=0
_XFER=0
_BACKUP=0
##########################################################################
usage()
@@ -48,6 +48,7 @@ usage()
echo "-s (--status) say if need to update or not based on global commit ID"
echo "-x (--xfer) update file by file, prompted for each file unless use of --force"
echo "-b (--backup) backup erased file (add extension ${BACKUPEXT} to the local file before ovewrite it) "
echo "-f (--force) force update"
echo "-d (--dest) set the destination folder (default is ${DESTFOLDER})"
echo "-p (--print) print action only, do nothing"
@@ -55,7 +56,8 @@ usage()
echo "-v (--verbose) for verbose"
echo "-u (--user) githup login/password (not mandatory, but sometime anonymous account get banned)"
echo "-h (--help) for this help"
echo
echo
echo "Note that ${EXCLUDEFILTER} will be excluded"
echo "Example:"
echo "Check that local folder is up to date (file by file): >$1 -c -d /system/sdcard"
echo "Check that local folder is up to date (based on last update and commit ID): >$1 -s"
@@ -181,6 +183,10 @@ do
shift
shift
;;
-b | --backup)
_BACKUP=1;
shift
;;
-p | --print)
_PRINTONLY=1
shift
@@ -245,6 +251,10 @@ if [ $_PRINTONLY = 1 ]; then
log "Print actions only, do nothing"
fi
if [ $_BACKUP = 1 ]; then
log "will backup files"
fi
if [ ${update} = true ]; then
if [ ${_CHECK} = 0 ]; then
@@ -259,6 +269,12 @@ if [ ${update} = true ]; then
# String to remove to get the local path
REMOVE="${GITHUBURLRAW}/${REPO}/${BRANCH}/${REMOTEFOLDER}/"
LOCALFILE="${DESTFOLDER}${i#$REMOVE}"
# Remove files that match the filter
res=$(echo ${LOCALFILE} | grep -E ${EXCLUDEFILTER})
if [ $? = 0 ]; then
echo "${LOCALFILE} is excluded due to filter"
continue
fi
# If check only or ask to xfer for all
if [ ${_CHECK} = 1 ] || [ ${_XFER} = 1 ] ; then
# Get the file temporally to calculate SHA
@@ -282,6 +298,9 @@ if [ ${update} = true ]; then
if [ ${_FORCE} = 1 ]; then
echo "${LOCALFILE} updated"
action "mkdir $(dirname ${LOCALFILE}) 2>/dev/null"
if [ ${_BACKUP} = 1 ]; then
action mv ${LOCALFILE} ${LOCALFILE}${BACKUPEXT}
fi
action mv ${TMPFILE} ${LOCALFILE}
else
echo "${LOCALFILE} need to be updated, overwrite [Y]es or [N]o or [A]ll ?"
@@ -291,7 +310,11 @@ if [ ${update} = true ]; then
rm -f ${TMPFILE} 2>/dev/null
else
action "mkdir $(dirname ${LOCALFILE}) 2>/dev/null"
if [ ${_BACKUP} = 1 ]; then
action mv ${LOCALFILE} ${LOCALFILE}${BACKUPEXT}
fi
action mv ${TMPFILE} ${LOCALFILE}
fi
if [ "${rep}" = "all" ]; then
_FORCE=1