-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathomekash
executable file
·743 lines (673 loc) · 21.2 KB
/
omekash
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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
#!/bin/bash
# Configurations: Accessible from hooks and can be overwritten by omeka-overrides
rootuser="root"
rootpass="root"
httproot="/var/www/html"
wwwuser="www-data"
wwwgroup="www-data"
# Functions
function usagehint {
if [ -z "$1" ]; then
>&2 echo "Usage: omekash (new|rm|clone <origslug>|log|update|plug|unplug <plugin>|theme|untheme <theme>|archive <zipname>|restore <zipname>) <slug> [--vanilla] [--branch <branch>] [--repo <repository>] [--url <url>]"
else
case "$1" in
"new")
>&2 echo -e "omekash new <slug>: Set up a new named Omeka instance. You will need to visit http://<server root>/omeka-<slug>/install/install.php to initialize its parameters."\
"\n"\
"\nAdditional parameters:"\
"\n--branch <branch>: Specify the branch to check out Omeka from. Default: master"\
"\n--repo <repository>: Specify the repository to check out Omeka from. Default: https://github.com/omeka/Omeka.git"\
"\n--url <url>: Use a download URL to a zip or tarball file instead of Git."\
"\n--vanilla: Skip the preconfigured omekash-after-new hook (if applicable)."\
;;
"rm")
>&2 echo -e "omekash rm <slug>: Remove the named Omeka instance."\
"\n"\
"\nAdditional parameters:"\
"\n--vanilla: Skip the preconfigured omekash-after-rm hook (if applicable)."\
;;
"clone")
>&2 echo -e "omekash clone <oldslug> <newslug>: Make a copy of the named Omeka instance."\
"\n"\
"\nAdditional parameters:"\
"\n--vanilla: Skip the preconfigured omekash-after-clone hook (if applicable)."\
;;
"log")
>&2 echo -e "omekash log <slug>: Show the logs of the named Omeka instance."\
"\n"\
"\nAdditional parameters:"\
"\n--vanilla: Skip the preconfigured omekash-after-log hook (if applicable)."\
;;
"update")
>&2 echo -e "omekash update <slug>: Update the named Omeka instance."\
"\nNOTE: This command can only be used on Omeka instances created from Git repositories."\
"\n"\
"\nAdditional parameters:"\
"\n--vanilla: Skip the preconfigured omekash-after-update hook (if applicable)."\
;;
"plug")
>&2 echo -e "omekash plug <slug> [--repo <repository>|--url <url>]: Download and add a plugin to the named Omeka instance. You must provide either a --repo or --url parameter, but not both."\
"\n"\
"\nAdditional parameters:"\
"\n--branch <branch>: Specify the branch to check out the plugin from. Can only be used with --repo. Default: master"\
"\n--repo <repository>: Specify the repository to check out the plugin from."\
"\n--url <url>: Specify the URL to a zip or tarball file to download the plugin from."\
"\n--vanilla: Skip the preconfigured omekash-after-plug hook (if applicable)."\
;;
"unplug")
>&2 echo -e "omekash unplug <plugin-name> <slug>: Directly remove a plugin from the named Omeka instance."\
"\nWARNING: Make sure to uninstall the plugin first!"\
"\n"\
"\nAdditional parameters:"\
"\n--vanilla: Skip the preconfigured omekash-after-unplug hook (if applicable)."\
;;
"theme")
>&2 echo -e "omekash theme <slug> [--repo <repository>|--url <url>]: Download and add a theme from the given URL to the named Omeka instance. You must provide either a --repo or --url parameter, but not both."\
"\n"\
"\nAdditional parameters:"\
"\n--branch <branch>: Specify the branch to check out the theme from. Can only be used with --repo. Default: master"\
"\n--repo <repository>: Specify the repository to check out the theme from."\
"\n--url <url>: Specify the URL to a zip or tarball file to download the theme from."\
"\n--vanilla: Skip the preconfigured omekash-after-theme hook (if applicable)."\
;;
"untheme")
>&2 echo -e "omekash untheme <theme-name> <slug>: Directly remove a theme from the named Omeka instance."\
"\nWARNING: Make sure that the theme is not currently used!"\
"\n"\
"\nAdditional parameters:"\
"\n--vanilla: Skip the preconfigured omekash-after-untheme hook (if applicable)."\
;;
"archive")
>&2 echo -e "omekash archive <zipname> <slug>: Save the named Omeka instance and its associated database in the given zip file."\
"\n"\
"\nAdditional parameters:"\
"\n--vanilla: Skip the preconfigured omekash-after-archive hook (if applicable)."\
;;
"restore")
>&2 echo -e "omekash restore <zipname> <slug>: Restore the Omeka instance archived in the given zip file (can be a local path or a download URL) to the new name. The new instance can be accessed at http://<server root>/omeka-<slug>."\
"\n"\
"\nAdditional parameters:"\
"\n--vanilla: Skip the preconfigured omekash-after-restore hook (if applicable)."\
;;
*)
>&2 echo "Unknown command: $1"
usagehint
;;
esac
fi
exit 2
}
function fail {
>&2 echo "FAIL"
exit 1
}
# omekanew <slug> <targetdir> <branch> <repository> <dbusername> <dbpassword>
function omekanew {
# Capture arguments
slug=$1
targetdir=$2
branch=$3
repository=$4
dbusername=$5
dbpassword=$6
# Stop if the target already exists
if [ -d "$targetdir" ]; then
>&2 echo "The target directory ${targetdir} already exists. Please remove this installation before continuing."
fail
fi
# Create commands for generating database and database user
sqlfile=`mktemp`
echo "CREATE DATABASE omeka_${slug};" >> $sqlfile
echo "CREATE DATABASE omeka_${slug}_test;" >> $sqlfile
echo "CREATE USER ${dbusername} IDENTIFIED BY '"${dbpassword}"';" >> $sqlfile
echo "GRANT ALL ON omeka_${slug}.* TO ${dbusername};" >> $sqlfile
echo "GRANT ALL ON omeka_${slug}_test.* TO ${dbusername};" >> $sqlfile
echo "FLUSH PRIVILEGES;" >> $sqlfile
# Execute commands with mysql
>&2 echo -n "Setting up MySQL database and user... "
mysql -u "$rootuser" --password="$rootpass" < $sqlfile || fail
>&2 echo "DONE"
# Clone Omeka to target directory
>&2 echo "Downloading Omeka..."
git clone -q --branch "$branch" --recursive "$repo" "$targetdir" || fail
>&2 echo "Omeka downloaded."
# Start configuring Omeka
>&2 echo -n "Configuring Omeka... "
# Fill db.ini
dbini="${targetdir}/db.ini"
: > $dbini
echo '[database]' >> $dbini
echo 'host="localhost"' >> $dbini
echo "username=\"${dbusername}\"" >> $dbini
echo "password=\"${dbpassword}\"" >> $dbini
echo "dbname=\"omeka_${slug}\"" >> $dbini
echo 'prefix="omeka_"' >> $dbini
echo 'charset="utf8"' >> $dbini
# Fill .htaccess
cp "${targetdir}/.htaccess.changeme" "${targetdir}/.htaccess" || fail
echo 'SetEnv APPLICATION_ENV development' >> "${targetdir}/.htaccess"
# Fill config.ini
cp "${targetdir}/application/config/config.ini.changeme" "${targetdir}/application/config/config.ini" || fail
# Fill tests/config.ini
testsconfig="${targetdir}/application/tests/config.ini"
teststemp="/tmp/omeka_${slug}_test"
mkdir $teststemp
: > $testsconfig
echo '[testing]' >> $testsconfig
echo 'db.host="localhost"' >> $testsconfig
echo "db.username=\"${dbusername}\"" >> $testsconfig
echo "db.password=\"${dbpassword}\"" >> $testsconfig
echo "db.dbname=\"omeka_${slug}_test\"" >> $testsconfig
echo 'paths.imagemagick="/usr/bin"' >> $testsconfig
echo "paths.tempDir=\"${teststemp}\"" >> $testsconfig
echo '[site]' >> $testsconfig
echo 'debug.exceptions=0' >> $testsconfig
echo 'debug.request=0' >> $testsconfig
echo 'log.sql=0' >> $testsconfig
echo 'log.errors=0' >> $testsconfig
echo 'jobs.dispatcher.default="Omeka_Job_Dispatcher_Adapter_Synchronous"' >> $testsconfig
echo 'locale=""' >> $testsconfig
# Add log file if it does not exist
touch "${targetdir}/application/logs/errors.log"
# Set permissions
chown -R "${wwwuser}:${wwwgroup}" "$targetdir" || fail
# Done configuring Omeka
>&2 echo "DONE"
# Clean up
>&2 echo -n "Cleaning up... "
rm -f $sqlfile || fail
>&2 echo "DONE"
# Instruct user to visit install/install.php
>&2 echo "Omeka is now installed. Visit /omeka-${slug}/install/install.php to complete setup."
}
# omekarm <slug> <targetdir> <dbusername>
function omekarm {
# Capture arguments
slug=$1
targetdir=$2
dbusername=$3
# Stop if the target doesn't already exist
if [ ! -d "$targetdir" ]; then
>&2 echo "The target directory ${targetdir} does not exist. Please ensure that there is an Omeka installation there."
fail
fi
# Blow up database and database user
sqlfile=`mktemp`
echo "DROP DATABASE omeka_${slug};" >> $sqlfile
echo "DROP DATABASE omeka_${slug}_test;" >> $sqlfile
echo "DROP USER '"${dbusername}"';" >> $sqlfile
>&2 echo -n "Clearing MySQL database and user... "
mysql -u "$rootuser" --password="$rootpass" < $sqlfile || fail
>&2 echo "DONE"
# Blow up the directory
>&2 echo -n "Removing installation directory... "
rm -Rf $targetdir || fail
rm -Rf "/tmp/omeka_${slug}_test"
>&2 echo "DONE"
# Clean up
>&2 echo -n "Cleaning up... "
rm -f $sqlfile || fail
>&2 echo "DONE"
}
# omekaclone <origslug> <origdir> <origusername> <origpassword> <slug> <targetdir> <dbusername> <dbpassword>
function omekaclone {
# Capture arguments
origslug=$1
origdir=$2
origusername=$3
origpassword=$4
slug=$5
targetdir=$6
dbusername=$7
dbpassword=$8
# Stop if the target already exists
if [ -d "$targetdir" ]; then
>&2 echo "The target directory ${targetdir} already exists. Please remove this installation before continuing."
fail
fi
# Stop if the original doesn't already exist
if [ ! -d "$origdir" ]; then
>&2 echo "The source directory ${origdir} does not exist. Please ensure that there is an Omeka installation there."
fail
fi
# Create commands for generating database user
sqlfile=`mktemp`
echo "CREATE DATABASE omeka_${slug};" >> $sqlfile
echo "CREATE DATABASE omeka_${slug}_test;" >> $sqlfile
echo "CREATE USER ${dbusername} IDENTIFIED BY '"${dbpassword}"';" >> $sqlfile
echo "GRANT ALL ON omeka_${slug}.* TO ${dbusername};" >> $sqlfile
echo "GRANT ALL ON omeka_${slug}_test.* TO ${dbusername};" >> $sqlfile
echo "FLUSH PRIVILEGES;" >> $sqlfile
# Run MySQL commands
>&2 echo -n "Creating new MySQL database and user... "
mysql -u "$rootuser" --password="$rootpass" < $sqlfile || fail
>&2 echo "DONE"
# Dump and reimport
>&2 echo -n "Copying MySQL databases... "
mysqldump "omeka_${origslug}" -u "$rootuser" --password="$rootpass" | mysql "omeka_${slug}" -u "$rootuser" --password="$rootpass" || fail
mysqldump "omeka_${origslug}_test" -u "$rootuser" --password="$rootpass" | mysql "omeka_${slug}_test" -u "$rootuser" --password="$rootpass" || fail
>&2 echo "DONE"
# Copy directories
>&2 echo -n "Copying Omeka Installation... "
cp -Rfp $origdir $targetdir || fail
>&2 echo "DONE"
# Start configuring Omeka
>&2 echo -n "Reconfiguring Omeka... "
# Fill db.ini
dbini="${targetdir}/db.ini"
: > $dbini
echo '[database]' >> $dbini
echo 'host="localhost"' >> $dbini
echo "username=\"${dbusername}\"" >> $dbini
echo "password=\"${dbpassword}\"" >> $dbini
echo "dbname=\"omeka_${slug}\"" >> $dbini
echo 'prefix="omeka_"' >> $dbini
echo 'charset="utf8"' >> $dbini
# Fill .htaccess
rm -f "${targetdir}/.htaccess" || fail
cp "${targetdir}/.htaccess.changeme" "${targetdir}/.htaccess" || fail
echo 'SetEnv APPLICATION_ENV development' >> "${targetdir}/.htaccess"
# Fill config.ini (keep original for now)
# rm -f "${targetdir}/application/config/config.ini" || fail
# cp "${targetdir}/application/config/config.ini.changeme" "${targetdir}/application/config/config.ini" || fail
# Fill tests/config.ini
testsconfig="${targetdir}/application/tests/config.ini"
teststemp="/tmp/omeka_${slug}_test"
mkdir $teststemp
: > $testsconfig
echo '[testing]' >> $testsconfig
echo 'db.host="localhost"' >> $testsconfig
echo "db.username=\"${dbusername}\"" >> $testsconfig
echo "db.password=\"${dbpassword}\"" >> $testsconfig
echo "db.dbname=\"omeka_${slug}_test\"" >> $testsconfig
echo 'paths.imagemagick="/usr/bin"' >> $testsconfig
echo "paths.tempDir=\"${teststemp}\"" >> $testsconfig
echo '[site]' >> $testsconfig
echo 'debug.exceptions=0' >> $testsconfig
echo 'debug.request=0' >> $testsconfig
echo 'log.sql=0' >> $testsconfig
echo 'log.errors=0' >> $testsconfig
echo 'jobs.dispatcher.default="Omeka_Job_Dispatcher_Adapter_Synchronous"' >> $testsconfig
echo 'locale=""' >> $testsconfig
# Add log file if it does not exist
touch "${targetdir}/application/logs/errors.log"
# Done configuring Omeka
>&2 echo "DONE"
# Clean up
>&2 echo -n "Cleaning up... "
rm -f $sqlfile || fail
>&2 echo "DONE"
}
# omekaarchive <slug> <targetdir> <filename>
function omekaarchive {
# Capture arguments
slug=$1
targetdir=$2
filename=$3
if [[ "${filename:0:1}" != "/" ]]; then
filename="`pwd`/$filename"
fi
# Stop if the target does not exist
if [ ! -d "$targetdir" ]; then
>&2 echo "The target directory ${targetdir} does not exist."
fail
fi
# Make temporary directory
tempdir=`mktemp -d`
mkdir "${tempdir}/omekapickle" || fail
# Copy installation
>&2 echo -n "Copying Omeka installation... "
ln -s "$targetdir" "${tempdir}/omekapickle/omeka" || fail
>&2 echo "DONE"
# Dump SQL
>&2 echo -n "Dumping SQL... "
mysqldump "omeka_${slug}" -u "$rootuser" --password="$rootpass" > "${tempdir}/omekapickle/main.sql" || fail
mysqldump "omeka_${slug}_test" -u "$rootuser" --password="$rootpass" > "${tempdir}/omekapickle/test.sql" || fail
>&2 echo "DONE"
# Create zip at filename
>&2 echo -n "Creating archive... "
pushd "${tempdir}/omekapickle" > /dev/null
zip -r9q "$filename" . || { popd; fail; }
popd > /dev/null
>&2 echo "DONE"
# Remove temporary
>&2 echo -n "Cleaning up... "
rm -Rf "$tempdir"
# Done archiving
>&2 echo "DONE"
}
# omekarestore <slug> <targetdir> <filename> <dbusername> <dbpassword>
function omekarestore {
# Capture arguments
slug=$1
targetdir=$2
filename=$3
dbusername=$4
dbpassword=$5
# Stop if the target already exists
if [ -d "$targetdir" ]; then
>&2 echo "The target directory ${targetdir} already exists."
fail
fi
# Make temporary directory
tempdir=`mktemp -d`
# Unzip contents
>&2 echo -n "Unzipping... "
extractto "$filename" "$tempdir" || fail
>&2 echo "DONE"
# Generate new user
>&2 echo -n "Creating new MySQL database and user... "
sqlfile=`mktemp`
echo "CREATE DATABASE omeka_${slug};" >> $sqlfile
echo "CREATE DATABASE omeka_${slug}_test;" >> $sqlfile
echo "CREATE USER ${dbusername} IDENTIFIED BY '"${dbpassword}"';" >> $sqlfile
echo "GRANT ALL ON omeka_${slug}.* TO ${dbusername};" >> $sqlfile
echo "GRANT ALL ON omeka_${slug}_test.* TO ${dbusername};" >> $sqlfile
echo "FLUSH PRIVILEGES;" >> $sqlfile
mysql -u "$rootuser" --password="$rootpass" < $sqlfile || fail
rm -f "$sqlfile"
>&2 echo "DONE"
# Import the SQL files
>&2 echo -n "Importing databases... "
mysql "omeka_${slug}" -u "$dbusername" --password="$dbpassword" < "${tempdir}/main.sql" || fail
mysql "omeka_${slug}_test" -u "$dbusername" --password="$dbpassword" < "${tempdir}/test.sql" || fail
>&2 echo "DONE"
# Move the extracted Omeka instance
>&2 echo -n "Moving Omeka into position... "
mv -f "${tempdir}/omeka" "$targetdir" || fail
>&2 echo "DONE"
# Start configuring Omeka
>&2 echo -n "Reconfiguring Omeka... "
# Fill db.ini
dbini="${targetdir}/db.ini"
: > $dbini
echo '[database]' >> $dbini
echo 'host="localhost"' >> $dbini
echo "username=\"${dbusername}\"" >> $dbini
echo "password=\"${dbpassword}\"" >> $dbini
echo "dbname=\"omeka_${slug}\"" >> $dbini
echo 'prefix="omeka_"' >> $dbini
echo 'charset="utf8"' >> $dbini
# Fill .htaccess
rm -f "${targetdir}/.htaccess" || fail
cp -p "${targetdir}/.htaccess.changeme" "${targetdir}/.htaccess" || fail
echo 'SetEnv APPLICATION_ENV development' >> "${targetdir}/.htaccess"
# Fill tests/config.ini
testsconfig="${targetdir}/application/tests/config.ini"
teststemp="/tmp/omeka_${slug}_test"
mkdir $teststemp
: > $testsconfig
echo '[testing]' >> $testsconfig
echo 'db.host="localhost"' >> $testsconfig
echo "db.username=\"${dbusername}\"" >> $testsconfig
echo "db.password=\"${dbpassword}\"" >> $testsconfig
echo "db.dbname=\"omeka_${slug}_test\"" >> $testsconfig
echo 'paths.imagemagick="/usr/bin"' >> $testsconfig
echo "paths.tempDir=\"${teststemp}\"" >> $testsconfig
echo '[site]' >> $testsconfig
echo 'debug.exceptions=0' >> $testsconfig
echo 'debug.request=0' >> $testsconfig
echo 'log.sql=0' >> $testsconfig
echo 'log.errors=0' >> $testsconfig
echo 'jobs.dispatcher.default="Omeka_Job_Dispatcher_Adapter_Synchronous"' >> $testsconfig
echo 'locale=""' >> $testsconfig
# Add log file if it does not exist
touch "${targetdir}/application/logs/errors.log"
# Set permissions
chown -R "${wwwuser}:${wwwgroup}" "$targetdir"
# Remove temporary
>&2 echo -n "Cleaning up... "
rm -Rf "$tempdir"
# Done restoring
>&2 echo "DONE"
}
# extractto <source> <target>
function extractto {
# Capture arguments
source="$1"
target="$2"
# If from an online source, download to temporary file
if [[ "$source" == http://* ]] || [[ "$source" == https://* ]]; then
fname=`mktemp`
rm -f "$fname"
fromlocal=0
wget -q -O "$fname" "$source"
# Otherwise, reference the local file directly
else
fname="$source"
fromlocal=1
fi
# Extract form the local file
extension="${source##*.}"
case "$extension" in
"zip")
unzip -qq "$fname" -d "$target" || failed=1
;;
"tgz")
tar -xzf "$fname" -C "$target" || failed=1
;;
"tar")
tar -xf "$fname" -C "$target" || failed=1
;;
*)
echo "Unsupported extension \"$extension\". Expected zip, tgz or tar."
failed=1
;;
esac
# If from an online source, delete the temporary file
if [ -z $fromlocal ]; then
rm -f "$fname"
fi
# Exit if error
if [ ! -z "$failed" ]; then
exit 2
fi
}
# Capture required parameters
if [ -z "$1" ]; then
usagehint
fi
if [ -z "$2" ]; then
usagehint "$1"
fi
# Capture the call to this script (command) and the verb used (verb). Accessible from hooks.
command=$0
verb=$1
case $verb in
"new")
slug=$2
shift
;;
"rm")
slug=$2
shift
;;
"clone")
if [ -z "$3" ]; then
usagehint "clone"
fi
origslug=$2
slug=$3
shift
shift
;;
"log")
slug=$2
shift
;;
"update")
slug=$2
shift
;;
"plug")
slug=$2
shift
;;
"unplug")
if [ -z "$3" ]; then
usagehint "unplug"
fi
slug=$3
plugslug=$2
shift
shift
;;
"theme")
slug=$2
shift
;;
"untheme")
if [ -z "$3" ]; then
usagehint "untheme"
fi
slug=$3
themeslug=$2
shift
shift
;;
"archive")
if [ -z "$3" ]; then
usagehint "archive"
fi
slug=$3
zipname=$2
shift
shift
;;
"restore")
if [ -z "$3" ]; then
usagehint "restore"
fi
slug=$3
zipname=$2
shift
shift
;;
*)
usagehint
;;
esac
# Derived parameter defaults: Accessible from hooks
origdir="${httproot}/omeka-${origslug}"
origuser="omeka${origslug}"
origpass="omeka${origslug}root1108"
targetdir="${httproot}/omeka-${slug}"
dbuser="omeka${slug}"
dbpass="omeka${slug}root1108"
branch="master"
repo="https://github.com/omeka/Omeka.git"
url=""
vanilla=""
# (optional) Override configurations and derived parameter defaults
if [ -f "`dirname "$command"`/omekash-config" ]; then
source "`dirname "$command"`/omekash-config"
fi
# Capture optional parameters
while [ ! -z "$2" ]
do
shift
case $1 in
"--branch")
shift
if [ -z "$1" ]; then
usagehint $verb
fi
branch=$1
;;
"--repo")
shift
if [ -z "$1" ]; then
usagehint $verb
fi
repo=$1
;;
"--url")
shift
if [ -z "$1" ]; then
usagehint $verb
fi
url=$1
;;
"--vanilla")
shift
vanilla=1
;;
esac
done
# Before-action hooks
if [ -f "`dirname "$command"`/omekash-before" ] && [ -z $vanilla ]; then
source "`dirname "$command"`/omekash-before"
fi
if [ -f "`dirname "$command"`/omekash-before-$verb" ] && [ -z $vanilla ]; then
source "`dirname "$command"`/omekash-before-$verb"
fi
# Run the right command
case $verb in
"new")
omekanew "$slug" "$targetdir" "$branch" "$repo" "$dbuser" "$dbpass"
;;
"rm")
omekarm "$slug" "$targetdir" "$dbuser"
;;
"clone")
omekaclone "$origslug" "$origdir" "$origuser" "$origpass" "$slug" "$targetdir" "$dbuser" "$dbpass"
;;
"log")
tail -f "$targetdir/application/logs/errors.log"
;;
"update")
pushd "$targetdir" >/dev/null 2>&1
git pull -q
popd >/dev/null 2>&1
;;
"plug")
if [ ! -z "$url" ]; then
extractto "$url" "$targetdir/plugins"
elif [ ! -z "$repo" ]; then
pushd "$targetdir/plugins" > /dev/null
git clone -q "$repo" --branch "$branch" --recursive
popd > /dev/null
else
>&2 echo "You must specify a plugin download URL in a --url parameter, or a repository in a --repo parameter."
failed=1
fi
if [ ! -z "$failed" ]; then
exit 2
fi
;;
"unplug")
rm -Rf "$targetdir/plugins/$plugslug"
;;
"theme")
if [ ! -z "$url" ]; then
extractto "$url" "$targetdir/themes"
elif [ ! -z "$repo" ]; then
pushd "$targetdir/plugins" > /dev/null
git clone -q "$repo" --branch "$branch" --recursive
popd > /dev/null
else
>&2 echo "You must specify a theme download URL in a --url parameter, or a repository in a --repo parameter."
failed=1
fi
if [ ! -z "$failed" ]; then
exit 2
fi
;;
"untheme")
rm -Rf "$targetdir/themes/$themeslug"
;;
"archive")
omekaarchive "$slug" "$targetdir" "$zipname"
;;
"restore")
omekarestore "$slug" "$targetdir" "$zipname" "$dbuser" "$dbpass"
;;
esac
# After-action hooks
# NOTE: These don't run if the command fails!
if [ -f "`dirname "$command"`/omekash-after-$verb" ] && [ -z $vanilla ]; then
source "`dirname "$command"`/omekash-after-$verb"
fi
if [ -f "`dirname "$command"`/omekash-after" ] && [ -z $vanilla ]; then
source "`dirname "$command"`/omekash-after"
fi