pigsty icon indicating copy to clipboard operation
pigsty copied to clipboard

New installation scripts: specify version as parameter

Open Vonng opened this issue 1 year ago • 0 comments

I'd like to modifiy the install script to add a version parameter, and print hint about operating systems.

For example, we can check version from Environment or args by:

#--------------------------------------------------------------#
# Version
#--------------------------------------------------------------#
DEFAULT_VERSION=v2.6.0
VALID_VERSIONS="\
v1.0.0 v1.1.1 v1.2.0 v1.3.0 v1.4.0 v1.4.1 v1.5.0 v1.5.1 v2.0.0 \
v2.0.1 v2.0.2 v2.1.0 v2.2.0 v2.3.0 v2.3.1 v2.4.0 v2.4.1 v2.5.0 v2.5.1 v2.6.0"
VERSION=${DEFAULT_VERSION}
VERSION_FROM="default"
KERNEL=$(uname)
ARCH=$(uname -m)

# arg1 > env > default
if [[ -n "$1" ]]; then
    VERSION=$1
    VERSION_FROM="arg"
fi

function check_version(){
    local found=false

    # validate version format
    if [[ ! ${VERSION} =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+[0-9]+)?$ ]]; then
        log_error "invalid version string from ${VERSION_FROM}: ${VERSION}"
        exit 1
    fi

    # check version in table
    for ver in ${VALID_VERSIONS}; do
        if [ "${ver}" = "${VERSION}" ]; then
            found="true"
            break
        fi
    done

    # print version string if valid
    if [[ "${found}" != "true" ]]; then
        log_error "invalid version from ${VERSION_FROM}: ${VERSION}"
        log_hint "valid pigsty versions:"
        for ver in ${VALID_VERSIONS}; do
            log_hint "  - ${ver}"
        done
        exit 1
    fi
}

check_version

Vonng avatar Apr 26 '24 12:04 Vonng