-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_redis_server.sh
More file actions
76 lines (64 loc) · 2.3 KB
/
install_redis_server.sh
File metadata and controls
76 lines (64 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
set -euo pipefail
# Check if redis-server (Debian name) or redis (RHEL/Fedora service name) is already installed
if command -v redis-server >/dev/null 2>&1 || command -v redis-cli >/dev/null 2>&1; then
echo "Redis is already installed."
exit 0
fi
echo "Redis is not installed. Installing now..."
if [[ "$(uname -s)" == "Darwin" ]]; then
# macOS
if ! command -v brew >/dev/null 2>&1; then
echo "Homebrew is not installed. Please install Homebrew first: https://brew.sh/"
exit 1
fi
brew update
brew install redis
elif [[ -r /etc/os-release ]]; then
# Linux
. /etc/os-release # loads variables: ID, ID_LIKE, etc.
# Helper: return 0 if $1 is contained in $ID or $ID_LIKE
has_like() {
local needle="${1,,}" # argument lowercased
local id_lc="${ID,,}" # ID lowercased
local like_lc="${ID_LIKE:-}" # ID_LIKE lowercased (may be empty)
[[ "$id_lc" == "$needle" ]] && return 0
[[ "$like_lc" == *"$needle"* ]] && return 0
return 1
}
if has_like debian || has_like ubuntu; then
# Debian/Ubuntu
sudo apt-get update
sudo apt-get install -y redis-server
elif has_like rhel || has_like centos || has_like fedora || has_like openeuler; then
# RHEL/CentOS/AlmaLinux/Rocky/Fedora/openEuler
PKG_MGR=""
if command -v dnf >/dev/null 2>&1; then
PKG_MGR="dnf"
elif command -v yum >/dev/null 2>&1; then
PKG_MGR="yum"
fi
if [[ -z "$PKG_MGR" ]]; then
echo "Could not find yum/dnf on this system."
exit 1
fi
# Optional: enable EPEL on older RHEL/CentOS if needed
if has_like rhel || has_like centos; then
if ! rpm -qa | grep -qi epel-release; then
sudo "$PKG_MGR" install -y epel-release || true
fi
fi
sudo "$PKG_MGR" install -y redis
elif has_like suse || has_like opensuse; then
# (open)SUSE
sudo zypper refresh
sudo zypper install -y redis
else
echo "Unsupported Linux distribution ($ID). Please install Redis manually."
exit 1
fi
else
echo "Unsupported OS. Please install Redis manually."
exit 1
fi
echo "Redis installation complete."