| 1 | CVS exercises |
|---|
| 2 | AROC Workshop |
|---|
| 3 | Guatemala City, Guatemala 2010 |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | 1. Install cvs |
|---|
| 7 | |
|---|
| 8 | $ sudo apt-get install cvs |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | 2. Init a new CVS ROOT: |
|---|
| 12 | |
|---|
| 13 | *NOTE* Do this exercise as the normal user, NOT ROOT! |
|---|
| 14 | |
|---|
| 15 | - First, set the environment variable "CVSROOT" to the path |
|---|
| 16 | Where your CVS repository will be created. We are going to |
|---|
| 17 | do this as the "tldadmin" user, so be sure you are not root. |
|---|
| 18 | |
|---|
| 19 | $ CVSROOT=/home/tldadmin/cvs |
|---|
| 20 | $ export CVSROOT |
|---|
| 21 | |
|---|
| 22 | - Now create the directory |
|---|
| 23 | |
|---|
| 24 | $ mkdir $CVSROOT |
|---|
| 25 | $ cvs init |
|---|
| 26 | |
|---|
| 27 | - Check that it was created correctly! |
|---|
| 28 | |
|---|
| 29 | $ ls -l /home/tldadmin/cvs |
|---|
| 30 | |
|---|
| 31 | - You should see a directory called "CVSROOT" |
|---|
| 32 | - Look at the contents of the directory. |
|---|
| 33 | |
|---|
| 34 | $ ls -l /home/tldadmin/cvs/CVSROOT |
|---|
| 35 | |
|---|
| 36 | There should be quite a few files in the directory. |
|---|
| 37 | |
|---|
| 38 | 3. Let's create a project in CVS for the Nagios configuration files on your system |
|---|
| 39 | and import these files into CVS! |
|---|
| 40 | |
|---|
| 41 | $ mkdir /home/tldadmin/temp |
|---|
| 42 | $ cp /etc/nagios3/conf.d/* /home/tldadmin/temp/. |
|---|
| 43 | |
|---|
| 44 | - Now we need to import these files into CVS: |
|---|
| 45 | - Let's make a new project called "configs" |
|---|
| 46 | |
|---|
| 47 | $ cd /home/tldadmin/temp |
|---|
| 48 | $ cvs import configs before_cvs start |
|---|
| 49 | |
|---|
| 50 | (Note: the "before_cvs" and "start" are just names to say that |
|---|
| 51 | we are importing from "before we used CVS, and this is the start of the |
|---|
| 52 | new project") |
|---|
| 53 | |
|---|
| 54 | - When you see this: |
|---|
| 55 | |
|---|
| 56 | Select an editor. To change later, run 'select-editor'. |
|---|
| 57 | 1. /bin/ed |
|---|
| 58 | 2. /bin/nano <---- easiest |
|---|
| 59 | 3. /usr/bin/vim.basic |
|---|
| 60 | 4. /usr/bin/vim.tiny |
|---|
| 61 | |
|---|
| 62 | Choose 1-4 [2]: |
|---|
| 63 | |
|---|
| 64 | Select the editor you wish to use for comments in CVS. Your instructor likes choice 3. |
|---|
| 65 | |
|---|
| 66 | Once you select an editor you will see this: |
|---|
| 67 | |
|---|
| 68 | CVS: ---------------------------------------------------------------------- |
|---|
| 69 | CVS: Enter Log. Lines beginning with `CVS:' are removed automatically |
|---|
| 70 | CVS: |
|---|
| 71 | CVS: ---------------------------------------------------------------------- |
|---|
| 72 | |
|---|
| 73 | ... just enter a message saying what you did. |
|---|
| 74 | |
|---|
| 75 | For example, add a line at the top of the file that says something like: |
|---|
| 76 | |
|---|
| 77 | "This is a first import of our config files" |
|---|
| 78 | |
|---|
| 79 | ... Then save the file + quit. |
|---|
| 80 | |
|---|
| 81 | You should see something like this: |
|---|
| 82 | |
|---|
| 83 | N configs/contacts_nagios2.cfg |
|---|
| 84 | N configs/services_nagios2.cfg |
|---|
| 85 | N configs/pcs.cfg |
|---|
| 86 | N configs/timeperiods_nagios2.cfg |
|---|
| 87 | N configs/switches.cfg |
|---|
| 88 | N configs/extinfo_nagios2.cfg |
|---|
| 89 | N configs/host-gateway_nagios3.cfg |
|---|
| 90 | N configs/generic-service_nagios2.cfg |
|---|
| 91 | N configs/localhost_nagios2.cfg |
|---|
| 92 | N configs/hostgroups_nagios2.cfg |
|---|
| 93 | N configs/routers.cfg |
|---|
| 94 | N configs/servicegroups.cfg |
|---|
| 95 | N configs/generic-host_nagios2.cfg |
|---|
| 96 | |
|---|
| 97 | No conflicts created by this import |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | 3b. Look at the contents of /home/tldadmin/cvs/configs |
|---|
| 101 | |
|---|
| 102 | $ ls -l /home/tldadmin/cvs/configs |
|---|
| 103 | |
|---|
| 104 | total 52 |
|---|
| 105 | -r--r--r-- 1 tldadmin tldadmin 2873 2010-07-21 17:00 contacts_nagios2.cfg,v |
|---|
| 106 | -r--r--r-- 1 tldadmin tldadmin 1354 2010-07-21 17:00 extinfo_nagios2.cfg,v |
|---|
| 107 | -r--r--r-- 1 tldadmin tldadmin 1654 2010-07-21 17:00 generic-host_nagios2.cfg,v |
|---|
| 108 | -r--r--r-- 1 tldadmin tldadmin 2305 2010-07-21 17:00 generic-service_nagios2.cfg,v |
|---|
| 109 | -r--r--r-- 1 tldadmin tldadmin 714 2010-07-21 17:00 host-gateway_nagios3.cfg,v |
|---|
| 110 | -r--r--r-- 1 tldadmin tldadmin 2642 2010-07-21 17:00 hostgroups_nagios2.cfg,v |
|---|
| 111 | -r--r--r-- 1 tldadmin tldadmin 2669 2010-07-21 17:00 localhost_nagios2.cfg,v |
|---|
| 112 | -r--r--r-- 1 tldadmin tldadmin 3669 2010-07-21 17:00 pcs.cfg,v |
|---|
| 113 | -r--r--r-- 1 tldadmin tldadmin 961 2010-07-21 17:00 routers.cfg,v |
|---|
| 114 | -r--r--r-- 1 tldadmin tldadmin 1088 2010-07-21 17:00 servicegroups.cfg,v |
|---|
| 115 | -r--r--r-- 1 tldadmin tldadmin 2253 2010-07-21 17:00 services_nagios2.cfg,v |
|---|
| 116 | -r--r--r-- 1 tldadmin tldadmin 997 2010-07-21 17:00 switches.cfg,v |
|---|
| 117 | -r--r--r-- 1 tldadmin tldadmin 2111 2010-07-21 17:00 timeperiods_nagios2.cfg,v |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | 4. Now we can remove our temp directory, and check out the |
|---|
| 121 | configs/ project from CVS! |
|---|
| 122 | |
|---|
| 123 | $ cd /home/tldadmin |
|---|
| 124 | $ rm -rf temp |
|---|
| 125 | |
|---|
| 126 | - Let's now check out from cvs : |
|---|
| 127 | |
|---|
| 128 | $ cvs -d /home/tldadmin/cvs co configs |
|---|
| 129 | |
|---|
| 130 | - You should see the following: |
|---|
| 131 | |
|---|
| 132 | cvs checkout: Updating configs |
|---|
| 133 | U configs/contacts_nagios2.cfg |
|---|
| 134 | U configs/extinfo_nagios2.cfg |
|---|
| 135 | U configs/generic-host_nagios2.cfg |
|---|
| 136 | U configs/generic-service_nagios2.cfg |
|---|
| 137 | U configs/host-gateway_nagios3.cfg |
|---|
| 138 | U configs/hostgroups_nagios2.cfg |
|---|
| 139 | U configs/localhost_nagios2.cfg |
|---|
| 140 | U configs/pcs.cfg |
|---|
| 141 | U configs/routers.cfg |
|---|
| 142 | U configs/servicegroups.cfg |
|---|
| 143 | U configs/services_nagios2.cfg |
|---|
| 144 | U configs/switches.cfg |
|---|
| 145 | U configs/timeperiods_nagios2.cfg |
|---|
| 146 | |
|---|
| 147 | $ ls -l /home/tldadmin/configs/ |
|---|
| 148 | |
|---|
| 149 | - Notice the CVS directory in /home/tldadmin/configs/ |
|---|
| 150 | |
|---|
| 151 | *NOTE* remember, never modify the CVS/ directory by hand. |
|---|
| 152 | It is only for experienced CVS users... |
|---|
| 153 | |
|---|
| 154 | - Note that the configs directory is created in whatever directory you in |
|---|
| 155 | in when you issue the cvs co (checkout) command. |
|---|
| 156 | |
|---|
| 157 | 5. Modify a file, add another one, and check things in again: |
|---|
| 158 | |
|---|
| 159 | $ cd /home/tldadmin/configs |
|---|
| 160 | $ vi pcs.cfg |
|---|
| 161 | |
|---|
| 162 | Modify the config – for example, you could add a comment line at the top of the file. |
|---|
| 163 | |
|---|
| 164 | "# This version of pcs is part of our Concurrent Versioning System repository" |
|---|
| 165 | |
|---|
| 166 | (Don't use the quotes "). Then save and quit. |
|---|
| 167 | |
|---|
| 168 | - Add the APT sources.list file to the directory: |
|---|
| 169 | |
|---|
| 170 | $ cp /etc/apt/sources.list . |
|---|
| 171 | |
|---|
| 172 | - Tell cvs to show us the status: |
|---|
| 173 | |
|---|
| 174 | $ cvs status |
|---|
| 175 | |
|---|
| 176 | - There's a lot, to see it all: |
|---|
| 177 | |
|---|
| 178 | $ cvs status | more |
|---|
| 179 | |
|---|
| 180 | - Add sources.list to CVS: |
|---|
| 181 | |
|---|
| 182 | $ cvs add sources.list |
|---|
| 183 | |
|---|
| 184 | - You should see this: |
|---|
| 185 | |
|---|
| 186 | cvs add: scheduling file `sources.list' for addition |
|---|
| 187 | cvs add: use `cvs commit' to add this file permanently |
|---|
| 188 | |
|---|
| 189 | - You are now ready to commit! |
|---|
| 190 | |
|---|
| 191 | $ cvs commit |
|---|
| 192 | |
|---|
| 193 | - If all goes well, you should have this in your editor window: |
|---|
| 194 | |
|---|
| 195 | CVS: ---------------------------------------------------------------------- |
|---|
| 196 | CVS: Enter Log. Lines beginning with `CVS:' are removed automatically |
|---|
| 197 | CVS: |
|---|
| 198 | CVS: Committing in . |
|---|
| 199 | CVS: |
|---|
| 200 | CVS: Modified Files: |
|---|
| 201 | CVS: pcs.cfg |
|---|
| 202 | CVS: Added Files: |
|---|
| 203 | CVS: sources.list |
|---|
| 204 | CVS: ---------------------------------------------------------------------- |
|---|
| 205 | |
|---|
| 206 | ... add a message: |
|---|
| 207 | |
|---|
| 208 | Importing APT sources.list, and modifying the pcs.cfg file. |
|---|
| 209 | |
|---|
| 210 | ... then save + quit |
|---|
| 211 | |
|---|
| 212 | You should see this: |
|---|
| 213 | |
|---|
| 214 | cvs commit: Examining . |
|---|
| 215 | /home/tldadmin/cvs/configs/pcs.cfg,v <-- pcs.cfg |
|---|
| 216 | new revision: 1.2; previous revision: 1.1 |
|---|
| 217 | /home/tldadmin/cvs/configs/sources.list,v <-- sources.list |
|---|
| 218 | initial revision: 1.1 |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | 6. Let's see the history for the pcs.cfg file: |
|---|
| 222 | |
|---|
| 223 | $ cvs log pcs.cfg |
|---|
| 224 | |
|---|
| 225 | ... notice the output |
|---|
| 226 | |
|---|
| 227 | - Finally, let's try and see the difference between two |
|---|
| 228 | versions of the config.smokeping file: |
|---|
| 229 | |
|---|
| 230 | $ cvs diff -r 1.1 -r 1.2 pcs.cfg |
|---|
| 231 | |
|---|
| 232 | - What do you notice ? |
|---|
| 233 | |
|---|