Toon firmware - update script

Forum about the Toon firmware, and its extensions

Moderators: marcelr, TheHogNL, Toonz

TheHogNL
Forum Moderator
Forum Moderator
Posts: 2125
Joined: Sun Aug 20, 2017 8:53 pm

Re: Toon firmware - update script

Post by TheHogNL »

Version 2.9 of the script is released which supports the fix for the resources file in version 4.16.8
See also the topic about version 4.16.8
Member of the Toon Software Collective
newwolf
Starting Member
Starting Member
Posts: 41
Joined: Thu Aug 23, 2012 9:30 pm

Re: Toon firmware - update script

Post by newwolf »

TheHogNL wrote:Version 2.9 of the script is released which supports the fix for the resources file in version 4.16.8
See also the topic about version 4.16.8
I used the script to upgrade from the previous version but it was stuck at 25% in the booting sequence.

Then I was looking for the resources-static-base.rcc file and only the backup was there.
So I think you have to check before renaming it if the zip file with fix is there.
If it's not not there Toon will not boot.
TheHogNL
Forum Moderator
Forum Moderator
Posts: 2125
Joined: Sun Aug 20, 2017 8:53 pm

Re: Toon firmware - update script

Post by TheHogNL »

Ok thanks. I will improve that. However it already checks if the download is succesful so I'm a bit confused what happened in your case.
Did you manage to fix your issue?
Member of the Toon Software Collective
TheHogNL
Forum Moderator
Forum Moderator
Posts: 2125
Joined: Sun Aug 20, 2017 8:53 pm

Re: Toon firmware - update script

Post by TheHogNL »

Owh I already see what probably has gone wrong.
The file in the zip is already the correct name "resources-static-base.rcc". I a test setup when I was developing the fix with Toonz we had that file in the zip to contain the version number.

So, the script unpacked the zip file already over the original file and then change that name to backup. So, your backup is the modified resource file. And you are missing the original file now (which you don't need anyway).

I fixed that now.
Member of the Toon Software Collective
Smiggel
Member
Member
Posts: 57
Joined: Wed Apr 11, 2018 2:20 pm

Re: Toon firmware - update script

Post by Smiggel »

Did anyone upgrade to version 4.16.8 with the latest version of the script and is it safe to do it?
TerrorSource
Administrator
Administrator
Posts: 494
Joined: Thu May 04, 2017 9:28 pm

Re: Toon firmware - update script

Post by TerrorSource »

Smiggel wrote:Did anyone upgrade to version 4.16.8 with the latest version of the script and is it safe to do it?
Should be no issue but there's still a very small risk with upgrading.
Also it's recommended to go to 4.10.6 if your current firmware is below 4.10.6 (and higher then 2.9.26)
Smiggel
Member
Member
Posts: 57
Joined: Wed Apr 11, 2018 2:20 pm

Re: Toon firmware - update script

Post by Smiggel »

TerrorSource wrote:
Smiggel wrote:Did anyone upgrade to version 4.16.8 with the latest version of the script and is it safe to do it?
Should be no issue but there's still a very small risk with upgrading.
Also it's recommended to go to 4.10.6 if your current firmware is below 4.10.6 (and higher then 2.9.26)
Already on version 4.15.6 so I guess the version will not be a problem. Will give it a try tomorrow. Thanks.
Toonz
Forum Moderator
Forum Moderator
Posts: 1873
Joined: Mon Dec 19, 2016 1:58 pm

Re: Toon firmware - update script

Post by Toonz »

I don't know one single reason to update from 4.15.6 to 4.16.8 to be honest on a rooted Toon. Don't fix what ain't broken. The script will work. Don't forget to download the new resource file as well for 4.16.8 in case you can't resist the temptation :)
member of the Toon Software Collective
TheHogNL
Forum Moderator
Forum Moderator
Posts: 2125
Joined: Sun Aug 20, 2017 8:53 pm

Re: Toon firmware - update script

Post by TheHogNL »

Toonz wrote:I don't know one single reason to update from 4.15.6 to 4.16.8 to be honest on a rooted Toon. Don't fix what ain't broken. The script will work. Don't forget to download the new resource file as well for 4.16.8 in case you can't resist the temptation :)
The script does that for you. However I do agree with that the fact 4.16.8 doesn't bring anything new. Keep it at 4.15.6 and wait until a firmware is released with features you really want/need/like.
Member of the Toon Software Collective
Smiggel
Member
Member
Posts: 57
Joined: Wed Apr 11, 2018 2:20 pm

Re: Toon firmware - update script

Post by Smiggel »

Toonz wrote:I don't know one single reason to update from 4.15.6 to 4.16.8 to be honest on a rooted Toon. Don't fix what ain't broken. The script will work. Don't forget to download the new resource file as well for 4.16.8 in case you can't resist the temptation :)

Hmmm, guess you have a point there. Maybe it’s better to wait. :-) Thanks
themman78
Starting Member
Starting Member
Posts: 8
Joined: Mon Jul 09, 2018 3:57 pm

Re: Toon firmware - update script

Post by themman78 »

hi guys, i bumping into a little problem.
I'm trying to run the auto update script from version 4.9.23 to version 4.10.6 (as instructed in the manual), but getting te message that the script updatescript is changed. md5 is different.

Code: Select all

Warning: upgrade script from source server is changed. Do you want to continue downloading the files (if not sure, type no and report in the forums)?
i included the upgrade-qb2.sh file. Can I, and should I, upgrade safely the this version and later to the latest version 4.16.8?
TheHogNL
Forum Moderator
Forum Moderator
Posts: 2125
Joined: Sun Aug 20, 2017 8:53 pm

Re: Toon firmware - update script

Post by TheHogNL »

themman78 wrote:hi guys, i bumping into a little problem.
I'm trying to run the auto update script from version 4.9.23 to version 4.10.6 (as instructed in the manual), but getting te message that the script updatescript is changed. md5 is different.

Code: Select all

Warning: upgrade script from source server is changed. Do you want to continue downloading the files (if not sure, type no and report in the forums)?
i included the upgrade-qb2.sh file. Can I, and should I, upgrade safely the this version and later to the latest version 4.16.8?
Ok that means that Eneco changed their script again. I will look at it someday soon and update the script. Better safe then sorry and wait for me to check it.
Member of the Toon Software Collective
themman78
Starting Member
Starting Member
Posts: 8
Joined: Mon Jul 09, 2018 3:57 pm

Re: Toon firmware - update script

Post by themman78 »

TheHogNL wrote:
themman78 wrote:hi guys, i bumping into a little problem.
I'm trying to run the auto update script from version 4.9.23 to version 4.10.6 (as instructed in the manual), but getting te message that the script updatescript is changed. md5 is different.

Code: Select all

Warning: upgrade script from source server is changed. Do you want to continue downloading the files (if not sure, type no and report in the forums)?
i included the upgrade-qb2.sh file. Can I, and should I, upgrade safely the this version and later to the latest version 4.16.8?
Ok that means that Eneco changed their script again. I will look at it someday soon and update the script. Better safe then sorry and wait for me to check it.
It seems that the file I attached was not included in the post. Here's the code of /mnt/data/update/upgrade-qb2.sh:

Code: Select all

export PATH="/sbin:/bin:/usr/sbin:/usr/bin:$PATH"

# NOTE: do not prepend !/bin/sh this script is executed directly via execve()

FEATURES="RTC_WRITE INITTAB_PREPARE EXEC_RESUME SUPPORT_REFLAVOR"
NOREBOOT_FROM=""
# check if these packages are still depended upon and if not remove them if they are installed (should be done automatically)
CHECK_QMF_PACKAGES_REMOVED="hcb-upnp hcb-core hcb-web flash-gui flash-qwidget-diy flash-lite-adobe boot-logos hcb-web happ-telmi"


SCRIPTPATH=`realpath $0`
SCRIPTDIR=`dirname $SCRIPTPATH`
SCRIPTNAME=`basename $SCRIPTPATH`
SCRIPTSTATUS=$0.res

export HCB_ARCH="$1"
export HCB_FLAV="$2"
export HCB_VERS="$3"
export ACTION="$4"

HCB_VERS_MAJOR="`echo $HCB_VERS | sed -n -r -e 's,([0-9]+).([0-9]+).([0-9]+),\1,p'`"
HCB_VERS_MINOR="`echo $HCB_VERS | sed -n -r -e 's,([0-9]+).([0-9]+).([0-9]+),\2,p'`"

featureEnabled()
{
	# test if this feature is enabled
	echo "$FEATURES" | grep -q "$1"
}

dropboxMessage()
{
	SUBJECT="$1"
	SUBTITLE="$2"
	MESSAGE="$3"
	ACTIONS="$4"
	TRANSLATION="$5"

	echo ">> dropboxMessage $MESSAGE"

	time=`date +%s`
	Message="
	<Config>
	<message>
	 <content>$MESSAGE</content>
	  <subject>$SUBJECT</subject>
	  <subtitle>$SUBTITLE</subtitle>
	  <messageType>critical</messageType>
	  <received_t>$time</received_t>
	  <internalAddress>dropboxed_$time</internalAddress>
	  <read_t></read_t>
	  <readMsgSend>1</readMsgSend>
	  <hideOnRemove>0</hideOnRemove>
	  <package>happ_usermsg</package>
	  <type>message</type>
	  <name>upgrade_msg</name>
	  <visibility>1</visibility>$ACTIONS$TRANSLATION
	 </message>
	</Config>"

	echo "$Message" > /tmp/dropbox_msg.xml
	mv /tmp/dropbox_msg.xml /HCBv2/config/dropbox/
}

statusSet()
{
	STATUS="$1"
	echo "$STATUS" > $SCRIPTSTATUS
	echo ">> `date +'%Y-%m-%d %H:%M:%S %z'` (pid $$) $STATUS"
}

errorExit()
{
	STATUS="$ACTION-error-$1"
	STRING="$2"
	echo "$STATUS" > $SCRIPTSTATUS
	echo ">> `date +'%Y-%m-%d %H:%M:%S %z'` (pid $$) $STATUS '$STRING'"
	exit 1
}

okExit()
{
	STATUS="$ACTION-ok-$1"
	STRING="$2"
	echo ">> `date +'%Y-%m-%d %H:%M:%S %z'` (pid $$) exit-0 $STATUS '$STRING'"
	exit 0
}

fbInitTextMode()
{
	# dim down fast
	echo '0:2' > /sys/class/backlight/ed2.0-bl.0/ramp_brightness_sync
	# setting mode reinits the console (and with it wipes the background)
	cat /sys/class/graphics/fb0/modes > /sys/class/graphics/fb0/mode
	# unblank
	echo 0 > /sys/class/graphics/fb0/blank
	# turn off blanking timeouts for terminal
	echo -n -e '\33[9;0]\33[14;0]'> /dev/tty0
	# clear screen (also done since boot-logos@46)
	echo -n -e '\33[2J'> /dev/tty0
	# reshow boot image
	/etc/init.d/show-fb-image start start
	# start output at line 23
	echo -n -e '\33[23;0f'> /dev/tty0
}

fbLinePrint()
{
	echo ">>> fbLinePrint: $1"
	echo "   $1" > /dev/tty0
}

fbLineUpdateStatus()
{
	DOTS="   ..."
	while sleep 1
	do
		PERC="`sed /tmp/update.status.vars -n -r -e 's,^.+item=(.+?)&items=(.+?)&.+$,\1,p' 2>/dev/null`"
		PERC="${PERC:-0}%"

		# do not append newline, \r to beginning of line after print, append space to overwrite prev-longer-sentences
		echo -n -e "   Voortgang: $PERC ${DOTS:0:3}    \r" > /dev/tty0

		# shift right
		DOTS="${DOTS:5:1}${DOTS:0:5}"
	done
}

# run after S39hostname.sh, before S41networking
EXEC_RESUME_SCRIPT=/etc/rcS.d/S40upgrade-execute-resume.sh

execResumeInProgress()
{
	if featureEnabled EXEC_RESUME
	then
		if [ "$ACTION" = "execute-resume" ] #[ -f $EXEC_RESUME_SCRIPT ]
		then
			return 0 # true
		fi
	fi
	return 1 # false
}

execSanityChecks()
{
	#* opkg_conf_load: Creating temp dir /tmp/opkg-0uAYDE failed: No such file or directory.
	if [ ! -w /tmp/ ]
	then
		fbLinePrint "> Repareren /tmp/"
		mount /proc 2>/dev/null
		grep -q /var/volatile /proc/mounts || mount /var/volatile
		mkdir -p /var/volatile/tmp
		[ ! -w /tmp/ ] && fbLinePrint "> Repareren /tmp/ [mislukt]"
	fi
}

# create a file that will resume the upgrade-execute at next boot
execResumeScheduleCheckForNextBoot()
{
	if featureEnabled EXEC_RESUME
	then
		if execResumeInProgress
		then
			# show progress on console
		  tail -f $SCRIPTPATH.log </dev/null >/dev/console 2>&1 &

			echo ">> Detected execute-resume, notifying the user via framebuffer."

			fbInitTextMode
			fbLinePrint "Aborted software update to version ${HCB_VERS} detected."
			fbLinePrint "Resuming update, please wait... do NOT turn off your display during the update."

			execSanityChecks

			# this means that the file is still here since the last (aborted) upgrade,
			# so we actually remove it to prevent an endless upgrade-loop!
			#echo ">> Detected execute-resume script from previous run, removing it."
			rm -f $EXEC_RESUME_SCRIPT

			# start a process that watches /tmp/update.status.vars
			fbLineUpdateStatus &
			STATUS_UPDATE_PID=$!
			echo ">> Spawned /tmp/update.status.vars watcher with PID $STATUS_UPDATE_PID"

			# we are running during early boot, HCBv2 apps are not running yet
			STOPSTARTAPPS=0
		else
			echo ">> Creating $EXEC_RESUME_SCRIPT with args '${HCB_ARCH} ${HCB_FLAV} ${HCB_VERS} execute-resume'"

			echo "#!/bin/sh" > $EXEC_RESUME_SCRIPT
			echo "echo '$0: Aborted upgrade-execute for ${HCB_ARCH}/${HCB_FLAV}/${HCB_VERS} detected,'" >> $EXEC_RESUME_SCRIPT
			echo "echo '$0: executing $SCRIPTPATH execute-resume'" >> $EXEC_RESUME_SCRIPT
			echo "$SCRIPTPATH ${HCB_ARCH} ${HCB_FLAV} ${HCB_VERS} execute-resume" >> $EXEC_RESUME_SCRIPT
			echo "echo '$0: done.'" >> $EXEC_RESUME_SCRIPT
			chmod a+x $EXEC_RESUME_SCRIPT
		fi

		sync
	fi
}

execResumeRemoveCheckForNextBoot()
{
	if featureEnabled EXEC_RESUME
	then
		if execResumeInProgress
		then
			# stop the process that watches /tmp/update.status.vars
			echo ">> Killing /tmp/update.status.vars watcher with PID $STATUS_UPDATE_PID"
			kill -9 $STATUS_UPDATE_PID

			if [ "$REBOOT" = "1" ]
			then
				fbLinePrint "Software update completed, the display is rebooting..."
			else
				fbLinePrint "Software update completed, the display is starting..."
			fi

			# give people time to read the message
			sleep 3
		fi

		echo ">> Removing $EXEC_RESUME_SCRIPT"
		rm -f $EXEC_RESUME_SCRIPT
	fi
}

# migrate the files in /HCBv2/tmp/opkg-cache to /mnt/data/update if this update is running from the new location
migratePkgCacheDirectory()
{
	OLD_PKGCACHE='/HCBv2/tmp/opkg-cache'
	NEW_PKGCACHE='/mnt/data/update'
	# only migrate if this script is running from the new location
	# otherwise, this could be a execute-resume run (new hcb_config, old script location)
	if [ -d "$OLD_PKGCACHE" -a $SCRIPTDIR = $NEW_PKGCACHE ]
	then
		echo ">> migrating files to '${NEW_PKGCACHE}' ..."
		if [ ! -d "$NEW_PKGCACHE" ]
		then
			# Normally that should not happen since the directory should be created by /etc/init.d/populate-volatile.sh
			echo "the directory '$NEW_PKGCACHE' is missing."
			mkdir -p "$NEW_PKGCACHE" || errorExit "opkg-migrate" "Failed to create the directory '$NEW_PKGCACHE'"
			echo "the directory '$NEW_PKGCACHE' was created."
		fi

		# If the dir is empty, don't do anything otherwise 'mv' will fail
		if [ "$(ls -A "$OLD_PKGCACHE")" ]
		then
			mv "$OLD_PKGCACHE"/* "$NEW_PKGCACHE"/ || echo "failed to move files to '$NEW_PKGCACHE'"
		else
			echo 'nothing to migrate'
		fi
		rmdir "$OLD_PKGCACHE" || echo "failed to remove the old directory '$OLD_PKGCACHE'."
		sync
		echo ">> migrating files to '${NEW_PKGCACHE}': finished"
	fi
}

checkForUniFlavorVersion()
{
	if featureEnabled SUPPORT_REFLAVOR
	then
		if ([ "$HCB_FLAV" = "qby" -o "$HCB_FLAV" = "ene" -o "$HCB_FLAV" = "ves" -o "$HCB_FLAV" = "euk" ] && \
			([ $HCB_VERS_MAJOR -gt 4 ] || [ $HCB_VERS_MAJOR -eq 4 -a $HCB_VERS_MINOR -ge 11 ])) || \
			([ "$HCB_FLAV" = "ebl" ] && ([ $HCB_VERS_MAJOR -gt 4 ] || [ $HCB_VERS_MAJOR -eq 4 -a $HCB_VERS_MINOR -ge 16 ]))
		then
			echo ">> Overriding HCB_FLAV to uni!"
			HCB_FLAV="uni"
		fi
	fi
}

getInstalledFlavor()
{
	OLDFLAV=`opkg list-installed base-$HCB_ARCH-\* | sed -r -e "s/base-$HCB_ARCH-([a-z]{3})\s.*/\1/"`
}

reflavorRequired()
{
	[ "$OLDFLAV" != "$HCB_FLAV" ]
}

getTenantPackage()
{
	case $OLDFLAV in
		qby)
			TENANT_PKG=tenant-qutility
		;;
		ene)
			TENANT_PKG=tenant-eneco-nl
		;;
		ves)
			TENANT_PKG=tenant-viesgo-es
		;;
		euk)
			TENANT_PKG=tenant-engie-uk
		;;
		ebl)
			TENANT_PKG=tenant-engie-be
		;;
		*)
			echo ">> Unknown old flavor! Aborting."
			errorExit "unknown-old-flavor" "Unknown old flavor $OLDFLAV! Aborting."
		;;
	esac
}

(
	echo ""
	echo ">> `date +'%Y-%m-%d %H:%M:%S %z'` (pid $$) $SCRIPTNAME $@"
	echo ""
	#echo "$$" > $SCRIPTPATH.pid
	statusSet "$ACTION"
	cd $SCRIPTDIR

	PKGCACHE=$SCRIPTDIR
	BASE_FEED_URL="http://feed.hae.orig/feeds"
	CN="`hostname`"
	REBOOT=1
	STOPSTARTAPPS=1
	CLEANUP="`grep -q '^root:DISABLED' /etc/passwd 2>/dev/null && echo 1`"
	# allow for :1337 on localhost and on any (see hcb_comm.CommIfaces=any)
	HCBV2_UP="`netstat -ltn 2>&1 | grep -q ':1337 ' && echo 1`"
	# expose our life story so support can access it - Part I
	if [ -w /qmf/log/ ]
	then
		ln -f -s $SCRIPTPATH.log /qmf/log/last-update.log
	elif [ -w /HCBv2/log/ ]
	then
		ln -f -s $SCRIPTPATH.log /HCBv2/log/last-update.log
	fi

	# Migration of files from the old to new location is performed the very first time
	# after the hcb_config supports the new location.
	migratePkgCacheDirectory

	# See if this version is replaced by the uni version
	checkForUniFlavorVersion
	HCB_AFV="${HCB_ARCH}/${HCB_FLAV}/${HCB_VERS}"

	case $ACTION in

		#####################################################################################################
		prepare)

			statusSet "preparing"

			# clean up some space for downloading new packages
			rm -f $PKGCACHE/*.ipk

			# Hotfix for writing System Time to RTC (ET-794)
			if featureEnabled RTC_WRITE
			then
				echo ">> Hotfix for writing System Time to RTC"
				echo "Hardware Clock before: `hwclock --show`"
				# here we know the system time is ok: script downloaded -> internet -> hae-timesync
				hwclock --systohc --utc
				echo "Hardware Clock after : `hwclock --show`"
			fi

			# set extra pkg system feeds
			EXTRA_FEEDS="`wget -q "${BASE_FEED_URL}/${HCB_ARCH}/${HCB_FLAV}/${HCB_VERS}/SystemFeed" -O -`"
			if [ "$EXTRA_FEEDS" = "" ]
			then
				echo "Failed retrieving '${BASE_FEED_URL}/${HCB_ARCH}/${HCB_FLAV}/${HCB_VERS}/SystemFeed', trying again verbosely:"
				wget "${BASE_FEED_URL}/${HCB_ARCH}/${HCB_FLAV}/${HCB_VERS}/SystemFeed" -O - 2>&1
				errorExit "dl-afv" "AFV download failed Maybe sync or non-existing?"
			fi

			# set correct feed location for initial install
			rm -f /etc/opkg/*-feed.conf /usr/lib/opkg/lists/*
			echo "src/gz base ${BASE_FEED_URL}/${HCB_ARCH}/${HCB_FLAV}/${HCB_VERS}" > /etc/opkg/base-feed.conf
			echo "$EXTRA_FEEDS" | {
				while read EF
				do
					EF_NAME="`echo "$EF" | cut -d ' ' -f1`"
					EF_PATH="`echo "$EF" | cut -d ' ' -f2`"
					echo "src/gz ${EF_NAME} ${BASE_FEED_URL}/${HCB_ARCH}/${EF_PATH}" > /etc/opkg/${EF_NAME}-feed.conf
				done;
			}

			echo ">> configured opkg feeds:"
			cat /etc/opkg/*-feed.conf

			# convenience helper to download packages to cache while capturing output into $OPKG_OUTPUT
			_opkg_download()
			{
				local step="$1"
				shift
				local cmd="opkg --cache $PKGCACHE --download-only $@"
				echo ">> ${cmd}"
				# prefix output with command, note that trailing newline(s) are eaten by $( )
				OPKG_OUTPUT="$(echo -e "\n> ${cmd}\n\n ")"
				# open extra fd pointing to stdout
				exec 9>&1
				#ls -la /proc/self/fd/
				# exec cmd and capture stdout+stderr output, duplicate output to stdout-at-fd9, append output to OPKG_OUTPUT
				{ OPKG_OUTPUT="${OPKG_OUTPUT}`{ ${cmd} 2>&1; echo "> Exit code: \$?"; } | tee -a /proc/self/fd/9`"; } 2>&1
				# close it again
				exec 9>&-
				# parse + store exit code of $cmd
				OPKG_EXITCODE="$(echo "${OPKG_OUTPUT}" | tail -n1 | sed -r -e 's,> Exit code: (.+),\1,')"

				# * opkg_install_pkg: Package xxx md5sum mismatch. Either the opkg or the package index are corrupt.
				if echo "$OPKG_OUTPUT" | grep -q 'md5sum mismatch'
				then
					rm -f $PKGCACHE/*.ipk
					errorExit "opkg-${step}-md5sum" "opkg found an md5sum mismatch: removed *.ipk!"
				fi

				# Test HTTP errors before signature errors
				# * opkg_download: Failed to download http://...ipk: Timeout was reached.
				# * opkg_download: Failed to download http://...ipk: Couldn't connect to server.
				# * opkg_download: Failed to download http://.../Packages.sig: HTTP response code said error.
				if echo "$OPKG_OUTPUT" | grep -q 'Failed to download'
				then
					errorExit "opkg-${step}-download" "opkg failed to download"
				fi
			}

			_opkg_download "update" update

			# Signature check failed.
			# Remove wrong Signature file.
			if echo "$OPKG_OUTPUT" | grep -q 'Signature check failed.'
			then
				errorExit "opkg-update-sig-failed" "opkg update Signature check failed"
			fi

			# Collected errors:
			if [ "$OPKG_EXITCODE" != "0" ]
			then
				# generic error
				errorExit "opkg-update" "Exit code $OPKG_EXITCODE for: opkg update"
			fi

			getInstalledFlavor
			if featureEnabled SUPPORT_REFLAVOR && reflavorRequired
			then
				getTenantPackage
				_opkg_download "download-flav" install base-$HCB_ARCH-$HCB_FLAV $TENANT_PKG

				if [ "$OPKG_EXITCODE" != "0" ]
				then
					errorExit "opkg-upgrade-flav-download" "Exit code $OPKG_EXITCODE for opkg flav download"
				fi
			fi

			# time to do the big one :)
			_opkg_download "download" upgrade

			# intermediate cleanup
			rm -rf /tmp/opkg-*
			# ensure the log greps below always work
			sync

			# generic error, most of which we do not want to break the upgrade
			# * resolve_conffiles: Existing conffile /etc/ca-certificates.conf is different from the conffile in the new package. The new conffile will be placed at /etc/ca-certificates.conf-opkg.
			if [ "$OPKG_EXITCODE" != "0" ]
			then
				echo errorExit "opkg-upgrade" "Exit code $OPKG_EXITCODE for: opkg upgrade" "IGNORED: continuing..."
			fi

			echo ">> downloaded:"
			du -ch $PKGCACHE/*.ipk | grep total

			statusSet "prepared"

			if featureEnabled FORCE_EXECUTE
			then
				echo "FORCE_EXECUTE enabled, sending DoFirmwareUpdate"
				/HCBv2/bin/bxt -u `hostname`:swf-gui -d :hcb_config -s specific1 -n DoFirmwareUpdate -a version -v $HCB_VERS -w 0
			fi

			;;

		#####################################################################################################
		execute|execute-resume)

			statusSet "executing"

			#OLD_VERSION="`cat /etc/opkg/base-feed.conf | cut -d'/' -f 8 | cut -d'.' -f1-2`"
			# note base-feed.conf is already overwritten here!
			OLD_MAJOR_MINOR="`opkg list_installed 'base-*-*' | sed -r -e 's,^.+ - ([0-9]+\.[0-9]+)\.[0-9]+-.+$,\\1,'`"
			OLD_MAJOR_MINOR_MICRO="`opkg list_installed 'base-*-*' | sed -r -e 's,^.+ - ([0-9]+\.[0-9]+\.[0-9]+)-.+$,\\1,'`"

			# check if we can suffice with a "soft reboot"
			if featureEnabled NOREBOOT_FROM
			then
				# (grep --word-regexp: Select only those lines containing matches that form whole words.)
				# check for word-match in list of versions
				if echo "$NOREBOOT_FROM" | grep -q -w "$OLD_MAJOR_MINOR_MICRO"
				then
					echo ">> Current version $OLD_MAJOR_MINOR_MICRO in ($NOREBOOT_FROM), doing soft reboot."
					REBOOT=0
				else
					echo ">> Current version $OLD_MAJOR_MINOR_MICRO not in ($NOREBOOT_FROM), doing regular reboot."
				fi
			fi

			if [ "$HCBV2_UP" ]
			then
				MSG="Upgrading application software from version '$OLD_MAJOR_MINOR_MICRO' to '$HCB_AFV'."
				echo ">> Logging \"$MSG\" to 99_DEBUG.log.json"
				/HCBv2/bin/bxt \
					-d $CN:hcb_log \
					-s Logger \
					-n LogMessage \
					-a facility -v 1 \
					-a categoryId -v 99 \
					-a timestampGenerated -v "`date +'%Y-%m-%d %H:%M:%S %z'`" \
					-a logText -v "$MSG" \
					-w 0 >/dev/null 2>/dev/null &

				sleep 1

				echo ">> Sending InitiatePreExit to hcb_config."
				/HCBv2/bin/bxt \
					-d $CN:hcb_config \
					-n InitiatePreExit \
					-w 0 >/dev/null 2>/dev/null &
			fi

			execResumeScheduleCheckForNextBoot

			if [ "$STOPSTARTAPPS" = "1" ]
			then
				echo ">> Sleep 2, give time to return 'upgrade started' messages to UI"
				sleep 2

				echo ">> Stopping HCBv2 apps + prevent restart..."
				/etc/init.d/HCBv2 stop
			fi

			# prevent restarting during upgrade
			echo 'exit' > /tmp/etc-default-HCBv2
			chmod a+x /tmp/etc-default-HCBv2

			if [ "$STOPSTARTAPPS" = "1" ]
			then
				# kill this one especially, left running in inittab by design.
				killall -9 hcb_netcon
				# NOTE: flash keeps running during upgrade, restart by inittab would fail because of /tmp/etc-default-HCBv2

				echo ">> Disabling watchdog /dev/watchdog"
				rm -f /dev/watchdog
				mknod /dev/watchdog c 10 130
				# make sure we don't reboot:
				echo V > /dev/watchdog
				rm -f /dev/watchdog
			fi

			# These packages will be installed before the kernel updates
			if [ "`opkg list kernel-image-\* | grep -c -e '^kernel-image-'`" != "1" ]
			then
				# Install firmware-zwave-ctrlr with --nodeps
				# Otherwise kernel upgrades are already installed at this point, because of dependencies
				# We assume the kernel-module-zwave300 to already have been installed at this point
				echo ">> opkg --cache $PKGCACHE install firmware-zwave-ctrlr --nodeps"
				opkg --cache $PKGCACHE install firmware-zwave-ctrlr --nodeps 2>&1;
			fi

			getInstalledFlavor
			if featureEnabled SUPPORT_REFLAVOR && reflavorRequired
			then
				getTenantPackage
				echo ">> opkg remove base-$HCB_ARCH-$OLDFLAV"
				opkg remove base-$HCB_ARCH-$OLDFLAV 2>&1

				for RETRY_ON_EXITCODE in 1 2 3
				do
					echo ">> opkg --cache $PKGCACHE install base-$HCB_ARCH-$HCB_FLAV $TENANT_PKG # attempt $RETRY_ON_EXITCODE"
					opkg --cache $PKGCACHE install base-$HCB_ARCH-$HCB_FLAV $TENANT_PKG 2>&1; EXITCODE=$?

					if [ "$EXITCODE" = "0" ]
					then
						break
					fi
				done

				[ "$EXITCODE" != "0" ] && errorExit "opkg-upgrade-flav-install" "Exit code $EXITCODE for opkg flav install"
			fi

			# opkg sometimes (incorrectly?) returns 255, therefore do 3 retries
			for RETRY_ON_EXITCODE in 1 2 3
			do
				echo ">> opkg --cache $PKGCACHE upgrade - attempt $RETRY_ON_EXITCODE"
				opkg --cache $PKGCACHE upgrade 2>&1; EXITCODE=$?

				echo ">> exitcode for opkg --cache $PKGCACHE upgrade was $EXITCODE"

				if [ "$EXITCODE" = "0" ]
				then
					break
				fi
			done

			# did any of the packages just installed request a reboot?
			if [ -f /tmp/opkg_reboot ]
			then
				echo ">> Detected /tmp/opkg_reboot, will reboot when done."
				REBOOT=1
			fi

			execResumeRemoveCheckForNextBoot

			# intermediate cleanup
			rm -rf /tmp/opkg-*
			[ "$CLEANUP" = "1" ] && rm -rf /var/lib/opkg/*
			sync

			if [ "$EXITCODE" != "0" ]
			then
				#
				# TODO: check if we can use /tmp/update.status.vars to communicate error
				#       to user in a more verbose manner instead of fb img "upfail"?
				#

				# stop flash/qt anim
				killall -9 flash qt-gui
				# show upgrade error msg
				/etc/init.d/show-fb-image upfail
				# and bail out...
				errorExit "opkg-upgrade" "Exit code $EXITCODE for: opkg upgrade"
			fi

			echo ">> Checking if these packages are not installed: $CHECK_QMF_PACKAGES_REMOVED"
			for a in $CHECK_QMF_PACKAGES_REMOVED
			do
				echo "checking $a"
				if ! opkg depends base-$HCB_ARCH-$HCB_FLAV | grep -q $a && [ "`opkg list_installed $a`" != "" ]
				then
					echo "removing $a as it is no longer depended upon by base package and it is not removed."
					opkg remove --force-depends $a
				fi
			done

			# upgrade OK: remove tmpfiles
			echo ">> upgrade OK: removing cached package files..."
			rm -f $PKGCACHE/*.ipk

			if [ "$CLEANUP" = "1" ]
			then
				# expose our life story so support can access it - Part II
				# Remove everything but our current log file
				find $PKGCACHE -name _opkg.\*.script.\* ! -name $SCRIPTNAME.log | xargs rm -f
				rm -f /etc/opkg/*-feed.conf
			fi

			sync

			if [ "$REBOOT" = "1" ]
			then
				# prepare the contents of inittab for next boot, only writes if changed
				if featureEnabled INITTAB_PREPARE
				then
					rm -f /tmp/etc-default-HCBv2
					/etc/init.d/HCBv2 prepare-start
					sync
				fi

				# TODO: trigger watchdog here?

				echo ">> Done, scheduling reboot in 2 secs..."
#removed shutdown

			else # no reboot

				# remove the "exit" in this file, so flash+HCBv2 apps can start:
				rm -f /tmp/etc-default-HCBv2

				# now we restart them?
				if [ "$STOPSTARTAPPS" = "1" ]
				then
					echo ">> Restarting flash..."
					killall -9 flash qt-gui
					# dims down, give time to quickly load flash + dim up
					sleep 3
					echo ">> Starting HCBv2 apps..."
					/etc/init.d/HCBv2 start
				fi

				echo ">> Done."
			fi

			# prevent last _opkg.*.script.sh.res file from being left behind
			if [ "$CLEANUP" != "1" ]
			then
				statusSet "executed"
			fi

			;;


		#####################################################################################################
		*)
			echo ">> Unknown ACTION arg! Aborting."
			errorExit "unknown-action" "Unknown ACTION arg! Aborting."
			;;

	esac

	echo ">> `date +'%Y-%m-%d %H:%M:%S %z'` (pid $$) exit-0 $SCRIPTNAME $@"

) </dev/null >>$SCRIPTPATH.log 2>&1
I will be waiting for your verdict if it's safe to proceed.
TheHogNL
Forum Moderator
Forum Moderator
Posts: 2125
Joined: Sun Aug 20, 2017 8:53 pm

Re: Toon firmware - update script

Post by TheHogNL »

It's ok. They added some disk space usage/free space so the update doesn't fail if disk free space is critically low. I have updated the script to containt a new md5 hash.
Member of the Toon Software Collective
mAiden
Member
Member
Posts: 330
Joined: Mon Jul 10, 2017 10:22 am

Re: Toon firmware - update script

Post by mAiden »

Can your script also downgrade @TheHogNL ?
Get the following notification to a forced update to 4.18.8..

Code: Select all


INIT: Id "qtqt" respawning too fast: disabled for 5 minutes
INIT: Id "qtqt" respawning too fast: disabled for 5 minutes

Member of the Toon Software Collective
Post Reply

Return to “Toon Firmware”