Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Use CVS to synch login scripts, etc. amongst machines UNIX
Like many of you, I maintain and work on many unix machines on a regular basis. Unlike many of you, I'm a bit off when it comes to my obsession of maintaining my login scripts and prefs across those machines. :) My login scripts and prefs have been evolving for ~10 years as I've picked up tricks and tips from various friends' versions, blatantly ripped off bits here and there, and modified them for use in various OSes and shells as needed. Because I've spent so much time feeding, grooming and caring for them, I wanted a way to keep them consistent across all the machines and operating systems I use.

Many years ago a friend and I began using CVS to help organize our collaborative work. The lightbulb went on and soon after my login scripts found themselves happily residing in CVS and, therefore, on every machine I use ... in perfect sync. Ahhhh. :)

I did need a way to keep the packaged login scripts and preference files tidy and make them work with shells expecting them to be in specific locations. I chose an arbitrary directory name in my home folder (corresponding with the name of the module on the CVS server) to keep them in. I call it transport. Inside transport are versions of my various login scripts and preference files I like to keep in sync across machines (without the leading dot for editing ease). I check them out on a new machine and symlink to them from the proper, shell expected location... ie:
 % cd ~wagner
 % ln -s transport/cshrc .cshrc
I do this for my login scripts (tcsh, .login, .login, etc.), .vim, .vimrc, .xinitrc, .screenrc, and other pref files. Each time I modify one of these items, I commit those changes to the CVS server and, when I log into another machine, I update that set with the version on the CVS server. This works great for other sets of items you may want to keep in sync across machines as well. ie: maintaining all your administration scripts across machines in a similar way.

It is also pretty easy to expand a login script with conditionals to set aliases, variables, etc. based on the hostname or the flavor of OS that it's being used on. ie: I prefer to see top display information sorted on CPU use. In linux, that is the default. top -u is how you'd see that type of sorting with the default OS X top. To get a similar display on both OSs without thinking about it, I use something like this in my (tcsh) login script:
# osx stuff
if (`uname` == 'Darwin') then
    alias top 'top -u'
bash users could use something like:
# osx stuff
if [ `uname` = "Linux" ]
  alias ls='puke1'
If I am on a linux machine this conditional returns false and, therefore runs top with no arguments. If I am on an OS X machine, it will run top with the -u argument. You can use a hostname conditional to set up different aliases based on the host name. When I excitedly begin to explain these ideas to my friends, they tend to look at me sideways and slowly shuffle away. :) I hope some of you here can use and benefit from them and I would appreciate any suggestions or ideas on improving upon them.

Remember, your login scripts can make your life in the shell oh so much easier and more efficient! Hopefully there is a CVS primer around here somewhere...

[ robg adds: There are a couple (1, 2) older hints (very older!) that may be helpful, and then this one that talks about CVS under 10.2 -- this may be the most applicable of the bunch, though I don't know if it still works this way in Panther.]
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)

Use CVS to synch login scripts, etc. amongst machines | 7 comments | Create New Account
Click here to return to the 'Use CVS to synch login scripts, etc. amongst machines' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use cfengine instead.
Authored by: Cerebus on Nov 19, '03 12:42:16PM
cfengine is designed to do exactly this kind of distributed configuration. Rather than beat CVS into doing what you want, you might consider a more appropriate tool.

-- Cerebus

[ Reply to This | # ]

Use cfengine instead.
Authored by: maxnuma on Nov 19, '03 04:37:17PM

Not to flame, but holy crap! If the documentation for cfengine reads like the description, I know why people don't read it!

"Cfengine, or the configuration engine is an autonomous agent and a middle to high level policy language for building expert systems which administrate and configure large computer networks. Cfengine uses the idea of classes and a primitive intelligence to define and automate the configuration and maintenance of system state, for small to huge configurations. Cfengine is designed to be a part of acomputer immune system, and can be thought of as a gaming agent. It is ideal for cluster management and has been adopted for use all over the world in small and huge organizations alike. "

What the heck does that mean? At least with CVS, I know what it is supposed to do.

[ Reply to This | # ]
Use cfengine instead.
Authored by: Cerebus on Nov 19, '03 09:52:51PM

The formal docs are written as academic papers, and are a bit thick.

Read the examples instead, and there's an excellent tutorial. It's really not hard once you get started. 8)

-- Cerebus

[ Reply to This | # ]
Um... This is Perfectly Legtimitate Use of CVS
Authored by: EatingPie on Nov 21, '03 06:14:01PM

I believe you've misinterpreted what he's doing. He's not using CVS to manage the environments, he's using distribute and keep his environment *files* up-to-date. This is exactly what CVS was designed to do.

And from what I've read on cfengine, it's for system administration and system configuration. Not for shell *environment* configuration (that's the job of your .bashrc/.cshrc/.tcshrc etc. files). Here's the relevant quote...

Although intended to be a scheme for system administation to be run by the superuser, cfengine can also be used a scripting language by ordinary users.


[ Reply to This | # ]

Use CVS to synch login scripts, etc. amongst machines
Authored by: hariya on Nov 19, '03 12:53:08PM
Minor but crucial typo
That ls -s in the hint should actually be ln -s

[ Reply to This | # ]
Use CVS to synch login scripts, etc. amongst machines
Authored by: robg on Nov 19, '03 01:35:22PM

Thanks -- just fixed it. Probably my fault :)


[ Reply to This | # ]
Use CVS to synch login scripts, etc. amongst machines
Authored by: klktrk on Nov 19, '03 01:32:03PM

I've been doing this for about a year now. It's paradise! In my .bash_profile I have a case statement for just those customizations that are specific to each host I work on, and then the rest of the script contains universal settings, functions, preferences, one of which is my command line implementation of a trash can, as follows:

function trash () {
if [ ! -e $TRASHCAN ];then
for F in $@;do
mv -v $F $TRASHCAN
diskusage=`du -hs $TRASHCAN | cut -f 1`
echo "$diskusage in trash"
function emptytrash () {
if [ -e $TRASHCAN ];then
for F in `ls -A $TRASHCAN`;do
echo "Shredding $F..."
shred -fuz $F
echo "Trash has been shredded."
cd $wd
echo "Trash can is empty."

Now, instead of 'rm filename', I type 'trash filename'. It's a little safer, and I just empty the trash every week or so

[ Reply to This | # ]