Skip to content

Instantly share code, notes, and snippets.

@hamstar
Created September 9, 2012 07:18
Show Gist options
  • Save hamstar/3683131 to your computer and use it in GitHub Desktop.
Save hamstar/3683131 to your computer and use it in GitHub Desktop.
autodeb builder for Braincase
#!/bin/bash
# Some vars
REPO="https://github.com/hamstar/Braincase.git";
LREPO="/var/www/test/repo";
BRANCH="sprint2"; # this could be replaced with ref
BUILDDIR="$LREPO/packages/debian";
WEBDIR="/var/www/test";
# Refresh the repo
rm $LREPO -fr;
git clone $REPO $LREPO;
# Checkout our branch and update submodules
cd $LREPO;
git checkout $BRANCH;
git submodule update --init;
# Determine the sha for the deb filename
SHA=`git log|head -1|cut -d' ' -f2|head -c 8`;
# Clear out the current build dir
cd $BUILDDIR;
rm usr var etc -fr;
# Add in fresh files and make bin executable
cd $LREPO;
cp -fR usr var etc -t $BUILDDIR;
chmod +x $BUILDDIR/usr/bin/*;
# untested code!!!!
function add_size_and_version() {
# Add the size automatically
size=`du $BUILDDIR -sk --exclude="DEBIAN|cut -d' ' -f1";
cat $BUILDDIR/DEBIAN/control | sed "s/Installed-Size: \d+/Installed-Size: $size/" > $WEBDIR/control.tmp;
cp $WEBDIR/control.tmp $BUILDDIR/DEBIAN/control;
# Increment the version patch number
version=`cat $BUILDDIR/DEBIAN/control|grep "Version: "|cut -d' ' -f2`;
major=`echo $version|cut -d'.' -f1`;
minor=`echo $version|cut -d'.' -f2`;
patch=`echo $version|cut -d'.' -f3`;
stored_version=`cat $WEBDIR/version.txt`;
smajor=`echo $stored_version|cut -d'.' -f1`;
sminor=`echo $stored_version|cut -d'.' -f2`;
# Don't reversion a new major or minor
if [ "$major" == "$smajor" && "$minor" == "$sminor" ]; then
patch="$(($patch+1))";
fi;
# Save the version to
version="$major.$minor.$patch";
echo "$version" > $WEBDIR/version.txt;
# Build a regex friendly version
version="$major\.$minor\.$patch";
cat $BUILDDIR/DEBIAN/control | sed "s/Version: \d+/Version: $version/" > $WEBDIR/control.tmp;
cp $WEBDIR/control.tmp $BUILDDIR/DEBIAN/control;
}
#add_size_and_version; # untested code!!!
# Debianize!
dpkg-deb --build $BUILDDIR;
# Make it accessible
mv $LREPO/packages/debian.deb $WEBDIR/deb/braincase-$SHA.deb;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment