#!/bin/bash # Default installation directory for redis-dump-go INSTALL_DIR="/usr/local/bin" # Default redis port DEFAULT_PORT="6379" # Function to check for required tools check_requirements() { local missing_counter=0 local dependencies=('wget' 'redis-cli') for dep in "${dependencies[@]}"; do if ! type "$dep" > /dev/null 2>&1; then echo >&2 "Error: $dep is required but it's not installed." ((missing_counter++)) fi done if (( missing_counter > 0 )); then echo "Please install the missing tools before running this script." exit 1 fi } check_requirements # Function to detect the architecture and set the corresponding binary name get_arch_name() { ARCH=$(uname -m) case $ARCH in x86_64) BIN_ARCH="amd64" ;; i386 | i686) BIN_ARCH="386" ;; aarch64 | arm64) BIN_ARCH="arm64" ;; arm*) BIN_ARCH="armv6" ;; *) echo "Architecture not supported" exit 1 ;; esac # Always Linux as we run this in a Docker container BIN_OS="linux" BIN_NAME="redis-dump-go-${BIN_OS}-${BIN_ARCH}.tar.gz" } # Function to parse named parameters parse_params() { # Default values of variables set from params SRC_HOST='' SRC_PORT=$DEFAULT_PORT SRC_PASSWORD='' DEST_HOST='' DEST_PORT=$DEFAULT_PORT DEST_PASSWORD='' DB_NAMES=() # Array to hold database names while :; do case "${1-}" in -h | --help) usage ;; --src-host) # Source host (required) SRC_HOST="${2-}" shift ;; --src-port) # Source port (optional, default is 6379) SRC_PORT="${2-}" shift ;; --src-password) # Source password (optional) SRC_PASSWORD="${2-}" shift ;; --dest-host) # Destination host (required) DEST_HOST="${2-}" shift ;; --dest-port) # Destination port (optional, default is 6379) DEST_PORT="${2-}" shift ;; --dest-password) # Destination password (optional) DEST_PASSWORD="${2-}" shift ;; --dbs) # Comma-separated list of database names (optional) IFS=',' read -r -a DB_NAMES <<< "${2-}" shift ;; -?*) echo "Unknown option: $1" >&2 exit 1 ;; *) # No more options break ;; esac shift done # Check required parameters [[ -z "$SRC_HOST" ]] && { echo "Missing required parameter: --src-host"; exit 1; } [[ -z "$DEST_HOST" ]] && { echo "Missing required parameter: --dest-host"; exit 1; } } # Usage info usage() { cat <