mickey mouse™ patch for rpi-update


10 posts
by ukscone » Mon Dec 31, 2012 7:43 pm
In the last few days I have been getting a bit peeved with rpi-update failing and not letting me know where (it was in the git checkout) so i've put a very mickey mouse™ patch together to let me switch between being quiet and being very loud and obnoxious. it's not great but it works for me but YMMV just don't laugh at how rubbish it is & there is lots of room for improvement and making it more granular.

after applying the patch run rpi-update with the following command (all other options work as well)

Code: Select all
sudo UPDATE2=0 SHOUTY=1 rpi-update


UPDATE2=0 is an already available option in rpi-update, it stops the rpi-update script from updating itself and overwriting the patch. SHOUTY=1 makes the script really verbose, SHOUTY=0 or not set reverts to the normal quiet function

the patch is below

Code: Select all
--- rpi-update  2012-12-31 13:19:01.057446020 -0500
+++ rpi-update.new      2012-12-31 14:34:47.773745263 -0500
@@ -14,6 +14,22 @@
        exit 1
 fi

+if [ ${SHOUTY:-"unset"} == "unset" ] || [ $SHOUTY == 0 ]; then
+        # Default
+        SSSHH="--quiet"
+       # git reset & git clean don't have a "be verbose" option so we have to be ugly
+       SPECIAL_GIT_SSSHH="--quiet"
+       # tar & cp don't have a "be quiet" option so we have to be ugly
+       TARCP_SSSHH=""
+else
+        # Default
+        SSSHH="--verbose"
+       # git reset & clean don't have a be "verbose" option so we have to be ugly
+       SPECIAL_GIT_SSSHH=""
+       # tar & cp don't have a "be quiet" option so we have to be ugly
+       TARCP_SSSHH="--verbose"
+fi
+
 ROOT_PATH=${ROOT_PATH:-"/"}
 BOOT_PATH=${BOOT_PATH:-"/boot"}
 SKIP_KERNEL=${SKIP_KERNEL:-0}
@@ -30,7 +46,7 @@
        echo "Performing self-update"
        _tempFileName="$0.tmp"

-       if ! wget --quiet --output-document="${_tempFileName}" "${UPDATE_URI}"; then
+       if ! wget ${SSSHH} --output-document="${_tempFileName}" "${UPDATE_URI}"; then
                echo "Failed to download update for rpi-update!"
                echo "Make sure you have ca-certificates installed and that the time is set correctly"
                exit 1
@@ -57,7 +73,7 @@

 function update_modules {
        if [[ ${SKIP_KERNEL} -eq 0 ]]; then
-               cp -R "${FW_REPOLOCAL}/modules/"* "${FW_MODPATH}/"
+               cp ${TARCP_SSSHH} -R "${FW_REPOLOCAL}/modules/"* "${FW_MODPATH}/"
                find "${FW_REPOLOCAL}/modules" -mindepth 1 -maxdepth 1 -type d | while read DIR; do
                        depmod -b "${ROOT_PATH}" -a $(basename "${DIR}")
                done
@@ -72,12 +88,12 @@
        ELFOUTPUT=$(readelf -a "${ROOT_PATH}/bin/bash")
        if [ "${ELFOUTPUT}" != "${ELFOUTPUT/VFP_args/}" ]; then
                echo "Using HardFP libraries"
-               cp -R "${FW_REPOLOCAL}/vc/hardfp/"* "${ROOT_PATH}/"
+               cp ${TARCP_SSSHH} -R "${FW_REPOLOCAL}/vc/hardfp/"* "${ROOT_PATH}/"
        else
                echo "Using SoftFP libraries"
-               cp -R "${FW_REPOLOCAL}/vc/softfp/"* "${ROOT_PATH}/"
+               cp ${TARCP_SSSHH} -R "${FW_REPOLOCAL}/vc/softfp/"* "${ROOT_PATH}/"
        fi
-       cp -R "${FW_REPOLOCAL}/vc/sdk/"* "${ROOT_PATH}/"
+       cp ${TARCP_SSSHH} -R "${FW_REPOLOCAL}/vc/sdk/"* "${ROOT_PATH}/"

        if [[ -f /etc/init.d/vcfiled ]]; then
                /etc/init.d/vcfiled start
@@ -87,11 +103,11 @@
 function update_firmware {
        rm -rf ${FW_PATH}/*.elf
        rm -rf ${FW_PATH}/*.bin
-       cp ${FW_REPOLOCAL}/*.elf "${FW_PATH}/"
-       cp ${FW_REPOLOCAL}/*.bin "${FW_PATH}/"
-       cp ${FW_REPOLOCAL}/*.dat "${FW_PATH}/"
+       cp ${TARCP_SSSHH} ${FW_REPOLOCAL}/*.elf "${FW_PATH}/"
+       cp ${TARCP_SSSHH} ${FW_REPOLOCAL}/*.bin "${FW_PATH}/"
+       cp ${TARCP_SSSHH} ${FW_REPOLOCAL}/*.dat "${FW_PATH}/"
        if [[ ${SKIP_KERNEL} -eq 0 ]]; then
-               cp "${FW_REPOLOCAL}/"*.img "${FW_PATH}/"
+               cp ${TARCP_SSSHH} "${FW_REPOLOCAL}/"*.img "${FW_PATH}/"
        else
                echo "Skipping kernel/modules updated as requested"
        fi
@@ -111,7 +127,7 @@
 function download_repo {
        echo "Setting up firmware (this will take a few minutes)"
        mkdir -p "${FW_REPOLOCAL}"
-       git clone "${FW_REPO}" "${FW_REPOLOCAL}" --depth=1 --quiet
+       git clone "${FW_REPO}" "${FW_REPOLOCAL}" --depth=1 ${SSSHH}
        RETVAL=$?
        if [[ ${RETVAL} -ne 0 ]]; then
                echo "Failed to download new firmware files"
@@ -121,15 +137,15 @@

 function update_repo {
        echo "Updating firmware (this will take a few minutes)"
-       eval ${GITCMD} fetch --quiet
+       eval ${GITCMD} fetch ${SSSHH}
        RETVAL=$?
        if [[ ${RETVAL} -ne 0 ]]; then
                echo "Failed to download updated firmware files"
                exit 1
        fi
-       eval ${GITCMD} reset --hard --quiet
-       eval ${GITCMD} clean -f -d --quiet
-       eval ${GITCMD} merge origin/master -m "automerge" --quiet
+       eval ${GITCMD} reset --hard ${SPECIAL_GIT_SSSHH}
+       eval ${GITCMD} clean -f -d ${SPECIAL_GIT_SSSHH}
+       eval ${GITCMD} merge origin/master -m "automerge" ${SSSHH}
        RETVAL=$?
        if [[ ${RETVAL} -ne 0 ]]; then
                echo "Failed to download updated firmware files"
@@ -138,8 +154,8 @@
 }
User avatar
Forum Moderator
Forum Moderator
Posts: 2764
Joined: Fri Jul 29, 2011 2:51 pm
by ukscone » Mon Dec 31, 2012 10:06 pm
I wasn't happy with the earlier patch so I redid it to give me a bit more flexibilty in future and to be more in keeping with the style of the original script.

i've changed it to use a envvar called VERBOSE & changed the original UPDATE2 envvar to be UPDATE_SELF so to use the script now

Code: Select all
sudo UPDATE_SELF=0 VERBOSE=1 rpi-update


to not overwrite the patched script & for it to be loud, obnoxious & verbose.

the new patch is below

Code: Select all
--- rpi-update  2012-12-31 13:19:01.057446020 -0500
+++ rpi-update.new      2012-12-31 17:04:23.691203383 -0500
@@ -5,7 +5,7 @@

 REPO_URI="http://github.com/Hexxeh/rpi-firmware"

-UPDATE2=${UPDATE2:-1}
+UPDATE_SELF=${UPDATE_SELF:-1}
 UPDATE_URI="https://github.com/Hexxeh/rpi-update/raw/master/rpi-update"

 if [[ ${BOOT_PATH:-"unset"} == "unset" && ${ROOT_PATH:-"unset"} != "unset" ]] ||
@@ -14,6 +14,7 @@
        exit 1
 fi

+VERBOSE=${VERBOSE:=0}
 ROOT_PATH=${ROOT_PATH:-"/"}
 BOOT_PATH=${BOOT_PATH:-"/boot"}
 SKIP_KERNEL=${SKIP_KERNEL:-0}
@@ -27,10 +28,10 @@
 [ "${RPI_UPDATE_UNSUPPORTED}" -ne 0 ] && echo -e "You appear to be trying to update firmware on an incompatible distribution. To force update, run the following:\nsudo -E RPI_UPDATE_UNSUPPORTED=0 ./rpi-update" && exit 1

 function update_self() {
-       echo "Performing self-update"
+echo "Performing self-update"
        _tempFileName="$0.tmp"

-       if ! wget --quiet --output-document="${_tempFileName}" "${UPDATE_URI}"; then
+       if ! wget  `[ $VERBOSE -eq 1 ] && echo "--verbose" || echo "--quiet"` --output-document="${_tempFileName}" "${UPDATE_URI}"; then
                echo "Failed to download update for rpi-update!"
                echo "Make sure you have ca-certificates installed and that the time is set correctly"
                exit 1
@@ -46,7 +47,7 @@
        #!/bin/bash
        if mv "${_tempFileName}" "$0"; then
                rm -- "\$0"
-               exec env UPDATE2=0 /bin/bash "$0" "${FW_REV}"
+               exec env UPDATE_SELF=0 /bin/bash "$0" "${FW_REV}"
        else
                echo "Failed!"
        fi
@@ -57,7 +58,7 @@

 function update_modules {
        if [[ ${SKIP_KERNEL} -eq 0 ]]; then
-               cp -R "${FW_REPOLOCAL}/modules/"* "${FW_MODPATH}/"
+               cp `[ $VERBOSE -eq 1 ] && echo "--verbose" || echo ""` -R "${FW_REPOLOCAL}/modules/"* "${FW_MODPATH}/"
                find "${FW_REPOLOCAL}/modules" -mindepth 1 -maxdepth 1 -type d | while read DIR; do
                        depmod -b "${ROOT_PATH}" -a $(basename "${DIR}")
                done
@@ -72,12 +73,12 @@
        ELFOUTPUT=$(readelf -a "${ROOT_PATH}/bin/bash")
        if [ "${ELFOUTPUT}" != "${ELFOUTPUT/VFP_args/}" ]; then
                echo "Using HardFP libraries"
-               cp -R "${FW_REPOLOCAL}/vc/hardfp/"* "${ROOT_PATH}/"
+               cp `[ $VERBOSE -eq 1 ] && echo "--verbose" || echo ""` -R "${FW_REPOLOCAL}/vc/hardfp/"* "${ROOT_PATH}/"
        else
                echo "Using SoftFP libraries"
-               cp -R "${FW_REPOLOCAL}/vc/softfp/"* "${ROOT_PATH}/"
+               cp `[ $VERBOSE -eq 1 ] && echo "--verbose" || echo ""` -R "${FW_REPOLOCAL}/vc/softfp/"* "${ROOT_PATH}/"
        fi
-       cp -R "${FW_REPOLOCAL}/vc/sdk/"* "${ROOT_PATH}/"
+       cp `[ $VERBOSE -eq 1 ] && echo "--verbose" || echo ""` -R "${FW_REPOLOCAL}/vc/sdk/"* "${ROOT_PATH}/"

        if [[ -f /etc/init.d/vcfiled ]]; then
                /etc/init.d/vcfiled start
@@ -87,11 +88,11 @@
 function update_firmware {
        rm -rf ${FW_PATH}/*.elf
        rm -rf ${FW_PATH}/*.bin
-       cp ${FW_REPOLOCAL}/*.elf "${FW_PATH}/"
-       cp ${FW_REPOLOCAL}/*.bin "${FW_PATH}/"
-       cp ${FW_REPOLOCAL}/*.dat "${FW_PATH}/"
+       cp `[ $VERBOSE -eq 1 ] && echo "--verbose" || echo ""` ${FW_REPOLOCAL}/*.elf "${FW_PATH}/"
+       cp `[ $VERBOSE -eq 1 ] && echo "--verbose" || echo ""` ${FW_REPOLOCAL}/*.bin "${FW_PATH}/"
+       cp `[ $VERBOSE -eq 1 ] && echo "--verbose" || echo ""` ${FW_REPOLOCAL}/*.dat "${FW_PATH}/"
        if [[ ${SKIP_KERNEL} -eq 0 ]]; then
-               cp "${FW_REPOLOCAL}/"*.img "${FW_PATH}/"
+               cp `[ $VERBOSE -eq 1 ] && echo "--verbose" || echo ""` "${FW_REPOLOCAL}/"*.img "${FW_PATH}/"
        else
                echo "Skipping kernel/modules updated as requested"
        fi
@@ -99,7 +100,7 @@

 function finalise {
        if [[ -f "${FW_PATH}/arm192_start.elf" ]]; then
-               cp "${FW_PATH}/arm192_start.elf" "${FW_PATH}/start.elf"
+               cp `[ $VERBOSE -eq 1 ] && echo "--verbose" || echo ""` "${FW_PATH}/arm192_start.elf" "${FW_PATH}/start.elf"
        fi
        ldconfig -r "${ROOT_PATH}"
        if [[ ${FW_REV} == "" ]]; then
@@ -111,7 +112,7 @@
 function download_repo {
        echo "Setting up firmware (this will take a few minutes)"
        mkdir -p "${FW_REPOLOCAL}"
-       git clone "${FW_REPO}" "${FW_REPOLOCAL}" --depth=1 --quiet
+       git clone "${FW_REPO}" "${FW_REPOLOCAL}" --depth=1 `[ $VERBOSE -eq 1 ] && echo "--verbose" || echo "--quiet"`
        RETVAL=$?
        if [[ ${RETVAL} -ne 0 ]]; then
                echo "Failed to download new firmware files"
@@ -121,15 +122,16 @@

 function update_repo {
        echo "Updating firmware (this will take a few minutes)"
-       eval ${GITCMD} fetch --quiet
+       eval ${GITCMD} fetch `[ $VERBOSE -eq 1 ] && echo "--verbose" || echo "--quiet"`
        RETVAL=$?
        if [[ ${RETVAL} -ne 0 ]]; then
                echo "Failed to download updated firmware files"
                exit 1
        fi
-       eval ${GITCMD} reset --hard --quiet
-       eval ${GITCMD} clean -f -d --quiet
-       eval ${GITCMD} merge origin/master -m "automerge" --quiet
+       eval ${GITCMD} reset --hard `[ $VERBOSE -eq 1 ] && echo "" || echo "--quiet"`
+       eval ${GITCMD} clean -f -d  `[ $VERBOSE -eq 1 ] && echo "" || echo "--quiet"`
+       eval ${GITCMD} merge origin/master -m "automerge" `[ $VERBOSE -eq 1 ] && echo "--verbose" || echo "--quiet"`
+
        RETVAL=$?
        if [[ ${RETVAL} -ne 0 ]]; then
                echo "Failed to download updated firmware files"
@@ -138,8 +140,8 @@
 }

 function do_backup {
-       cp -a "${FW_PATH}" "${FW_PATH}.bak"
-       cp -a "${FW_MODPATH}" "${FW_MODPATH}.bak"
+       cp `[ $VERBOSE -eq 1 ] && echo "--verbose" || echo ""` -a "${FW_PATH}" "${FW_PATH}.bak"
+       cp `[ $VERBOSE -eq 1 ] && echo "--verbose" || echo ""` -a "${FW_MODPATH}" "${FW_MODPATH}.bak"
 }

 function do_update {
@@ -156,8 +158,8 @@
 function download_rev {
        echo "Downloading specific firmware revision (this will take a few minutes)"
        mkdir -p "${FW_REPOLOCAL}"
-       wget -q "${REPO_URI}/tarball/${FW_REV}" -O "${FW_REPOLOCAL}/${FW_REV}.tar.gz"
-       tar xzf "${FW_REPOLOCAL}/${FW_REV}.tar.gz" -C "${FW_REPOLOCAL}" --strip-components=1
+       wget  `[ $VERBOSE -eq 1 ] && echo "--verbose" || echo "--quiet"` "${REPO_URI}/tarball/${FW_REV}" -O "${FW_REPOLOCAL}/${FW_REV}.tar.gz"
+       tar xzf "${FW_REPOLOCAL}/${FW_REV}.tar.gz" -C "${FW_REPOLOCAL}" --strip-components=1 `[ $VERBOSE -eq 1 ] && echo "--verbose" || echo ""`
        rm "${FW_REPOLOCAL}/${FW_REV}.tar.gz"
 }

@@ -166,7 +168,7 @@
        exit 1
 fi

-if [[ ${UPDATE2} -ne 0 ]]; then
+if [[ ${UPDATE_SELF} -ne 0 ]]; then
        echo "Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS"
        update_self
 fi
User avatar
Forum Moderator
Forum Moderator
Posts: 2764
Joined: Fri Jul 29, 2011 2:51 pm
by rspitz » Tue Jan 01, 2013 2:20 pm
Hi ukscone,

would you please share with us what errors or glitches in the rpi-update process your "verbose" setting has revealed?

I'm experiencing frequent hangs of the "rpi-update" script, about every other run will never terminate and lock up the system eventually, requiring a hard reset by pulling the power.

Regards, Richard
Posts: 49
Joined: Tue Jul 31, 2012 7:25 pm
by ukscone » Tue Jan 01, 2013 5:14 pm
i've not had the errors for the last 24hours but the ones that caused me to patch rpi-update & i can remember were something to do remote object unpacking
User avatar
Forum Moderator
Forum Moderator
Posts: 2764
Joined: Fri Jul 29, 2011 2:51 pm
by ukscone » Wed Jan 02, 2013 6:03 pm
i've tidied up the patch a bit more, fixed what I consider to be a bug (you might not), changed the UPDATE_SELF default to not update the script & made VERBOSE= a bit more granular.

http://russelldavis.org/2013/01/02/patc ... pi-update/
User avatar
Forum Moderator
Forum Moderator
Posts: 2764
Joined: Fri Jul 29, 2011 2:51 pm
by dom » Wed Jan 02, 2013 6:17 pm
Might be worth submitting a pull request to Hexxeh's repo.

Also worth checking how it overlaps this (not yet accepted) pull request:
https://github.com/Hexxeh/rpi-update/pull/51
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3993
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge
by ukscone » Wed Jan 02, 2013 6:21 pm
dom wrote:Might be worth submitting a pull request to Hexxeh's repo.

Also worth checking how it overlaps this (not yet accepted) pull request:
https://github.com/Hexxeh/rpi-update/pull/51


the problem is that i know nowt about github or git for that matter other than how to cut & paste a string & prefix git clone to the pasted string. I use fossil if i am actually going to do thing properly otherwise it's just patch files or new directories.
User avatar
Forum Moderator
Forum Moderator
Posts: 2764
Joined: Fri Jul 29, 2011 2:51 pm
by dom » Wed Jan 02, 2013 7:21 pm
ukscone wrote:the problem is that i know nowt about github or git for that matter other than how to cut & paste a string & prefix git clone to the pasted string. I use fossil if i am actually going to do thing properly otherwise it's just patch files or new directories.


We like to encourage people to learn new things here...
https://help.github.com/articles/using-pull-requests
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3993
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge
by ukscone » Wed Jan 02, 2013 7:33 pm
dom wrote:.
We like to encourage people to learn new things here...
https://help.github.com/articles/using-pull-requests


reading up on it and annoying a friend who uses github with stupid questions. i might be able to work it out eventually.
User avatar
Forum Moderator
Forum Moderator
Posts: 2764
Joined: Fri Jul 29, 2011 2:51 pm
by ukscone » Wed Jan 02, 2013 7:59 pm
i think i've requested a pull request correctly but who knows :) my forked version of rpi-update is on github now (i think :) ) https://github.com/ukscone/rpi-update
User avatar
Forum Moderator
Forum Moderator
Posts: 2764
Joined: Fri Jul 29, 2011 2:51 pm