Add RPM support to rpxy-start.sh
This commit is contained in:
parent
11135e3e1c
commit
76dfd09bec
1 changed files with 53 additions and 20 deletions
|
|
@ -1,29 +1,62 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
CACHE_DIR="/tmp/rpxy/.cache"
|
||||||
|
CONFIG_DIR="/etc/rpxy"
|
||||||
|
CONFIG_FILE="$CONFIG_DIR/config.toml"
|
||||||
|
WEBUI_CONFIG="/var/www/rpxy-webui/storage/app/config.toml"
|
||||||
|
COMMENT_MARKER="# IMPORTANT: DEACTIVATED This config is deactivated because rpxy-webui is installed"
|
||||||
|
|
||||||
# Ensure the cache directory exists as it could get deleted on system restart
|
# Ensure the cache directory exists as it could get deleted on system restart
|
||||||
if [ ! -d /tmp/rpxy/.cache ]; then
|
create_cache_dir() {
|
||||||
# Create the temporary directory for rpxy
|
# Create the temporary directory for rpxy
|
||||||
mkdir -p /tmp/rpxy/.cache
|
mkdir -p "$CACHE_DIR"
|
||||||
chown -R rpxy:rpxy /tmp/rpxy
|
chown -R rpxy:rpxy /tmp/rpxy
|
||||||
chmod 700 /tmp/rpxy/.cache
|
chmod 700 "$CACHE_DIR"
|
||||||
fi
|
}
|
||||||
|
|
||||||
# Check if rpxy-webui is installed
|
# Check if rpxy-webui is installed
|
||||||
if dpkg-query -W -f='${Status}' rpxy-webui 2>/dev/null | grep -q "install ok installed"; then
|
is_package_installed() {
|
||||||
echo "rpxy-webui is installed. Starting rpxy with rpxy-webui"
|
if command -v rpm >/dev/null 2>&1; then
|
||||||
exec /usr/bin/rpxy -w -c /var/www/rpxy-webui/storage/app/config.toml
|
rpm -q "$1" >/dev/null 2>&1
|
||||||
|
elif command -v dpkg-query >/dev/null 2>&1; then
|
||||||
|
dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -q "install ok installed"
|
||||||
else
|
else
|
||||||
echo "rpxy-webui is not installed. Starting with default config"
|
echo "Neither rpm nor dpkg-query found. Cannot verify installation status of rpxy-webui package." >&2
|
||||||
|
return 1
|
||||||
# Ensure the /etc/rpxy directory exists
|
|
||||||
if [ ! -d /etc/rpxy ]; then
|
|
||||||
mkdir -p /etc/rpxy
|
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Create the config file if it doesn't exist
|
# Create the config file if it doesn't exist
|
||||||
if [ ! -f /etc/rpxy/config.toml ]; then
|
ensure_config_exists() {
|
||||||
echo "# Default rpxy config file" > /etc/rpxy/config.toml
|
mkdir -p "$CONFIG_DIR"
|
||||||
fi
|
[ -f "$CONFIG_FILE" ] || echo "# Standard rpxy Konfigurationsdatei" > "$CONFIG_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
exec /usr/bin/rpxy -c /etc/rpxy/config.toml
|
add_comment_to_config() {
|
||||||
|
if ! grep -q "^$COMMENT_MARKER" "$CONFIG_FILE"; then
|
||||||
|
sed -i "1i$COMMENT_MARKER\n" "$CONFIG_FILE"
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
remove_comment_from_config() {
|
||||||
|
sed -i "/^$COMMENT_MARKER/d" "$CONFIG_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
[ -d "$CACHE_DIR" ] || create_cache_dir
|
||||||
|
ensure_config_exists
|
||||||
|
|
||||||
|
if is_package_installed rpxy-webui; then
|
||||||
|
echo "rpxy-webui is installed. Starting rpxy with rpxy-webui"
|
||||||
|
add_comment_to_config
|
||||||
|
exec /usr/bin/rpxy -w -c "$WEBUI_CONFIG"
|
||||||
|
else
|
||||||
|
echo "rpxy-webui is not installed. Starting with default config"
|
||||||
|
remove_comment_from_config
|
||||||
|
exec /usr/bin/rpxy -c "$CONFIG_FILE"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
main "$@"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue