Check-in [edd156adcd]
Overview
Comment:Added script to create simple appfs directory tree for serving
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:edd156adcd70f5dafa0b90ea399d3e9f9a00a04c
User & Date: rkeene on 2014-09-08 19:59:22
Other Links: manifest | tags
Context
2014-09-08
20:02
Updated to create contents in SHA1 tree check-in: 074c41c6ce user: rkeene tags: trunk
19:59
Added script to create simple appfs directory tree for serving check-in: edd156adcd user: rkeene tags: trunk
07:17
More work towards parsing directory entries check-in: 85bda525b9 user: rkeene tags: trunk
Changes

Added appfs-mk version [c545d80ced].

            1  +#! /usr/bin/env bash
            2  +
            3  +pkgsdir="$1"
            4  +appfsdir="$2"
            5  +
            6  +if [ -z  "${pkgsdir}" -o -z "${appfsdir}" ]; then
            7  +	echo 'Usage: appfs-mk <pkgsdir> <appfsdir>' >&2
            8  +
            9  +	exit 1
           10  +fi
           11  +
           12  +appfsdir="$(cd "${appfsdir}" && pwd)"
           13  +if [ -z "${appfsdir}" ]; then
           14  +	echo "Unable to find appfs directory." >&2
           15  +
           16  +	exit 1
           17  +fi
           18  +
           19  +function sha1() {
           20  +	local filename
           21  +
           22  +	filename="$1"
           23  +
           24  +	openssl sha1 "${filename}" | sed 's@.*= @@'
           25  +}
           26  +
           27  +function emit_manifest() {
           28  +	find . -print0 | while IFS='' read -r -d $'\0' filename; do
           29  +		if [ "${filename}" = '.' ]; then
           30  +			continue
           31  +		fi
           32  +
           33  +		filename="$(echo "${filename}" | sed 's@^\./@@' | head -n 1)"
           34  +
           35  +		if [ ! -e "${filename}" ]; then
           36  +			continue
           37  +		fi
           38  +
           39  +		if [ -h "${filename}" ]; then
           40  +			type='symlink'
           41  +		elif [ -d "${filename}" ]; then
           42  +			type='directory'
           43  +		elif [ -f "${filename}" ]; then
           44  +			type='file'
           45  +		else
           46  +			continue
           47  +		fi
           48  +
           49  +		case "${type}" in
           50  +			directory)
           51  +				stat_format='%Y'
           52  +				extra_data=''
           53  +				;;
           54  +			symlink)
           55  +				stat_format='%Y'
           56  +				extra_data="$(readlink "${filename}")"
           57  +				;;
           58  +			file)
           59  +				stat_format='%Y,%s'
           60  +				extra_data="$(sha1 "${filename}")"
           61  +				;;
           62  +		esac
           63  +		stat_data="$(stat --format="${stat_format}" "${filename}")"
           64  +
           65  +		if [ -z "${extra_data}" ]; then
           66  +			echo "${type},${stat_data},${extra_data},${filename}"
           67  +		else
           68  +			echo "${type},${stat_data},${extra_data},${filename}"
           69  +		fi
           70  +	done
           71  +}
           72  +
           73  +cd "${pkgsdir}" || exit 1
           74  +
           75  +for package in *; do
           76  +	packagelistfile="${appfsdir}/sha1/${RANDOM}${RANDOM}${RANDOM}${RANDOM}${RANDOM}.tmp"
           77  +	(
           78  +		cd "${package}" || exit 1
           79  +
           80  +		for os_cpuArch in *; do
           81  +			os="$(echo "${os_cpuArch}" | cut -f 1 -d '-')"
           82  +			cpuArch="$(echo "${os_cpuArch}" | cut -f 2- -d '-')"
           83  +
           84  +			(
           85  +				cd "${os_cpuArch}" || exit 1
           86  +
           87  +
           88  +				for version in *; do
           89  +					if [ -h "${version}" ]; then
           90  +						continue
           91  +					fi
           92  +
           93  +					manifestfile="${appfsdir}/sha1/${RANDOM}${RANDOM}${RANDOM}${RANDOM}${RANDOM}.tmp"
           94  +
           95  +					(
           96  +						cd "${version}" || exit 1
           97  +
           98  +						emit_manifest
           99  +					) > "${manifestfile}"
          100  +
          101  +					manifestfile_hash="$(sha1 "${manifestfile}")"
          102  +					mv "${manifestfile}" "${appfsdir}/sha1/${manifestfile_hash}"
          103  +
          104  +					# XXX:TODO: Determine if this is the latest version
          105  +					isLatest='0'
          106  +
          107  +					echo "${package},${version},${os},${cpuArch},${manifestfile_hash},${isLatest}"
          108  +				done
          109  +
          110  +			)
          111  +		done
          112  +	) > "${packagelistfile}"
          113  +
          114  +	packagelistfile_hash="$(sha1 "${packagelistfile}")"
          115  +	mv "${packagelistfile}" "${appfsdir}/sha1/${packagelistfile_hash}"
          116  +
          117  +	echo "${packagelistfile_hash},sha1" > "${appfsdir}/index"
          118  +done