menu: added new Keywords tag to .desktop files
[barry.git] / maintainer / save.sh
blob32c24897ee28829e4823ea4701ec452fe345bae4
1 #!/bin/bash
3 if [ -z "$1" -o -z "$2" -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 directory dir_tag and"
9 echo "renames all the files to include <file_tag> in the name."
10 echo
11 echo "file_tag can be an empty string to skip the rename."
12 echo
13 echo "Expects CHOWNUSER to be set appropriately"
14 echo "in the environment if run as root."
15 echo
16 exit 1
19 RESULTSDIR="$1"
20 shift
21 TAG="$1"
22 shift
23 SHORTTAG="$1"
24 shift
26 set -e
28 # run the script
29 echo "Running: $@"
30 "$@"
32 # copy the results back to the target directory
33 mkdir -p "$TAG"
34 cp "$RESULTSDIR"/* "$TAG"
35 if [ "$(whoami)" = "root" ] ; then
36 chown -R "$CHOWNUSER" "$TAG"
39 # We do this manually in a for loop, since the rename command is
40 # not the same across various linux distros...
41 if [ -n "$SHORTTAG" ] ; then
43 cd "$TAG"
45 for f in *.deb ; do
46 if [ -f "$f" ] ; then
47 mv "$f" "$(echo $f | sed "s/_\([^_]*\)\.deb$/_${SHORTTAG}_\1.deb/")"
49 done
51 for f in *.rpm ; do
52 if [ -f "$f" ] ; then
53 mv "$f" "$(echo $f | sed "s/\.\([^.]*\)\.rpm$/.${SHORTTAG}.\1.rpm/")"
55 done