Skip to content

Commit 0ae127e

Browse files
committed
Add v-change-sys-webmail, a script to change webmail alias.
1 parent 477170a commit 0ae127e

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

bin/v-change-sys-webmail

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
# info: change webmail alias url
3+
# options: PORT
4+
#
5+
# The function is to change the webmail url in apache2 or nginx configuration.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument definition
13+
WEBMAIL=$1
14+
15+
# Includes
16+
source $HESTIA/func/main.sh
17+
source $HESTIA/conf/hestia.conf
18+
19+
20+
#----------------------------------------------------------#
21+
# Verifications #
22+
#----------------------------------------------------------#
23+
24+
check_args '1' "$#" 'PMA'
25+
26+
27+
#----------------------------------------------------------#
28+
# Action #
29+
#----------------------------------------------------------#
30+
31+
# Get existing apache2 webmail alias
32+
if [ -f /etc/apache2/conf.d/roundcube.conf ]; then
33+
apache_webmail=$(tail -n+3 /etc/apache2/conf.d/roundcube.conf | grep "Alias" | { IFS=' '; read -r -a array; echo "${array[1]}"; })
34+
fi
35+
36+
# Get existing nginx webmail alias
37+
if [ -f /etc/nginx/conf.d/roundcube.inc ]; then
38+
nginx_webmail=$(cat /etc/nginx/conf.d/webmail.inc | grep "location" | { IFS=' '; read -r -a array; echo "${array[1]}"; })
39+
fi
40+
41+
# Check if alias is different for apach2
42+
if [ -z "$apache2_webmail" ];
43+
if [ ! "$apache2_webmail" = "$WEBMAIL" ]; then
44+
# Replace webmail alias in config files.
45+
sed -i "s|Alias $nginx_webmail|Alias $WEBMAIL|" /etc/apache2/conf.d/roundcube.conf
46+
47+
# Restart services
48+
$HESTIA/bin/v-restart-service apache2
49+
fi
50+
fi
51+
52+
# Check if alias is different for nginx
53+
if [ -z "$nginx_webmail" ];
54+
if [ ! "$nginx_webmail" = "$WEBMAIL" ]; then
55+
# Replace webmail alias in config files.
56+
sed -i "s|$nginx_webmail|$WEBMAIL|" /etc/nginx/conf.d/webmail.inc
57+
58+
# Restart services
59+
$HESTIA/bin/v-restart-service nginx
60+
fi
61+
fi
62+
63+
64+
#----------------------------------------------------------#
65+
# Hestia #
66+
#----------------------------------------------------------#
67+
68+
# Logging
69+
#log_event "$OK" "$ARGUMENTS"
70+
71+
exit

0 commit comments

Comments
 (0)