CVS exercises AROC Workshop Guatemala City, Guatemala 2010 1. Install cvs $ sudo apt-get install cvs 2. Init a new CVS ROOT: *NOTE* Do this exercise as the normal user, NOT ROOT! - First, set the environment variable "CVSROOT" to the path Where your CVS repository will be created. We are going to do this as the "tldadmin" user, so be sure you are not root. $ CVSROOT=/home/tldadmin/cvs $ export CVSROOT - Now create the directory $ mkdir $CVSROOT $ cvs init - Check that it was created correctly! $ ls -l /home/tldadmin/cvs - You should see a directory called "CVSROOT" - Look at the contents of the directory. $ ls -l /home/tldadmin/cvs/CVSROOT There should be quite a few files in the directory. 3. Let's create a project in CVS for the Nagios configuration files on your system and import these files into CVS! $ mkdir /home/tldadmin/temp $ cp /etc/nagios3/conf.d/* /home/tldadmin/temp/. - Now we need to import these files into CVS: - Let's make a new project called "configs" $ cd /home/tldadmin/temp $ cvs import configs before_cvs start (Note: the "before_cvs" and "start" are just names to say that we are importing from "before we used CVS, and this is the start of the new project") - When you see this: Select an editor. To change later, run 'select-editor'. 1. /bin/ed 2. /bin/nano <---- easiest 3. /usr/bin/vim.basic 4. /usr/bin/vim.tiny Choose 1-4 [2]: Select the editor you wish to use for comments in CVS. Your instructor likes choice 3. Once you select an editor you will see this: CVS: ---------------------------------------------------------------------- CVS: Enter Log. Lines beginning with `CVS:' are removed automatically CVS: CVS: ---------------------------------------------------------------------- ... just enter a message saying what you did. For example, add a line at the top of the file that says something like: "This is a first import of our config files" ... Then save the file + quit. You should see something like this: N configs/contacts_nagios2.cfg N configs/services_nagios2.cfg N configs/pcs.cfg N configs/timeperiods_nagios2.cfg N configs/switches.cfg N configs/extinfo_nagios2.cfg N configs/host-gateway_nagios3.cfg N configs/generic-service_nagios2.cfg N configs/localhost_nagios2.cfg N configs/hostgroups_nagios2.cfg N configs/routers.cfg N configs/servicegroups.cfg N configs/generic-host_nagios2.cfg No conflicts created by this import 3b. Look at the contents of /home/tldadmin/cvs/configs $ ls -l /home/tldadmin/cvs/configs total 52 -r--r--r-- 1 tldadmin tldadmin 2873 2010-07-21 17:00 contacts_nagios2.cfg,v -r--r--r-- 1 tldadmin tldadmin 1354 2010-07-21 17:00 extinfo_nagios2.cfg,v -r--r--r-- 1 tldadmin tldadmin 1654 2010-07-21 17:00 generic-host_nagios2.cfg,v -r--r--r-- 1 tldadmin tldadmin 2305 2010-07-21 17:00 generic-service_nagios2.cfg,v -r--r--r-- 1 tldadmin tldadmin 714 2010-07-21 17:00 host-gateway_nagios3.cfg,v -r--r--r-- 1 tldadmin tldadmin 2642 2010-07-21 17:00 hostgroups_nagios2.cfg,v -r--r--r-- 1 tldadmin tldadmin 2669 2010-07-21 17:00 localhost_nagios2.cfg,v -r--r--r-- 1 tldadmin tldadmin 3669 2010-07-21 17:00 pcs.cfg,v -r--r--r-- 1 tldadmin tldadmin 961 2010-07-21 17:00 routers.cfg,v -r--r--r-- 1 tldadmin tldadmin 1088 2010-07-21 17:00 servicegroups.cfg,v -r--r--r-- 1 tldadmin tldadmin 2253 2010-07-21 17:00 services_nagios2.cfg,v -r--r--r-- 1 tldadmin tldadmin 997 2010-07-21 17:00 switches.cfg,v -r--r--r-- 1 tldadmin tldadmin 2111 2010-07-21 17:00 timeperiods_nagios2.cfg,v 4. Now we can remove our temp directory, and check out the configs/ project from CVS! $ cd /home/tldadmin $ rm -rf temp - Let's now check out from cvs : $ cvs -d /home/tldadmin/cvs co configs - You should see the following: cvs checkout: Updating configs U configs/contacts_nagios2.cfg U configs/extinfo_nagios2.cfg U configs/generic-host_nagios2.cfg U configs/generic-service_nagios2.cfg U configs/host-gateway_nagios3.cfg U configs/hostgroups_nagios2.cfg U configs/localhost_nagios2.cfg U configs/pcs.cfg U configs/routers.cfg U configs/servicegroups.cfg U configs/services_nagios2.cfg U configs/switches.cfg U configs/timeperiods_nagios2.cfg $ ls -l /home/tldadmin/configs/ - Notice the CVS directory in /home/tldadmin/configs/ *NOTE* remember, never modify the CVS/ directory by hand. It is only for experienced CVS users... - Note that the configs directory is created in whatever directory you in in when you issue the cvs co (checkout) command. 5. Modify a file, add another one, and check things in again: $ cd /home/tldadmin/configs $ vi pcs.cfg Modify the config – for example, you could add a comment line at the top of the file. "# This version of pcs is part of our Concurrent Versioning System repository" (Don't use the quotes "). Then save and quit. - Add the APT sources.list file to the directory: $ cp /etc/apt/sources.list . - Tell cvs to show us the status: $ cvs status - There's a lot, to see it all: $ cvs status | more - Add sources.list to CVS: $ cvs add sources.list - You should see this: cvs add: scheduling file `sources.list' for addition cvs add: use `cvs commit' to add this file permanently - You are now ready to commit! $ cvs commit - If all goes well, you should have this in your editor window: CVS: ---------------------------------------------------------------------- CVS: Enter Log. Lines beginning with `CVS:' are removed automatically CVS: CVS: Committing in . CVS: CVS: Modified Files: CVS: pcs.cfg CVS: Added Files: CVS: sources.list CVS: ---------------------------------------------------------------------- ... add a message: Importing APT sources.list, and modifying the pcs.cfg file. ... then save + quit You should see this: cvs commit: Examining . /home/tldadmin/cvs/configs/pcs.cfg,v <-- pcs.cfg new revision: 1.2; previous revision: 1.1 /home/tldadmin/cvs/configs/sources.list,v <-- sources.list initial revision: 1.1 6. Let's see the history for the pcs.cfg file: $ cvs log pcs.cfg ... notice the output - Finally, let's try and see the difference between two versions of the config.smokeping file: $ cvs diff -r 1.1 -r 1.2 pcs.cfg - What do you notice ?