#!/bin/bash

# extension/Documentation/_make/conf.py: release, version
# extension/Documentation/Settings.yml: version
# extension/ext_emconf.php: version

ST="'"

function confPy() {
    FILE=extension/Documentation/_make/conf.py

    sed -i -r 's/^\s*version\s*=.+$/version = '"'"$SHORT"'"'/g'  ${FILE}
    sed -i -r 's/^\s*release\s*=.+$/release = '"'"$VERSION"'"'/g'  ${FILE}
}

function settingsCfg() {

    FILE="extension/Documentation/Settings.cfg"

    sed -i -r 's/^\s*version\s*=.+$/version     = '$SHORT'/g'  ${FILE}
    sed -i -r 's/^\s*release\s*=.+$/release     = '$VERSION'/g'  ${FILE}

}

function extEmConf() {
    FILE="extension/ext_emconf.php"

    sed  -i -r 's/^\s*'${ST}'version'${ST}'\s*=>.+$/    '${ST}'version'${ST}' => '${ST}${VERSION}${ST}'/g'  ${FILE}
}

function myExit() {
    [ ! -z "$2" ] && echo "$2"

    exit $1
}

#==================================
MAJOR="$1"
MINOR="$2"
MICRO="$3"

[ -z "$MAJOR" -o -z "$MINOR" -o -z "$MICRO" ] && myExit 1 "Missing Version"

VERSION="$MAJOR.$MINOR.$MICRO"
SHORT="$MAJOR.$MINOR"

confPy
settingsCfg
extEmConf
