#!/bin/bash

function print_file_header {
	echo "# Lines starting with '#' are comments and can be ignored."
	echo "# Blank lines are also ignored."
	echo "#"
	echo "# Entries with the string 'beta' in the filename are considered beta"
	echo "# test versions.  These will only be downloaded by downloaders set"
	echo "# to beta test mode."
	echo "#"
	echo "# The downloader will always update to the first valid entry in this"
	echo "# list.  Beta binaries are ignored unless the downloader is in beta"
	echo "# test mode."
	echo "#"
	echo "# The downloader will also restore or update files in this list, if"
	echo "# the file already exists and (has a different hash in the saved"
	echo "# manifest, a different size in the saved manifest, or a different"
	echo "# size on disk.)  This means you can download previous versions by" 
	echo "# touching the filename in the destination directory, then rerunning."
	echo "# the updater."
	echo
}


#-------------------------------------------------------
# build win32 executable list
#-------------------------------------------------------
rm -f xx-manifest-tmp.txt
for i in `ls -1 AlterAeon_*win32*.exe`; do
    SHA=`cat "$i" | sha256sum | cut -b -20`
    SIZE=`ls -l "$i" | awk '{ print $5 }'`
    printf "%s %10d %s\n" $SHA $SIZE "$i" >> xx-manifest-tmp.txt
done

echo "# Win32 executable list for Alter Aeon DClient" > manifest_win32_executables.txt
print_file_header >> manifest_win32_executables.txt
sort xx-manifest-tmp.txt -r -k 3,5 -f >> manifest_win32_executables.txt

gzip -cn manifest_win32_executables.txt > manifest_win32_executables.txt.gz




#-------------------------------------------------------
# build macos executable list
#-------------------------------------------------------
rm -f xx-manifest-tmp.txt
for i in `ls -1 AlterAeon_*mac*.exe`; do
    SHA=`cat "$i" | sha256sum | cut -b -20`
    SIZE=`ls -l "$i" | awk '{ print $5 }'`
    printf "%s %10d %s\n" $SHA $SIZE "$i" >> xx-manifest-tmp.txt
done

echo "# Win32 executable list for Alter Aeon DClient" > manifest_macos_executables.txt
print_file_header >> manifest_macos_executables.txt
sort xx-manifest-tmp.txt -r -k 3,5 -f >> manifest_macos_executables.txt

gzip -cn manifest_macos_executables.txt > manifest_macos_executables.txt.gz


#-------------------------------------------------------
# build 32 bit linux executable list
#-------------------------------------------------------
rm -f xx-manifest-tmp.txt
for i in `ls -1 AlterAeon_*linux32*.exe AlterAeon_*linux32*.bin`; do
    SHA=`cat "$i" | sha256sum | cut -b -20`
    SIZE=`ls -l "$i" | awk '{ print $5 }'`
    printf "%s %10d %s\n" $SHA $SIZE "$i" >> xx-manifest-tmp.txt
done

echo "# Linux 32-bit executable list for Alter Aeon DClient" > manifest_linux32_executables.txt
print_file_header >> manifest_linux32_executables.txt
sort xx-manifest-tmp.txt -r -k 3,5 -f >> manifest_linux32_executables.txt

gzip -cn manifest_linux32_executables.txt > manifest_linux32_executables.txt.gz



#-------------------------------------------------------
# build 64 bit linux executable list
#-------------------------------------------------------
rm -f xx-manifest-tmp.txt
for i in `ls -1 AlterAeon_*linux64*.exe AlterAeon_*linux64*.bin`; do
    SHA=`cat "$i" | sha256sum | cut -b -20`
    SIZE=`ls -l "$i" | awk '{ print $5 }'`
    printf "%s %10d %s\n" $SHA $SIZE "$i" >> xx-manifest-tmp.txt
done

echo "# Linux 64-bit executable list for Alter Aeon DClient" > manifest_linux64_executables.txt
print_file_header >> manifest_linux64_executables.txt
sort xx-manifest-tmp.txt -r -k 3,5 -f >> manifest_linux64_executables.txt

gzip -cn manifest_linux64_executables.txt > manifest_linux64_executables.txt.gz

