Translated using Weblate (Russian)
[phpmyadmin.git] / bin / transformations_generator_plugin.sh
blob8b4796ef445223828572f6710023886d9c586301
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 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
21 echo -e "Usage: ./generator_plugin.sh MIMEType MIMESubtype TransformationName [Description]\n"
22 exit 65
25 # make sure that the MIME Type, MIME Subtype and Transformation names
26 # are in the correct format
28 # make all names lowercase
29 MT="$(echo "$1" | tr '[:upper:]' '[:lower:]')"
30 MS="$(echo "$2" | tr '[:upper:]' '[:lower:]')"
31 TN="$(echo "$3" | tr '[:upper:]' '[:lower:]')"
32 # make first letter uppercase
33 MT="${MT^}"
34 MS="${MS^}"
35 TN="${TN^}"
37 # make the first letter after each underscore uppercase
38 # define the name of the main class file and of its template
39 CLASS_NAME=$(echo "$MT"_"$MS"_"$TN" | sed -e 's/_./\U&\E/g')
40 BASE_DIR="./src/Plugins/Transformations"
41 ClassFile="$BASE_DIR"/"$CLASS_NAME".php
42 Template="$BASE_DIR"/TEMPLATE
43 # define the name of the abstract class file and its template
44 AbstractClassFile="$BASE_DIR"/Abs/"$TN"TransformationsPlugin.php
45 AbstractTemplate="$BASE_DIR"/TEMPLATE_ABSTRACT
46 # replace template names with argument names
47 sed "s/\[MIMEType]/$MT/; s/\[MIMESubtype\]/$MS/; s/\[TransformationName\]/$TN/;" < $Template > "$ClassFile"
48 echo "Created $ClassFile"
50 GenerateAbstractClass=1
51 if [ -n "$4" ]; then
52 if [ "$4" == "--generate_only_main_class" ]; then
53 if [ -e "$AbstractClassFile" ]; then
54 GenerateAbstractClass=0
59 if [ $GenerateAbstractClass -eq 1 ]; then
60 # replace template names with argument names
61 sed "s/\[TransformationName\]/$TN/; s/Description of the transformation./$4/;" < $AbstractTemplate > "$AbstractClassFile"
62 echo "Created $AbstractClassFile"