OLD | NEW |
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 # Common constants for build scripts | 5 # Common constants for build scripts |
6 # This must evaluate properly for both /bin/bash and /bin/sh | 6 # This must evaluate properly for both /bin/bash and /bin/sh |
7 | 7 |
8 # All scripts should die on error unless commands are specifically excepted | 8 # All scripts should die on error unless commands are specifically excepted |
9 # by prefixing with '!' or surrounded by 'set +e' / 'set -e'. | 9 # by prefixing with '!' or surrounded by 'set +e' / 'set -e'. |
10 # TODO: Re-enable this once shflags is less prone to dying. | 10 # TODO: Re-enable this once shflags is less prone to dying. |
11 #set -e | 11 #set -e |
12 | 12 |
13 # The number of jobs to pass to tools that can run in parallel (such as make | 13 # The number of jobs to pass to tools that can run in parallel (such as make |
14 # and dpkg-buildpackage | 14 # and dpkg-buildpackage |
15 NUM_JOBS=`grep -c "^processor" /proc/cpuinfo` | 15 NUM_JOBS=$(grep -c "^processor" /proc/cpuinfo) |
16 | 16 |
17 # Store location of the calling script. | 17 # Make sure we have the location and name of the calling script, using |
18 TOP_SCRIPT_DIR="${TOP_SCRIPT_DIR:-$(dirname $0)}" | 18 # the current value if it is already set. |
| 19 SCRIPT_LOCATION=${SCRIPT_LOCATION:-$(dirname "$(readlink -f "$0")")} |
| 20 SCRIPT_NAME=${SCRIPT_NAME:-$(basename "$0")} |
19 | 21 |
20 # Detect whether we're inside a chroot or not | 22 # Detect whether we're inside a chroot or not |
21 if [ -e /etc/debian_chroot ] | 23 if [ -e /etc/debian_chroot ] |
22 then | 24 then |
23 INSIDE_CHROOT=1 | 25 INSIDE_CHROOT=1 |
24 else | 26 else |
25 INSIDE_CHROOT=0 | 27 INSIDE_CHROOT=0 |
26 fi | 28 fi |
27 | 29 |
28 # Construct a list of possible locations for the source tree. This list is | 30 # Construct a list of possible locations for the source tree. This list is |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 72 |
71 # Find root of source tree | 73 # Find root of source tree |
72 get_gclient_root | 74 get_gclient_root |
73 | 75 |
74 # Canonicalize the directories for the root dir and the calling script. | 76 # Canonicalize the directories for the root dir and the calling script. |
75 # readlink is part of coreutils and should be present even in a bare chroot. | 77 # readlink is part of coreutils and should be present even in a bare chroot. |
76 # This is better than just using | 78 # This is better than just using |
77 # FOO = "$(cd $FOO ; pwd)" | 79 # FOO = "$(cd $FOO ; pwd)" |
78 # since that leaves symbolic links intact. | 80 # since that leaves symbolic links intact. |
79 # Note that 'realpath' is equivalent to 'readlink -f'. | 81 # Note that 'realpath' is equivalent to 'readlink -f'. |
80 TOP_SCRIPT_DIR=`readlink -f $TOP_SCRIPT_DIR` | 82 SCRIPT_LOCATION=$(readlink -f $SCRIPT_LOCATION) |
81 GCLIENT_ROOT=`readlink -f $GCLIENT_ROOT` | 83 GCLIENT_ROOT=$(readlink -f $GCLIENT_ROOT) |
82 | 84 |
83 # Other directories should always be pathed down from GCLIENT_ROOT. | 85 # Other directories should always be pathed down from GCLIENT_ROOT. |
84 SRC_ROOT="$GCLIENT_ROOT/src" | 86 SRC_ROOT="$GCLIENT_ROOT/src" |
85 SRC_INTERNAL="$GCLIENT_ROOT/src-internal" | 87 SRC_INTERNAL="$GCLIENT_ROOT/src-internal" |
86 SCRIPTS_DIR="$SRC_ROOT/scripts" | 88 SCRIPTS_DIR="$SRC_ROOT/scripts" |
87 | 89 |
88 # Load developer's custom settings. Default location is in scripts dir, | 90 # Load developer's custom settings. Default location is in scripts dir, |
89 # since that's available both inside and outside the chroot. By convention, | 91 # since that's available both inside and outside the chroot. By convention, |
90 # settings from this file are variables starting with 'CHROMEOS_' | 92 # settings from this file are variables starting with 'CHROMEOS_' |
91 CHROMEOS_DEV_SETTINGS="${CHROMEOS_DEV_SETTINGS:-$SCRIPTS_DIR/.chromeos_dev}" | 93 CHROMEOS_DEV_SETTINGS="${CHROMEOS_DEV_SETTINGS:-$SCRIPTS_DIR/.chromeos_dev}" |
92 if [ -f $CHROMEOS_DEV_SETTINGS ] | 94 if [ -f $CHROMEOS_DEV_SETTINGS ]; then |
93 then | |
94 # Turn on exit-on-error during custom settings processing | 95 # Turn on exit-on-error during custom settings processing |
95 SAVE_OPTS=`set +o` | 96 SAVE_OPTS=$(set +o) |
96 set -e | 97 set -e |
97 | 98 |
98 # Read settings | 99 # Read settings |
99 . $CHROMEOS_DEV_SETTINGS | 100 . $CHROMEOS_DEV_SETTINGS |
100 | 101 |
101 # Restore previous state of exit-on-error | 102 # Restore previous state of exit-on-error |
102 eval "$SAVE_OPTS" | 103 eval "$SAVE_OPTS" |
103 fi | 104 fi |
104 | 105 |
105 # Load shflags | 106 # Load shflags |
106 if [[ -f /usr/lib/shflags ]]; then | 107 if [[ -f /usr/lib/shflags ]]; then |
107 . /usr/lib/shflags | 108 . /usr/lib/shflags |
108 elif [ -f ./lib/shflags/shflags ]; then | 109 elif [ -f ./lib/shflags/shflags ]; then |
109 . "./lib/shflags/shflags" | 110 . ./lib/shflags/shflags |
110 else | 111 else |
111 . "${SRC_ROOT}/scripts/lib/shflags/shflags" | 112 . "${SRC_ROOT}/scripts/lib/shflags/shflags" |
112 fi | 113 fi |
113 | 114 |
114 # Our local mirror | 115 # Our local mirror |
115 DEFAULT_CHROMEOS_SERVER=${CHROMEOS_SERVER:-"http://build.chromium.org/mirror"} | 116 DEFAULT_CHROMEOS_SERVER=${CHROMEOS_SERVER:-"http://build.chromium.org/mirror"} |
116 | 117 |
117 # Upstream mirrors and build suites come in 2 flavors | 118 # Upstream mirrors and build suites come in 2 flavors |
118 # DEV - development chroot, used to build the chromeos image | 119 # DEV - development chroot, used to build the chromeos image |
119 # IMG - bootable image, to run on actual hardware | 120 # IMG - bootable image, to run on actual hardware |
(...skipping 15 matching lines...) Expand all Loading... |
135 if [ -d $SRC_ROOT/overlays ]; then | 136 if [ -d $SRC_ROOT/overlays ]; then |
136 ALL_BOARDS=$(cd $SRC_ROOT/overlays;ls -1d overlay-* 2>&-|sed 's,overlay-,,g') | 137 ALL_BOARDS=$(cd $SRC_ROOT/overlays;ls -1d overlay-* 2>&-|sed 's,overlay-,,g') |
137 fi | 138 fi |
138 # Strip CR | 139 # Strip CR |
139 ALL_BOARDS=$(echo $ALL_BOARDS) | 140 ALL_BOARDS=$(echo $ALL_BOARDS) |
140 # Set a default BOARD | 141 # Set a default BOARD |
141 #DEFAULT_BOARD=x86-generic # or... | 142 #DEFAULT_BOARD=x86-generic # or... |
142 DEFAULT_BOARD=$(echo $ALL_BOARDS | awk '{print $NF}') | 143 DEFAULT_BOARD=$(echo $ALL_BOARDS | awk '{print $NF}') |
143 | 144 |
144 # Enable --fast by default. | 145 # Enable --fast by default. |
145 DEFAULT_FAST="${FLAGS_TRUE}" | 146 DEFAULT_FAST=${FLAGS_TRUE} |
146 | 147 |
147 # Directory locations inside the dev chroot | 148 # Directory locations inside the dev chroot |
148 CHROOT_TRUNK_DIR="/home/$USER/trunk" | 149 CHROOT_TRUNK_DIR="/home/$USER/trunk" |
149 | 150 |
150 # Install make for portage ebuilds. Used by build_image and gmergefs. | 151 # Install make for portage ebuilds. Used by build_image and gmergefs. |
151 # TODO: Is /usr/local/autotest-chrome still used by anyone? | 152 # TODO: Is /usr/local/autotest-chrome still used by anyone? |
152 DEFAULT_INSTALL_MASK=" | 153 DEFAULT_INSTALL_MASK=" |
153 *.a | 154 *.a |
154 *.la | 155 *.la |
155 /etc/init.d | 156 /etc/init.d |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 case "$(basename $0)" in | 210 case "$(basename $0)" in |
210 build_image.sh|build_platform_packages.sh|customize_rootfs.sh|make_chroot.sh) | 211 build_image.sh|build_platform_packages.sh|customize_rootfs.sh|make_chroot.sh) |
211 echo | 212 echo |
212 echo "$V_REVERSE============================================================" | 213 echo "$V_REVERSE============================================================" |
213 echo "=========================== WARNING ======================" | 214 echo "=========================== WARNING ======================" |
214 echo "============================================================$V_VIDOFF" | 215 echo "============================================================$V_VIDOFF" |
215 echo | 216 echo |
216 echo "RUNNING OLD BUILD SYSTEM SCRIPTS. RUN THE PORTAGE-BASED BUILD HERE:" | 217 echo "RUNNING OLD BUILD SYSTEM SCRIPTS. RUN THE PORTAGE-BASED BUILD HERE:" |
217 echo "http://www.chromium.org/chromium-os/building-chromium-os/portage-based-b
uild" | 218 echo "http://www.chromium.org/chromium-os/building-chromium-os/portage-based-b
uild" |
218 echo | 219 echo |
219 if [ "$USER" != "chrome-bot" ] | 220 if [ "$USER" != "chrome-bot" ]; then |
220 then | |
221 read -n1 -p "Press any key to continue using the OLD build system..." | 221 read -n1 -p "Press any key to continue using the OLD build system..." |
222 echo | 222 echo |
223 echo | 223 echo |
224 fi | 224 fi |
225 ;; | 225 ;; |
226 esac | 226 esac |
227 | 227 |
228 # ----------------------------------------------------------------------------- | 228 # ----------------------------------------------------------------------------- |
229 # Functions | 229 # Functions |
230 | 230 |
231 function setup_board_warning { | 231 function setup_board_warning { |
232 echo | 232 echo |
233 echo "$V_REVERSE================= WARNING ======================$V_VIDOFF" | 233 echo "$V_REVERSE================= WARNING ======================$V_VIDOFF" |
234 echo | 234 echo |
235 echo "*** No default board detected in " \ | 235 echo "*** No default board detected in " \ |
236 "$GCLIENT_ROOT/src/scripts/.default_board" | 236 "$GCLIENT_ROOT/src/scripts/.default_board" |
237 echo "*** Either run setup_board with default flag set" | 237 echo "*** Either run setup_board with default flag set" |
238 echo "*** or echo |board_name| > $GCLIENT_ROOT/src/scripts/.default_board" | 238 echo "*** or echo |board_name| > $GCLIENT_ROOT/src/scripts/.default_board" |
239 echo | 239 echo |
240 } | 240 } |
241 | 241 |
242 | 242 |
243 # Sets the default board variable for calling script | 243 # Sets the default board variable for calling script |
244 function get_default_board { | 244 function get_default_board { |
245 DEFAULT_BOARD= | 245 DEFAULT_BOARD= |
246 | 246 |
247 if [ -f "$GCLIENT_ROOT/src/scripts/.default_board" ] ; then | 247 if [ -f "$GCLIENT_ROOT/src/scripts/.default_board" ] ; then |
248 DEFAULT_BOARD=`cat "$GCLIENT_ROOT/src/scripts/.default_board"` | 248 DEFAULT_BOARD=$(cat "$GCLIENT_ROOT/src/scripts/.default_board") |
249 fi | 249 fi |
250 } | 250 } |
251 | 251 |
252 | 252 |
253 # Make a package | 253 # Make a package |
254 function make_pkg_common { | 254 function make_pkg_common { |
255 # Positional parameters from calling script. :? means "fail if unset". | 255 # Positional parameters from calling script. :? means "fail if unset". |
256 set -e | 256 set -e |
257 PKG_BASE=${1:?} | 257 PKG_BASE=${1:?} |
258 shift | 258 shift |
259 set +e | 259 set +e |
260 | 260 |
261 # All packages are built in the chroot | 261 # All packages are built in the chroot |
262 assert_inside_chroot | 262 assert_inside_chroot |
263 | 263 |
264 # Command line options | 264 # Command line options |
265 DEFINE_string build_root "$DEFAULT_BUILD_ROOT" "Root of build output" | 265 DEFINE_string build_root "$DEFAULT_BUILD_ROOT" "Root of build output" |
266 | 266 |
267 # Parse command line and update positional args | 267 # Parse command line and update positional args |
268 FLAGS "$@" || exit 1 | 268 FLAGS "$@" || exit 1 |
269 eval set -- "${FLAGS_ARGV}" | 269 eval set -- "${FLAGS_ARGV}" |
270 | 270 |
271 # Die on any errors | 271 # Die on any errors |
272 set -e | 272 set -e |
273 | 273 |
274 # Make output dir | 274 # Make output dir |
275 OUT_DIR="$FLAGS_build_root/x86/local_packages" | 275 local out_dir="$FLAGS_build_root/x86/local_packages" |
276 mkdir -p "$OUT_DIR" | 276 mkdir -p "$out_dir" |
277 | 277 |
278 # Remove previous package from output dir | 278 # Remove previous package from output dir |
279 rm -f "$OUT_DIR"/${PKG_BASE}_*.deb | 279 rm -f "$out_dir"/${PKG_BASE}_*.deb |
280 | 280 |
281 # Rebuild the package | 281 # Rebuild the package |
282 pushd "$TOP_SCRIPT_DIR" | 282 pushd "$SCRIPT_LOCATION" |
283 rm -f ../${PKG_BASE}_*.deb | 283 rm -f ../${PKG_BASE}_*.deb |
284 dpkg-buildpackage -b -tc -us -uc -j$NUM_JOBS | 284 dpkg-buildpackage -b -tc -us -uc -j$NUM_JOBS |
285 mv ../${PKG_BASE}_*.deb "$OUT_DIR" | 285 mv ../${PKG_BASE}_*.deb "$out_dir" |
286 rm ../${PKG_BASE}_*.changes | 286 rm ../${PKG_BASE}_*.changes |
287 popd | 287 popd |
288 } | 288 } |
289 | 289 |
290 # Enter a chroot and restart the current script if needed | 290 # Enter a chroot and restart the current script if needed |
291 function restart_in_chroot_if_needed { | 291 function restart_in_chroot_if_needed { |
292 # NB: Pass in ARGV: restart_in_chroot_if_needed "$@" | 292 # NB: Pass in ARGV: restart_in_chroot_if_needed "$@" |
293 if [ $INSIDE_CHROOT -ne 1 ] | 293 if [ $INSIDE_CHROOT -ne 1 ]; then |
294 then | 294 local abspath=$(readlink -f "$0") |
295 # Equivalent to enter_chroot.sh -- <current command> | 295 # strip everything up to (and including) /scripts/ from abspath |
| 296 local path_from_scripts="${abspath##*/scripts/}" |
296 exec $SCRIPTS_DIR/enter_chroot.sh -- \ | 297 exec $SCRIPTS_DIR/enter_chroot.sh -- \ |
297 $CHROOT_TRUNK_DIR/src/scripts/$(basename $0) "$@" | 298 "$CHROOT_TRUNK_DIR/src/scripts/$path_from_scripts" "$@" |
298 fi | 299 fi |
299 } | 300 } |
300 | 301 |
301 # Fail unless we're inside the chroot. This guards against messing up your | 302 # Fail unless we're inside the chroot. This guards against messing up your |
302 # workstation. | 303 # workstation. |
303 function assert_inside_chroot { | 304 function assert_inside_chroot { |
304 if [ $INSIDE_CHROOT -ne 1 ] | 305 if [ $INSIDE_CHROOT -ne 1 ]; then |
305 then | |
306 echo "This script must be run inside the chroot. Run this first:" | 306 echo "This script must be run inside the chroot. Run this first:" |
307 echo " $SCRIPTS_DIR/enter_chroot.sh" | 307 echo " $SCRIPTS_DIR/enter_chroot.sh" |
308 exit 1 | 308 exit 1 |
309 fi | 309 fi |
310 } | 310 } |
311 | 311 |
312 # Fail if we're inside the chroot. This guards against creating or entering | 312 # Fail if we're inside the chroot. This guards against creating or entering |
313 # nested chroots, among other potential problems. | 313 # nested chroots, among other potential problems. |
314 function assert_outside_chroot { | 314 function assert_outside_chroot { |
315 if [ $INSIDE_CHROOT -ne 0 ] | 315 if [ $INSIDE_CHROOT -ne 0 ]; then |
316 then | |
317 echo "This script must be run outside the chroot." | 316 echo "This script must be run outside the chroot." |
318 exit 1 | 317 exit 1 |
319 fi | 318 fi |
320 } | 319 } |
321 | 320 |
322 function assert_not_root_user { | 321 function assert_not_root_user { |
323 if [ `id -u` = 0 ]; then | 322 if [ $(id -u) = 0 ]; then |
324 echo "This script must be run as a non-root user." | 323 echo "This script must be run as a non-root user." |
325 exit 1 | 324 exit 1 |
326 fi | 325 fi |
327 } | 326 } |
328 | 327 |
329 # Install a package if it's not already installed | |
330 function install_if_missing { | |
331 # Positional parameters from calling script. :? means "fail if unset". | |
332 PKG_NAME=${1:?} | |
333 shift | |
334 | |
335 if [ -z `which $PKG_NAME` ] | |
336 then | |
337 echo "Can't find $PKG_NAME; attempting to install it." | |
338 sudo apt-get --yes --force-yes install $PKG_NAME | |
339 fi | |
340 } | |
341 | |
342 # Returns true if the input file is whitelisted. | 328 # Returns true if the input file is whitelisted. |
343 # | 329 # |
344 # $1 - The file to check | 330 # $1 - The file to check |
345 is_whitelisted() { | 331 is_whitelisted() { |
346 local file=$1 | 332 local file=$1 |
347 local whitelist="$FLAGS_whitelist" | 333 local whitelist="$FLAGS_whitelist" |
348 test -f "$whitelist" || (echo "Whitelist file missing ($whitelist)" && exit 1) | 334 test -f "$whitelist" || (echo "Whitelist file missing ($whitelist)" && exit 1) |
349 | 335 |
350 local checksum=$(md5sum "$file" | awk '{ print $1 }') | 336 local checksum=$(md5sum "$file" | awk '{ print $1 }') |
351 local count=$(sed -e "s/#.*$//" "${whitelist}" | grep -c "$checksum" \ | 337 local count=$(sed -e "s/#.*$//" "${whitelist}" | grep -c "$checksum" \ |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 } | 381 } |
396 | 382 |
397 function die { | 383 function die { |
398 error "$1" | 384 error "$1" |
399 exit 1 | 385 exit 1 |
400 } | 386 } |
401 | 387 |
402 # Retry an emerge command according to $FLAGS_retries | 388 # Retry an emerge command according to $FLAGS_retries |
403 # The $EMERGE_JOBS flags will only be added the first time the command is run | 389 # The $EMERGE_JOBS flags will only be added the first time the command is run |
404 function eretry () { | 390 function eretry () { |
405 local i= | 391 local i |
406 for i in $(seq $FLAGS_retries); do | 392 for i in $(seq $FLAGS_retries); do |
407 echo Retrying $* | 393 echo "Retrying $@" |
408 $* $EMERGE_JOBS && return 0 | 394 "$@" $EMERGE_JOBS && return 0 |
409 done | 395 done |
410 $* && return 0 | 396 "$@" && return 0 |
411 return 1 | 397 return 1 |
412 } | 398 } |
413 | 399 |
414 # Removes single quotes around parameter | 400 # Removes single quotes around parameter |
415 # Arguments: | 401 # Arguments: |
416 # $1 - string which optionally has surrounding quotes | 402 # $1 - string which optionally has surrounding quotes |
417 # Returns: | 403 # Returns: |
418 # None, but prints the string without quotes. | 404 # None, but prints the string without quotes. |
419 function remove_quotes() { | 405 function remove_quotes() { |
420 echo "$1" | sed -e "s/^'//; s/'$//" | 406 echo "$1" | sed -e "s/^'//; s/'$//" |
(...skipping 27 matching lines...) Expand all Loading... |
448 sudo umount -d -l "${path}" || die "Failed to lazily unmount ${path}" | 434 sudo umount -d -l "${path}" || die "Failed to lazily unmount ${path}" |
449 fi | 435 fi |
450 } | 436 } |
451 | 437 |
452 # Fixes symlinks that are incorrectly prefixed with the build root ${1} | 438 # Fixes symlinks that are incorrectly prefixed with the build root ${1} |
453 # rather than the real running root '/'. | 439 # rather than the real running root '/'. |
454 # TODO(sosa) - Merge setup - cleanup below with this method. | 440 # TODO(sosa) - Merge setup - cleanup below with this method. |
455 fix_broken_symlinks() { | 441 fix_broken_symlinks() { |
456 local build_root="${1}" | 442 local build_root="${1}" |
457 local symlinks=$(find "${build_root}/usr/local" -lname "${build_root}/*") | 443 local symlinks=$(find "${build_root}/usr/local" -lname "${build_root}/*") |
| 444 local symlink |
458 for symlink in ${symlinks}; do | 445 for symlink in ${symlinks}; do |
459 echo "Fixing ${symlink}" | 446 echo "Fixing ${symlink}" |
460 local target=$(ls -l "${symlink}" | cut -f 2 -d '>') | 447 local target=$(ls -l "${symlink}" | cut -f 2 -d '>') |
461 # Trim spaces from target (bashism). | 448 # Trim spaces from target (bashism). |
462 target=${target/ /} | 449 target=${target/ /} |
463 # Make new target (removes rootfs prefix). | 450 # Make new target (removes rootfs prefix). |
464 new_target=$(echo ${target} | sed "s#${build_root}##") | 451 new_target=$(echo ${target} | sed "s#${build_root}##") |
465 | 452 |
466 echo "Fixing symlink ${symlink}" | 453 echo "Fixing symlink ${symlink}" |
467 sudo unlink "${symlink}" | 454 sudo unlink "${symlink}" |
(...skipping 16 matching lines...) Expand all Loading... |
484 | 471 |
485 # If our var target is actually the standard var, we are cleaning up the | 472 # If our var target is actually the standard var, we are cleaning up the |
486 # symlinks (could also check for /usr/local for the dev_image_target). | 473 # symlinks (could also check for /usr/local for the dev_image_target). |
487 if [ ${var_target} = "/var" ]; then | 474 if [ ${var_target} = "/var" ]; then |
488 echo "Cleaning up /usr/local symlinks for ${dev_image_root}" | 475 echo "Cleaning up /usr/local symlinks for ${dev_image_root}" |
489 else | 476 else |
490 echo "Setting up symlinks for /usr/local for ${dev_image_root}" | 477 echo "Setting up symlinks for /usr/local for ${dev_image_root}" |
491 fi | 478 fi |
492 | 479 |
493 # Set up symlinks that should point to ${dev_image_target}. | 480 # Set up symlinks that should point to ${dev_image_target}. |
| 481 local path |
494 for path in usr local; do | 482 for path in usr local; do |
495 if [ -h "${dev_image_root}/${path}" ]; then | 483 if [ -h "${dev_image_root}/${path}" ]; then |
496 sudo unlink "${dev_image_root}/${path}" | 484 sudo unlink "${dev_image_root}/${path}" |
497 elif [ -e "${dev_image_root}/${path}" ]; then | 485 elif [ -e "${dev_image_root}/${path}" ]; then |
498 die "${dev_image_root}/${path} should be a symlink if exists" | 486 die "${dev_image_root}/${path} should be a symlink if exists" |
499 fi | 487 fi |
500 sudo ln -s ${dev_image_target} "${dev_image_root}/${path}" | 488 sudo ln -s ${dev_image_target} "${dev_image_root}/${path}" |
501 done | 489 done |
502 | 490 |
503 # Setup var symlink. | 491 # Setup var symlink. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 printf '\000' | | 537 printf '\000' | |
550 sudo dd of="$rootfs" seek=$((offset + ro_compat_offset)) \ | 538 sudo dd of="$rootfs" seek=$((offset + ro_compat_offset)) \ |
551 conv=notrunc count=1 bs=1 | 539 conv=notrunc count=1 bs=1 |
552 } | 540 } |
553 | 541 |
554 # Get current timestamp. Assumes common.sh runs at startup. | 542 # Get current timestamp. Assumes common.sh runs at startup. |
555 start_time=$(date +%s) | 543 start_time=$(date +%s) |
556 | 544 |
557 # Print time elsapsed since start_time. | 545 # Print time elsapsed since start_time. |
558 print_time_elapsed() { | 546 print_time_elapsed() { |
559 end_time=$(date +%s) | 547 local end_time=$(date +%s) |
560 elapsed_seconds="$(( $end_time - $start_time ))" | 548 local elapsed_seconds=$(($end_time - $start_time)) |
561 minutes="$(( $elapsed_seconds / 60 ))" | 549 local minutes=$(($elapsed_seconds / 60)) |
562 seconds="$(( $elapsed_seconds % 60 ))" | 550 local seconds=$(($elapsed_seconds % 60)) |
563 echo "Elapsed time: ${minutes}m${seconds}s" | 551 echo "Elapsed time: ${minutes}m${seconds}s" |
564 } | 552 } |
565 | 553 |
566 # This function is a place to put code to incrementally update the | 554 # This function is a place to put code to incrementally update the |
567 # chroot so that users don't need to fully re-make it. It should | 555 # chroot so that users don't need to fully re-make it. It should |
568 # be called from scripts that are run _outside_ the chroot. | 556 # be called from scripts that are run _outside_ the chroot. |
569 # | 557 # |
570 # Please put date information so it's easy to keep track of when | 558 # Please put date information so it's easy to keep track of when |
571 # old hacks can be retired and so that people can detect when a | 559 # old hacks can be retired and so that people can detect when a |
572 # hack triggered when it shouldn't have. | 560 # hack triggered when it shouldn't have. |
573 # | 561 # |
574 # ${1} specifies the location of the chroot. | 562 # ${1} specifies the location of the chroot. |
575 chroot_hacks_from_outside() { | 563 chroot_hacks_from_outside() { |
576 # Give args better names. | 564 # Give args better names. |
577 local chroot_dir="${1}" | 565 local chroot_dir=$1 |
578 | 566 |
579 # Add root as a sudoer if not already done. | 567 # Add root as a sudoer if not already done. |
580 if ! sudo grep -q '^root ALL=(ALL) ALL$' "${chroot_dir}/etc/sudoers" ; then | 568 if ! sudo grep -q '^root ALL=(ALL) ALL$' "${chroot_dir}/etc/sudoers" ; then |
581 info "Upgrading old chroot (pre 2010-10-19) - adding root to sudoers" | 569 info "Upgrading old chroot (pre 2010-10-19) - adding root to sudoers" |
582 sudo bash -c "echo root ALL=\(ALL\) ALL >> \"${chroot_dir}/etc/sudoers\"" | 570 sudo bash -c "echo root ALL=\(ALL\) ALL >> \"${chroot_dir}/etc/sudoers\"" |
583 fi | 571 fi |
584 } | 572 } |
585 | 573 |
586 # The board and variant command line options can be used in a number of ways | 574 # The board and variant command line options can be used in a number of ways |
587 # to specify the board and variant. The board can encode both pieces of | 575 # to specify the board and variant. The board can encode both pieces of |
588 # information separated by underscores. Or the variant can be passed using | 576 # information separated by underscores. Or the variant can be passed using |
589 # the separate variant option. This function extracts the canonical board and | 577 # the separate variant option. This function extracts the canonical board and |
590 # variant information and provides it in the BOARD, VARIANT and BOARD_VARIANT | 578 # variant information and provides it in the BOARD, VARIANT and BOARD_VARIANT |
591 # variables. | 579 # variables. |
592 get_board_and_variant() { | 580 get_board_and_variant() { |
593 local flags_board="${1}" | 581 local flags_board="${1}" |
594 local flags_variant="${2}" | 582 local flags_variant="${2}" |
595 | 583 |
596 BOARD=$(echo "$flags_board" | cut -d '_' -f 1) | 584 BOARD=$(echo "$flags_board" | cut -d '_' -f 1) |
597 VARIANT=${flags_variant:-$(echo "$flags_board" | cut -s -d '_' -f 2)} | 585 VARIANT=${flags_variant:-$(echo "$flags_board" | cut -s -d '_' -f 2)} |
598 | 586 |
599 if [ -n "$VARIANT" ]; then | 587 if [ -n "$VARIANT" ]; then |
600 BOARD_VARIANT="${BOARD}_${VARIANT}" | 588 BOARD_VARIANT="${BOARD}_${VARIANT}" |
601 else | 589 else |
602 BOARD_VARIANT="${BOARD}" | 590 BOARD_VARIANT="${BOARD}" |
603 fi | 591 fi |
604 } | 592 } |
OLD | NEW |