@@ -6,98 +6,243 @@ set -u
6
6
set -o pipefail
7
7
8
8
# Get absolute directory of this script
9
- CWD=" $( cd -P -- " $( dirname -- " $0 " ) " && pwd -P) "
9
+ SCRIPT_PATH=" $( cd -P -- " $( dirname -- " $0 " ) " && pwd -P) "
10
+ SCRIPT_NAME=" $( basename " ${SCRIPT_PATH} " ) "
11
+ REPO_PATH=" ${SCRIPT_PATH} /.."
12
+ README=" ${REPO_PATH} /doc/php-modules.md"
10
13
11
- IMAGE=" ${1} "
12
- ARCH=" ${2} "
13
- TAG_BASE=" ${3} "
14
- TAG_MODS=" ${4} "
15
- VERSION=" ${5:- } "
16
14
15
+ # --------------------------------------------------------------------------------------------------
16
+ # Evaluate given cli arguments
17
+ # --------------------------------------------------------------------------------------------------
17
18
18
19
# ##
19
20
# ## Show Usage
20
21
# ##
21
22
print_usage () {
22
- echo " Usage: gen-readme.sh <IMAGE> <ARCH> <TAG_BASE> <TAG_MODS> [<VERSION>]"
23
+ echo " Usage: ${SCRIPT_NAME} <IMAGE> <ARCH> <STAGE> [<VERSION>]"
24
+ }
25
+
26
+ if [ " ${# } " -lt " 3" ]; then
27
+ print_usage
28
+ exit 1
29
+ fi
30
+
31
+ IMAGE=" ${1} "
32
+ ARCH=" ${2} "
33
+ STAGE=" ${3} "
34
+ VERSION=" ${4:- } "
35
+
36
+ if [ " ${STAGE} " != " base" ] && [ " ${STAGE} " != " mods" ]; then
37
+ echo " [SKIP]: Skipping for STAGE: ${STAGE} (only 'base' and 'mods' supported"
38
+ exit 0
39
+ fi
40
+
41
+
42
+ # --------------------------------------------------------------------------------------------------
43
+ # Module functions
44
+ # --------------------------------------------------------------------------------------------------
45
+
46
+ # ##
47
+ # ## Get all modules defined in README
48
+ # ##
49
+ get_modules_from_readme () {
50
+ local php_version=" ${1} " # PHP version
51
+ local modules
52
+ modules=" $( \
53
+ grep -Eo " ext_${STAGE} _.+_${php_version} " " ${README} " \
54
+ | sed " s/^ext_${STAGE} _//g" \
55
+ | sed " s/_${php_version} //g" \
56
+ ) "
57
+ echo " ${modules} " | sort -fu
23
58
}
24
59
25
60
26
61
# ##
27
- # ## Extract PHP modules in alphabetical order and comma separated in one line
62
+ # ## Get modules available in PHP image
28
63
# ##
29
- get_modules () {
30
- current_tag=" ${1} "
31
- # Retrieve all modules
32
- PHP_MODULES=" $( docker run --rm --platform " ${ARCH} " " $( tty -s && echo ' -it' || echo) " --entrypoint=php " ${IMAGE} :${current_tag} " -m ) "
33
- ALL_MODULES=
34
-
35
- if docker run --rm --platform " ${ARCH} " " $( tty -s && echo ' -it' || echo) " --entrypoint=find " ${IMAGE} :${current_tag} " /usr/local/lib/php/extensions -name ' ioncube.so' | grep -q ioncube.so; then
36
- ALL_MODULES=" ${ALL_MODULES} ,ioncube" ;
64
+ get_modules_from_image () {
65
+ local php_version=" ${1} "
66
+ local img_tag=" ${2} "
67
+ local modules
68
+
69
+ modules=" $( \
70
+ docker run --rm " $( tty -s && echo ' -it' || echo) " --platform " ${ARCH} " --entrypoint=php " ${IMAGE} :${img_tag} " -m \
71
+ | sed ' s/Zend //g' \
72
+ | sed ' s/xdebug/Xdebug/g' \
73
+ | sed ' s/Core//g' \
74
+ | sed ' s/standard//g' \
75
+ | grep -E ' ^[a-zA-Z]' \
76
+ | sort -fu \
77
+ ) "
78
+
79
+ # Get modules which might be disabled
80
+ if docker run --rm --platform " ${ARCH} " " $( tty -s && echo ' -it' || echo) " --entrypoint=find " ${IMAGE} :${img_tag} " /usr/local/lib/php/extensions -name ' ioncube.so' | grep -q ioncube.so; then
81
+ modules=" $( printf " %s\n%s\n" " ${modules} " " ioncube" ) " ;
37
82
fi
38
83
39
- if docker run --rm --platform " ${ARCH} " " $( tty -s && echo ' -it' || echo) " --entrypoint=find " ${IMAGE} :${current_tag } " /usr/local/lib/php/extensions -name ' blackfire.so' | grep -q blackfire.so; then
40
- ALL_MODULES =" ${ALL_MODULES} , blackfire" ;
84
+ if docker run --rm --platform " ${ARCH} " " $( tty -s && echo ' -it' || echo) " --entrypoint=find " ${IMAGE} :${img_tag } " /usr/local/lib/php/extensions -name ' blackfire.so' | grep -q blackfire.so; then
85
+ modules =" $( printf " %s\n%s\n " " ${modules} " " blackfire" ) " ;
41
86
fi
42
87
43
- if docker run --rm --platform " ${ARCH} " " $( tty -s && echo ' -it' || echo) " --entrypoint=find " ${IMAGE} :${current_tag } " /usr/local/lib/php/extensions -name ' psr.so' | grep -q psr.so; then
44
- ALL_MODULES =" ${ALL_MODULES} , psr" ;
88
+ if docker run --rm --platform " ${ARCH} " " $( tty -s && echo ' -it' || echo) " --entrypoint=find " ${IMAGE} :${img_tag } " /usr/local/lib/php/extensions -name ' psr.so' | grep -q psr.so; then
89
+ modules =" $( printf " %s\n%s\n " " ${modules} " " psr" ) " ;
45
90
fi
46
91
47
- if docker run --rm --platform " ${ARCH} " " $( tty -s && echo ' -it' || echo) " --entrypoint=find " ${IMAGE} :${current_tag } " /usr/local/lib/php/extensions -name ' phalcon.so' | grep -q phalcon.so; then
48
- ALL_MODULES =" ${ALL_MODULES} , phalcon" ;
92
+ if docker run --rm --platform " ${ARCH} " " $( tty -s && echo ' -it' || echo) " --entrypoint=find " ${IMAGE} :${img_tag } " /usr/local/lib/php/extensions -name ' phalcon.so' | grep -q phalcon.so; then
93
+ modules =" $( printf " %s\n%s\n " " ${modules} " " phalcon" ) " ;
49
94
fi
50
95
51
- # Process module string into correct format for README.md
52
- PHP_MODULES=" $( echo " ${PHP_MODULES} " | sed ' s/^\[.*//g' ) " # Remove PHP Modules headlines
53
- PHP_MODULES=" ${ALL_MODULES}${PHP_MODULES} " # Append all available modules
54
- PHP_MODULES=" $( echo " ${PHP_MODULES} " | sort -fu ) " # Unique
55
- PHP_MODULES=" $( echo " ${PHP_MODULES} " | sed ' /^\s*$/d' ) " # Remove empty lines
56
- PHP_MODULES=" $( echo " ${PHP_MODULES} " | tr ' \r\n' ' ,' ) " # Newlines to commas
57
- PHP_MODULES=" $( echo " ${PHP_MODULES} " | tr ' \n' ' ,' ) " # Newlines to commas
58
- PHP_MODULES=" $( echo " ${PHP_MODULES} " | tr ' \r' ' ,' ) " # Newlines to commas
59
- PHP_MODULES=" $( echo " ${PHP_MODULES} " | sed ' s/^M/,/g' ) " # Newlines to commas
60
- PHP_MODULES=" $( echo " ${PHP_MODULES} " | sed ' s/,,/,/g' ) " # Remove PHP Modules headlines
61
- PHP_MODULES=" $( echo " ${PHP_MODULES} " | sed ' s/,/\n/g' ) " # Back to newlines
62
- PHP_MODULES=" $( echo " ${PHP_MODULES} " | sort -fu ) " # Unique
63
- PHP_MODULES=" $( echo " ${PHP_MODULES} " | sed ' /^\s*$/d' ) " # Remove empty lines
64
- PHP_MODULES=" $( echo " ${PHP_MODULES} " | tr ' \n' ' ,' ) " # Newlines to commas
65
- PHP_MODULES=" $( echo " ${PHP_MODULES} " | sed ' s/,$//g' ) " # Remove trailing comma
66
- PHP_MODULES=" $( echo " ${PHP_MODULES} " | sed ' s/,/, /g' ) " # Add space to comma
67
-
68
- echo " ${PHP_MODULES} "
96
+ # Sort alphabetically
97
+ modules=" $( echo " ${modules} " | sort -fu ) "
98
+
99
+ # Remove weired line endings
100
+ while read -r line; do
101
+ echo " ${line} " | tr -d ' \r' | tr -d ' \n'
102
+ echo
103
+ done < <( echo " ${modules} " )
69
104
}
70
105
71
106
72
107
# ##
73
- # ## Replace modules in Readme for specified PHP version
108
+ # ## Validate that README.md has all modules defined that are found in the PHP docker image
109
+ # ##
110
+ validate_readme () {
111
+ local php_version=" ${1} "
112
+ local modules_img=" ${2} " # Modules found in the PHP docker image
113
+ local stage=" ${3} " # base or mods
114
+
115
+ # Check if README.md contains all modules we have retrieved from the PHP image
116
+ while read -r line; do
117
+ module=" $( echo " ${line} " | tr ' [:upper:]' ' [:lower:]' ) "
118
+ search=" ext_${stage} _${module} _${php_version} "
119
+ if ! grep -q " ${search} " " ${README} " ; then
120
+ echo " [ERROR] Module: '${module} ' not present in ${README} for PHP ${php_version} , STAGE: ${stage} "
121
+ echo " grep -q \" ${search} \" \" ${README} \" "
122
+ exit 1
123
+ fi
124
+ done < <( echo " ${modules_img} " )
125
+ }
126
+
127
+
128
+ # ##
129
+ # ## Update README.md for a specific PHP version
74
130
# ##
75
131
update_readme () {
76
- v=" ${1} "
77
- # Those sections must exist in README.md, otherwise this script will exit with errors
78
- sed -i' ' " s|<td id=\" ${v// .} -base\" >.*<\/td>|<td id=\" ${v// .} -base\" >$( get_modules " ${TAG_BASE} " ) <\/td>|g" " ${CWD} /../README.md"
79
- sed -i' ' " s|<td id=\" ${v// .} -mods\" >.*<\/td>|<td id=\" ${v// .} -mods\" >$( get_modules " ${TAG_MODS} " ) <\/td>|g" " ${CWD} /../README.md"
132
+ local php_version=" ${1} "
133
+ local modules_image=" ${2} "
134
+ local modules_avail=" ${3} "
135
+ local stage=" ${4} " # base or mods
136
+
137
+ while read -r line_avail; do
138
+ module_avail=" $( echo " ${line_avail} " | tr ' [:upper:]' ' [:lower:]' ) "
139
+
140
+ avail=0
141
+ while read -r line_image; do
142
+ module_image=" $( echo " ${line_image} " | tr ' [:upper:]' ' [:lower:]' ) "
143
+ if [ " ${module_image} " = " ${module_avail} " ]; then
144
+ avail=1
145
+ break
146
+ fi
147
+ done < <( echo " ${modules_image} " )
148
+
149
+ if [ " ${avail} " = " 1" ]; then
150
+ sed -i " s|\(<td class=\" ext_${stage} _${module_avail} _${php_version} \" ><sup>\)\(.*\)\(<\/sup><\/td>\)|\1🗸\3|g" " ${README} "
151
+ echo " [YES] [${stage} ] PHP ${php_version} , mod: '${module_avail} '"
152
+ else
153
+ sed -i " s|\(<td class=\" ext_${stage} _${module_avail} _${php_version} \" ><sup>\)\(.*\)\(<\/sup><\/td>\)|\1\3|g" " ${README} "
154
+ echo " [NO] [${stage} ] PHP ${php_version} , mod: '${module_avail} '"
155
+ fi
156
+ done < <( echo " ${modules_avail} " )
80
157
}
81
158
82
159
160
+ # The following commented code is used to generate the README initially
161
+ # echo "<table>"
162
+ # echo " <tr>"
163
+ # echo " <th><sup>Ext</sup></th>"
164
+ # echo " <th><sup>PHP 5.2</sup></th>"
165
+ # echo " <th><sup>PHP 5.3</sup></th>"
166
+ # echo " <th><sup>PHP 5.4</sup></th>"
167
+ # echo " <th><sup>PHP 5.5</sup></th>"
168
+ # echo " <th><sup>PHP 5.6</sup></th>"
169
+ # echo " <th><sup>PHP 7.0</sup></th>"
170
+ # echo " <th><sup>PHP 7.1</sup></th>"
171
+ # echo " <th><sup>PHP 7.2</sup></th>"
172
+ # echo " <th><sup>PHP 7.3</sup></th>"
173
+ # echo " <th><sup>PHP 7.4</sup></th>"
174
+ # echo " <th><sup>PHP 8.0</sup></th>"
175
+ # echo " <th><sup>PHP 8.1</sup></th>"
176
+ # echo " <th><sup>PHP 8.2</sup></th>"
177
+ # echo " </tr>"
178
+ #
179
+ # while read -r line; do
180
+ # MOD_NAME="$( echo "${line}" )"
181
+ # MOD_LOWER="$( echo "${MOD_NAME}" | tr '[:upper:]' '[:lower:]' )"
182
+ # echo " <tr>"
183
+ # echo " <td><sup><a href=\"php_modules/${MOD_LOWER}\">${MOD_NAME}</a></sup></td>"
184
+ # echo " <td class=\"ext_mods_${MOD_LOWER}_5.2\"><sup>🗸</sup></td>"
185
+ # echo " <td class=\"ext_mods_${MOD_LOWER}_5.3\"><sup>🗸</sup></td>"
186
+ # echo " <td class=\"ext_mods_${MOD_LOWER}_5.4\"><sup>🗸</sup></td>"
187
+ # echo " <td class=\"ext_mods_${MOD_LOWER}_5.5\"><sup>🗸</sup></td>"
188
+ # echo " <td class=\"ext_mods_${MOD_LOWER}_5.6\"><sup>🗸</sup></td>"
189
+ # echo " <td class=\"ext_mods_${MOD_LOWER}_7.0\"><sup>🗸</sup></td>"
190
+ # echo " <td class=\"ext_mods_${MOD_LOWER}_7.1\"><sup>🗸</sup></td>"
191
+ # echo " <td class=\"ext_mods_${MOD_LOWER}_7.2\"><sup>🗸</sup></td>"
192
+ # echo " <td class=\"ext_mods_${MOD_LOWER}_7.3\"><sup>🗸</sup></td>"
193
+ # echo " <td class=\"ext_mods_${MOD_LOWER}_7.4\"><sup>🗸</sup></td>"
194
+ # echo " <td class=\"ext_mods_${MOD_LOWER}_8.0\"><sup>🗸</sup></td>"
195
+ # echo " <td class=\"ext_mods_${MOD_LOWER}_8.1\"><sup>🗸</sup></td>"
196
+ # echo " <td class=\"ext_mods_${MOD_LOWER}_8.2\"><sup>🗸</sup></td>"
197
+ # echo " </tr>"
198
+ # done < <(echo "${MODS_IMAGE}")
199
+ # echo "<table>"
200
+ # exit
201
+
202
+
203
+ # --------------------------------------------------------------------------------------------------
204
+ # Main functions
205
+ # --------------------------------------------------------------------------------------------------
206
+
207
+ # ##
208
+ # ## Replace module available in README for a specific PHP version
209
+ # ##
210
+ update () {
211
+ local php_version=" ${1} "
212
+ local mods_in_readme
213
+ local mods_in_image
214
+
215
+ mods_in_readme=" $( get_modules_from_readme " ${php_version} " ) "
216
+
217
+ mods_in_image=" $( get_modules_from_image " ${php_version} " " ${php_version} -${STAGE} " ) "
218
+
219
+ validate_readme " ${php_version} " " ${mods_in_image} " " ${STAGE} "
220
+ update_readme " ${php_version} " " ${mods_in_image} " " ${mods_in_readme} " " ${STAGE} "
221
+ }
222
+
223
+
224
+ # --------------------------------------------------------------------------------------------------
225
+ # Entrypoint
226
+ # --------------------------------------------------------------------------------------------------
227
+
83
228
# ##
84
229
# ## Entrypoint
85
230
# ##
86
231
if [ " ${VERSION} " = " " ]; then
87
232
# Update PHP modules for all versions at once
88
- update_readme " 5.2"
89
- update_readme " 5.3"
90
- update_readme " 5.4"
91
- update_readme " 5.5"
92
- update_readme " 5.6"
93
- update_readme " 7.0"
94
- update_readme " 7.1"
95
- update_readme " 7.2"
96
- update_readme " 7.3"
97
- update_readme " 7.4"
98
- update_readme " 8.0"
99
- update_readme " 8.1"
100
- update_readme " 8.2"
233
+ update " 5.2"
234
+ update " 5.3"
235
+ update " 5.4"
236
+ update " 5.5"
237
+ update " 5.6"
238
+ update " 7.0"
239
+ update " 7.1"
240
+ update " 7.2"
241
+ update " 7.3"
242
+ update " 7.4"
243
+ update " 8.0"
244
+ update " 8.1"
245
+ update " 8.2"
101
246
else
102
247
if [ " ${VERSION} " != " 5.2" ] \
103
248
&& [ " ${VERSION} " != " 5.3" ] \
118
263
exit 1
119
264
else
120
265
# Update PHP modules for one specific PHP version
121
- update_readme " ${VERSION} "
266
+ update " ${VERSION} "
122
267
fi
123
268
fi
0 commit comments