OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # Script to archive build results. Used by the buildbots. | 7 # Script to archive build results. Used by the buildbots. |
8 | 8 |
9 # Load common constants. This should be the first executable line. | 9 # Load common constants. This should be the first executable line. |
10 # The path to common.sh should be relative to your script's location. | 10 # The path to common.sh should be relative to your script's location. |
11 . "$(dirname "$0")/common.sh" | 11 . "$(dirname "$0")/common.sh" |
12 | 12 |
13 # Script must be run outside the chroot | 13 # Script must be run outside the chroot |
14 assert_outside_chroot | 14 assert_outside_chroot |
15 | 15 |
16 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images" | 16 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images" |
17 # Default to the most recent image | 17 # Default to the most recent image |
18 DEFAULT_FROM="${IMAGES_DIR}/`ls -t1 $IMAGES_DIR | head -1`" | 18 DEFAULT_FROM="${IMAGES_DIR}/`ls -t1 $IMAGES_DIR | head -1`" |
19 DEFAULT_TO="${GCLIENT_ROOT}/archive" | 19 DEFAULT_TO="${GCLIENT_ROOT}/archive" |
20 | 20 |
21 # Flags | 21 # Flags |
22 DEFINE_string from "$DEFAULT_FROM" \ | 22 DEFINE_string from "$DEFAULT_FROM" \ |
23 "Directory to archive" | 23 "Directory to archive" |
24 DEFINE_string to "$DEFAULT_TO" "Directory of build archive" | 24 DEFINE_string to "$DEFAULT_TO" "Directory of build archive" |
25 DEFINE_integer keep_max 0 "Maximum builds to keep in archive (0=all)" | 25 DEFINE_integer keep_max 0 "Maximum builds to keep in archive (0=all)" |
26 DEFINE_string zipname "image.zip" "Name of zip file to create." | 26 DEFINE_string zipname "image.zip" "Name of zip file to create." |
27 DEFINE_boolean official_build $FLAGS_FALSE "Set CHROMEOS_OFFICIAL=1 for release
builds." | 27 DEFINE_boolean official_build $FLAGS_FALSE "Set CHROMEOS_OFFICIAL=1 for release
builds." |
28 DEFINE_string build_number "" \ | 28 DEFINE_string build_number "" \ |
29 "The build-bot build number (when called by buildbot only)." "b" | 29 "The build-bot build number (when called by buildbot only)." "b" |
| 30 DEFINE_boolean test_mod $FLAGS_TRUE "Modify image for testing purposes" |
30 | 31 |
31 # Parse command line | 32 # Parse command line |
32 FLAGS "$@" || exit 1 | 33 FLAGS "$@" || exit 1 |
33 eval set -- "${FLAGS_ARGV}" | 34 eval set -- "${FLAGS_ARGV}" |
34 | 35 |
35 # Die on any errors. | 36 # Die on any errors. |
36 set -e | 37 set -e |
37 | 38 |
38 if [ $FLAGS_official_build -eq $FLAGS_TRUE ] | 39 if [ $FLAGS_official_build -eq $FLAGS_TRUE ] |
39 then | 40 then |
(...skipping 23 matching lines...) Expand all Loading... |
63 | 64 |
64 # Create the output directory | 65 # Create the output directory |
65 OUTDIR="${FLAGS_to}/${LAST_CHANGE}" | 66 OUTDIR="${FLAGS_to}/${LAST_CHANGE}" |
66 ZIPFILE="${OUTDIR}/${FLAGS_zipname}" | 67 ZIPFILE="${OUTDIR}/${FLAGS_zipname}" |
67 echo "archive to dir: $OUTDIR" | 68 echo "archive to dir: $OUTDIR" |
68 echo "archive to file: $ZIPFILE" | 69 echo "archive to file: $ZIPFILE" |
69 | 70 |
70 rm -rf "$OUTDIR" | 71 rm -rf "$OUTDIR" |
71 mkdir -p "$OUTDIR" | 72 mkdir -p "$OUTDIR" |
72 | 73 |
| 74 # Modify image for test if flag set. |
| 75 if [ $FLAGS_test_mod -eq $FLAGS_TRUE ] |
| 76 then |
| 77 echo "Modifying image for test" |
| 78 cp "${DEFAULT_FROM}/rootfs.image" "${DEFAULT_FROM}/rootfs_test.image" |
| 79 . "${SCRIPTS_DIR}/mod_image_for_test.sh" --image rootfs_test.image |
| 80 cd - |
| 81 fi |
| 82 |
73 # Zip the build | 83 # Zip the build |
74 echo "Compressing and archiving build..." | 84 echo "Compressing and archiving build..." |
75 cd "$DEFAULT_FROM" | 85 cd "$DEFAULT_FROM" |
76 zip -r "$ZIPFILE" * | 86 zip -r "$ZIPFILE" * |
77 cd - | 87 cd - |
78 | 88 |
79 # Update LATEST file | 89 # Update LATEST file |
80 echo "$LAST_CHANGE" > "${FLAGS_to}/LATEST" | 90 echo "$LAST_CHANGE" > "${FLAGS_to}/LATEST" |
81 | 91 |
82 # Make sure files are readable | 92 # Make sure files are readable |
83 chmod 644 "$ZIPFILE" "${FLAGS_to}/LATEST" | 93 chmod 644 "$ZIPFILE" "${FLAGS_to}/LATEST" |
84 chmod 755 "$OUTDIR" | 94 chmod 755 "$OUTDIR" |
85 | 95 |
86 # Purge old builds if necessary | 96 # Purge old builds if necessary |
87 if [ $FLAGS_keep_max -gt 0 ] | 97 if [ $FLAGS_keep_max -gt 0 ] |
88 then | 98 then |
89 echo "Deleting old builds (all but the newest ${FLAGS_keep_max})..." | 99 echo "Deleting old builds (all but the newest ${FLAGS_keep_max})..." |
90 cd "$FLAGS_to" | 100 cd "$FLAGS_to" |
91 # +2 because line numbers start at 1 and need to skip LATEST file | 101 # +2 because line numbers start at 1 and need to skip LATEST file |
92 rm -rf `ls -t1 | tail --lines=+$(($FLAGS_keep_max + 2))` | 102 rm -rf `ls -t1 | tail --lines=+$(($FLAGS_keep_max + 2))` |
93 cd - | 103 cd - |
94 fi | 104 fi |
95 | 105 |
96 echo "Done." | 106 echo "Done." |
OLD | NEW |