Handle errors from a git update by cloning a fresh repo.

Remove old backup directory before creating a new one. Avoids recursive backup when removing .rpi-firmware
This commit is contained in:
popcornmix
2013-01-08 17:11:40 +00:00
parent 0609fa400a
commit 214184a62f

View File

@@ -123,8 +123,10 @@ function finalise {
function download_repo { function download_repo {
echo " *** Setting up firmware (this may take a few minutes)" echo " *** Setting up firmware (this may take a few minutes)"
mkdir -p "${FW_REPOLOCAL}" mkdir -p "${FW_REPOLOCAL}"
set +e
git clone "${FW_REPO}" "${FW_REPOLOCAL}" --depth=1 git clone "${FW_REPO}" "${FW_REPOLOCAL}" --depth=1
RETVAL=$? RETVAL=$?
set -e
if [[ ${RETVAL} -ne 0 ]]; then if [[ ${RETVAL} -ne 0 ]]; then
echo " !!! Failed to download new firmware files" echo " !!! Failed to download new firmware files"
exit 1 exit 1
@@ -133,26 +135,34 @@ function download_repo {
function update_repo { function update_repo {
echo " *** Updating firmware (this may take a few minutes)" echo " *** Updating firmware (this may take a few minutes)"
set +e
eval ${GITCMD} fetch --depth=1 eval ${GITCMD} fetch --depth=1
RETVAL=$? RETVAL=$?
set -e
if [[ ${RETVAL} -ne 0 ]]; then if [[ ${RETVAL} -ne 0 ]]; then
echo " !!! Failed to download updated firmware files" echo " !!! Failed to fetch updated firmware files, trying a fresh checkout"
exit 1 rm -rf ${FW_REPOLOCAL}
download_repo
return
fi fi
eval ${GITCMD} reset --hard set +e
eval ${GITCMD} clean -f -d eval ${GITCMD} reset --hard && eval ${GITCMD} clean -f -d && eval ${GITCMD} merge origin/master -m "automerge"
eval ${GITCMD} merge origin/master -m "automerge"
RETVAL=$? RETVAL=$?
set -e
if [[ ${RETVAL} -ne 0 ]]; then if [[ ${RETVAL} -ne 0 ]]; then
echo " !!! Failed to download updated firmware files" echo " !!! Failed to merge updated firmware files, trying a fresh checkout"
exit 1 rm -rf ${FW_REPOLOCAL}
download_repo
return
fi fi
} }
function do_backup { function do_backup {
echo " *** Backing up files" echo " *** Backing up files"
rm -rf "${FW_PATH}.bak"
cp -va "${FW_PATH}" "${FW_PATH}.bak" cp -va "${FW_PATH}" "${FW_PATH}.bak"
cp -va "${FW_MODPATH}" "${FW_MODPATH}.bak" rm -rf "${FW_MODPATH}.bak"
cp -va "${FW_MODPATH}" ""
} }
function do_update { function do_update {
@@ -189,10 +199,6 @@ if [[ ! -d "${FW_PATH}" ]]; then
echo " !!! ${FW_PATH} doesn't exist" echo " !!! ${FW_PATH} doesn't exist"
exit 1 exit 1
fi fi
if [[ ! -f "${FW_PATH}/start.elf" ]]; then
echo " !!! ${FW_PATH}/start.elf doesn't exist."
exit 1
fi
if [[ ! -d "${FW_MODPATH}" ]]; then if [[ ! -d "${FW_MODPATH}" ]]; then
echo " !!! ${FW_MODPATH} doesn't exist" echo " !!! ${FW_MODPATH} doesn't exist"
exit 1 exit 1