#!/bin/sh

[ ! -e sdfs ] && git clone https://github.com/opendedup/sdfs

cd sdfs
git pull

VER=$(grep -i version src/changes.txt|head -n1|awk '{print $2}' > /tmp/sdfs_ver; fromdos < /tmp/sdfs_ver > /tmp/sdfs_ver2; cat /tmp/sdfs_ver2 )

cd install-packages/deb
ARCH=$(file usr/share/sdfs/bin/libBUSE.so 2>/dev/null | grep -i "64-bit" 2>/dev/null)
if [ "$ARCH" = "" ]; then
    ARCH=i586
else
    ARCH=x86_64
fi

[ ! -e install ] && mkdir install
echo "# HOW TO EDIT THIS FILE:" > install/slack-desc
echo "# The \handy ruler\" below makes it easier to edit a package description.  Line" >> install/slack-desc
echo "# up the first '|' above the ':' following the base package name, and the '|' on">> install/slack-desc
echo "# the right side marks the last column you can put a character in.  You must make">> install/slack-desc
echo "# exactly 11 lines for the formatting to be correct.  It's also customary to">> install/slack-desc
echo "# leave one space after the ':'.">> install/slack-desc
echo "" >> install/slack-desc
echo "      |-----handy-ruler------------------------------------------------------|">> install/slack-desc
echo "opendedup: opendedup ">> install/slack-desc
echo "opendedup: ">> install/slack-desc
echo "opendedup: A clustered deduplicated file system.">> install/slack-desc
echo "opendedup: ">> install/slack-desc
echo "opendedup: http://opendedup.org/">> install/slack-desc
echo "opendedup: ">> install/slack-desc
echo "opendedup: ">> install/slack-desc
echo "opendedup: ">> install/slack-desc
echo "opendedup: ">> install/slack-desc
echo "opendedup: ">> install/slack-desc
echo "opendedup: ">> install/slack-desc

makepkg -l y -c y /tmp/sdfs-${VER}-${ARCH}-1airaghi.txz