#!/bin/bash
#Run this script to download and install the latest CH build from build.sk89q.com. It names
#it and symlinks it properly.
version='3.3.1'
#Delete old downloads
if [ -a commandhelper-$version-SNAPSHOT.jar ]; then
rm -f commandhelper-$version-SNAPSHOT.jar
fi
#Download the latest version
#wget http://build.sk89q.com/job/CommandHelper/lastSuccessfulBuild/artifact/target/commandhelper-$version-SNAPSHOT.jar
echo "Downloading latest build..."
wget http://builds.enginehub.org/job/commandhelper/last-successful/download/commandhelper-$version-SNAPSHOT.zip
echo "Unzipping..."
unzip -p commandhelper-$version-SNAPSHOT.zip CommandHelper.jar > commandhelper-$version-SNAPSHOT.jar
rm -f commandhelper-$version-SNAPSHOT.zip
echo "Gathering build info..."
#Store the build hash from the version number
buildhash=$(unzip -c commandhelper-$version-SNAPSHOT.jar plugin.yml | grep 'version: ".*"' | sed -rn 's/version: "'$version'-SNAPSHOT:[ [:digit:] ]{4}-(.*),.*"/\1/p')
#Build the time string
timestamp=$(date +"%Y%m%d")
#rename the file
filename=CommandHelper-$version-$timestamp-$buildhash.jar
echo "Naming file properly and moving into position..."
mv commandhelper-$version-SNAPSHOT.jar $filename
#Now remove the old symlink
rm CommandHelper.jar
#And create the new one
echo "Creating symlink..."
ln -s $filename CommandHelper.jar
echo "Updating syntax file..."
#Update the syntax file for this version
java -jar CommandHelper.jar syntax vim > ~/.vim/syntax/commandhelper.vim
echo "Done!"