You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.0 KiB
64 lines
2.0 KiB
#!/usr/bin/env miaou-recipe
|
|
|
|
# CONSTANTS
|
|
|
|
GLOBAL_CONF=/etc/sympa/sympa/sympa.conf
|
|
MESSAGE_PM=/usr/share/sympa/lib/Sympa/Message.pm
|
|
LIST_DATA_DIR=/var/lib/sympa/list_data
|
|
FOUND=false
|
|
|
|
# FUNCTIONS
|
|
|
|
function fix_personalization {
|
|
if ! grep -q "^personalization_feature.*\*$" $GLOBAL_CONF; then
|
|
/opt/miaou-bash/tools/append_or_replace '^personalization_feature.*$' 'personalization_feature on' $GLOBAL_CONF
|
|
/opt/miaou-bash/tools/append_or_replace '^personalization.mail_apply_on.*$' 'personalization.mail_apply_on footer' $GLOBAL_CONF
|
|
echo 'personalization now enabled'
|
|
FOUND=true
|
|
else
|
|
echo 'personalization already enabled globally!'
|
|
fi
|
|
}
|
|
|
|
function patch_message_pm {
|
|
if [[ -f $MESSAGE_PM ]]; then
|
|
if grep -q '^.*qw/subject x-originating-ip message-id date x-original-to x-original-from.*$' "$MESSAGE_PM"; then
|
|
/opt/miaou-bash/tools/append_or_replace '^.*qw/subject x-originating-ip message-id date x-original-to.*$' ' qw/subject x-originating-ip message-id date x-original-to x-original-from from to thread-topic content-type/' "$MESSAGE_PM"
|
|
FOUND=true
|
|
else
|
|
echo 'already patched!'
|
|
fi
|
|
message=$(prepend_2lines_of_text_before_existing_line "$MESSAGE_PM" '$data->{sender} = $self->{sender};' '$data->{gecos} = $self->{gecos};' '$data->{subject} = $self->{decoded_subject};')
|
|
[[ $message =~ 'do prepend' ]] && FOUND=true || true
|
|
else
|
|
echo "file: $MESSAGE_PM not found!" && exit 11
|
|
fi
|
|
}
|
|
|
|
## arg1=file, arg2=text, arg3='existing_line'
|
|
function prepend_2lines_of_text_before_existing_line {
|
|
local file="$1"
|
|
local line1="$2"
|
|
local line2="$3"
|
|
local existing="$4"
|
|
|
|
[[ ! -f $file ]] && echo "file: $file not found!" && exit 20
|
|
|
|
if ! grep "^$existing$" $file -B2 | grep -qz "$line1.*$line2.*$existing"; then
|
|
echo 'do prepend'
|
|
sed -i "/^$existing$/s/^/$line1\n$line2\n/" $file
|
|
else
|
|
echo 'already done!'
|
|
fi
|
|
}
|
|
|
|
function restart_services {
|
|
$FOUND && systemctl restart sympa wwsympa.socket || true
|
|
}
|
|
|
|
# MAIN
|
|
|
|
set -Eue
|
|
patch_message_pm
|
|
fix_personalization
|
|
restart_services
|