Translated using Weblate (Estonian)
[phpmyadmin.git] / scripts / transformations_generator_plugin.sh
blob9d6ba28d542b84b9299b0b0f8c36bf6597757614
1 #!/bin/bash
3 # Shell script that creates a new transformation plug-in (both main and
4 # abstract class) using a template.
6 # The 'description' parameter will add a new entry in the language file.
7 # Watch out for special escaping.
9 # $1: MIMEType
10 # $2: MIMESubtype
11 # $3: Transformation Name
12 # $4: (optional) Description
14 # Do not run as CGI
15 if [ -n "$GATEWAY_INTERFACE" ] ; then
16 echo 'Can not invoke as CGI!'
17 exit 1
20 echo $#
21 if [ $# -ne 3 -a $# -ne 4 ]; then
22 echo -e "Usage: ./generator_plugin.sh MIMEType MIMESubtype TransformationName [Description]\n"
23 exit 65
26 # make sure that the MIME Type, MIME Subtype and Transformation names
27 # are in the correct format
29 # make all names lowercase
30 MT="`echo $1 | tr [:upper:] [:lower:]`"
31 MS="`echo $2 | tr [:upper:] [:lower:]`"
32 TN="`echo $3 | tr [:upper:] [:lower:]`"
33 # make first letter uppercase
34 MT="${MT^}"
35 MS="${MS^}"
36 TN="${TN^}"
37 # make the first letter after each underscore uppercase
38 MT="`echo $MT`"
39 MT="`echo $MT | sed -e 's/_./\U&\E/g'`"
40 MS="`echo $MS`"
41 MS="`echo $MS | sed -e 's/_./\U&\E/g'`"
42 TN="`echo $TN`"
43 TN="`echo $TN | sed -e 's/_./\U&\E/g'`"
45 # define the name of the main class file and of its template
46 ClassFile=$MT\_$MS\_$TN.php
47 Template=TEMPLATE
48 # define the name of the abstract class file and its template
49 AbstractClassFile=abs/"$TN"TransformationsPlugin.php
50 AbstractTemplate=TEMPLATE_ABSTRACT
51 # replace template names with argument names
52 sed "s/\[MIMEType]/$MT/; s/\[MIMESubtype\]/$MS/; s/\[TransformationName\]/$TN/;" < $Template > $ClassFile
53 echo "Created $ClassFile"
55 GenerateAbstractClass=1
56 if [ -n $4 ]; then
57 if [ "$4" == "--generate_only_main_class" ]; then
58 if [ -e $AbstractClassFile ]; then
59 GenerateAbstractClass=0
64 if [ $GenerateAbstractClass -eq 1 ]; then
65 # replace template names with argument names
66 sed "s/\[TransformationName\]/$TN/; s/Description of the transformation./$4/;" < $AbstractTemplate > $AbstractClassFile
67 echo "Created $AbstractClassFile"
70 echo ""