-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpostinst
155 lines (129 loc) · 4.25 KB
/
postinst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash -e
#DEBHELPER#
# Include alternc function (and mysql)
. /usr/lib/alternc/functions.sh
function list_php_version() {
if [[ $1 == "short" ]]; then
php_list=$(echo /usr/sbin/php-fpm* | fmt -1 | grep -oE '[0-9]+\.[0-9]+' |sed 's/[^0-9]*//g')
else
php_list=$(echo /usr/sbin/php-fpm* | fmt -1 | grep -oE '[0-9]+\.[0-9]+')
fi
echo "$php_list"
}
function remove_old_php_template() {
template_target_path="/etc/alternc/templates/php/"
find $template_target_path -regex "${template_target_path}fpm-[0-9]\.[0-9]" -delete
printf "\tAll old php-fpm template are deleted\n"
}
function remove_domains_type() {
alternc_version=$1
template_target_path="/etc/alternc/templates/apache2/"
php_version_short_list=$(list_php_version "short")
sql=""
##Retrieve only php-fpm templates
for template_path_file in "$template_target_path"*-fpm.conf
do
template_file=$(basename "$template_path_file")
if [[ $template_file =~ ^php[[:digit:]]+.* ]]; then
php_version_short=${template_file//[^[:digit:]]}
#Template found without their php version
if [[ ! ${php_version_short_list[*]} =~ (^|[[:space:]])$php_version_short($|[[:space:]]) ]]; then
rm "$template_path_file"
type_name="php$php_version_short-fpm"
sql="$sql \
DELETE FROM domaines_type WHERE \
name='$type_name' \
;"
fi
fi
done
mysql --defaults-file=/etc/alternc/my.cnf -e "$sql"
}
function generate_template_apache() {
alternc_version=$1
template_apache_path="/etc/alternc/templates/3.5/apache2/"
php_list=$(list_php_version)
if dpkg --compare-versions "${alternc_version:-0}" "<<" "3.5"; then
template_apache_path="/etc/alternc/templates/3.3/apache2/"
fi
for php_version in $php_list
do
php_version_short=${php_version//./}
for template_source_path in "$template_apache_path"*
do
template_source_name=$(basename "$template_source_path")
template_target_path=/etc/alternc/templates/apache2/${template_source_name//php-/php$php_version_short-}
cp -n "$template_source_path" "$template_target_path" || true
sed -i "$template_target_path" -e "s/%%PHPVERSION%%/$php_version/"
done
done
}
function generate_domains_type() {
alternc_version=$1
php_list=$(list_php_version)
sql=""
sql_in=""
set_default=""
##Set https option only if column is present
##During upgrade process from <3.5, schema is not yet updated
if [[ -n $(mysql_query "SHOW COLUMNS FROM domaines_type LIKE 'has_https_option';") ]]; then
set_default="has_https_option=1,"
fi
#If any php, nothing to do
if [[ -z "${php_list}" ]]; then
return 0;
fi
for php_version in $php_list
do
type_name="php${php_version/[^0-9]/}-fpm"
sql="$sql \
INSERT IGNORE INTO domaines_type SET \
name='$type_name', \
description='PHP $php_version FPM', \
target='DIRECTORY', \
entry='%SUB% IN A @@PUBLIC_IP@@', \
compatibility='txt,defmx,defmx2,mx,mx2', \
enable='ALL', \
need_dns=0, \
$set_default \
create_targetdir=1 \
;"
sql_in="$sql_in,'$type_name'"
done
sql="$sql\
UPDATE sub_domaines SET web_action='UPDATE' WHERE type IN (${sql_in/,/});
"
mysql --defaults-file=/etc/alternc/my.cnf -e "$sql"
}
alternc_version=$(dpkg-query --showformat='${Version}\n' --show alternc)
printf "Alternc PHP FPM\n"
case "$1" in
configure)
printf "\tEnabling apache modules\n"
a2enmod proxy_fcgi setenvif
service apache2 restart
printf "\tGenerating related apache template\n"
generate_template_apache "$alternc_version"
printf "\tClean php-fpm templates\n"
remove_old_php_template
printf "\tInstall php-fpm type\n"
generate_domains_type "$alternc_version"
printf "\tRemove unused php-fpm version\n"
remove_domains_type "$alternc_version"
printf "\tGenerate php fpm configuration...\n"
/usr/lib/alternc/php7-fpm force
;;
triggered)
printf "\tGenerating related apache template\n"
generate_template_apache "$alternc_version"
printf "\tUpdate php-fpm type\n"
generate_domains_type "$alternc_version"
printf "\tRemove unused php-fpm version\n"
remove_domains_type "$alternc_version"
printf "\tGenerate php fpm configuration...\n"
/usr/lib/alternc/php7-fpm force
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#