With GNU tar (the default tar implementation on non-embedded Linux and on Cygwin):
tar czf env.tgz --transform 's/-deploy$//' .bashrc-deploy .profile …
This is also possible with pax, the POSIX replacement for cpio and tar, which unfortunately is missing from many default Linux installations, and also with BSD tar:
pax -w -x ustar '-s/-deploy$//' .bashrc-deploy .profile … | gzip >env.tgz
bsdtar -czf env.tgz '-s/-deploy$//' .bashrc-deploy .profile …
In all three cases, the s/REGEX/REPLACEMENT/
syntax is the same as ed
or sed
.
I question your approach. Having files with the same name but different contents on different machines is hard to maintain. Furthermore, it's easy to make a mistake if some files must remain private. My recommendation is to store your configuration files in subdirectories, and use symbolic links. For example, if .bashrc
must be private and site-specific and .profile
must be public and is the same everywhere:
.bashrc -> etc/local/private/.bashrc
.profile -> etc/.profile
Make etc/local
a symbolic link to a directory whose name is site-dependent (e.g. ~/etc/home
or ~/etc/work
), ensure that ~/etc/private
and ~/etc/*/private
are only accessible by you, and you're set. You can deploy the whole ~/etc
directory, and you'll only need to set the etc/local
symbolic link after unzipping the archive (or, even better, checking out from version control).
For a file like .bashrc
, which is probably mostly site-independent and public, split the file into two (or up to four) parts, public and private (plus site-specific files if necessary). Have the main part include the local parts:
if [ -e ~/etc/private/.bashrc ]; then . ~/etc/private/.bashrc; fi
if [ -e ~/etc/local/.bashrc ]; then . ~/etc/local/.bashrc; fi
if [ -e ~/etc/local/private/.bashrc ]; then . ~/etc/local/private/.bashrc; fi
In files which are written in a programming language, you can test the host name or domain name or other site-dependent characteristic dynamically, which lets you have a single file to maintain.
case $HOSTNAME in
darkstar) alias foo=some-local-command;;
esac
It's a bit surprising to have confidential content in .bashrc
. If you're defining environment variables, they belong in ~/.profile
.
pax
and the BSD version oftar
. – dotancohen Nov 13 '12 at 11:44bsdtar
is available on many Linux installations, such as an Arch default install (well, at least it was a year ago, I'm not using Arch anymore). IIRC, it's part oflibarchive
. – dubiousjim Nov 13 '12 at 14:01pax
andbsdtar
implementations I have access to, the pattern is applied to the whole path, not the filename (so anchoring wouldn't work that way) and POSIX is not clear about that. – Stéphane Chazelas Nov 13 '12 at 22:04