Blob Blame History Raw
#!/bin/sh

export PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '
export HOME=/home/midipix

if [ -z "$SYSROOT" ]; then
	echo '$SYSROOT is not set!'
	exit 2
else
	mkdir -p "$SYSROOT" || exit 2
fi

if [ -f "$SYSROOT/etc/localtime" ]; then
	rm -f "$SYSROOT/etc/localtime.site"
	cat   "$SYSROOT/etc/localtime" > "$SYSROOT/etc/localtime.site"
fi

tarballs=$(ls /updates/*.tar.gz 2>/dev/null)

if [ "$tarballs" = '/updates/*.tar.gz' ]; then
	exit 0
fi

if [ -f /etc/vendor.cfg ]; then
	. /etc/vendor.cfg
fi

for tarball in $tarballs; do
	tarball="${tarball##*/}"

	echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	echo extracting files from /updates/$tarball
	echo ..................................................

	if [ "$tarball" != 'updater.tar.gz' ]; then
		tar -xpvf /updates/$tarball -C "$SYSROOT" || exit 2
	fi

	echo archiving old $tarball
	echo ..................................................

	if [ -f /tarballs/$tarball ]; then
		pkgsig=$(sha256sum /tarballs/$tarball)
		pkgsig=${pkgsig%% *}
		pkgdir=/tarballs/archive/${tarball%%.tar.gz}/
		mkdir -p $pkgdir
		printf '%s\n' "$pkgsig" >> ${pkgdir}/pkgsigs.log
		mkdir -p $pkgdir/$pkgsig/
		mv /tarballs/$tarball $pkgdir/$pkgsig/

		case ${keep:-'-1'} in
			-1 )
				;;

			* )
				tail -n ${keep} ${pkgdir}/pkgsigs.log > ${pkgdir}/pkgsigs.keep

				for pkgsigdir in ${pkgdir}/*; do
					if [ -d $pkgsigdir ]; then
						if ! grep ${pkgsigdir##*/} ${pkgdir}/pkgsigs.keep; then
							rm    $pkgsigdir/$tarball
							rmdir $pkgsigdir
						fi
					fi
				done

				;;
		esac
	fi

	echo caching the current $tarball
	echo ..................................................
	mv /updates/$tarball        /tarballs/
	mv /updates/$tarball.sha256 /tarballs/

	grep -v $tarball /etc/tarballs.sha256 > /etc/tarballs.sha256.tmp
	printf '%s  %s\n' $pkgsig $tarball >> /etc/tarballs.sha256.tmp
	mv /etc/tarballs.sha256.tmp /etc/tarballs.sha256

	echo ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	echo
done

if [ -f "$SYSROOT/etc/localtime.site" ]; then
	cat "$SYSROOT/etc/localtime.site" > "$SYSROOT/etc/localtime"
	rm -f "$SYSROOT/etc/localtime.site"
fi

rm -f /updates/update.pending

echo
echo
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo Congrats! All tarballs were successfully extracted.
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!