Updated Esperanto translation
[banshee.git] / src / create-extension
blobdcf27fd2a866615a9f66ad3bc138f1acbaee81d9
1 #!/bin/bash
3 function show_extension_points () {
4 echo "Valid extension points are:"
5 echo
6 for point in $V_EX_POINTS; do
7 echo " ${point}"
8 done
9 echo
12 function find_extension_points () {
13 for file in $(find -iname '*addin.xml'); do
14 points=$(grep '<ExtensionPoint' $file | \
15 awk 'BEGIN { FS="=" } { print $2 }' | \
16 sed 's,[>"],,g')
18 id=$(awk 'BEGIN { FS="id=\"" } { print $2 }' < $file | \
19 awk 'BEGIN { FS="\" " } { print $1 }')
21 [[ -z $points || -z $id ]] && continue
23 for point in $points; do
24 V_EX_POINTS="${V_EX_POINTS} ${point}"
25 V_EX_POINTS_IDS="${V_EX_POINTS_IDS} ${point},${id}"
26 done
27 done
30 function usage () {
31 echo "Usage: $0 <name> <path> [<extension-point> ...]"
32 echo
33 echo "Example: ./create-extension Banshee.InternetRadio Extensions/"
34 echo
35 show_extension_points
36 exit 1
39 find_extension_points
41 EX_NAME=$1; test -z $EX_NAME && usage || shift
42 EX_PATH="Extensions"
44 case "$1" in
45 \/*) ;;
46 *) test -z $1 || EX_PATH="$1"; shift ;;
47 esac
49 if test ! -d "${EX_PATH}"; then
50 echo "Extension root path \`${EX_PATH}' does not exist."
51 exit 1
54 EX_PATH="${EX_PATH}/${EX_NAME}"
55 TEMPLATE_PATH="Extensions/Template"
57 if test ! -d $TEMPLATE_PATH; then
58 echo "Extension template path \`${TEMPLATE_PATH}' does not exist."
59 echo "This script must be run from the src/ directory of a Banshee checkout"
60 exit 1
63 if test -d "${EX_PATH}"; then
64 echo "Extension \`${EX_PATH}' already exists."
65 exit 1
68 for point in $@; do
69 found=0
70 for v_point in $V_EX_POINTS; do
71 if [ "x$point" = "x$v_point" ]; then
72 found=1
73 break
75 done
76 if [ $found -eq 0 ]; then
77 echo "Extension point \`${point}' is not valid."
78 echo
79 show_extension_points
80 exit 1
82 done
84 echo "Creating Extension ($EX_PATH)..."
86 for point in $@; do
87 for v_point in $V_EX_POINTS_IDS; do
88 if [ "$point" = "${v_point%,*}" ]; then
89 dependency="${v_point##*,}"
90 dep_found=0
91 for dep_added in $deps_added; do
92 if test "x${dependency}" = "x${dep_added}"; then
93 dep_found=1
94 break
96 done
98 if [ $dep_found -eq 0 ]; then
99 deps_added="${deps_added} ${dependency}"
100 EX_DEPS="${EX_DEPS} <Addin id=\"${dependency}\" version=\"1.0\"/>^"
103 name="${point##*/}"
104 EX_NODES="${EX_NODES} <Extension path=\"${point}\">^ <${name} class=\"\"/>^ </Extension>^^"
106 echo " Added extension node \`${name}' at path \`${point}'"
108 done
109 done
111 EX_DEPS=" <Dependencies>^${EX_DEPS}^ </Dependencies>"
113 mkdir -p "${EX_PATH}/${EX_NAME}"
114 cp ${TEMPLATE_PATH}/Template.mdp "${EX_PATH}/${EX_NAME}.mdp"
115 cp ${TEMPLATE_PATH}/Template.addin.xml "${EX_PATH}/${EX_NAME}.addin.xml"
116 cp ${TEMPLATE_PATH}/Makefile.am "${EX_PATH}"
118 pushd "${EX_PATH}" &>/dev/null
120 for file in *; do
121 sed -e "s/\@EXTENSION_NAME\@/${EX_NAME}/g" < $file > $file.tmp &&
122 mv $file.tmp $file
123 sed -e "s,\@EXTENSION_DEPS\@,${EX_DEPS},g" < $file |
124 sed -r 's,[\^]+,\^,g' | tr ^ '\n' > $file.tmp &&
125 mv $file.tmp $file
126 sed -e "s,\@EXTENSION_NODES\@,${EX_NODES},g" < $file |
127 tr ^ '\n' > $file.tmp &&
128 mv $file.tmp $file
129 done
131 popd &>/dev/null
133 echo "Done."
134 echo "You will need to fix the generated Makefile.am, .addins.xml file, "
135 echo "and add an entry to ../configure.ac, then run autogen.sh again."