|
3 | 3 | # This script is used to install the required packages and download |
4 | 4 | # the latest version of GatewayD from GitHub and install the plugins. |
5 | 5 |
|
| 6 | +# Set the architecture to amd64 if it is not set |
| 7 | +if [ -z "${ARCH}" ]; then |
| 8 | + architecture=$(uname -m) |
| 9 | + if [[ "${architecture}" = "x86_64" ]]; then |
| 10 | + echo "Setting architecture to amd64" |
| 11 | + ARCH=amd64 && export ARCH |
| 12 | + elif [[ "${architecture}" = "aarch64" ]] || [[ "${architecture}" = "arm64" ]]; then |
| 13 | + echo "Setting architecture to arm64" |
| 14 | + ARCH=arm64 && export ARCH |
| 15 | + fi |
| 16 | +fi |
| 17 | +echo "Using architecture: ${ARCH}" |
| 18 | + |
| 19 | +# Install the required packages |
| 20 | +apk add --no-cache curl git |
| 21 | + |
6 | 22 | # Get the latest released version of GatewayD from GitHub |
7 | 23 | [ -z "${GATEWAYD_VERSION}" ] && GATEWAYD_VERSION=$(git ls-remote --tags --sort=v:refname "https://github.com/gatewayd-io/gatewayd" | cut -d/ -f3- | tail -n1) && export GATEWAYD_VERSION |
8 | 24 |
|
| 25 | +# Check if the GatewayD version is set |
| 26 | +if [ -z "${GATEWAYD_VERSION}" ]; then |
| 27 | + echo "Failed to set GatewayD version. Consider setting the GATEWAYD_VERSION environment variable manually." |
| 28 | + exit 126 |
| 29 | +fi |
| 30 | + |
| 31 | +echo "Installing GatewayD ${GATEWAYD_VERSION}" |
| 32 | + |
9 | 33 | # Set the environment variables if they are not set |
10 | 34 | [ -z "${GATEWAYD_FILES}" ] && GATEWAYD_FILES=/gatewayd-files && export GATEWAYD_FILES |
11 | 35 |
|
12 | | -# Install the required packages |
13 | | -apk add --no-cache curl git |
14 | | - |
15 | 36 | # Create the directory to store the gatewayd files |
16 | 37 | [ -d "${GATEWAYD_FILES}" ] || mkdir "${GATEWAYD_FILES}" |
17 | 38 |
|
18 | | -cd "${GATEWAYD_FILES}" || exit 1 |
| 39 | +# Change the directory to the gatewayd-files directory to download the GatewayD archive |
| 40 | +# and install the plugins. This will fail exit code 127 (file or directory not found). |
| 41 | +cd "${GATEWAYD_FILES}" || exit 127 |
19 | 42 |
|
20 | 43 | # Download the GatewayD archive if it doesn't exist |
21 | | -[ -f "${GATEWAYD_FILES}"/gatewayd-linux-amd64-"${GATEWAYD_VERSION}".tar.gz ] || curl -L https://github.com/gatewayd-io/gatewayd/releases/download/"${GATEWAYD_VERSION}"/gatewayd-linux-amd64-"${GATEWAYD_VERSION}".tar.gz | tar zxvf - |
| 44 | +[ -f "${GATEWAYD_FILES}"/gatewayd-linux-"${ARCH}"-"${GATEWAYD_VERSION}".tar.gz ] || curl -L https://github.com/gatewayd-io/gatewayd/releases/download/"${GATEWAYD_VERSION}"/gatewayd-linux-"${ARCH}"-"${GATEWAYD_VERSION}".tar.gz -o gatewayd-linux-"${ARCH}"-"${GATEWAYD_VERSION}".tar.gz |
| 45 | +if [ -f "${GATEWAYD_FILES}"/gatewayd-linux-"${ARCH}"-"${GATEWAYD_VERSION}".tar.gz ]; then |
| 46 | + echo "GatewayD archive downloaded successfully." |
| 47 | +else |
| 48 | + echo "GatewayD archive download failed." |
| 49 | + exit 1 |
| 50 | +fi |
| 51 | + |
| 52 | +# Extract the GatewayD archive |
| 53 | +echo "Extracting GatewayD archive..." |
| 54 | +tar zxvf gatewayd-linux-"${ARCH}"-"${GATEWAYD_VERSION}".tar.gz -C "${GATEWAYD_FILES}" |
| 55 | + |
| 56 | +# Set execute permission for the GatewayD binary |
| 57 | +echo "Setting execute permission for the GatewayD binary..." |
22 | 58 | chmod +x gatewayd |
23 | 59 |
|
24 | 60 | # Install the GatewayD plugins |
25 | | -"${GATEWAYD_FILES}"/gatewayd plugin install --skip-path-slip-verification --output-dir "${GATEWAYD_FILES}" --plugin-config "${GATEWAYD_FILES}"/gatewayd_plugins.yaml --cleanup=false --update --overwrite-config |
| 61 | +# If the installation fails, the script will exit with exit code 126 (command invoke error). |
| 62 | +echo "Installing GatewayD plugins..." |
| 63 | +"${GATEWAYD_FILES}"/gatewayd plugin install --skip-path-slip-verification --output-dir "${GATEWAYD_FILES}" --plugin-config "${GATEWAYD_FILES}"/gatewayd_plugins.yaml --cleanup=false --update --overwrite-config || exit 126 |
26 | 64 |
|
27 | | -# Replace the default Redis URL |
| 65 | +# Replace the default Redis URL with the Redis container URL |
28 | 66 | sed -i 's/redis:\/\/localhost:6379/redis:\/\/redis:6379/' "${GATEWAYD_FILES}"/gatewayd_plugins.yaml |
| 67 | + |
| 68 | +echo "GatewayD ${GATEWAYD_VERSION} and plugins installed successfully. Exiting..." |
0 commit comments