This repository has been archived by the owner on Dec 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
38 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,51 @@ | ||
#!/usr/bin/env bash | ||
# Usage: setup-redis.sh [redis-stack-server-options] | ||
set -eEuo pipefail | ||
|
||
tmpdir="${PREM_APPDIR:-.}/redis-$(uuidgen 2>/dev/null || uuid)" | ||
# Set strict error handling | ||
set -euo pipefail | ||
|
||
cleanup(){ | ||
for i in $(jobs -p); do | ||
kill -n 9 $i || : | ||
done | ||
rm -rf "$tmpdir" | ||
exit 0 | ||
# Define the Redis directory in the home directory | ||
REDIS_DIR="$HOME/redis-stack-server" | ||
|
||
# Function to clean up on exit or error | ||
cleanup() { | ||
echo "Cleaning up..." | ||
rm -rf "$REDIS_DIR" | ||
} | ||
|
||
trap "cleanup" SIGTERM | ||
trap "cleanup" SIGINT | ||
trap "cleanup" ERR | ||
# Set traps to clean up on SIGINT, SIGTERM, or script exit | ||
trap cleanup SIGINT SIGTERM ERR EXIT | ||
|
||
# Create the Redis directory | ||
mkdir -p "$REDIS_DIR" | ||
|
||
# Detect architecture for correct Redis stack server version | ||
ARCH=$(uname -m) | ||
case "$ARCH" in | ||
x86_64) | ||
arch_suffix=catalina.x86_64 ;; | ||
arm64|aarch64) | ||
arch_suffix=monterey.arm64 ;; | ||
*) | ||
echo "Unsupported architecture: $ARCH"; exit 1 ;; | ||
x86_64) | ||
ARCH_SUFFIX="catalina.x86_64" ;; | ||
arm64 | aarch64) | ||
ARCH_SUFFIX="monterey.arm64" ;; | ||
*) | ||
echo "Unsupported architecture: $ARCH" >&2 | ||
exit 1 ;; | ||
esac | ||
url="https://packages.redis.io/redis-stack/redis-stack-server-7.2.0-v6.$arch_suffix.zip" | ||
|
||
mkdir -p "$tmpdir" | ||
curl -fsSL "$url" > "$tmpdir/redis-stack-server.zip" | ||
unzip -d "$tmpdir" "$tmpdir/redis-stack-server.zip" | ||
# Download the Redis Stack Server zip file for the detected architecture | ||
REDIS_STACK_URL="https://packages.redis.io/redis-stack/redis-stack-server-7.2.0-v6.$ARCH_SUFFIX.zip" | ||
echo "Downloading Redis Stack Server for $ARCH..." | ||
curl -fsSL "$REDIS_STACK_URL" -o "$REDIS_DIR/redis-stack-server.zip" | ||
|
||
# Unpack the Redis Stack Server and remove the zip file | ||
echo "Unpacking Redis Stack Server..." | ||
unzip "$REDIS_DIR/redis-stack-server.zip" -d "$REDIS_DIR" && rm "$REDIS_DIR/redis-stack-server.zip" | ||
|
||
# Export PATH to include the Redis bin directory | ||
export PATH="$REDIS_DIR/bin:$PATH" | ||
|
||
PATH="$tmpdir/bin:$PATH" "$tmpdir/bin/redis-stack-server" "$@" & | ||
# Run Redis Stack Server in the background | ||
echo "Starting Redis Stack Server..." | ||
redis-stack-server "$@" & | ||
|
||
wait | ||
# Wait for all background jobs to finish | ||
wait $! |