Chris Sosa | 8951738 | 2012-03-15 23:16:31 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
| 7 | # This script takes a checksum file and merges it into the packages |
| 8 | # checksum file in ../packages/packages.checksum. |
| 9 | |
Chris Sosa | 68c3e55 | 2012-03-19 16:16:38 -0700 | [diff] [blame] | 10 | # This script is thread-safe. |
Chris Sosa | 8951738 | 2012-03-15 23:16:31 -0700 | [diff] [blame] | 11 | |
| 12 | set -e |
| 13 | |
| 14 | function main () { |
| 15 | local merge_file="$1" |
| 16 | local packages_dir="$(dirname $0)/../packages" |
| 17 | local checksum_file="${packages_dir}/packages.checksum" |
| 18 | |
| 19 | # Preparatory work. |
| 20 | mkdir -p "${packages_dir}" |
| 21 | touch ${checksum_file} |
| 22 | |
| 23 | if [ ! -f "${merge_file}" ]; then |
| 24 | return |
| 25 | fi |
| 26 | |
Chris Sosa | 68c3e55 | 2012-03-19 16:16:38 -0700 | [diff] [blame] | 27 | # This operation is performed using an flock on the packages dir |
Chris Sosa | 8951738 | 2012-03-15 23:16:31 -0700 | [diff] [blame] | 28 | # to allow it to run concurrently. |
| 29 | flock "${packages_dir}" \ |
| 30 | -c "sort -k2,2 -u ${merge_file} ${checksum_file} -o ${checksum_file}" |
| 31 | } |
| 32 | |
| 33 | if [ $# != 1 ]; then |
| 34 | echo "Not enough arguments." |
| 35 | exit 1 |
| 36 | fi |
| 37 | |
| 38 | main $1 |