blob: e27ca667fd405d3593b35905ca1cdd0ba1cda01b [file] [log] [blame]
Chris Sosa89517382012-03-15 23:16:31 -07001#!/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 Sosa68c3e552012-03-19 16:16:38 -070010# This script is thread-safe.
Chris Sosa89517382012-03-15 23:16:31 -070011
12set -e
13
14function 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 Sosa68c3e552012-03-19 16:16:38 -070027 # This operation is performed using an flock on the packages dir
Chris Sosa89517382012-03-15 23:16:31 -070028 # 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
33if [ $# != 1 ]; then
34 echo "Not enough arguments."
35 exit 1
36fi
37
38main $1