Blame once/update.sh

4721ce
#!/bin/sh
4721ce
4721ce
export PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '
4721ce
export HOME=/home/midipix
4721ce
4721ce
if [ -z "$SYSROOT" ]; then
4721ce
	echo '$SYSROOT is not set!'
4721ce
	exit 2
4721ce
else
4721ce
	mkdir -p "$SYSROOT" || exit 2
4721ce
fi
4721ce
38461f
if [ -f "$SYSROOT/etc/localtime" ]; then
fe0e58
	rm -f "$SYSROOT/etc/localtime.site"
fe0e58
	cat   "$SYSROOT/etc/localtime" > "$SYSROOT/etc/localtime.site"
38461f
fi
38461f
ee6784
tarballs=$(ls /updates/*.tar.gz 2>/dev/null)
ee6784
ee6784
if [ "$tarballs" = '/updates/*.tar.gz' ]; then
ee6784
	exit 0
ee6784
fi
ee6784
e06f87
if [ -f /etc/vendor.cfg ]; then
e06f87
	. /etc/vendor.cfg
e06f87
fi
e06f87
ee6784
for tarball in $tarballs; do
67d57a
	tarball="${tarball##*/}"
67d57a
4721ce
	echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
67d57a
	echo extracting files from /updates/$tarball
67d57a
	echo ..................................................
2ddf27
2ddf27
	if [ "$tarball" != 'updater.tar.gz' ]; then
81ae60
		tar -xpv --no-same-owner -f /updates/$tarball -C "$SYSROOT" || exit 2
2ddf27
	fi
67d57a
67d57a
	echo archiving old $tarball
4721ce
	echo ..................................................
67d57a
67d57a
	if [ -f /tarballs/$tarball ]; then
67d57a
		pkgsig=$(sha256sum /tarballs/$tarball)
67d57a
		pkgsig=${pkgsig%% *}
bea4b7
		pkgdir=/tarballs/archive/${tarball%%.tar.gz}/
bea4b7
		mkdir -p $pkgdir
bea4b7
		printf '%s\n' "$pkgsig" >> ${pkgdir}/pkgsigs.log
e06f87
		mkdir -p $pkgdir/$pkgsig/
e06f87
		mv /tarballs/$tarball $pkgdir/$pkgsig/
e06f87
e06f87
		case ${keep:-'-1'} in
e06f87
			-1 )
e06f87
				;;
e06f87
e06f87
			* )
e06f87
				tail -n ${keep} ${pkgdir}/pkgsigs.log > ${pkgdir}/pkgsigs.keep
e06f87
e06f87
				for pkgsigdir in ${pkgdir}/*; do
e06f87
					if [ -d $pkgsigdir ]; then
e06f87
						if ! grep ${pkgsigdir##*/} ${pkgdir}/pkgsigs.keep; then
e06f87
							rm    $pkgsigdir/$tarball
e06f87
							rmdir $pkgsigdir
e06f87
						fi
e06f87
					fi
e06f87
				done
e06f87
e06f87
				;;
e06f87
		esac
67d57a
	fi
67d57a
67d57a
	echo caching the current $tarball
67d57a
	echo ..................................................
67d57a
	mv /updates/$tarball        /tarballs/
67d57a
	mv /updates/$tarball.sha256 /tarballs/
67d57a
3f01df
	grep -v $tarball /etc/tarballs.sha256 > /etc/tarballs.sha256.tmp
3f01df
	printf '%s  %s\n' $pkgsig $tarball >> /etc/tarballs.sha256.tmp
3f01df
	mv /etc/tarballs.sha256.tmp /etc/tarballs.sha256
3f01df
4721ce
	echo ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4721ce
	echo
4721ce
done
4721ce
38461f
if [ -f "$SYSROOT/etc/localtime.site" ]; then
fe0e58
	cat "$SYSROOT/etc/localtime.site" > "$SYSROOT/etc/localtime"
fe0e58
	rm -f "$SYSROOT/etc/localtime.site"
38461f
fi
38461f
661bd8
rm -f /updates/update.pending
661bd8
4721ce
echo
4721ce
echo
4721ce
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
4721ce
echo Congrats! All tarballs were successfully extracted.
4721ce
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!