summaryrefslogtreecommitdiff
path: root/create-lw-file
blob: 106d46dda2e85261110c7018b4b1637134a90743 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash

exitstatus="0"
# put the files given on the command line into a tarball with the same name as the first file in that list.  that first file gets overwritten.
files=$*
tmpdir=`mktemp -q -d /tmp/lw-tar.XXXXXX `
# -q is quiet and -d is --directory.
# short options are used here for portability purposes on systems that don't
# see the benefit of the explanatory power of long options.
file=`basename $1`
if [ "x$tmpdir" != "x" ]; then
  cp $files $tmpdir
  tarball=$file.tar
  origdir=`pwd`
  cd $tmpdir
  tmpfiles=""
  for f in $files; do
          tmpfiles="$tmpfiles `basename $f`"
  done
  #we want to use --clamp-mtime but it is too new. (requires GNU tar version 1.29)
  #we want to use --sort=name but it is too new.
  tar -cvf $tarball $tmpfiles --mtime="@${SOURCE_DATE_EPOCH:-$(date +%s)}" --mode=go=rX,u+rw,a-s --owner=root --group=root --numeric-owner
  if [ "$?" != "0" ]; then
    exitstatus="1";
  fi
  cd $origdir
  cp -f $tmpdir/$tarball $1
  rm -f $tmpdir/*
  rmdir $tmpdir
fi

exit $exitstatus