test: unify valkey.sh/alpine-valkey.sh, msg_menu OS choice

This commit is contained in:
MickLesk
2026-08-17 10:44:13 +02:00
parent b19dad1809
commit 098b858101
2 changed files with 107 additions and 27 deletions
+32 -12
View File
@@ -13,12 +13,23 @@ setting_up_container
network_check
update_os
IS_ALPINE=0
[[ -f /etc/alpine-release ]] && IS_ALPINE=1
msg_info "Installing Valkey"
$STD apt update
$STD apt install -y valkey openssl
if [[ "$IS_ALPINE" == "1" ]]; then
$STD apk add valkey valkey-openrc valkey-cli
else
$STD apt update
$STD apt install -y valkey openssl
fi
sed -i 's/^bind .*/bind 0.0.0.0/' /etc/valkey/valkey.conf
PASS="$(openssl rand -base64 48 | tr -dc 'a-zA-Z0-9' | head -c32)"
if [[ "$IS_ALPINE" == "1" ]]; then
PASS="$(head -c 100 /dev/urandom | tr -dc 'a-zA-Z0-9' | head -c32)"
else
PASS="$(openssl rand -base64 48 | tr -dc 'a-zA-Z0-9' | head -c32)"
fi
echo "requirepass $PASS" >>/etc/valkey/valkey.conf
echo "$PASS" >~/valkey.creds
chmod 600 ~/valkey.creds
@@ -34,9 +45,12 @@ echo "maxmemory-policy allkeys-lru" >>/etc/valkey/valkey.conf
echo "maxmemory-samples 10" >>/etc/valkey/valkey.conf
msg_ok "Installed Valkey"
echo
read -r -p "${TAB3}Enable TLS for Valkey (Sentinel mode does not supported)? [y/N]: " prompt
if [[ ${prompt,,} =~ ^(y|yes)$ ]]; then
if [[ "$IS_ALPINE" == "1" ]]; then
msg_info "Skipping TLS (Alpine's valkey package is compiled without TLS support)"
else
echo
read -r -p "${TAB3}Enable TLS for Valkey (Sentinel mode does not supported)? [y/N]: " prompt
if [[ ${prompt,,} =~ ^(y|yes)$ ]]; then
read -r -p "${TAB3}Use TLS-only mode (disable TCP port 6379)? [y/N]: " tls_only
msg_info "Configuring TLS for Valkey..."
@@ -47,7 +61,7 @@ if [[ ${prompt,,} =~ ^(y|yes)$ ]]; then
chown valkey:valkey "$TLS_CERT" "$TLS_KEY"
if [[ ${tls_only,,} =~ ^(y|yes)$ ]]; then
cat <<EOF >/etc/valkey/valkey.conf
cat <<EOF >>/etc/valkey/valkey.conf
# TLS configuration generated by Proxmox VE Valkey helper-script
port 0
@@ -56,9 +70,9 @@ tls-cert-file $TLS_DIR/valkey.crt
tls-key-file $TLS_DIR/valkey.key
tls-auth-clients no
EOF
msg_ok "Enabled TLS-only mode on port 6379"
msg_ok "Enabled TLS-only mode on port 6379"
else
cat <<EOF >/etc/valkey/valkey.conf
cat <<EOF >>/etc/valkey/valkey.conf
# TLS configuration generated by Proxmox VE Valkey helper-script
tls-port 6380
@@ -66,12 +80,18 @@ tls-cert-file $TLS_DIR/valkey.crt
tls-key-file $TLS_DIR/valkey.key
tls-auth-clients no
EOF
msg_ok "Enabled TLS on port 6380 and TCP on 6379"
msg_ok "Enabled TLS on port 6380 and TCP on 6379"
fi
fi
fi
systemctl enable -q --now valkey-server
systemctl restart valkey-server
if [[ "$IS_ALPINE" == "1" ]]; then
$STD rc-update add valkey default
$STD rc-service valkey start
else
systemctl enable -q --now valkey-server
systemctl restart valkey-server
fi
motd_ssh
customize