#!/bin/bash

HERE=$(dirname $(readlink -f 0))

NEW_VERSION=$1

MAJOR=$(echo $NEW_VERSION | cut -d'.' -f 1)
MINOR=$(echo $NEW_VERSION | cut -d'.' -f 2)
PATCH=$(echo $NEW_VERSION | cut -d'.' -f 3)

PATCH_DIGITS=$(printf '%02d' $PATCH) 
TODAY=$(date '+%Y-%m-%d')

sed -i "s/full=.*/full=$MAJOR.$MINOR.$PATCH/" $HERE/fusion/var/fusionversion
sed -i "s/major=[0-9]*/major=$MAJOR/" $HERE/fusion/var/fusionversion
sed -i "s/minor=[0-9]*\.[0-9]*/minor=$MINOR.$PATCH/" $HERE/fusion/var/fusionversion
sed -i "s/releasedate=.*/releasedate=$TODAY/" $HERE/fusion/var/fusionversion
sed -i "s/release=[0-9][0-9][0-9][0-9]/release=$MAJOR$MINOR$PATCH_DIGITS/" $HERE/fusion/var/fusionversion

sed -i "s/return [0-9][0-9][0-9][0-9];/return $MAJOR$MINOR$PATCH_DIGITS;/" $HERE/fusion/html/includes/utils/license.inc.php
sed -i "s/\$major='[0-9]';/\$major='$MAJOR';/" $HERE/fusion/html/includes/utils/license.inc.php
sed -i "s/\$minor='[0-9\.]*';/\$minor='$MINOR.$PATCH';/" $HERE/fusion/html/includes/utils/license.inc.php
