2

I have a project with the usual stuff (source code, yadda, yadda) and I want to have a command to Scons (but it could be whatever build system to be honest) that will do the following:

  1. Build the system -- this is easy.
  2. Create a tar ball of the system -- this is easy.
  3. When the content of the tar ball are extracted, they extract in a fubar-VERSION/ directory -- this is the tricky part.

I can do the latter manually by creating a symlink, then taring from one directory above the project one but that feel inelegant. Any idea?

To clarify, I want to be able to do this:

; pwd
~/project
; scons release
[...]
; cp project-X.Y.Z.tbz /tmp
; cd /tmp
; tar jxvf project-X.Y.Z.tbz
./project-X.Y.Z/[...]

Thus the archives extracts in a directory named after the project with the right version number.

2
  • Shouldn't this be configured in your build system?
    – rahmu
    Mar 1, 2012 at 11:44
  • In an ideal world yes... But the question is more to do with tar rather then the build system/release mechanism. Mar 1, 2012 at 12:13

2 Answers 2

5

With GNU tar:

tar cjf ../fubar-4.2.tar.bz2 --transform='s/^\./fubar-4.2/' --exclude='*.o' .

Traditional tar implementations have no way to do this. Even FreeBSD tar has no similar feature that I know of.

With pax, the POSIX replacement for cpio and tar:

pax -w -s '/^\./fubar-4.2/' -s '/\.o$//' . | bzip2 >../fubar-4.2.tar.bz2

Although pax is mandatory in current POSIX/Single Unix standards, many Linux distributions don't install it by default. If you support both GNU tar and pax, you'll cover almost all non-embedded unices out there.

0
2

At least bsdtar 2.8.4 and up has the -s pattern option to modify file or archive member names according to the given basic regex pattern.

# using '^\.' as pattern
bsdtar -czvf test.tar.gz .
bsdtar -tzvf test.tar.gz
bsdtar -s '|^\.|archive-X.Y.Z|' -xzvf test.tar.gz

# using '^[^/]*' as pattern
bsdtar -C .. -czvf test.tar.gz "$(basename "$(pwd -P)")"
bsdtar -tzvf test.tar.gz
bsdtar -s '|^[^/]*|archive-X.Y.Z|' -xzvf test.tar.gz

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .