From 214184a62fa790c26705e2b3d516255e592accb2 Mon Sep 17 00:00:00 2001 From: popcornmix Date: Tue, 8 Jan 2013 17:11:40 +0000 Subject: [PATCH] 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 --- rpi-update | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/rpi-update b/rpi-update index e46281d..9255299 100755 --- a/rpi-update +++ b/rpi-update @@ -123,8 +123,10 @@ function finalise { function download_repo { echo " *** Setting up firmware (this may take a few minutes)" mkdir -p "${FW_REPOLOCAL}" + set +e git clone "${FW_REPO}" "${FW_REPOLOCAL}" --depth=1 RETVAL=$? + set -e if [[ ${RETVAL} -ne 0 ]]; then echo " !!! Failed to download new firmware files" exit 1 @@ -133,26 +135,34 @@ function download_repo { function update_repo { echo " *** Updating firmware (this may take a few minutes)" + set +e eval ${GITCMD} fetch --depth=1 RETVAL=$? + set -e if [[ ${RETVAL} -ne 0 ]]; then - echo " !!! Failed to download updated firmware files" - exit 1 + echo " !!! Failed to fetch updated firmware files, trying a fresh checkout" + rm -rf ${FW_REPOLOCAL} + download_repo + return fi - eval ${GITCMD} reset --hard - eval ${GITCMD} clean -f -d - eval ${GITCMD} merge origin/master -m "automerge" + set +e + eval ${GITCMD} reset --hard && eval ${GITCMD} clean -f -d && eval ${GITCMD} merge origin/master -m "automerge" RETVAL=$? + set -e if [[ ${RETVAL} -ne 0 ]]; then - echo " !!! Failed to download updated firmware files" - exit 1 + echo " !!! Failed to merge updated firmware files, trying a fresh checkout" + rm -rf ${FW_REPOLOCAL} + download_repo + return fi } function do_backup { echo " *** Backing up files" + rm -rf "${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 { @@ -189,10 +199,6 @@ if [[ ! -d "${FW_PATH}" ]]; then echo " !!! ${FW_PATH} doesn't exist" exit 1 fi -if [[ ! -f "${FW_PATH}/start.elf" ]]; then - echo " !!! ${FW_PATH}/start.elf doesn't exist." - exit 1 -fi if [[ ! -d "${FW_MODPATH}" ]]; then echo " !!! ${FW_MODPATH} doesn't exist" exit 1