-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwordpress_upload.sh
More file actions
executable file
·471 lines (418 loc) · 13.2 KB
/
Copy pathwordpress_upload.sh
File metadata and controls
executable file
·471 lines (418 loc) · 13.2 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
#!/bin/bash
# ToDo - add debug options to plugin, which are removed when uploading to wordpress.org
# options
wuFORCE=0
wuUPLOAD=0
wuRELEASE=0
wuDRY=0
wuTEST=0
wuZIP=0
while [[ $# -ge 1 ]]
do
case $1 in
-f|--force)
wuFORCE=1
;;
-u|--upload)
wuUPLOAD=1
;;
-r|--release)
wuRELEASE=1
;;
-d|--dry|--dry-run)
wuDRY=1
;;
-t|--test)
wuTEST=1
;;
-z|--zip)
wuZIP=1
;;
-h|--help)
echo ""
echo "wordpress_upload.sh beta-release :-)"
echo ""
echo " -f|--force force upload to wordpress, with pending git changes"
echo " -u|--upload upload the code to wordpress.org trunk"
echo " -r|--release upload a new release version to wordpress.org"
echo " -d|--dry|--dry-run run all checks, but stop before uploading to wordpress.org"
echo " -t|--test upload files to test-server"
echo " -z|--zip make a zip-file to install in a wordpress for testing"
echo ""
exit
;;
*)
echo "unknown option \"$1\" use --help to list possible options"
exit
;;
esac
shift
done
# check for needed commands
needed_commands=("sed" "curl" "rsync" "git" "svn" "zip" "php" "msgmerge" "msgcmp" "msgfmt")
for needed_command in ${needed_commands[@]}
do
which ${needed_command} >/dev/null 2>&1
needed_command_result=$?
if [ "${needed_command_result}" != "0" ]
then
echo "!> command ${needed_command} not found! please install..."
needed_commands_found="no"
fi
done
if [ "${needed_commands_found}" != "" ]
then
exit
fi
# ToDo - load from .conf file
plugin_name="wpsol"
plugin_name_disp="wpSOL"
# make a zip file
if [ $wuZIP == 1 ]
then
# make a temp dir
temp_zip_dir=$(mktemp -dt ${plugin_name}-zip-XXXXXX)
# copy files to temp dir
mkdir "$temp_zip_dir/${plugin_name}"
cp ./assets/readme.txt "$temp_zip_dir/${plugin_name}"
cp -R ./sources/* "$temp_zip_dir/${plugin_name}"
# generate zip filename
temp_zip_name="/tmp/${plugin_name}-test.zip"
# zip temp dir
cd "$temp_zip_dir"
zip -rq "$temp_zip_name" ./${plugin_name}
# remove temp dir
rm -r "$temp_zip_dir"
echo "zip test-file: $temp_zip_name"
exit
fi
# confirm that this is a production run
if [ $wuUPLOAD == 0 ] && [ $wuRELEASE == 0 ] && [ $wuDRY == 0 ] && [ $wuTEST == 0 ]
then
read -p "do you want to upload to wordpress.org ? [y/N] " production_ok
if [ "$production_ok" == "y" ] || [ "$production_ok" == "Y" ]
then
wuUPLOAD=1
read -p "do you want to release a new version ? [y/N] " release_ok
if [ "$release_ok" == "y" ] || [ "$release_ok" == "Y" ]
then
wuRELEASE=1
fi
else
wuDRY=1
read -p "do you want to upload to test server ? [y/N] " testupload_ok
if [ "$testupload_ok" == "Y" ] || [ "$testupload_ok" == "y" ]
then
wuTEST=1
fi
fi
fi
# check for existence of /tmp/${plugin_name}_tmp_svn
if [ -d /tmp/${plugin_name}_tmp_svn ]
then
echo "! the temporary subversion repository was not removed by a previous run...[ /tmp/${plugin_name}_tmp_svn ]"
exit
fi
if [ -d ./sources/languages ]
then
# check for existence of /tmp/i18ntools
if [ ! -d /tmp/i18ntools/ ]
then
echo "> checkout i18ntools"
svn checkout http://i18n.svn.wordpress.org/tools/trunk/ /tmp/i18ntools > /dev/null
# - fail when svn checkout failed !
if [ ! -f /tmp/i18ntools/makepot.php ]
then
echo "! i18ntools-checkout failed, stop."
rm -rf /tmp/i18ntools
exit
fi
# - fix some 'errors' in makepot.php
sed -i s/\'trunk\'/\'sources\'/ /tmp/i18ntools/makepot.php
sed -i s/\'Y-m-d\ H:i:s+00:00\'/\'Y-m-d\ 00:00:00+00:00\'/ /tmp/i18ntools/makepot.php
fi
# generate .pot file
echo "> generate .pot file"
php /tmp/i18ntools/makepot.php wp-plugin sources/ sources/languages/${plugin_name}.pot
# get Project-Id-Version from .pot file
project_id_version=$(grep 'Project-Id-Version' sources/languages/${plugin_name}.pot|cut -d\" -f2|sed s/"\\\n"//)
# set languages
languages=('nl_NL')
for lang in "${languages[@]}"
do
# update .po file from .pot
echo "> update $lang.po file from .pot"
msgmerge --update "sources/languages/${plugin_name}-$lang.po" sources/languages/${plugin_name}.pot
# compare .pot to .po (fail when incomplete)
echo "> compare .pot to $lang.po"
lang_compare=$(msgcmp "sources/languages/${plugin_name}-$lang.po" sources/languages/${plugin_name}.pot 2>&1)
if [ "$lang_compare" != "" ]
then
echo "! incomplete translation $lang"
echo "! $lang_compare"
if [ $wuFORCE == 1 ]
then
echo ">> FORCED CONTINUE..."
else
exit
fi
fi
# update Project-Id-Version in .po from .pot
sed -i s/'.*Project-Id-Version.*'/"\"$project_id_version\\\n\""/ sources/languages/${plugin_name}-nl_NL.po
# make .mo file
echo "> make $lang.mo file"
lang_make=$(msgfmt -o "sources/languages/${plugin_name}-$lang.mo" -v "sources/languages/${plugin_name}-$lang.po" 2>&1)
echo "> update $lang: $lang_make"
done
fi
# convert wordpress-readme to github-readme
echo "> convert wordpress-readme to github-readme"
if [ ! -f /tmp/wp2md ]
then
curl -s https://api.github.com/repos/wpreadme2markdown/wp2md/releases/latest \
| grep "browser_download_url.*phar" \
| cut -d : -f 2,3 \
| tr -d \" \
| wget -q -i - -O /tmp/wp2md
chmod +x /tmp/wp2md
fi
/tmp/wp2md assets/readme.txt README.md
index="## Index\n\n"
grep '^## ' README.md | sed s/'## '// | sed s/' $'// | sed s/' '/-/g > /tmp/${plugin_name}_readme
while read line
do
line_lower=$(echo "$line" | tr '[:upper:]' '[:lower:]')
index="$index* [$line](#$line_lower)\n"
done < /tmp/${plugin_name}_readme
sed -i s/"# ${plugin_name_disp}"/"# ${plugin_name_disp}\n[](https:\/\/wordpress.org\/plugins\/${plugin_name}\/)\n"/ README.md
sed -i s/"# ${plugin_name_disp}"/"# ${plugin_name_disp}\n[](https:\/\/wordpress.org\/plugins\/${plugin_name}\/)"/ README.md
sed -i s/"# ${plugin_name_disp}"/"# ${plugin_name_disp}\n[](https:\/\/wordpress.org\/plugins\/${plugin_name}\/)"/ README.md
sed -i s/"# ${plugin_name_disp}"/"# ${plugin_name_disp}\n[](https:\/\/wordpress.org\/plugins\/${plugin_name}\/)"/ README.md
sed -i s/'## Description'/"${index}\n## Description"/ README.md
imgcache=$(date +%Y%m%d)
sed -i s/'.png'/".png?rev=$imgcache"/ README.md
# Replace double emtpy lines with one
sed -i '/^$/N;/^\n$/D' README.md
if [ $wuTEST == 1 ]
then
echo "> test changes on ${plugin_name} test system"
if [ ! -f ./wordpress_upload.conf ]
then
echo "! wptest_user=\"user\""
echo "! wptest_host=\"example.org\""
echo "! wptest_dir=\"/var/www/wordpress\""
echo "! wptest_chown_user=\"user\""
echo "! wptest_chown_group=\"user\""
echo "! no wordpress_upload.conf found"
exit
else
wptest_user=""
wptest_host=""
wptest_dir=""
wptest_chown_user=""
wptest_chown_group=""
. ./wordpress_upload.conf
if [ "$wptest_user" == "" ] || [ "$wptest_host" == "" ] || [ "$wptest_dir" == "" ] || [ "$wptest_chown_user" == "" ] || [ "$wptest_chown_group" == "" ]
then
echo "! wptest_user=\"$wptest_user\""
echo "! wptest_host=\"$wptest_host\""
echo "! wptest_dir=\"$wptest_dir\""
echo "! wptest_chown_user=\"$wptest_chown_user\""
echo "! wptest_chown_group=\"$wptest_chown_group\""
echo "! wordpress_upload.conf does not contain neccesary config options, or some options are empty"
exit
fi
fi
echo "> rsync"
rsync --recursive --info=progress2 --delete ./sources/ $wptest_user@$wptest_host:$wptest_dir/wp-content/plugins/${plugin_name}/
echo "> chown wordpress www-dir"
ssh $wptest_user@$wptest_host chown -R $wptest_chown_user:$wptest_chown_group $wptest_dir/
echo "> Done!"
exit
fi
# check that git is clean
echo "> check that git is clean"
git_clean=$(git clean -n; git status --porcelain)
if [ "$git_clean" != "" ]
then
git status
echo
echo "! there are pending changes in the sources dir (use --force to override)"
if [ $wuFORCE == 1 ]
then
echo ">> FORCED CONTINUE..."
elif [ $wuDRY == 1 ] && [ $wuTEST == 0 ]
then
echo ">> just a dry-run, continue..."
elif [ $wuRELEASE == 0 ] && [ $wuDRY == 0 ]
then
read -p "continue ? [Y/n] " git_pending_continue
if [ "$git_pending_continue" == "n" ] || [ "$git_pending_continue" == "N" ]
then
exit
fi
else
exit
fi
fi
# check that git is on branch master
echo "> check that git is on branch master"
git_branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$git_branch" != "master" ]
then
git status
echo
echo "! git is not on the master-branch"
exit
fi
if [ $wuRELEASE == 1 ]
then
# check version numbers
echo "> check version numbers"
# get current version number from wordpress...
echo "> get current version number from wordpress..."
cv_plugin=$(curl -s http://plugins.svn.wordpress.org/${plugin_name}/trunk/${plugin_name}.php | grep Version | cut -d" " -f2)
# get version number from local files
echo "> get version number from local files..."
cv_local=$(grep Version sources/${plugin_name}.php | cut -d" " -f2)
cv_stable=$(grep 'Stable tag:' assets/readme.txt | cut -d" " -f3)
if [ -d sources/languages/ ]
then
cv_lang=$(grep Project-Id-Version sources/languages/${plugin_name}.pot | cut -d" " -f3 | cut -d"\\" -f1)
cv_langNL=$(grep Project-Id-Version sources/languages/${plugin_name}-nl_NL.po | cut -d" " -f3 | cut -d"\\" -f1)
else
cv_lang=$cv_local
cv_langNL=$cv_local
fi
# check matching version numbers in local files
echo "> check matching version numbers in local files"
if [ "$cv_local" != "$cv_stable" ] || [ "$cv_local" != "$cv_lang" ] || [ "$cv_local" != "$cv_langNL" ]
then
echo "> php: $cv_local"
echo "> stable: $cv_stable"
echo "> pot: $cv_lang"
echo "> nl_NL.po: $cv_langNL"
echo "! Plugin versions do not match..."
if [ $wuFORCE == 1 ]
then
echo ">> FORCED CONTINUE..."
else
exit
fi
fi
# check changelog for current version
echo "> check changelog for current version"
cv_changelog=$(grep "= $cv_local =" assets/readme.txt)
if [ "$cv_changelog" == "" ]
then
echo ">! No Changelog for version $cv_local"
exit
fi
# check for version number increase
echo "> check for version number increase"
if [ "$cv_plugin" == "$cv_local" ] || [ "$cv_plugin" == "$cv_stable" ] || [ "$cv_plugin" == "$cv_lang" ] || [ "$cv_plugin" == "$cv_langNL" ]
then
echo "> WP.org: $cv_plugin"
echo "> php: $cv_local"
echo "> stable: $cv_stable"
echo "> pot: $cv_lang"
echo "> nl_NL.po: $cv_langNL"
echo "! Plugin version not updated..."
if [ $wuFORCE == 1 ]
then
echo ">> FORCED CONTINUE..."
else
exit
fi
fi
# confirm version number increase
read -p "Increase version number from $cv_plugin to $cv_local ? [y/N] " increase_ok
if [ "$increase_ok" != "y" ] && [ "$increase_ok" != "Y" ]
then
echo "stop!"
exit
fi
fi
if [ $wuDRY == 1 ]
then
echo "! dry-run, no upload"
exit
fi
# subversion checkout
svn checkout http://plugins.svn.wordpress.org/${plugin_name} /tmp/${plugin_name}_tmp_svn
if [ ! -f /tmp/${plugin_name}_tmp_svn/trunk/${plugin_name}.php ]
then
if [ ! -d /tmp/${plugin_name}_tmp_svn/trunk/ ]
then
echo "! plugin-checkout failed"
rm -rf /tmp/${plugin_name}_tmp_svn
exit
fi
# the main-file is not in svn, is this a new plugin?
read -p "The file svn://trunk/${plugin_name}.php does not exist, is this the first commit for this plugin ? [y/N] " plugin_svn_init
if [ "$plugin_svn_init" != "y" ] && [ "$plugin_svn_init" != "Y" ]
then
rm -rf /tmp/${plugin_name}_tmp_svn
exit
fi
fi
# rsync git release to svn trunk
rsync --recursive --delete sources/ /tmp/${plugin_name}_tmp_svn/trunk/
# cp readme file to svn trunk
cp assets/readme.txt /tmp/${plugin_name}_tmp_svn/trunk/readme.txt
# cp screenshots to svn assets
cp assets/screenshot* /tmp/${plugin_name}_tmp_svn/assets/
# cp icons to svn assets
cp assets/icon* /tmp/${plugin_name}_tmp_svn/assets/
# cp banners to svn assets
cp assets/banner* /tmp/${plugin_name}_tmp_svn/assets/
# changedir, remember current dir
startdir=$(pwd)
cd /tmp/${plugin_name}_tmp_svn
# add new and delete removed files from subversion
files_to_add=$(svn status | grep "^\?")
if [ "$files_to_add" != "" ]
then
svn status | grep "^\?" | sed 's/? *//' | xargs -d'\n' svn add
fi
files_to_rm=$(svn status | grep "^\!")
if [ "$files_to_rm" != "" ]
then
svn status | grep "^\!" | sed 's/? *//' | xargs -d'\n' svn rm
fi
# copy the code to a tags/VERSION directory
if [ $wuRELEASE == 1 ]
then
echo "> make a tags/$cv_local directory on the wp.org SVN-server"
cp -r trunk "tags/$cv_local"
svn add "tags/$cv_local"
fi
# check-in the changes
if [ $wuRELEASE == 1 ]
then
commit_msg="auto-commit [] stable: $cv_plugin -> $cv_local"
else
read -p "please enter a commit message: " trunk_commit_msg
if [ "$trunk_commit_msg" == "" ]
then
echo "! you need to specify a commit message"
# remove temporary svn repo
rm -rf /tmp/${plugin_name}_tmp_svn
exit
fi
commit_msg="auto-commit [] trunk: $trunk_commit_msg"
fi
echo "> commit svn with msg: \"$commit_msg\""
svn ci -m "$commit_msg"
# go back to start dir
cd "$startdir"
# remove temporary svn repo
rm -rf /tmp/${plugin_name}_tmp_svn
echo "> Done!"
echo "> you should:"
if [ $wuRELEASE == 1 ]
then
echo "> git push && git tag $cv_local && git push origin $cv_local"
else
echo "> git push"
fi