Blame publish/publish.sh

6dca2e
#!/bin/bash
6dca2e
6dca2e
set -e
6dca2e
6dca2e
PUBLISH_DIR=$(cd `dirname "$0"`; pwd)
6dca2e
a80e72
publish() {
6dca2e
    local NAME="$1"
2c4a34
    local TEMPLATE="$2" # Xxxxx-%VERSION%-%DATE%-%COMMIT%-xxxxx.xxx
a80e72
    local FILEPATH="$3"
6dca2e
    local MASK="$4"
6dca2e
    local VERSION_FILE="$5"
6dca2e
a80e72
    local FILE=`ls "$FILEPATH/"$MASK`
6dca2e
6dca2e
    local VERSION=`cat "$VERSION_FILE" | cut -d'-' -f 1`
6dca2e
    local COMMIT=`cat "$VERSION_FILE" | cut -d'-' -f 2-`
6dca2e
    COMMIT="${COMMIT:0:5}"
91875d
    local DATE=`date -u +%y.%m.%d`
6dca2e
    if [ -z "$COMMIT" ]; then
6dca2e
        echo "Cannot find version, pheraps package not ready. Cancel."
6dca2e
        return 1
6dca2e
    fi
6dca2e
6dca2e
    local CHECK_MASK=` \
6dca2e
        echo "$TEMPLATE" \
6dca2e
        | sed "s|%VERSION%|$VERSION|g" \
6dca2e
        | sed "s|%DATE%|*|g" \
6dca2e
        | sed "s|%COMMIT%|$COMMIT|g" `
34c295
    local RM_MASK=` \
34c295
        echo "$TEMPLATE" \
34c295
        | sed "s|%VERSION%|*|g" \
34c295
        | sed "s|%DATE%|*|g" \
34c295
        | sed "s|%COMMIT%|*|g" `
b22744
    local CHECK=`ls "$PUBLISH_DIR/"$CHECK_MASK 2>/dev/null`
6dca2e
    if [ -z "$CHECK" ]; then
6dca2e
        local TARGET_NAME=` \
6dca2e
            echo "$TEMPLATE" \
6dca2e
            | sed "s|%VERSION%|$VERSION|g" \
6dca2e
            | sed "s|%DATE%|$DATE|g" \
6dca2e
            | sed "s|%COMMIT%|$COMMIT|g" `
6dca2e
        local TARGET="$PUBLISH_DIR/$TARGET_NAME"
6dca2e
6dca2e
        echo "Publish new version $VERSION-$COMMIT ($TARGET_NAME)"
34c295
        `rm -f "$PUBLISH_DIR/"$RM_MASK`
6dca2e
        cp "$FILE" "$TARGET"
6dca2e
        if [ -f "$PUBLISH_DIR/publish-$NAME.sh" ]; then
6dca2e
            echo "Call publish-$NAME.sh"
6dca2e
            "$PUBLISH_DIR/publish-$NAME.sh" "$TARGET"
6dca2e
        fi
6dca2e
    else
6dca2e
        echo "Version $VERSION-$COMMIT already published ($CHECK)"
6dca2e
    fi
6dca2e
}
6dca2e
6dca2e
publish $@