1#!/bin/bash
2
3##########################################################################
4# Copyright (c) 2010, ETH Zurich.
5# All rights reserved.
6#
7# This file is distributed under the terms in the attached LICENSE file.
8# If you do not find this file, copies can be found by writing to:
9# ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
10##########################################################################
11
12# exit immediately on error
13set -e
14
15# grab arguments
16SRCDIR="$1"
17ARCHIVE="$2"
18shift 2
19
20TMPDIR=$(mktemp -d)
21
22for src in $*; do
23    # construct destination file name relative to archive dir
24    # $SRCDIR/foo/bar/baz.txt -> skb/bar/baz.txt
25    dst=skb/${src#$SRCDIR/*/}
26
27    # ensure target directory exists
28    mkdir -p $TMPDIR/$(dirname $dst)
29
30    # copy to target and add to list
31    cp $src $TMPDIR/$dst
32    echo $dst >> $TMPDIR/files
33done
34
35# run cpio in the temp dir
36cd $TMPDIR
37cpio -o -H crc -O ramfs.cpio < files
38cd "$OLDPWD"
39
40# compress it
41gzip $TMPDIR/ramfs.cpio
42
43# move it to the right place
44mv $TMPDIR/ramfs.cpio.gz $ARCHIVE
45
46# clean up
47rm -rf $TMPDIR
48