~thbraeutigam/x10customizer/main

« back to all changes in this revision

Viewing changes to program/bin/101_configure.sh

  • Committer: thbraeutigam
  • Date: 2010-11-22 02:40:12 UTC
  • Revision ID: thorben.braeutigam@gmail.com-20101122024012-tq4tznx1rzdrugc5
v0.99.2pre

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
###
 
4
# x10 2.1 Configurator
 
5
# (c) 2010 ttxdragon
 
6
# Licensed under GPL v2
 
7
##
 
8
 
 
9
###
 
10
# Documentation Portion
 
11
##
 
12
 
 
13
###
 
14
# Menu Entry Name for Selector:
 
15
#& Configure Tasks
 
16
##
 
17
#*****************************************************************************#
 
18
#*                  Configure One-Click Operations                           *#
 
19
#*                                                                           *#
 
20
#*  This program will run you through options available and create a         *#
 
21
#*  configuration file containing your selected options for later use by     *#
 
22
#*  the automated customization process.                                     *#
 
23
#*                                                                           *#
 
24
#*  This is a very verbose process that will ask many questions.             *#
 
25
#*  Try not to get annoyed ;)                                                *#
 
26
#*                                                                           *#
 
27
#*****************************************************************************#
 
28
 
 
29
####
 
30
#  Dev Documentation:
 
31
#  $1 -> project root
 
32
#  $2 -> config already selected? true/false
 
33
##
 
34
 
 
35
clear
 
36
croot="$1"
 
37
cfgtmp="$croot/program/tmp"
 
38
cd "$croot"
 
39
if [ ! -d "$cfgtmp" ]
 
40
then
 
41
    mkdir -p "$cfgtmp"
 
42
fi
 
43
 
 
44
###
 
45
# Functions
 
46
##
 
47
 
 
48
repeat_string()
 
49
{
 
50
    ###
 
51
    # Repeats a given string
 
52
    # $1 -> times to repeat string
 
53
    # $2 -> string to repeat
 
54
    ##
 
55
    for i in `seq 1 $1`;
 
56
        do
 
57
        printf "$2"
 
58
    done
 
59
}
 
60
 
 
61
function mkcfg {
 
62
    ###
 
63
    # Archive Configuration for Storage
 
64
    # $1 -> Name for Archive/Config
 
65
    # $2 -> directory with config
 
66
    ##
 
67
    cd "$2" 
 
68
    tar -czf config.tgz config
 
69
    rm -rf config
 
70
    if [ -d customization ]
 
71
        then
 
72
        tar -czf customization.tgz customization
 
73
        rm -rf customization
 
74
    fi
 
75
    tar -cf "$1".x10conf *
 
76
    mv "$1".x10conf "$croot/config/"
 
77
    rm -rf "$2"
 
78
}
 
79
 
 
80
function excfg {
 
81
    ###
 
82
    # Extract Configuration for Usage
 
83
    # $1 -> config file to use
 
84
    ##
 
85
    cp "$croot/config/$1" "$cfgtmp/"
 
86
 
 
87
    cd "$cfgtmp"
 
88
    tar -xf "$1"
 
89
    rm "$1"
 
90
    tar -xzf "config.tgz"
 
91
    rm "config.tgz"
 
92
    if [ -e "customization.tgz" ]
 
93
        then
 
94
        tar -xzf "customization.tgz"
 
95
        rm "customization.tgz"
 
96
    fi
 
97
    cd "$croot"
 
98
}
 
99
 
 
100
 
 
101
###
 
102
# Execution
 
103
##
 
104
 
 
105
 
 
106
echo "###############################################################################
 
107
#                  x10 2.1 Customization Configurator                         #
 
108
#                                                                             #
 
109
# This will guide you through the Configuration for automated routines.       #
 
110
# You can give these routines their own names. The Program will ask you which #
 
111
# Configuration file you want to use for the routine, each time.              #
 
112
###############################################################################"
 
113
OLD_IFS=$IFS
 
114
IFS='
 
115
'
 
116
 
 
117
if [ -z "$2" ]
 
118
    then
 
119
        cd "$croot/program/bin/"
 
120
        bash ./010_config-selector.sh "$1" "$0" 2> "$croot/local-logs/config-selector-configure.txt"
 
121
        exit 0
 
122
fi
 
123
 
 
124
###
 
125
# Edit Configuration
 
126
##
 
127
cd "$cfgtmp/config"
 
128
for name in `ls -1d --color=never * | grep -v .x10conf | grep -v customization`
 
129
    do
 
130
        if [ -d "$name" ]
 
131
            then
 
132
                printf "$(cat $name/folder-cfg | grep "\#QQ" | sed -e "s_\#QQ\ __")"
 
133
                printf " [yes/no] (default: yes):"
 
134
                read decision
 
135
                if [ "$decision" = "yes" ] || [ "$decision" = "y" ]
 
136
                    then
 
137
                        cd $name
 
138
                        question="$(cat folder-cfg | grep "\#FQ" | sed -e "s_\#FQ\ __")"
 
139
                        for app in `ls -1d --color=never * | grep -v "folder-cfg"`
 
140
                            do
 
141
                            printf "$question $app [yes/no] (default: yes)?: "
 
142
                            read decision
 
143
                            if [ "$decision" = "yes" ] || [ "$decision" = "y" ]
 
144
                                then
 
145
                                printf " \r"
 
146
                            elif [ "$decision" = "no" ] || [ "$decision" = "n" ]
 
147
                                then
 
148
                                rm $app
 
149
                            else
 
150
                                echo "Will remove the application from your phone."
 
151
                                echo "If you want to change that, re-run the configurator"
 
152
                                echo "with the config you're creating right now selected"
 
153
                                echo "as base for the new configuration."
 
154
                            fi
 
155
                        done
 
156
                        cd ..
 
157
                elif [ "$decision" = "no" ] || [ "$decision" = "n" ]
 
158
                    then
 
159
                            rm -r $name
 
160
                else
 
161
                    echo "Will remove the default set of applications from your phone."
 
162
                fi
 
163
        elif [ -f "$name" ]
 
164
            then
 
165
                printf "$(cat $name | grep "\#QQQ" | sed -e "s_\#QQQ\ __")"
 
166
                ncf=`cat $name | grep "\#NCF"`
 
167
                if [ ! -z $ncf ]
 
168
                    then
 
169
                        printf " [yes/no/keep]: "
 
170
                else
 
171
                    printf " [yes/no]: "
 
172
                fi
 
173
                read decision
 
174
                
 
175
                if [ "$decision" = "yes" ] || [ "$decision" = "y" ]
 
176
                    then
 
177
                    ###
 
178
                    # Check for extra-questions for the case of a positive answer.
 
179
                    # @TODO: Make more generic so that stuff aside from positive answers can use it.
 
180
                    ##
 
181
                    if [ $(cat $name | grep "\#POQ") ]
 
182
                        then
 
183
                        printf "`cat $name | grep "\#POQ" | sed -e "s_\#POQ\ __"`"
 
184
                        read input
 
185
                        sed -i "s/\#POV\ [0-9]*/\#POV\ $input/g" $name
 
186
                        printf "Applying Value: `cat $name | grep "\#POV" | sed -e "s_\#POV\ __"`\n"
 
187
                    fi
 
188
                    mv $name $(cat $name | grep "\#PAF" | sed -e "s_\#PAF\ __") &> /dev/null
 
189
                elif [ "$decision" = "no" ] || [ "$decision" = "n" ]
 
190
                    then
 
191
                    target=$(cat $name | grep "\#NAF" | sed -e "s_\#NAF\ __")
 
192
                    if [ "$target" = "delete" ]
 
193
                    then
 
194
                        rm $name
 
195
                    else
 
196
                        mv $name $target &> /dev/null
 
197
                    fi
 
198
                elif [ "$decision" = "keep" ] || [ "$decision" = "k" ] && [ ! -z $ncf ]
 
199
                    then
 
200
                    target=$(cat $name | grep "\#NCF" | sed -e "s_\#NCF\ __")
 
201
                    if [ "$target" = "delete" ]
 
202
                    then
 
203
                        rm $name
 
204
                    else
 
205
                        mv $name $target &> /dev/null
 
206
                    fi
 
207
                else
 
208
                    echo "Using default value 'yes'."
 
209
                    mv $name $(cat $name | grep "\#PAF" | sed -e "s_\#PAF\ __") &> /dev/null
 
210
                fi
 
211
        else
 
212
            printf " \r"
 
213
        fi
 
214
done
 
215
 
 
216
 
 
217
printf "If you want to provide all needed files within the configuration.\nCopy them over into program/tmp/customization now.\n
 
218
Press Enter to continue"
 
219
read unneeded
 
220
 
 
221
###
 
222
# Set Configuration Name
 
223
##
 
224
cd "$cfgtmp"
 
225
printf "Give the new Configuration a name: "
 
226
read packname
 
227
 
 
228
sed -i "s/\#N\ .*/\#N\ $packname/g" config-info
 
229
 
 
230
###
 
231
# Set Type
 
232
# *Disabled for now as only Configurations available. Needs better selection, too.
 
233
#
 
234
##
 
235
#
 
236
#printf "What kind of Configuration is it? [Case Sensitive!]\n"
 
237
#printf "Known Types: "
 
238
#cd "$croot/program/types/"
 
239
#for ctype in `ls -1 *`;
 
240
#do
 
241
#    printf "$ctype "
 
242
#done
 
243
#printf "\nYours is a: "
 
244
#read ptype
 
245
#cd "$cfgtmp"
 
246
ptype="Configuration"
 
247
sed -i "s/\#T\ .*/\#T\ $ptype/g" ./config-info
 
248
 
 
249
###
 
250
# Set Authorname
 
251
##
 
252
cd "$cfgtmp"
 
253
printf "Enter what's gonna be the author-name: "
 
254
read authorname
 
255
 
 
256
sed -i "s/\#A\ .*/\#A\ $authorname/g" ./config-info
 
257
 
 
258
 
 
259
###
 
260
# Set Description
 
261
##
 
262
 
 
263
sed -i "s_\#\*.*__g" ./config-info
 
264
sed -i '/^$/d' ./config-info
 
265
echo "#*****************************************************************************#" >> ./config-info
 
266
 
 
267
printf "Enter a brief description of what your $ptype does:\n"
 
268
state=true
 
269
i="0"
 
270
while $state;
 
271
    do
 
272
        i=$(($i+1))
 
273
        printf "[$i] "
 
274
        read descline
 
275
        if [ -z "$descline" ]
 
276
        then
 
277
            state=false
 
278
        else
 
279
            printf "#* $descline `repeat_string $((73-${#descline})) " "`*#\n" >> ./config-info
 
280
        fi
 
281
    done
 
282
echo "#*****************************************************************************#" >> ./config-info
 
283
 
 
284
 
 
285
mkcfg "$packname" "$cfgtmp"
 
286
if [ -e "$croot/config/$packname.x10conf" ]
 
287
  then
 
288
    clear
 
289
    echo "Your Configuration has been created. Find it in the config folder."
 
290
    echo "The filename is: $packname.x10conf"
 
291
else
 
292
    echo "For some reason or another your config did not get created."
 
293
    echo "Look for updates to this program or report the bug. (Please incl. logs)"
 
294
    exit 0
 
295
fi
 
296
cd "$croot/program/"
 
297
rm -rf tmp
 
298
bash ./selector "$croot"