root / rebuild.sh @ master
History | View | Annotate | Download (10.4 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 | #set date here, so it's guaranteed the same for all images |
| 15 | #even though build can take several hours |
| 16 | build_date=$(date +"%B %d, %Y") |
| 17 | |
| 18 | gargoyle_git_revision=$(git log -1 --pretty=format:%h) |
| 19 | |
| 20 | } |
| 21 | set_version_variables() |
| 22 | {
|
| 23 | # Full display version in gargoyle web interface |
| 24 | full_gargoyle_version="$1" |
| 25 | if [ -z "$full_gargoyle_version" ] ; then |
| 26 | full_gargoyle_version="Unknown" |
| 27 | fi |
| 28 | |
| 29 | # Used in gargoyle banner |
| 30 | short_gargoyle_version=$(echo "$full_gargoyle_version" | awk '{ print $1 ; }' | sed 's/[^0-9^A-Z^a-z^\.^\-^_].*$//g' )
|
| 31 | |
| 32 | # Used for file naming |
| 33 | lower_short_gargoyle_version=$(echo "$short_gargoyle_version" | tr 'A-Z' 'a-z' ) |
| 34 | |
| 35 | # Used for package versioning/numbering, needs to be a numeric, eg 1.2.3 |
| 36 | numeric_gargoyle_version=$(echo "$short_gargoyle_version" | sed 's/[Xx]/0/' ) |
| 37 | not_numeric=$(echo "$numeric_gargoyle_version" | sed 's/[\.0123456789]//g') |
| 38 | if [ -n "$not_numeric" ] ; then |
| 39 | numeric_gargoyle_version="0.9.9" |
| 40 | fi |
| 41 | |
| 42 | #echo "full = \"$full_gargoyle_version\"" |
| 43 | #echo "short = \"$short_gargoyle_version\"" |
| 44 | #echo "short lower = \"$lower_short_gargoyle_version\"" |
| 45 | #echo "numeric = \"$numeric_gargoyle_version\"" |
| 46 | |
| 47 | } |
| 48 | |
| 49 | get_target_from_config() |
| 50 | {
|
| 51 | config_file_path="$1" |
| 52 | cat .config | grep "^CONFIG_TARGET_BOARD=" | sed 's/\"$//g' | sed 's/^.*\"//g' |
| 53 | } |
| 54 | |
| 55 | |
| 56 | create_gargoyle_banner() |
| 57 | {
|
| 58 | echo "BUILDING BANNER" |
| 59 | local target="$1" |
| 60 | local profile="$2" |
| 61 | local date="$3" |
| 62 | local gargoyle_version="$4" |
| 63 | local gargoyle_commit="$5" |
| 64 | local openwrt_branch="$6" |
| 65 | local openwrt_revision="$7" |
| 66 | local banner_file_path="$8" |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | local openwrt_branch_str="OpenWrt $openwrt_branch branch" |
| 73 | if [ "$openwrt_branch" = "trunk" ] ; then |
| 74 | openwrt_branch_str="OpenWrt trunk" |
| 75 | fi |
| 76 | |
| 77 | local top_line=$(printf "| %-26s| %-32s|" "Gargoyle version $gargoyle_version" "$openwrt_branch_str") |
| 78 | local middle_line=$(printf "| %-26s| %-32s|" "Gargoyle revision $gargoyle_commit" "OpenWrt revision r$openwrt_revision") |
| 79 | local bottom_line=$(printf "| %-26s| %-32s|" "Built $date" "Target $target/$profile") |
| 80 | |
| 81 | cat << 'EOF' >"$banner_file_path" |
| 82 | --------------------------------------------------------------- |
| 83 | | _____ _ | |
| 84 | | | __ \ | | | |
| 85 | | | | \/ __ _ _ __ __ _ ___ _ _| | ___ | |
| 86 | | | | __ / _` | '__/ _` |/ _ \| | | | |/ _ \ | |
| 87 | | | |_\ \ (_| | | | (_| | (_) | |_| | | __/ | |
| 88 | | \____/\__,_|_| \__, |\___/ \__, |_|\___| | |
| 89 | | __/ | __/ | | |
| 90 | | |___/ |___/ | |
| 91 | | | |
| 92 | |-------------------------------------------------------------| |
| 93 | EOF |
| 94 | echo "$top_line" >> "$banner_file_path" |
| 95 | echo "$middle_line" >> "$banner_file_path" |
| 96 | echo "$bottom_line" >> "$banner_file_path" |
| 97 | echo '---------------------------------------------------------------' >> "$banner_file_path" |
| 98 | } |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | #initialize constants |
| 107 | set_constant_variables |
| 108 | |
| 109 | |
| 110 | #parse parameters |
| 111 | targets=$1 |
| 112 | if [ "$targets" = "ALL" ] || [ -z "$targets" ] ; then |
| 113 | targets=$(ls $targets_dir | sed 's/custom//g' 2>/dev/null) |
| 114 | fi |
| 115 | |
| 116 | set_version_variables "$2" |
| 117 | |
| 118 | verbosity=$3 |
| 119 | js_compress=$4 |
| 120 | if [ -z "$js_compress" ] ; then |
| 121 | js_compress="true" |
| 122 | fi |
| 123 | |
| 124 | |
| 125 | #compress javascript |
| 126 | if [ "$js_compress" = "true" ] || [ "$js_compress" = "TRUE" ] || [ "$js_compress" = "1" ] ; then |
| 127 | uglify_test=$( echo 'var abc = 1;' | uglifyjs 2>/dev/null ) |
| 128 | if [ "$uglify_test" != 'var abc=1' ] && [ "$uglify_test" != 'var abc=1;' ] ; then |
| 129 | js_compress="false" |
| 130 | echo "" |
| 131 | echo "**************************************************************************" |
| 132 | echo "** WARNING: Cannot compress javascript -- uglifyjs is not installed! **" |
| 133 | echo "**************************************************************************" |
| 134 | echo "" |
| 135 | else |
| 136 | js_compress="true" |
| 137 | rm -rf "$compress_js_dir" |
| 138 | cp -r "package/gargoyle/files/www/js" "$compress_js_dir" |
| 139 | cd "$compress_js_dir" |
| 140 | jsfiles=*.js |
| 141 | for jsf in $jsfiles ; do |
| 142 | uglifyjs "$jsf" > "$jsf.cmp" |
| 143 | mv "$jsf.cmp" "$jsf" |
| 144 | done |
| 145 | cd "$top_dir" |
| 146 | fi |
| 147 | fi |
| 148 | |
| 149 | |
| 150 | |
| 151 | for target in $targets ; do |
| 152 | |
| 153 | #if user tries to build brcm-2.4 warn them that this has been removed in favor of brcm47xx and build that instead |
| 154 | #if user tries to build brcm-2.4 warn them that this has been removed in favor of brcm47xx and build that instead |
| 155 | if [ "$target" = "brcm-2.4" ] || [ "$target" = "brcm" ] ; then |
| 156 | echo "" |
| 157 | echo "" |
| 158 | echo "*************************************************************************" |
| 159 | echo " WARNING: brcm-2.4 target has been deprecated in favor of newer brcm47xx" |
| 160 | echo " Setting target to brcm47xx" |
| 161 | echo "*************************************************************************" |
| 162 | target="brcm47xx" |
| 163 | fi |
| 164 | |
| 165 | if [ -d "$target-src" ] ; then |
| 166 | echo "" |
| 167 | echo "" |
| 168 | echo "**************************************************************" |
| 169 | echo " Gargoyle is now rebuilding target: $target" |
| 170 | echo "**************************************************************" |
| 171 | echo "" |
| 172 | echo "" |
| 173 | |
| 174 | #remove old packages and images |
| 175 | rm -rf "built/$target" |
| 176 | rm -rf "images/$target" |
| 177 | |
| 178 | #copy gargoyle-specific packages to build directory |
| 179 | package_dir="package" |
| 180 | gargoyle_packages=$(ls "$package_dir" ) |
| 181 | for gp in $gargoyle_packages ; do |
| 182 | if [ -d "$target-src/package/$gp" ] ; then |
| 183 | rm -rf "$target-src/package/$gp" |
| 184 | fi |
| 185 | cp -r "$package_dir/$gp" "$target-src/package" |
| 186 | done |
| 187 | |
| 188 | #copy compressed javascript to build directory |
| 189 | if [ "$js_compress" = "true" ] ; then |
| 190 | rm -rf "$target-src/package/gargoyle/files/www/js" |
| 191 | cp -r "$compress_js_dir" "$target-src/package/gargoyle/files/www/js" |
| 192 | fi |
| 193 | |
| 194 | default_profile="default" |
| 195 | profile_target_dir="$target" |
| 196 | if [ "$target" = "custom" ] && [ -n "$custom_template" ] ; then |
| 197 | profile_target_dir="$custom_template" |
| 198 | fi |
| 199 | if [ ! -e "$targets_dir/$profile_target_dir/profiles/$default_profile/config" ] ; then |
| 200 | profile_dir="" |
| 201 | profile_dirs="$targets_dir/$profile_target_dir/profiles"/* |
| 202 | for pd in $profile_dirs ; do |
| 203 | if [ -z "$profile_dir" ] && [ -e "$pd/config" ] ; then |
| 204 | profile_dir="$pd" |
| 205 | default_profile=$(echo "$profile_dir" | sed 's/^.*\///g' | sed 's/^.*\\//g') |
| 206 | fi |
| 207 | done |
| 208 | fi |
| 209 | |
| 210 | #copy this target configuration to build directory |
| 211 | cp "$targets_dir/$target/profiles/$default_profile/config" "$target-src/.config" |
| 212 | |
| 213 | profile_name="$default_profile" |
| 214 | if [ "$target" = "custom" ] ; then |
| 215 | profile_name="custom" |
| 216 | fi |
| 217 | |
| 218 | #enter build directory and make sure we get rid of all those pesky .svn files, |
| 219 | #and any crap left over from editing |
| 220 | cd "$target-src" |
| 221 | find . -name ".svn" | xargs rm -rf |
| 222 | find . -name "*~" | xargs rm -rf |
| 223 | find . -name ".*sw*" | xargs rm -rf |
| 224 | |
| 225 | branch_name=$(cat "OPENWRT_BRANCH") |
| 226 | rnum=$(cat "OPENWRT_REVISION") |
| 227 | |
| 228 | |
| 229 | #if version name specified, set gargoyle official version parameter in gargoyle package |
| 230 | echo "OFFICIAL_VERSION:=$full_gargoyle_version" > .ver |
| 231 | cat .ver "$package_dir/gargoyle/Makefile" >.vermake |
| 232 | rm .ver |
| 233 | mv .vermake "$package_dir/gargoyle/Makefile" |
| 234 | |
| 235 | #build, if verbosity is 0 dump most output to /dev/null, otherwise dump everything |
| 236 | openwrt_target=$(get_target_from_config "./.config") |
| 237 | create_gargoyle_banner "$openwrt_target" "$profile_name" "$build_date" "$short_gargoyle_version" "$gargoyle_git_revision" "$branch_name" "$rnum" "package/base-files/files/etc/banner" "." |
| 238 | if [ "$verbosity" = "0" ] ; then |
| 239 | make -j 4 GARGOYLE_VERSION="$numeric_gargoyle_version" |
| 240 | else |
| 241 | make -j 4 V=99 GARGOYLE_VERSION="$numeric_gargoyle_version" |
| 242 | fi |
| 243 | |
| 244 | #copy packages to built/target directory |
| 245 | mkdir -p ../built/$target |
| 246 | arch=$(ls bin) |
| 247 | if [ -d "bin/$arch/packages/" ] ; then |
| 248 | package_files=$(find bin -name "*.ipk") |
| 249 | index_files=$(find bin -name "Packa*") |
| 250 | for p in $package_files ; do |
| 251 | cp "$p" ../built/$target |
| 252 | done |
| 253 | for i in $index_files ; do |
| 254 | cp "$i" ../built/$target |
| 255 | done |
| 256 | fi |
| 257 | |
| 258 | #copy images to images/target directory |
| 259 | mkdir -p ../images/$target |
| 260 | arch=$(ls bin) |
| 261 | image_files=$(ls bin/$arch/ 2>/dev/null) |
| 262 | if [ ! -e $targets_dir/$target/profiles/default/profile_images ] ; then |
| 263 | for i in $image_files ; do |
| 264 | if [ ! -d "bin/$arch/$i" ] ; then |
| 265 | newname=$(echo "$i" | sed "s/openwrt/gargoyle_$lower_short_gargoyle_version/g") |
| 266 | cp "bin/$arch/$i" "../images/$target/$newname" |
| 267 | fi |
| 268 | done |
| 269 | else |
| 270 | profile_images=$(cat $targets_dir/$target/profiles/default/profile_images 2>/dev/null) |
| 271 | for pi in $profile_images ; do |
| 272 | candidates=$(ls bin/$arch/*$pi* 2>/dev/null | sed 's/^.*\///g') |
| 273 | for c in $candidates ; do |
| 274 | if [ ! -d "bin/$arch/$c" ] ; then |
| 275 | newname=$(echo "$c" | sed "s/openwrt/gargoyle_$lower_short_gargoyle_version/g") |
| 276 | cp "bin/$arch/$c" "../images/$target/$newname" |
| 277 | fi |
| 278 | done |
| 279 | done |
| 280 | fi |
| 281 | |
| 282 | #if we didn't build anything, die horribly |
| 283 | if [ -z "$image_files" ] ; then |
| 284 | exit |
| 285 | fi |
| 286 | |
| 287 | other_profiles="" |
| 288 | if [ "$target" != "custom" ] ; then |
| 289 | other_profiles=$(ls $targets_dir/$target/profiles | grep -v "^$default_profile$" ) |
| 290 | fi |
| 291 | for p in $other_profiles ; do |
| 292 | |
| 293 | profile_name="$p" |
| 294 | |
| 295 | #copy profile config and rebuild |
| 296 | cp $targets_dir/$target/profiles/$p/config .config |
| 297 | |
| 298 | openwrt_target=$(get_target_from_config "./.config") |
| 299 | create_gargoyle_banner "$openwrt_target" "$profile_name" "$build_date" "$short_gargoyle_version" "$gargoyle_git_revision" "$branch_name" "$rnum" "package/base-files/files/etc/banner" "." |
| 300 | |
| 301 | |
| 302 | if [ "$verbosity" = "0" ] ; then |
| 303 | make -j 4 GARGOYLE_VERSION="$numeric_gargoyle_version" |
| 304 | else |
| 305 | make -j 4 V=99 GARGOYLE_VERSION="$numeric_gargoyle_version" |
| 306 | fi |
| 307 | |
| 308 | |
| 309 | #if we didn't build anything, die horribly |
| 310 | image_files=$(ls bin/$arch/ 2>/dev/null) |
| 311 | if [ -z "$image_files" ] ; then |
| 312 | exit |
| 313 | fi |
| 314 | |
| 315 | #copy relevant images for which this profile applies |
| 316 | profile_images=$(cat $targets_dir/$target/profiles/$p/profile_images 2>/dev/null) |
| 317 | for pi in $profile_images ; do |
| 318 | candidates=$(ls bin/$arch/*$pi* 2>/dev/null | sed 's/^.*\///g') |
| 319 | for c in $candidates ; do |
| 320 | if [ ! -d "bin/$arch/$c" ] ; then |
| 321 | newname=$(echo "$c" | sed "s/openwrt/gargoyle_$lower_short_gargoyle_version/g") |
| 322 | cp "bin/$arch/$c" "../images/$target/$newname" |
| 323 | fi |
| 324 | done |
| 325 | done |
| 326 | done |
| 327 | |
| 328 | |
| 329 | #cd back to parent directory for next target (if there is one) |
| 330 | cd .. |
| 331 | fi |
| 332 | done |
| 333 |