Created usage function
[maemo-efl] / trunk / build-all.sh
1 #!/bin/bash
2
3 source "helper-functions.sh"
4 __this_script=`basename $0`
5 __this_script_dir=`dirname $0`
6
7 # Binaries
8 __date=`which date`
9 __git=`which git`
10 __head=`which head`
11 __mkdir=`which mkdir`
12 __sed=`which sed`
13 __uname=`which uname`
14
15 # git definitions
16 __git_clone="$__git clone"
17 __git_pull="$__git pull"
18 __git_clean="$__git clean"
19 __git_repo="git://staff.get-e.org/"
20
21 # e17 repositories paths
22 __e17_libs="e17/libs"
23 __e17_proto="e17/proto"
24 __e17_python_efl="$__e17_proto/python-efl"
25 __e17_python_etk="users/cmarcelo"
26
27 # modules
28 #__lib_modules="edb eet evas ecore embryo edje efreet epeg epsilon emotion etk ewl e_dbus exml enhance"
29 __lib_modules="eet:evas:ecore:embryo:edje:epsilon:etk:e_dbus"
30 __python_modules="python-evas:python-ecore:python-edje:python-epsilon:python-e_dbus"
31 __python_etk_module="python-etk"
32
33 # dpkg definitions
34 __arch=`$__uname -m`
35 __common_build_pkg_options="-rfakeroot -us -uc -D -tc"
36 __build_pkg_options="$__common_build_pkg_options -sa"
37 if [ "x$__arch" = "xarm" ] ; then
38     __build_pkg_options="$__common_build_pkg_options -B"
39 fi
40
41 # Distro
42 __distro=`$__head -1 /etc/apt/sources.list|cut -d" " -f3`
43
44 # Packages dirs and log file
45 __today=`$__date +%Y%m%d`
46 __base_pkg_dir="$__this_script_dir/packages_$__today"
47 __pkg_dir="$__base_pkg_dir/$__distro/$__arch"
48 __output_file="$PWD/$__base_pkg_dir/packages_$__today.log"
49
50 # Scratchbox definitions
51 __scratchbox=/scratchbox
52
53 # Function definitions
54 function usage() {
55     cat << EOF
56
57 Usage: $__this_script [OPTIONS]
58
59 Build script for EFL debian packages for Maemo.
60
61 Options:
62     -h      Show this usage guide.
63     -s PATH Specify alternate scratchbox path (default: $__scratchbox).
64
65 EOF
66 }
67
68 function log_to_file() {
69     local now
70     local msg
71     msg=$1
72
73     if [ ! -r $__output_file ]; then
74         error "log_to_file(): Log file does not exist"
75     fi
76
77     now=`$__date +%H:%M:%S`
78     echo "$now: $msg" >> $__output_file
79 }
80
81 function start_log() {
82     local now
83     now=`$__date -R`
84
85     if [ ! -r $__output_file ]; then
86         msg_begin "Creating log file"
87         touch $__output_file
88         msg_end $?
89     else
90         echo "" >> $__output_file
91     fi
92
93     if [ $? != 0 ] ; then
94         error "start_log(): Could not create $__output_file file"
95     fi
96
97     cat << EOF >> $__output_file
98 *********************************************************
99 * Started $__this_script: $now *
100 *********************************************************
101
102 Configuration:
103    Distro.: $__distro
104    Arch...: $__arch
105
106 EOF
107 }
108
109 function finish_log() {
110     local now
111     now=`$__date -R`
112
113     if [ ! -r $__output_file ]; then
114         error "finish_log(): Log file does not exist"
115     fi
116
117     cat << EOF >> $__output_file
118
119 * Finished $__this_script: $now
120 EOF
121 }
122
123 function clone() {
124     local repo
125     repo=$1
126     `$__git_clone $repo.git 2>&1>> $__output_file`
127     return $?
128 }
129
130 function pull() {
131     `$__git_pull 2>&1>> $__output_file`
132     return $?
133 }
134
135 function clean() {
136     return $?
137 }
138
139 function build_pkg() {
140     echo "build_pkg"
141     return $?
142 }
143
144 function install_pkg() {
145     echo "install_pkg"
146     return $?
147 }
148
149 function uninstall_pkg() {
150     echo "uninstall_pkg"
151     return $?
152 }
153
154 function get_sources() {
155     local modules
156     local repo
157     modules=`echo $1|$__sed -e 's/:/ /g'`
158     repo=$2
159
160     for module in $modules; do
161         if [ -d $module/$module/.git ]; then
162             log_to_file "Updating existing repository at $PWD/$module/$module"
163             cd $module/$module
164             msg_begin "  Updating $module repository"
165             pull
166             msg_end $?
167             cd - 2>&1 >> /dev/null
168         elif [ -d $module/$module ]; then
169             log_to_file "Removing invalid repository at $PWD/$module/$module"
170             rm -rf $module/$module
171         fi
172
173         if [ ! -d $module/$module ]; then
174             cd $module
175             msg_begin "  Cloning $repo/$module.git"
176             clone $repo/$module
177             msg_end $?
178             cd - 2>&1 >> /dev/null
179         elif [ ! -d $module ]; then
180             error "Directory $module does not exist."
181         fi
182     done
183 }
184
185 # Verify options
186 while getopts "hs" opt ; do
187     case "$opt" in
188         h)
189             usage
190             exit 0
191             ;;
192         s)
193             __scratchbox=$OPTARG
194             ;;
195         [?])
196             usage
197             exit 1
198             ;;
199     esac
200 done
201
202 # Initial checks
203
204 # Distro variable must not be empty
205 msg_begin "Checking maemo distro"
206 test "x$__distro" != "x"
207 msg_end $?
208
209 # Check if we're running inside scratchbox
210 msg_begin "Checking for scratchbox environment"
211 test -r /targets/links/scratchbox.config
212 msg_end $?
213
214 # Create packages dir and log file
215 $__mkdir -p $__pkg_dir
216 start_log
217 log_to_file "Created $__pkg_dir"
218
219 # Download modules under e17/libs
220 msg "Downloading e17 modules"
221 get_sources $__lib_modules $__git_repo$__e17_libs
222
223 # Download python modules under proto/python/efl
224 msg "Downloading python modules"
225 get_sources $__python_modules $__git_repo$__e17_python_efl
226
227 # Download python-etk module
228 get_sources $__python_etk_module $__git_repo$__e17_python_etk
229
230 # Build package
231
232 # Install package
233
234 # Download user modules (python-etk)
235
236 # Build package
237
238 # Install package
239
240 # Uninstall all packages
241
242 # END
243 finish_log