next_file() {
	FILENUM=$((FILENUM+1))
	eval FILE_SRC="\$FILE${FILENUM}_SRC"
	eval FILE_DST="\$FILE${FILENUM}_DST"
	eval FILE_PRM="\$FILE${FILENUM}_PRM"
	[ -n "$FILE_SRC" ]
}

tar_extract() {
        extractdir=$(mktemp -d --tmpdir=/tmp)
	if [ -z "$extractdir" ]; then
		echo "Error during extraction." >&2
		exit 1
	fi

	cd "$extractdir" || exit 1

	if [ "$(head -c4 "/var/lib/flash-player-plugin/flash-plugin-11.2.202.238-release.i386.rpm")" = $'\xED\xAB\xEE\xDB' ]; then
		rpm2cpio "/var/lib/flash-player-plugin/flash-plugin-11.2.202.238-release.i386.rpm" | cpio -i --quiet -d -R root:root
	else
		tar -xzf "/var/lib/flash-player-plugin/flash-plugin-11.2.202.238-release.i386.rpm" --no-same-owner --no-same-permissions
	fi

	# Avoid leaving old files in case of failure below
	FILENUM=0
	while next_file; do
		rm -f "$FILE_DST"
	done

	FILENUM=0
	while next_file; do
		if [ ! -f "$FILE_SRC" ]; then
			echo "Warning: $FILE_SRC not found in the Flash Player archive," >&2
			echo "         skipping installation of $FILE_DST." >&2
			echo "         Please file a bug report at https://bugs.mageia.org/ ." >&2
			continue
		fi
			
		chmod "$FILE_PRM" "$FILE_SRC"
		mv -f "$FILE_SRC" "$FILE_DST"
	done
	rm -rf "$extractdir"
}
