Vonng / pigsty

Battery-Included PostgreSQL Distro as a Free RDS Alternative
https://pigsty.io
GNU Affero General Public License v3.0
2.97k stars 241 forks source link

New installation scripts: specify version as parameter #395

Closed Vonng closed 1 month ago

Vonng commented 2 months ago

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 commented 1 month ago

Resolve by https://github.com/Vonng/pigsty/commit/00e7f0cf714b145875c052b57ab0f186fcd9efea

Now you can download pigsty with:

bash -c "$(curl -fsSL https://get.pigsty.cc/i)"
bash -c "$(curl -fsSL https://get.pigsty.cc/install)"
bash -c "$(curl -fsSL https://get.pigsty.cc/latest)"

# To install a specific version of pigsty (e.g. v2.6.0)
bash -c "$(curl -fsSL https://get.pigsty.cc/i)" -- v2.6.0
curl -fsSL https://get.pigsty.cc/i | bash -s v2.6.0