lib: make usbwrap API style match the rest of Barry (Get/Set consistency)
[barry/progweb.git] / maintainer / save.sh
blob3d19e3a0b6f49071eda2401a8e7ef6181046c78c
1 #!/bin/sh
3 if [ -z "$1" -o -z "$2" -o -z "$3" -o \( "$(whoami)" = "root" -a -z "$CHOWNUSER" \) ] ; then
4 echo
5 echo "Usage: ./save.sh results_dir dir_tag file_tag [script args...]"
6 echo
7 echo "Runs the given script, and then copies all resulting binaries"
8 echo "from <results_dir>/results/ into build/<TAG> and renames all"
9 echo "the files to include <file_tag> in the name."
10 echo
11 echo "Expects CHOWNUSER to be set appropriately"
12 echo "in the environment if run as root."
13 echo
14 exit 1
17 RESULTSDIR="$1"
18 shift
19 TAG="$1"
20 shift
21 SHORTTAG="$1"
22 shift
24 set -e
26 # run the script
27 echo "Running: $@"
28 "$@"
30 # copy the results back to the target directory
31 mkdir -p "build/$TAG"
32 cp "$RESULTSDIR"/* "build/$TAG"
33 if [ "$(whoami)" = "root" ] ; then
34 chown -R "$CHOWNUSER" "build/$TAG"
37 # We do this manually in a for loop, since the rename command is
38 # not the same across various linux distros...
40 cd "build/$TAG"
42 for f in *.deb ; do
43 if [ -f "$f" ] ; then
44 mv "$f" "$(echo $f | sed "s/_\([^_]*\)\.deb$/_${SHORTTAG}_\1.deb/")"
46 done
48 for f in *.rpm ; do
49 if [ -f "$f" ] ; then
50 mv "$f" "$(echo $f | sed "s/\.\([^.]*\)\.rpm$/.${SHORTTAG}.\1.rpm/")"
52 done