Import alt-mysql plugin
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
# shellcheck source=./roundcube_common.sh
|
||||
source "$SCRIPT_DIR/roundcube_common.sh"
|
||||
|
||||
rewrite_roundcube_config() {
|
||||
local source_file="$1"
|
||||
local target_file="$2"
|
||||
local dsn="$3"
|
||||
local tmp parent
|
||||
|
||||
[ -f "$source_file" ] || {
|
||||
echo "roundcube: source config file not found: $source_file" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
if [ -e "$target_file" ]; then
|
||||
[ -w "$target_file" ] || {
|
||||
echo "roundcube: config file is not writable: $target_file" >&2
|
||||
return 1
|
||||
}
|
||||
else
|
||||
parent="$(dirname "$target_file")"
|
||||
mkdir -p "$parent"
|
||||
fi
|
||||
|
||||
tmp="$(mktemp)"
|
||||
awk '
|
||||
/BEGIN DIRECTADMIN MYSQL PLUGIN ROUNDCUBE/ { skip=1; next }
|
||||
/END DIRECTADMIN MYSQL PLUGIN ROUNDCUBE/ { skip=0; next }
|
||||
skip != 1 { print }
|
||||
' "$source_file" > "$tmp"
|
||||
|
||||
cat >> "$tmp" <<PHP
|
||||
|
||||
// BEGIN DIRECTADMIN MYSQL PLUGIN ROUNDCUBE
|
||||
\$config['db_dsnw'] = '$dsn';
|
||||
// END DIRECTADMIN MYSQL PLUGIN ROUNDCUBE
|
||||
PHP
|
||||
|
||||
if [ -e "$target_file" ]; then
|
||||
cat "$tmp" > "$target_file"
|
||||
else
|
||||
install -m 0644 "$tmp" "$target_file"
|
||||
fi
|
||||
rm -f "$tmp"
|
||||
}
|
||||
|
||||
roundcube_enabled || {
|
||||
echo "roundcube: integration disabled by ROUNDCUBE_ENABLED."
|
||||
exit 0
|
||||
}
|
||||
|
||||
CONFIG_FILE="$(roundcube_config_file)"
|
||||
[ -f "$CONFIG_FILE" ] || {
|
||||
echo "roundcube: config file not found: $CONFIG_FILE" >&2
|
||||
exit 1
|
||||
}
|
||||
[ -w "$CONFIG_FILE" ] || {
|
||||
echo "roundcube: config file is not writable: $CONFIG_FILE" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
DSN="$(roundcube_alt_dsn)"
|
||||
rewrite_roundcube_config "$CONFIG_FILE" "$CONFIG_FILE" "$DSN"
|
||||
|
||||
echo "roundcube: config repaired: $CONFIG_FILE"
|
||||
|
||||
if roundcube_write_custombuild_config; then
|
||||
CUSTOM_CONFIG_FILE="$(roundcube_custom_config_file)"
|
||||
if [ -f "$CUSTOM_CONFIG_FILE" ]; then
|
||||
rewrite_roundcube_config "$CUSTOM_CONFIG_FILE" "$CUSTOM_CONFIG_FILE" "$DSN"
|
||||
else
|
||||
rewrite_roundcube_config "$CONFIG_FILE" "$CUSTOM_CONFIG_FILE" "$DSN"
|
||||
fi
|
||||
echo "roundcube: CustomBuild config repaired: $CUSTOM_CONFIG_FILE"
|
||||
fi
|
||||
Reference in New Issue
Block a user