forked from ericpaulbishop/gargoyle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rebuild.sh
executable file
·798 lines (660 loc) · 27.2 KB
/
rebuild.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
#!/bin/bash
set_constant_variables()
{
#working directories
scriptpath="$(readlink -f "$0")"
top_dir="${scriptpath%/${0##*/}}"
targets_dir="$top_dir/targets"
patches_dir="$top_dir/patches-generic"
compress_js_dir="$top_dir/compressed_javascript"
compress_css_dir="$top_dir/compressed_css"
node_version_tag="v6.3.1"
npm_version_tag="v3.10.4"
#script for building netfilter patches
netfilter_patch_script="$top_dir/netfilter-match-modules/integrate_netfilter_modules.sh"
#set date here, so it's guaranteed the same for all images
#even though build can take several hours
build_date=$(LC_ALL=C date +"%B %d, %Y")
gargoyle_git_revision=$(git log -1 --pretty=format:%h )
}
set_version_variables()
{
#set date here, so it is guaranteed the same for all images
#even though build can take several hours
build_date=$(LC_ALL=C date +"%B %d, %Y")
gargoyle_git_revision=$(git log -1 --pretty=format:%h )
# Full display version in gargoyle web interface
if [ -z "$full_gargoyle_version" ] ; then
full_gargoyle_version="$1"
fi
if [ -z "$full_gargoyle_version" ] ; then
full_gargoyle_version="Unknown"
fi
# Used in gargoyle banner
short_gargoyle_version=$(echo "$full_gargoyle_version" | awk '{ print $1 ; }' | sed 's/[^0-9^A-Z^a-z^\.^\-^_].*$//g' )
# Used for file naming
lower_short_gargoyle_version=$(echo "$short_gargoyle_version" | tr 'A-Z' 'a-z' )
# Used for package versioning/numbering, needs to be a numeric, eg 1.2.3
numeric_gargoyle_version=$(echo "$short_gargoyle_version" | sed 's/[Xx]/0/' )
not_numeric=$(echo "$numeric_gargoyle_version" | sed 's/[\.0123456789]//g')
if [ -n "$not_numeric" ] ; then
numeric_gargoyle_version="0.9.9"
fi
#echo "full = \"$full_gargoyle_version\""
#echo "short = \"$short_gargoyle_version\""
#echo "short lower = \"$lower_short_gargoyle_version\""
#echo "numeric = \"$numeric_gargoyle_version\""
}
get_target_from_config()
{
config_file_path="$1"
cat .config | grep "^CONFIG_TARGET_BOARD=" | sed 's/\"$//g' | sed 's/^.*\"//g'
}
get_subtarget_from_config()
{
config_file_path="$1"
cat .config | grep "^CONFIG_TARGET_SUBTARGET" | sed 's/^.*="\(.*\)"/\1/g'
}
get_pkg_arch_from_config()
{
config_file_path="$1"
cat .config | grep "^CONFIG_TARGET_ARCH_PACKAGES" | sed 's/^.*="\(.*\)"/\1/g'
}
create_gargoyle_banner()
{
echo "BUILDING BANNER"
local target="$1"
local profile="$2"
local date="$3"
local gargoyle_version="$4"
local gargoyle_commit="$5"
local openwrt_branch="$6"
local openwrt_revision="$7"
local banner_file_path="$8"
local revision_save_dir="$9"
local openwrt_branch_str="OpenWrt $openwrt_branch branch"
if [ "$openwrt_branch" = "trunk" ] ; then
openwrt_branch_str="OpenWrt trunk"
fi
local top_line=$(printf "| %-26s| %-35s|" "Gargoyle version $gargoyle_version" "$openwrt_branch_str")
local middle_line=$(printf "| %-26s| %-35s|" "Gargoyle revision $gargoyle_commit" "OpenWrt commit $openwrt_revision")
local bottom_line=$(printf "| %-26s| %-35s|" "Built $date" "Target $target/$profile")
cat << 'EOF' >"$banner_file_path"
------------------------------------------------------------------
| _____ _ |
| | __ \ | | |
| | | \/ __ _ _ __ __ _ ___ _ _| | ___ |
| | | __ / _` | '__/ _` |/ _ \| | | | |/ _ \ |
| | |_\ \ (_| | | | (_| | (_) | |_| | | __/ |
| \____/\__,_|_| \__, |\___/ \__, |_|\___| |
| __/ | __/ | |
| |___/ |___/ |
| |
|----------------------------------------------------------------|
EOF
echo "$top_line" >> "$banner_file_path"
echo "$middle_line" >> "$banner_file_path"
echo "$bottom_line" >> "$banner_file_path"
echo '------------------------------------------------------------------' >> "$banner_file_path"
#save openwrt variables for rebuild
echo "$openwrt_revision" > "$revision_save_dir/OPENWRT_REVISION"
echo "$openwrt_branch" > "$revision_save_dir/OPENWRT_BRANCH"
}
do_js_compress()
{
uglifyjs_arg1="$1"
uglifyjs_arg2="$2"
rm -rf "$compress_js_dir"
mkdir "$compress_js_dir"
escaped_package_dir=$(echo "$top_dir/package-prepare/" | sed 's/\//\\\//g' | sed 's/\-/\\-/g' ) ;
for jsdir in $(find "${top_dir}/package-prepare" -path "*/www/js") ; do
pkg_rel_path=$(echo $jsdir | sed "s/$escaped_package_dir//g");
mkdir -p "$compress_js_dir/$pkg_rel_path"
cp "$jsdir/"*.js "$compress_js_dir/$pkg_rel_path/"
cd "$compress_js_dir/$pkg_rel_path/"
for jsf in *.js ; do
if [ -n "$uglifyjs_arg2" ] ; then
"$uglifyjs_arg1" "$uglifyjs_arg2" "$jsf" > "$jsf.cmp"
else
"$uglifyjs_arg1" "$jsf" > "$jsf.cmp"
fi
mv "$jsf.cmp" "$jsf"
done
done
cp -r "$compress_js_dir"/* "$top_dir/package-prepare/"
cd "$top_dir"
}
do_css_compress()
{
echo "Compressing CSS files..."
uglifycss_arg1="$1"
uglifycss_arg2="$2"
rm -rf "$compress_css_dir"
mkdir "$compress_css_dir"
escaped_package_dir=$(echo "$top_dir/package-prepare/" | sed 's/\//\\\//g' | sed 's/\-/\\-/g' ) ;
for cssdir in $(find "${top_dir}/package-prepare" -maxdepth 5 -path "*/www/themes/*") ; do
pkg_rel_path=$(echo $cssdir | sed "s/$escaped_package_dir//g");
mkdir -p "$compress_css_dir/$pkg_rel_path"
cp "$cssdir/"*.css "$compress_css_dir/$pkg_rel_path/"
cd "$compress_css_dir/$pkg_rel_path/"
for cssf in *.css ; do
if [ -n "$uglifycss_arg2" ] ; then
"$uglifycss_arg1" "$uglifycss_arg2" "$cssf" > "$cssf.cmp"
else
"$uglifycss_arg1" "$cssf" > "$cssf.cmp"
fi
mv "$cssf.cmp" "$cssf"
done
done
cp -r "$compress_css_dir"/* "$top_dir/package-prepare/"
cd "$top_dir"
echo "Done!"
}
distrib_copy_arch_ind_ipk()
{
local tgt="$1"
local ltype="$2"
local di=1
local dpkgs=$(find "$top_dir/package" -path '*plugin-gargoyle-*' -and -name 'Makefile' -and -not -path '*-i18n-*' | xargs grep -s -l "DEPENDS:=+gargoyle$" | xargs grep -s -l "PKGARCH:=all$" | awk -F'/' '{print $(NF-1)}')
# printf -- '%s\n' "${dpkgs[@]}"
if [ ! -d "$top_dir/Distribution/architecture-independent packages ]" ] ; then
mkdir -p "$top_dir/Distribution/architecture-independent packages"
fi
#if [ ! -d "$top_dir/Distribution/theme packages ]" ] ; then
# mkdir -p "$top_dir/Distribution/theme packages"
#fi
if [ ! -d "$top_dir/Distribution/theme packages ]" ] && [ "$ltype" = 'internationalize' ] ; then
mkdir -p "$top_dir/Distribution/language packages"
fi
while true; do
local apkg=$(echo "$dpkgs" | awk -v rec=$di 'NR==rec {print $0}')
[[ -z "$apkg" ]] &&
{
break
} || {
ipkg=("$top_dir/$tgt-src/bin/$tgt/packages/${apkg}"*"ipk")
[[ -f "${ipkg[0]}" ]] &&
{
cp -f "$top_dir/$tgt-src/bin/$tgt/packages/$apkg"*".ipk" "$top_dir/Distribution/architecture-independent packages/"
}
}
let di++
done
#cp -f "$top_dir/$tgt-src/bin/$tgt/packages/plugin-gargoyle-theme-"*".ipk" "$top_dir/Distribution/theme packages/"
if [ "$ltype" = 'internationalize' ] ; then
cp -f "$top_dir/$tgt-src/bin/$tgt/packages/plugin-gargoyle-i18n-"*".ipk" "$top_dir/Distribution/language packages/"
fi
}
distrib_init ()
{
if [ ! -d "$top_dir/Distribution" ] ; then
mkdir "$top_dir/Distribution"
fi
#git log --since=5/16/2013 $(git log -1 --pretty=format:%h) --pretty=format:"%h%x09%ad%x09%s" --date=short > "$top_dir/Distribution/changelog.txt"
git log $(git log $(git describe --abbrev=0 --tags)..$(git log -1 --pretty=format:%h) --no-merges --pretty=format:"%h%x09%ad%x09%s" --date=short)..$(git log -1 --pretty=format:%h) --no-merges --pretty=format:"%h%x09%ad%x09%s" --date=short > "$top_dir/Distribution/Gargoyle changelog.txt"
cp -fR "$top_dir/LICENSES" "$top_dir/Distribution/"
}
######################################################################################################
## Begin Main Body of Build Script ##
######################################################################################################
if [ -z "${BASH_VERSION}" ] || [ "${BASH_VERSION:0:1}" -lt '4' ]; then
echo 'Build script was designed to work with bash in version 4 (at least). Exiting...'
exit 1
fi
#initialize constants
set_constant_variables
cd "$top_dir"
#parse parameters
targets="$1"
full_gargoyle_version="$2"
verbosity="$3"
js_compress="$4"
css_compress="$5"
specified_profile="$6"
translation_type="$7"
fallback_lang="$8"
active_lang="$9"
num_build_threads="${10}"
distribution="${11}"
num_build_thread_str=""
if [ "$num_build_threads" = "single" ] ; then
num_build_threads="1"
num_build_thread_str="-j1"
elif [ "$num_build_threads" = "" ] || [ "$num_build_threads" = "unspecified" ] ; then
num_build_threads="unspecified"
num_build_thread_str=""
elif [ "$num_build_threads" = "auto" ] ; then
num_cores=$(grep -c "^processor" /proc/cpuinfo 2>/dev/null)
if [ -z "$num_cores" ] ; then num_cores=1 ; fi
num_build_threads=$(($num_cores + 2)) # more threads than cores, since each thread will sometimes block for i/o
elif [ "$num_build_threads" -lt 1 ] ; then
num_build_threads="1"
num_build_thread_str="-j1"
else
num_build_thread_str="-j$num_build_threads"
fi
if [ "$targets" = "ALL" ] || [ -z "$targets" ] ; then
targets=$(ls $targets_dir | sed 's/custom//g' 2>/dev/null)
fi
if [ -z "$js_compress" ] ; then
js_compress="true"
fi
set_version_variables "$full_gargoyle_version"
if [ -d "$top_dir/package-prepare" ] ; then
rm -rf "$top_dir/package-prepare"
fi
#NOTE: because 'make ALL' calls this script in a for loop, rm -rf "$top_dir/Distribution" cannot be done here
[ ! -z $(which python 2>&1) ] && {
#whether localize or internationalize, the packages directory is going to be modified
#default behavior is internationalize; defined in Makefile
[ "$translation_type" = "localize" ] && "$top_dir/i18n-scripts/localize.py" "$fallback_lang" "$active_lang" \
|| "$top_dir/i18n-scripts/internationalize.py" "$active_lang"
} || {
active_lang=$(sh ./i18n-scripts/intl_ltd.sh "$translation_type" "$active_lang")
}
#compress javascript AND css
if [ "$js_compress" = "true" ] || [ "$js_compress" = "TRUE" ] || [ "$js_compress" = "1" ] ; then
cd "$top_dir/minifiers/node_modules/.bin" 2>/dev/null
npm_test=$( npm -v 2>/dev/null )
nodeglobal=$npm_test
node_binary="node"
node_version=$( "$node_binary" -v 2>/dev/null)
if [ -n "$npm_test" ] && [ -z "$node_version" ] ; then
node_binary="nodejs"
node_version=$( "$node_binary" -v 2>/dev/null)
fi
if [ -z "$node_version" ] ; then
npm_test=""
nodeglobal="$npm_test"
fi
if [ -z "$npm_test" ] ; then
echo ""
echo "**************************************************************************"
echo "** node/npm not installed globally! Attempting to build them **"
echo "**************************************************************************"
echo ""
#node
if [ ! -e "$top_dir/node/bin/node" ] ; then
rm -rf "$top_dir"/node
cd "$top_dir"
git clone git://github.com/nodejs/node.git
cd node
git checkout "$node_version_tag"
./configure
make
mkdir bin
cp node bin/
cd "$top_dir"
fi
PATH="$PATH:$top_dir/node/bin"
export PATH
#npm
if [ ! -e "$top_dir/node/bin/npm" ] ; then
rm -rf "$top_dir"/npm
cd "$top_dir"
git clone git://github.com/npm/npm.git
cd npm
git checkout "$npm_version_tag"
export PREFIX="$top_dir/node"
./configure
make
make install
fi
npm_test=$( npm -v 2>/dev/null )
else
echo "node/npm ok!"
fi
if [ -z "npm_test" ] ; then
echo ""
echo "**************************************************************************"
echo "** WARNING: node/npm could not be installed, cannot compress css/js **"
echo "**************************************************************************"
echo ""
else
uglifyjs_bin="$top_dir/minifiers/node_modules/.bin/uglifyjs"
if [ ! -e "$uglifyjs_bin" ] ; then
echo ""
echo "**************************************************************************"
echo "** UglifyJS2 is not installed, attempting to install from npm **"
echo "**************************************************************************"
echo ""
mkdir -p "$top_dir/minifiers/node_modules/.bin"
cd "$top_dir"
npm install uglify-js --prefix minifiers > /dev/null 2>&1
else
echo "uglifyjs ok!"
fi
cd "$top_dir/minifiers/node_modules/.bin"
uglify_test=$( echo 'var abc = 1;' | ${nodeglobal:+$node_binary} "$uglifyjs_bin" 2>/dev/null )
if [ "$uglify_test" = 'var abc=1' ] || [ "$uglify_test" = 'var abc=1;' ] ; then
js_compress="true"
do_js_compress ${nodeglobal:+"$node_binary"} "$uglifyjs_bin"
else
js_compress="false"
echo ""
echo "**************************************************************************"
echo "** WARNING: Cannot compress javascript, uglifyjs could not be installed **"
echo "**************************************************************************"
echo ""
fi
if [ "$css_compress" = "true" ] || [ "$css_compress" = "TRUE" ] || [ "$css_compress" = "1" ] ; then
uglifycss_bin="$top_dir/minifiers/node_modules/.bin/uglifycss"
if [ ! -e "$uglifycss_bin" ] ; then
echo ""
echo "**************************************************************************"
echo "** UglifyCSS is not installed, attempting to install from npm **"
echo "**************************************************************************"
echo ""
cd "$top_dir"
npm install uglifycss -q --prefix minifiers > /dev/null 2>&1
else
echo "uglifycss ok!"
fi
cd "$top_dir/minifiers/node_modules/.bin"
uglify_test=$( echo -e '#test {\nabc: 1;\ndef: 1;\n}' | ${nodeglobal:+$node_binary} "$uglifycss_bin" 2>/dev/null )
if [ "$uglify_test" = '#test{abc:1;def:1}' ] ; then
css_compress="true"
do_css_compress ${nodeglobal:+"$node_binary"} "$uglifycss_bin"
else
css_compress="false"
echo ""
echo "**************************************************************************"
echo "** WARNING: Cannot compress css, uglifycss could not be installed **"
echo "**************************************************************************"
echo ""
fi
fi
fi
cd "$top_dir"
fi
for target in $targets ; do
if [ -d "$target-src" ] ; then
#remove old build files
if [ -z "$specified_profile" ] ; then
rm -rf "$top_dir/built/$target"
rm -rf "$top_dir/images/$target"
else
profile_images=$(cat "$targets_dir/$target/profiles/$specified_profile/profile_images" 2>/dev/null)
mkdir -p "$top_dir/images/$target/"
for pi in $profile_images ; do
rm -rf "$top_dir/images/$target/"*"$pi"*
done
fi
#copy gargoyle-specific packages to build directory
package_dir="$top_dir/package-prepare"
if [ ! -d "$package_dir" ] ; then
package_dir="$top_dir/package"
fi
gargoyle_packages=$(ls "$package_dir" )
for gp in $gargoyle_packages ; do
IFS_ORIG="$IFS"
IFS_LINEBREAK="$(printf '\n\r')"
IFS="$IFS_LINEBREAK"
matching_packages=$(find "$target-src/package" -name "$gp")
for mp in $matching_packages ; do
if [ -d "$mp" ] && [ -e "$mp/Makefile" ] ; then
rm -rf "$mp"
fi
done
IFS="$IFS_ORIG"
cp -pr "$package_dir/$gp" "$target-src/package"
done
# specify default build profile
default_profile="default"
if [ -n "$specified_profile" ] ; then
default_profile="$specified_profile"
fi
profile_target_dir="$target"
if [ "$target" = "custom" ] && [ -n "$custom_template" ] ; then
profile_target_dir="$custom_template"
fi
if [ ! -e "$targets_dir/$profile_target_dir/profiles/$default_profile/config" ] ; then
profile_dir=""
profile_dirs="$targets_dir/$profile_target_dir/profiles"/*
for pd in $profile_dirs ; do
if [ -z "$profile_dir" ] && [ -e "$pd/config" ] ; then
profile_dir="$pd"
default_profile=$(echo "$profile_dir" | sed 's/^.*\///g' | sed 's/^.*\\//g')
fi
done
fi
profile_name="$default_profile"
if [ "$target" = "custom" ] ; then
profile_name="custom"
fi
echo ""
echo ""
echo "**************************************************************************"
echo " Gargoyle is now rebuilding target: $target / $profile_name"
echo " (with $num_build_threads build threads)"
echo "**************************************************************************"
echo ""
echo ""
#copy this target configuration to build directory
cp "$targets_dir/$target/profiles/$default_profile/config" "$top_dir/${target}-src/.config"
#clean out old bin folder to prevent contamination between profiles
arch=$(ls "$top_dir/${target}-src/bin/targets")
profile_images=$(cat "$targets_dir/$target/profiles/$profile_name/profile_images" 2>/dev/null)
for pi in $profile_images ; do
escaped_pi=$(echo $pi | sed 's/-/\\-/g')
candidates=$(find "$top_dir/${target}-src/bin/targets/$arch/" 2>/dev/null | grep "$escaped_pi" )
for c in $candidates ; do
if [ ! -d "$c" ] ; then
rm "$c"
fi
done
done
[ ! -z $(which python 2>&1) ] && {
#finish internationalization by setting the target language & adding the i18n plugin to the config file
#finish localization just deletes the (now unnecessary) language packages from the config file
[ "$translation_type" = "localize" ] && "$top_dir/i18n-scripts/finalize_translation.py" 'localize' "$target" \
|| "$top_dir/i18n-scripts/finalize_translation.py" 'internationalize' "$active_lang" "$target"
} || {
#NOTE: localize is not supported because it requires python
"$top_dir/i18n-scripts/finalize_tran_ltd.sh" "$target-src" "$active_lang"
}
#enter build directory and make sure we get rid of all those pesky .svn files,
#and any crap left over from editing
cd "$top_dir/$target-src"
find . -name ".svn" | xargs rm -rf
find . -name "*~" | xargs rm -rf
find . -name ".*sw*" | xargs rm -rf
branch_name=$(cat "OPENWRT_BRANCH")
openwrt_commit=$(cat "OPENWRT_REVISION")
openwrt_abbrev_commit=$( echo "$openwrt_commit" | cut -b 1-7 )
#if version name specified, set gargoyle official version parameter in gargoyle package
echo "OFFICIAL_VERSION:=$full_gargoyle_version" > .ver
cat .ver "$package_dir/gargoyle/Makefile" >.vermake
rm .ver
mv .vermake "$top_dir/$target-src/package/gargoyle/Makefile"
#build, if verbosity is 0 dump most output to /dev/null, otherwise dump everything
openwrt_target=$(get_target_from_config "./.config")
create_gargoyle_banner "$openwrt_target" "$profile_name" "$build_date" "$short_gargoyle_version" "$gargoyle_git_revision" "$branch_name" "${openwrt_abbrev_commit}" "package/base-files/files/etc/banner" "."
if [ "$verbosity" = "0" ] ; then
make $num_build_thread_str GARGOYLE_VERSION="$numeric_gargoyle_version" GARGOYLE_VERSION_NAME="$lower_short_gargoyle_version" GARGOYLE_PROFILE="$default_profile"
else
make $num_build_thread_str V=99 GARGOYLE_VERSION="$numeric_gargoyle_version" GARGOYLE_VERSION_NAME="$lower_short_gargoyle_version" GARGOYLE_PROFILE="$default_profile"
fi
if [ "$distribution" = "true" ] || [ "$distribution" = "TRUE" ] || [ "$distribution" = "1" ] ; then
distribution="true"
distrib_init
mkdir -p "$top_dir/Distribution/Images/$target-$default_profile"
fi
#copy packages to build/target directory
pkg_arch=$(get_pkg_arch_from_config "./.config")
mkdir -p "$top_dir/built/$target/$profile_name"
package_base_dir=$(find "bin/packages/$pkg_arch" -name "base")
package_files=$(find "$package_base_dir" -name "*.ipk")
index_files=$(find "$package_base_dir" -name "Packa*")
if [ -n "$package_files" ] && [ -n "$index_files" ] ; then
for pf in $package_files ; do
cp "$pf" "$top_dir/built/$target/$profile_name/"
done
for inf in $index_files ; do
cp "$inf" "$top_dir/built/$target/$profile_name/"
done
fi
#copy build specific packages to build/target specific directory
openwrt_target=$(get_target_from_config "./.config")
subtarget_arch=$(get_subtarget_from_config "./.config")
mkdir -p "$top_dir/built/$target/$profile_name"_kernelspecific
package_base_dir=$(find "bin/targets/$openwrt_target/$subtarget_arch" -name "packages")
package_files=$(find "$package_base_dir" -name "*.ipk")
index_files=$(find "$package_base_dir" -name "Packa*")
if [ -n "$package_files" ] && [ -n "$index_files" ] ; then
for pf in $package_files ; do
cp "$pf" "$top_dir/built/$target/$default_profile"_kernelspecific/
done
for inf in $index_files ; do
cp "$inf" "$top_dir/built/$target/$default_profile"_kernelspecific/
done
fi
#copy images to images/target directory
mkdir -p "$top_dir/images/$target"
arch=$(ls bin/targets)
image_files=$(find "bin/targets/$arch/$subtarget_arch" 2>/dev/null)
if [ ! -e "$targets_dir/$target/profiles/$default_profile/profile_images" ] ; then
for imf in $image_files ; do
if [ ! -d "$imf" ] ; then
newname=$(echo "$imf" | sed 's/^.*\///g' | sed "s/openwrt/gargoyle_$lower_short_gargoyle_version/g")
cp "$imf" "$top_dir/images/$target/$newname"
if [ "$distribution" = "true" ] ; then
cp "$imf" "$top_dir/Distribution/Images/$target-$default_profile/$newname"
fi
fi
done
else
profile_images=$(cat "$targets_dir/$target/profiles/$default_profile/profile_images" 2>/dev/null)
for pi in $profile_images ; do
escaped_pi=$(echo $pi | sed 's/-/\\-/g')
candidates=$(find "bin/targets/$arch/$subtarget_arch/" 2>/dev/null | grep "$escaped_pi" )
for c in $candidates ; do
if [ ! -d "$c" ] ; then
newname=$(echo "$c" | sed 's/^.*\///g' | sed "s/openwrt/gargoyle_$lower_short_gargoyle_version/g")
cp "$c" "$top_dir/images/$target/$newname"
if [ "$distribution" = "true" ] ; then
cp "$c" "$top_dir/Distribution/Images/$target-$default_profile/$newname"
fi
fi
done
done
fi
#if we didn't build anything, die horribly
if [ -z "$image_files" ] ; then
exit
fi
if [ "$distribution" = "true" ] ; then
#Generate licenses file for each profile
#Copy architecture independent packages & themes to Distribution folder
echo "Generating Licenses file (expect it to take 5+ minutes)"
"$top_dir/dev-utils/GenLicences.sh" "$target" "$profile_name" 1 2>&1
distrib_copy_arch_ind_ipk "$target" "$translation_type"
fi
other_profiles=""
if [ "$target" != "custom" ] && [ -z "$specified_profile" ] ; then
other_profiles=$(ls "$targets_dir/$target/profiles" | grep -v "^$default_profile$" )
fi
for profile_name in $other_profiles ; do
#copy profile config and rebuild
cp "$targets_dir/$target/profiles/$profile_name/config" .config
#clean out old bin folder to prevent contamination between profiles
arch=$(ls bin/targets)
profile_images=$(cat "$targets_dir/$target/profiles/$profile_name/profile_images" 2>/dev/null)
for pi in $profile_images ; do
escaped_pi=$(echo $pi | sed 's/-/\\-/g')
candidates=$(find "bin/targets/$arch/" 2>/dev/null | grep "$escaped_pi" )
for c in $candidates ; do
if [ ! -d "$c" ] ; then
rm "$c"
fi
done
done
[ ! -z $(which python 2>&1) ] && {
#finish internationalization by setting the target language & adding the i18n plugin to the config file
#finish localization just deletes the (now unnecessary) language packages from the config file
[ "$translation_type" = "localize" ] && "$top_dir/i18n-scripts/finalize_translation.py" 'localize' "$target" \
|| "$top_dir/i18n-scripts/finalize_translation.py" 'internationalize' "$active_lang" "$target"
} || {
#NOTE: localize is not supported because it requires python
"$top_dir/i18n-scripts/finalize_tran_ltd.sh" "$target-src" "$active_lang"
}
openwrt_target=$(get_target_from_config "./.config")
create_gargoyle_banner "$openwrt_target" "$profile_name" "$build_date" "$short_gargoyle_version" "$gargoyle_git_revision" "$branch_name" "$openwrt_abbrev_commit" "package/base-files/files/etc/banner" "."
echo ""
echo ""
echo "**************************************************************************"
echo " Gargoyle is now rebuilding target: $target / $profile_name"
echo " (with $num_build_threads build threads)"
echo "**************************************************************************"
echo ""
echo ""
if [ "$verbosity" = "0" ] ; then
make $num_build_thread_str GARGOYLE_VERSION="$numeric_gargoyle_version" GARGOYLE_VERSION_NAME="$lower_short_gargoyle_version" GARGOYLE_PROFILE="$profile_name"
else
make $num_build_thread_str V=99 GARGOYLE_VERSION="$numeric_gargoyle_version" GARGOYLE_VERSION_NAME="$lower_short_gargoyle_version" GARGOYLE_PROFILE="$profile_name"
fi
#if we didn't build anything, die horribly
image_files=$(ls "bin/targets/$arch/" 2>/dev/null)
if [ -z "$image_files" ] ; then
exit
fi
#copy packages to build/target directory
pkg_arch=$(get_pkg_arch_from_config "./.config")
mkdir -p "$top_dir/built/$target/$profile_name"
package_base_dir=$(find "bin/packages/$pkg_arch" -name "base")
package_files=$(find "$package_base_dir" -name "*.ipk")
index_files=$(find "$package_base_dir" -name "Packa*")
if [ -n "$package_files" ] && [ -n "$index_files" ] ; then
for pf in $package_files ; do
cp "$pf" "$top_dir/built/$target/$profile_name/"
done
for inf in $index_files ; do
cp "$inf" "$top_dir/built/$target/$profile_name/"
done
fi
#copy build specific packages to build/target specific directory
openwrt_target=$(get_target_from_config "./.config")
subtarget_arch=$(get_subtarget_from_config "./.config")
mkdir -p "$top_dir/built/$target/$profile_name"_kernelspecific
package_base_dir=$(find "bin/targets/$openwrt_target/$subtarget_arch" -name "packages")
package_files=$(find "$package_base_dir" -name "*.ipk")
index_files=$(find "$package_base_dir" -name "Packa*")
if [ -n "$package_files" ] && [ -n "$index_files" ] ; then
for pf in $package_files ; do
cp "$pf" "$top_dir/built/$target/$profile_name"_kernelspecific/
done
for inf in $index_files ; do
cp "$inf" "$top_dir/built/$target/$profile_name"_kernelspecific/
done
fi
if [ "$distribution" = "true" ] ; then
mkdir -p "$top_dir/Distribution/Images/$target-$profile_name"
fi
#copy relevant images for which this profile applies
arch=$(ls bin/targets)
profile_images=$(cat $targets_dir/$target/profiles/$profile_name/profile_images 2>/dev/null)
for pi in $profile_images ; do
escaped_pi=$(echo $pi | sed 's/-/\\-/g')
candidates=$(find "bin/targets/$arch/$subtarget_arch/" 2>/dev/null | grep "$escaped_pi" )
for c in $candidates ; do
if [ ! -d "$c" ] ; then
newname=$(echo "$c" | sed 's/^.*\///g' | sed "s/openwrt/gargoyle_$lower_short_gargoyle_version/g")
cp "$c" "$top_dir/images/$target/$newname"
if [ "$distribution" = "true" ] ; then
cp "$c" "$top_dir/Distribution/Images/$target-$default_profile/$newname"
fi
fi
done
done
if [ "$distribution" = "true" ] ; then
#Generate licenses file for each profile
#Copy architecture independent packages & themes to Distribution folder
echo "Generating Licenses file (expect it to take 5+ minutes)"
"$top_dir/dev-utils/GenLicences.sh" "$target" "$profile_name" 1 2>&1
distrib_copy_arch_ind_ipk "$target" "$translation_type"
fi
done
#cd back to parent directory for next target (if there is one)
cd "$top_dir"
fi
done