Constness changes
[melted] / demo / demo
1 #!/bin/bash
2
3 function show_consumers( )
4 {
5         awk -F '\t' '{ printf( "%d. %s\n", ++ i, $1 ); }' < consumers.ini
6 }
7
8 function get_consumer( )
9 {
10         option=$1
11         [ "$option" != "" ] && [ $option -gt 0 ] && sed 's/\t\+/\t/g' < consumers.ini | cut -f 2 | head -n $option | tail -n -1
12 }
13
14 function show_menu( )
15 {
16         sed 's/\t\+/\t/g' < demo.ini |
17         awk -F '\t' '{ printf( "%2d. %-30.30s", ++ i, $2 ); if ( i % 2 == 0 ) printf( "\n" ); } END { if ( i % 2 == 1 ) printf( "\n" ); }'
18 }
19
20 function check_dependencies( )
21 {
22         option=$1
23         if [ $option -gt 0 ]
24         then
25                 deps=`sed 's/\t\+/\t/g' < demo.ini | cut -f 3 | head -n $option | tail -n -1`
26                 if [ "$deps" != "" ]
27                 then
28                         echo "$deps" | 
29                         tr ',' '\n' | 
30                         while read dep 
31                         do
32                                 ls $dep > /dev/null 2>&1
33                                 val=$?
34                                 [ $val != 0 ] && echo Failed to find $dep >&2 && echo $val
35                         done
36                 fi
37                 echo 0
38         fi
39 }
40
41 function get_demo( )
42 {
43         option=$1
44         if [ $option -gt 0 ]
45         then
46                 cut -f 1 demo.ini | head -n $option | tail -n -1
47         fi
48 }
49
50 while [ 1 ]
51 do
52
53         echo Select Consumer
54         echo
55
56         show_consumers
57
58         echo
59         echo 0. Exit
60         echo
61         echo -n "Option: "
62         read option
63         echo
64
65         [ "$option" == "0" ] && break
66
67         export MLT_CONSUMER=`get_consumer $option`
68
69         while [ "$option" != "0" -a "$MLT_CONSUMER" != "" ]
70         do
71                 echo Choose Demo
72                 echo
73         
74                 show_menu
75         
76                 echo
77                 echo -n "Option: "
78                 read option
79                 echo
80
81                 [ "$option" == "" ] && break
82         
83                 demo=`get_demo $option`
84                 usable=`check_dependencies $option`
85         
86                 if [ "$usable" = "0" -a "$demo" != "" ]
87                 then
88                         if [ "$MLT_CONSUMER" == "westley:" ]
89                         then    export WESTLEY_CONSUMER="westley:$demo.westley"
90                                         bash $demo -consumer $WESTLEY_CONSUMER
91                                         inigo +$demo.txt out=100 $demo.westley $demo.westley -filter watermark:watermark1.png composite.fill=1 composite.geometry=85%,5%:10%x10%
92                         elif [ "$MLT_CONSUMER" == "westley" ]
93                         then    bash $demo -consumer $MLT_CONSUMER | less
94                         else    bash $demo -consumer $MLT_CONSUMER
95                         fi
96                 elif [ "$usable" != "" ]
97                 then
98                         echo 
99                         echo Unable to locate suitable files for the demo - please provide them.
100                         read pause
101                 fi
102         
103                 stty sane
104         done
105
106 done