root / full-build.sh @ master
History | View | Annotate | Download (12.8 KB)
| 1 | #!/bin/bash |
|---|---|
| 2 | |
| 3 | set_constant_variables() |
| 4 | {
|
| 5 | #working directories |
| 6 | top_dir=$(pwd) |
| 7 | targets_dir="$top_dir/targets" |
| 8 | patches_dir="$top_dir/patches-generic" |
| 9 | compress_js_dir="$top_dir/compressed_javascript" |
| 10 | |
| 11 | #script for building netfilter patches |
| 12 | netfilter_patch_script="$top_dir/netfilter-match-modules/integrate_netfilter_modules_backfire.sh" |
| 13 | |
| 14 | #openwrt branch |
| 15 | branch_name="backfire" |
| 16 | |
| 17 | # set svn revision number to use |
| 18 | # you can set this to an alternate revision |
| 19 | # or empty to checkout latest |
| 20 | rnum=30752 |
| 21 | |
| 22 | #set date here, so it's guaranteed the same for all images |
| 23 | #even though build can take several hours |
| 24 | build_date=$(date +"%B %d, %Y") |
| 25 | |
| 26 | gargoyle_git_revision=$(git log -1 --pretty=format:%h) |
| 27 | |
| 28 | } |
| 29 | set_version_variables() |
| 30 | {
|
| 31 | # Full display version in gargoyle web interface |
| 32 | full_gargoyle_version="$1" |
| 33 | if [ -z "$full_gargoyle_version" ] ; then |
| 34 | full_gargoyle_version="Unknown" |
| 35 | fi |
| 36 | |
| 37 | # Used in gargoyle banner |
| 38 | short_gargoyle_version=$(echo "$full_gargoyle_version" | awk '{ print $1 ; }' | sed 's/[^0-9^A-Z^a-z^\.^\-^_].*$//g' )
|
| 39 | |
| 40 | # Used for file naming |
| 41 | lower_short_gargoyle_version=$(echo "$short_gargoyle_version" | tr 'A-Z' 'a-z' ) |
| 42 | |
| 43 | # Used for package versioning/numbering, needs to be a numeric, eg 1.2.3 |
| 44 | numeric_gargoyle_version=$(echo "$short_gargoyle_version" | sed 's/[Xx]/0/' ) |
| 45 | not_numeric=$(echo "$numeric_gargoyle_version" | sed 's/[\.0123456789]//g') |
| 46 | if [ -n "$not_numeric" ] ; then |
| 47 | numeric_gargoyle_version="0.9.9" |
| 48 | fi |
| 49 | |
| 50 | #echo "full = \"$full_gargoyle_version\"" |
| 51 | #echo "short = \"$short_gargoyle_version\"" |
| 52 | #echo "short lower = \"$lower_short_gargoyle_version\"" |
| 53 | #echo "numeric = \"$numeric_gargoyle_version\"" |
| 54 | |
| 55 | } |
| 56 | |
| 57 | get_target_from_config() |
| 58 | {
|
| 59 | config_file_path="$1" |
| 60 | cat .config | grep "^CONFIG_TARGET_BOARD=" | sed 's/\"$//g' | sed 's/^.*\"//g' |
| 61 | } |
| 62 | |
| 63 | |
| 64 | create_gargoyle_banner() |
| 65 | {
|
| 66 | echo "BUILDING BANNER" |
| 67 | local target="$1" |
| 68 | local profile="$2" |
| 69 | local date="$3" |
| 70 | local gargoyle_version="$4" |
| 71 | local gargoyle_commit="$5" |
| 72 | local openwrt_branch="$6" |
| 73 | local openwrt_revision="$7" |
| 74 | local banner_file_path="$8" |
| 75 | local revision_save_dir="$9" |
| 76 | |
| 77 | local openwrt_branch_str="OpenWrt $openwrt_branch branch" |
| 78 | if [ "$openwrt_branch" = "trunk" ] ; then |
| 79 | openwrt_branch_str="OpenWrt trunk" |
| 80 | fi |
| 81 | |
| 82 | local top_line=$(printf "| %-26s| %-32s|" "Gargoyle version $gargoyle_version" "$openwrt_branch_str") |
| 83 | local middle_line=$(printf "| %-26s| %-32s|" "Gargoyle revision $gargoyle_commit" "OpenWrt revision r$openwrt_revision") |
| 84 | local bottom_line=$(printf "| %-26s| %-32s|" "Built $date" "Target $target/$profile") |
| 85 | |
| 86 | cat << 'EOF' >"$banner_file_path" |
| 87 | --------------------------------------------------------------- |
| 88 | | _____ _ | |
| 89 | | | __ \ | | | |
| 90 | | | | \/ __ _ _ __ __ _ ___ _ _| | ___ | |
| 91 | | | | __ / _` | '__/ _` |/ _ \| | | | |/ _ \ | |
| 92 | | | |_\ \ (_| | | | (_| | (_) | |_| | | __/ | |
| 93 | | \____/\__,_|_| \__, |\___/ \__, |_|\___| | |
| 94 | | __/ | __/ | | |
| 95 | | |___/ |___/ | |
| 96 | | | |
| 97 | |-------------------------------------------------------------| |
| 98 | EOF |
| 99 | echo "$top_line" >> "$banner_file_path" |
| 100 | echo "$middle_line" >> "$banner_file_path" |
| 101 | echo "$bottom_line" >> "$banner_file_path" |
| 102 | echo '---------------------------------------------------------------' >> "$banner_file_path" |
| 103 | |
| 104 | #save openwrt variables for rebuild |
| 105 | echo "$openwrt_revision" > "$revision_save_dir/OPENWRT_REVISION" |
| 106 | echo "$openwrt_branch" > "$revision_save_dir/OPENWRT_BRANCH" |
| 107 | |
| 108 | } |
| 109 | |
| 110 | |
| 111 | #initialize constants |
| 112 | set_constant_variables |
| 113 | |
| 114 | |
| 115 | #parse parameters |
| 116 | targets=$1 |
| 117 | if [ "$targets" = "ALL" ] || [ -z "$targets" ] ; then |
| 118 | targets=$(ls $targets_dir | sed 's/custom//g' 2>/dev/null) |
| 119 | fi |
| 120 | |
| 121 | set_version_variables "$2" |
| 122 | |
| 123 | verbosity=$3 |
| 124 | custom_template=$4 |
| 125 | js_compress=$5 |
| 126 | if [ -z "$js_compress" ] ; then |
| 127 | js_compress="true" |
| 128 | fi |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | #compress javascript |
| 134 | if [ "$js_compress" = "true" ] || [ "$js_compress" = "TRUE" ] || [ "$js_compress" = "1" ] ; then |
| 135 | uglify_test=$( echo 'var abc = 1;' | uglifyjs 2>/dev/null ) |
| 136 | if [ "$uglify_test" != 'var abc=1' ] && [ "$uglify_test" != 'var abc=1;' ] ; then |
| 137 | js_compress="false" |
| 138 | echo "" |
| 139 | echo "**************************************************************************" |
| 140 | echo "** WARNING: Cannot compress javascript -- uglifyjs is not installed! **" |
| 141 | echo "**************************************************************************" |
| 142 | echo "" |
| 143 | else |
| 144 | js_compress="true" |
| 145 | rm -rf "$compress_js_dir" |
| 146 | cp -r "package/gargoyle/files/www/js" "$compress_js_dir" |
| 147 | cd "$compress_js_dir" |
| 148 | jsfiles=*.js |
| 149 | for jsf in $jsfiles ; do |
| 150 | uglifyjs "$jsf" > "$jsf.cmp" |
| 151 | mv "$jsf.cmp" "$jsf" |
| 152 | done |
| 153 | cd "$top_dir" |
| 154 | fi |
| 155 | fi |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | #create common download directory if it doesn't exist |
| 163 | if [ ! -d "downloaded" ] ; then |
| 164 | mkdir "downloaded" |
| 165 | fi |
| 166 | |
| 167 | openwrt_src_dir="$top_dir/downloaded/$branch_name-$rnum" |
| 168 | |
| 169 | #download openwrt source if we haven't already |
| 170 | if [ ! -d "$openwrt_src_dir" ] ; then |
| 171 | revision="" |
| 172 | if [ -n "$rnum" ] ; then |
| 173 | revision=" -r $rnum " |
| 174 | fi |
| 175 | echo "fetching openwrt source" |
| 176 | rm -rf "$branch_name" |
| 177 | svn checkout $revision svn://svn.openwrt.org/openwrt/branches/$branch_name/ |
| 178 | if [ ! -d "$branch_name" ] ; then |
| 179 | echo "ERROR: could not download source, exiting" |
| 180 | exit |
| 181 | fi |
| 182 | cd "$branch_name" |
| 183 | find . -name ".svn" | xargs -r rm -rf |
| 184 | cd .. |
| 185 | mv "$branch_name" "$openwrt_src_dir" |
| 186 | fi |
| 187 | |
| 188 | |
| 189 | rm -rf $openwrt_src_dir/dl |
| 190 | ln -s $top_dir/downloaded $openwrt_src_dir/dl |
| 191 | |
| 192 | |
| 193 | for target in $targets ; do |
| 194 | |
| 195 | #if user tries to build brcm-2.4 warn them that this has been removed in favor of brcm47xx and build that instead |
| 196 | if [ "$target" = "brcm-2.4" ] || [ "$target" = "brcm" ] ; then |
| 197 | echo "" |
| 198 | echo "" |
| 199 | echo "*************************************************************************" |
| 200 | echo " WARNING: brcm-2.4 target has been deprecated in favor of newer brcm47xx" |
| 201 | echo " Setting target to brcm47xx" |
| 202 | echo "*************************************************************************" |
| 203 | target="brcm47xx" |
| 204 | fi |
| 205 | |
| 206 | echo "" |
| 207 | echo "" |
| 208 | echo "**************************************************************" |
| 209 | echo " Gargoyle is now building target: $target" |
| 210 | echo "**************************************************************" |
| 211 | echo "" |
| 212 | echo "" |
| 213 | |
| 214 | #remove old build files |
| 215 | rm -rf "$target-src" |
| 216 | rm -rf "built/$target" |
| 217 | rm -rf "images/$target" |
| 218 | |
| 219 | #copy source to new, target build directory |
| 220 | cp -r "$openwrt_src_dir" "$target-src" |
| 221 | |
| 222 | |
| 223 | #copy gargoyle-specific packages to build directory |
| 224 | package_dir="package" |
| 225 | gargoyle_packages=$(ls "$package_dir" ) |
| 226 | for gp in $gargoyle_packages ; do |
| 227 | if [ -d "$target-src/package/$gp" ] ; then |
| 228 | rm -rf "$target-src/package/$gp" |
| 229 | fi |
| 230 | cp -r "$package_dir/$gp" "$target-src/package" |
| 231 | done |
| 232 | |
| 233 | #copy compressed javascript to build directory |
| 234 | if [ "$js_compress" = "true" ] ; then |
| 235 | rm -rf "$target-src/package/gargoyle/files/www/js" |
| 236 | cp -r "$compress_js_dir" "$target-src/package/gargoyle/files/www/js" |
| 237 | fi |
| 238 | |
| 239 | |
| 240 | default_profile="default" |
| 241 | profile_target_dir="$target" |
| 242 | if [ "$target" = "custom" ] && [ -n "$custom_template" ] ; then |
| 243 | profile_target_dir="$custom_template" |
| 244 | fi |
| 245 | if [ ! -e "$targets_dir/$profile_target_dir/profiles/$default_profile/config" ] ; then |
| 246 | profile_dir="" |
| 247 | profile_dirs="$targets_dir/$profile_target_dir/profiles"/* |
| 248 | for pd in $profile_dirs ; do |
| 249 | if [ -z "$profile_dir" ] && [ -e "$pd/config" ] ; then |
| 250 | profile_dir="$pd" |
| 251 | default_profile=$(echo "$profile_dir" | sed 's/^.*\///g' | sed 's/^.*\\//g') |
| 252 | fi |
| 253 | done |
| 254 | fi |
| 255 | |
| 256 | |
| 257 | #copy this target configuration to build directory |
| 258 | cp "$targets_dir/$target/profiles/$default_profile/config" "$target-src/.config" |
| 259 | |
| 260 | |
| 261 | #if target is custom, checkout optional packages and copy all that don't |
| 262 | #share names with gargoyle-specific packages to build directory |
| 263 | if [ "$target" = "custom" ] ; then |
| 264 | if [ ! -d packages ] ; then |
| 265 | svn checkout $revision svn://svn.openwrt.org/openwrt/packages |
| 266 | |
| 267 | cd packages |
| 268 | find . -name ".svn" | xargs rm -rf |
| 269 | for gp in $gargoyle_packages ; do |
| 270 | find . -name "$gp" | xargs rm -rf |
| 271 | done |
| 272 | cd .. |
| 273 | fi |
| 274 | other_packages=$(ls packages) |
| 275 | for other in $other_packages ; do |
| 276 | if [ ! -d "$target-src/package/$other" ] ; then |
| 277 | cp -r packages/$other $target-src/package |
| 278 | fi |
| 279 | done |
| 280 | fi |
| 281 | |
| 282 | profile_name="$default_profile" |
| 283 | if [ "$target" = "custom" ] ; then |
| 284 | profile_name="custom" |
| 285 | fi |
| 286 | |
| 287 | #enter build directory and make sure we get rid of all those pesky .svn files, |
| 288 | #and any crap left over from editing |
| 289 | cd "$target-src" |
| 290 | find . -name ".svn" | xargs rm -rf |
| 291 | find . -name "*~" | xargs rm -rf |
| 292 | find . -name ".*sw*" | xargs rm -rf |
| 293 | |
| 294 | #Set gargoyle official version parameter in gargoyle package |
| 295 | echo "OFFICIAL_VERSION:=$full_gargoyle_version" > .ver |
| 296 | cat .ver "$package_dir/gargoyle/Makefile" >.vermake |
| 297 | rm .ver |
| 298 | mv .vermake "$package_dir/gargoyle/Makefile" |
| 299 | |
| 300 | #build, if verbosity is 0 dump most output to /dev/null, otherwise dump everything |
| 301 | if [ "$verbosity" = "0" ] ; then |
| 302 | scripts/patch-kernel.sh . "$patches_dir/" >/dev/null 2>&1 |
| 303 | scripts/patch-kernel.sh . "$targets_dir/$target/patches/" >/dev/null 2>&1 |
| 304 | if [ "$target" = "custom" ] ; then |
| 305 | sh $netfilter_patch_script . ../netfilter-match-modules 1 0 >/dev/null 2>&1 |
| 306 | make menuconfig |
| 307 | sh $netfilter_patch_script . ../netfilter-match-modules 0 1 >/dev/null 2>&1 |
| 308 | else |
| 309 | sh $netfilter_patch_script . ../netfilter-match-modules 1 1 >/dev/null 2>&1 |
| 310 | fi |
| 311 | |
| 312 | openwrt_target=$(get_target_from_config "./.config") |
| 313 | create_gargoyle_banner "$openwrt_target" "$profile_name" "$build_date" "$short_gargoyle_version" "$gargoyle_git_revision" "$branch_name" "$rnum" "package/base-files/files/etc/banner" "." |
| 314 | |
| 315 | make -j 4 GARGOYLE_VERSION="$numeric_gargoyle_version" |
| 316 | else |
| 317 | scripts/patch-kernel.sh . "$patches_dir/" |
| 318 | scripts/patch-kernel.sh . "$targets_dir/$target/patches/" |
| 319 | if [ "$target" = "custom" ] ; then |
| 320 | sh $netfilter_patch_script . ../netfilter-match-modules 1 0 |
| 321 | make menuconfig |
| 322 | sh $netfilter_patch_script . ../netfilter-match-modules 0 1 |
| 323 | else |
| 324 | sh $netfilter_patch_script . ../netfilter-match-modules 1 1 |
| 325 | fi |
| 326 | |
| 327 | openwrt_target=$(get_target_from_config "./.config") |
| 328 | create_gargoyle_banner "$openwrt_target" "$profile_name" "$build_date" "$short_gargoyle_version" "$gargoyle_git_revision" "$branch_name" "$rnum" "package/base-files/files/etc/banner" "." |
| 329 | |
| 330 | make -j 4 V=99 GARGOYLE_VERSION="$numeric_gargoyle_version" |
| 331 | fi |
| 332 | |
| 333 | #copy packages to built/target directory |
| 334 | mkdir -p ../built/$target |
| 335 | arch=$(ls bin) |
| 336 | if [ -d "bin/$arch/packages/" ] ; then |
| 337 | package_files=$(find bin -name "*.ipk") |
| 338 | index_files=$(find bin -name "Packa*") |
| 339 | for p in $package_files ; do |
| 340 | cp "$p" ../built/$target |
| 341 | done |
| 342 | for i in $index_files ; do |
| 343 | cp "$i" ../built/$target |
| 344 | done |
| 345 | fi |
| 346 | |
| 347 | #copy images to images/target directory |
| 348 | mkdir -p ../images/$target |
| 349 | arch=$(ls bin) |
| 350 | image_files=$(ls bin/$arch/ 2>/dev/null) |
| 351 | if [ ! -e $targets_dir/$target/profiles/default/profile_images ] ; then |
| 352 | for i in $image_files ; do |
| 353 | if [ ! -d "bin/$arch/$i" ] ; then |
| 354 | newname=$(echo "$i" | sed "s/openwrt/gargoyle_$lower_short_gargoyle_version/g") |
| 355 | cp "bin/$arch/$i" "../images/$target/$newname" |
| 356 | fi |
| 357 | done |
| 358 | else |
| 359 | profile_images=$(cat $targets_dir/$target/profiles/default/profile_images 2>/dev/null) |
| 360 | for pi in $profile_images ; do |
| 361 | candidates=$(ls bin/$arch/*$pi* 2>/dev/null | sed 's/^.*\///g') |
| 362 | for c in $candidates ; do |
| 363 | if [ ! -d "bin/$arch/$c" ] ; then |
| 364 | newname=$(echo "$c" | sed "s/openwrt/gargoyle_$lower_short_gargoyle_version/g") |
| 365 | cp "bin/$arch/$c" "../images/$target/$newname" |
| 366 | fi |
| 367 | done |
| 368 | done |
| 369 | fi |
| 370 | |
| 371 | #if we didn't build anything, die horribly |
| 372 | if [ -z "$image_files" ] ; then |
| 373 | exit |
| 374 | fi |
| 375 | |
| 376 | other_profiles="" |
| 377 | if [ "$target" != "custom" ] ; then |
| 378 | other_profiles=$(ls $targets_dir/$target/profiles | grep -v "^$default_profile$" ) |
| 379 | fi |
| 380 | for p in $other_profiles ; do |
| 381 | |
| 382 | profile_name="$p" |
| 383 | |
| 384 | #copy profile config and rebuild |
| 385 | cp $targets_dir/$target/profiles/$p/config .config |
| 386 | |
| 387 | openwrt_target=$(get_target_from_config "./.config") |
| 388 | create_gargoyle_banner "$openwrt_target" "$profile_name" "$build_date" "$short_gargoyle_version" "$gargoyle_git_revision" "$branch_name" "$rnum" "package/base-files/files/etc/banner" "." |
| 389 | |
| 390 | |
| 391 | if [ "$verbosity" = "0" ] ; then |
| 392 | make -j 4 GARGOYLE_VERSION="$numeric_gargoyle_version" |
| 393 | else |
| 394 | make -j 4 V=99 GARGOYLE_VERSION="$numeric_gargoyle_version" |
| 395 | fi |
| 396 | |
| 397 | |
| 398 | #if we didn't build anything, die horribly |
| 399 | image_files=$(ls bin/$arch/ 2>/dev/null) |
| 400 | if [ -z "$image_files" ] ; then |
| 401 | exit |
| 402 | fi |
| 403 | |
| 404 | #copy relevant images for which this profile applies |
| 405 | profile_images=$(cat $targets_dir/$target/profiles/$p/profile_images 2>/dev/null) |
| 406 | for pi in $profile_images ; do |
| 407 | candidates=$(ls bin/$arch/*$pi* 2>/dev/null | sed 's/^.*\///g') |
| 408 | for c in $candidates ; do |
| 409 | if [ ! -d "bin/$arch/$c" ] ; then |
| 410 | newname=$(echo "$c" | sed "s/openwrt/gargoyle_$lower_short_gargoyle_version/g") |
| 411 | cp "bin/$arch/$c" "../images/$target/$newname" |
| 412 | fi |
| 413 | done |
| 414 | done |
| 415 | done |
| 416 | |
| 417 | |
| 418 | |
| 419 | #cd back to parent directory for next target (if there is one) |
| 420 | cd .. |
| 421 | done |
| 422 |