Home Build Bootcamp

Using Git to Get Code

Using Git to retrieve a current baseline of the code

Aside from it's popularity as an open source version control system (VCS), Git is also really useful as a way to get current baselines of software. Let's work through a typical example of how this works.

In this example, the systems admin clones a git repository from the awesome GitHub repository which hosts many excellent open source projects. I recently created a GitHub project for CM Best Practices and will be using it to promote tools and procedures for Configuration Audits. But for now, we will use Github to pull down a copy of libpcap, which is used by many projects for low level network monitoring. Next we will configure, build and then install libpcap. This is a common task for a systems administrator.

GNU Make for Building and Installing Linux Packages

I am sometimes surprised to hear that some build engineers are only familiar with Ant and Maven and somehow managed never learned how to use the Make. If you are a build engineer then you really should be familiar with Ant, Maven, Make and also MS Build for Microsoft Windows applications. There are others, but these are the most build tools that you will come across.

1. The first step is to clone the repository, pulling a local copy to your workspace.

[testuser@ip-123-123-123-123 gitwork]$ git clone git://github.com/mcr/libpcap.git
Initialized empty Git repository in /home/testuser/gitwork/libpcap/.git/
remote: Counting objects: 9383, done.
remote: Compressing objects: 100% (2336/2336), done.
remote: Total 9383 (delta 6951), reused 9364 (delta 6933)
Receiving objects: 100% (9383/9383), 2.63 MiB | 1711 KiB/s, done.
Resolving deltas: 100% (6951/6951), done.

2. Next take a look at the files that you have downloaded and most importantly take note of the configure script.
(I will be writing an article in the future on Autoconf and other configure utilities.) The configure script sets the default values necessary in order to build the application. There are also some cool option such as setting the prefix that I will show briefly later in this article. But usually, I just take the defaults and run the configure script as shown in step 3. (Note also that I abbreviated some of the output as indicated below.)

[testuser@ip-123-123-123-123 gitwork]$ ls -lt
total 12
drwxr-xr-x 14 testuser testuser 12288 Apr  8 19:40 libpcap
[testuser@ip-123-123-123-123 gitwork]$ cd libpcap
[testuser@ip-123-123-123-123 libpcap]$ ls -lt
total 2252
-rw-rw-r-- 1 testuser testuser  26446 Apr  8 19:40 CHANGES
-rw-rw-r-- 1 testuser testuser   9541 Apr  8 19:40 CREDITS
drwxrwxr-x 2 testuser testuser   4096 Apr  8 19:40 ChmodBPF
-rw-rw-r-- 1 testuser testuser  17769 Apr  8 19:40 INSTALL.txt
-rw-rw-r-- 1 testuser testuser    873 Apr  8 19:40 LICENSE
-rw-rw-r-- 1 testuser testuser  23318 Apr  8 19:40 Makefile.in
-rw-rw-r-- 1 testuser testuser   4191 Apr  8 19:40 README
-rw-rw-r-- 1 testuser testuser   2214 Apr  8 19:40 README.Win32
-rw-rw-r-- 1 testuser testuser   2810 Apr  8 19:40 README.aix
-rw-rw-r-- 1 testuser testuser   4960 Apr  8 19:40 README.dag
-rw-rw-r-- 1 testuser testuser   8264 Apr  8 19:40 README.hpux
-rw-rw-r-- 1 testuser testuser   5000 Apr  8 19:40 README.linux
-rw-rw-r-- 1 testuser testuser   3521 Apr  8 19:40 README.macosx
-rw-rw-r-- 1 testuser testuser   2045 Apr  8 19:40 README.septel
-rw-rw-r-- 1 testuser testuser   2465 Apr  8 19:40 README.sita
-rw-rw-r-- 1 testuser testuser   1687 Apr  8 19:40 README.tru64
drwxrwxr-x 2 testuser testuser   4096 Apr  8 19:40 SUNOS4
-rw-rw-r-- 1 testuser testuser   1555 Apr  8 19:40 TODO
-rw-rw-r-- 1 testuser testuser     14 Apr  8 19:40 VERSION
drwxrwxr-x 5 testuser testuser   4096 Apr  8 19:40 Win32
-rw-rw-r-- 1 testuser testuser  30161 Apr  8 19:40 aclocal.m4


3. Run the configure script before you try to build the application

[testuser@ip-123-123-123-123 libpcap]$ ./configure
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed


4. Next we will build (compile and link) the application using the make command

[testuser@ip-123-123-123-123 libpcap]$ make
gcc -O2 -fpic -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -g -O2 -c ./pcap-linux.c
gcc -O2 -fpic -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -g -O2 -c ./pcap-usb-linux.c
gcc -O2 -fpic -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -g -O2 -c ./fad-getad.c
if grep GIT ./VERSION >/dev/null; then \
read ver <./VERSION; \
echo $ver | tr -d '\012'; \
date +_%Y_%m_%d; \
else \
cat ./VERSION; \
fi | sed -e 's/.*/static const char pcap_version_string[] = "libpcap version &";/' > version.h
gcc -O2 -fpic -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -g -O2 -c ./pcap.c
gcc -O2 -fpic -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -g -O2 -c ./inet.c
gcc -O2 -fpic -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -g -O2 -c ./gencode.c
gcc -O2 -fpic -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -g -O2 -c ./optimize.c
gcc -O2 -fpic -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -g -O2 -c ./nametoaddr.c
gcc -O2 -fpic -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -g -O2 -c ./etherent.c
gcc -O2 -fpic -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -g -O2 -c ./savefile.c
gcc -O2 -fpic -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -g -O2 -c ./sf-pcap.c
gcc -O2 -fpic -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -g -O2 -c ./sf-pcap-ng.c
gcc -O2 -fpic -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -g -O2 -c ./pcap-common.c
gcc -O2 -fpic -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -g -O2 -c ./bpf_image.c
gcc -O2 -fpic -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -g -O2 -c ./bpf_dump.c
./runlex.sh flex -Ppcap_ -oscanner.c scanner.l
bison -y -p pcap_ -d grammar.y
mv y.tab.c grammar.c
mv y.tab.h tokdefs.h
gcc -O2 -fpic -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -g -O2 -c scanner.c
gcc -O2 -fpic -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -g -O2 -Dyylval=pcap_lval -c

rm -f bpf_filter.c
ln -s ./bpf/net/bpf_filter.c bpf_filter.c
gcc -O2 -fpic -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -g -O2 -c bpf_filter.c


5. Next you will su to root (or use sudo) and then issue the  make install command to copy the build to the runtime location (e.g. /usr/local/lib)

make install

6. You may want to examine the options available in the configure script. For example, you can set default locations for installation using the --prefix option

[testuser@ip-123-123-123-123 libpcap]$ ./configure --help
`configure' configures this package to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.


7. Even though you downloaded this code to simply compile and install, you may want to make some customizations and then tagging and branching can help you keep track of your work.

Let's first see what tags we inherited when we cloned the repository

[testuser@ip-123-123-123-123 libpcap]$ git tag

Next we will add our own tag for tragging purposes (which will only exist in out local copy)

[testuser@ip-123-123-123-123 libpcap]$ git tag -a v1.0 -m'CMBP Version 1.0'


Version Control Systems are a must-have for controlling changes to source code during the software and systems development effort. In this article we looked at how a systems administrator might use Git to obtain a copy of libpcap and also control local baselines to track any required changes. In future articles, we will cover more details on how to manage branches and baselines using Git. Please drop me a line and let me know what features and challenges you would like us to cover in upcoming issues of the CM Best Practices Newsletter!

Bob Aiello
This e-mail address is being protected from spambots. You need JavaScript enabled to view it

More articles by this author

Micro Focus Completes Acquisition of Serena Software, Inc. Application Lifecycle Management Acquisition Boosts Micro Focus’s DevOps Capability ROCKVILLE, Md., May 2, 2016 /PRNewswire/ -- Micro Focus (LSE: MCRO.L) today announced the completion of its acquisition of Serena Software, a leading provider of Application Lifecycle Management (ALM) software, under the terms of the definitive agreement disclosed on March 22, 2016. "Our customers continue to look at DevOps as a way to deploy critical applications and services quickly and with greater reliability to meet business demands," said Stephen Murdoch, CEO, Micro Focus. "The Serena acquisition extends our ability to help customers meet these challenges so they can drive greater innovation faster with lower risk." According to industry analyst firm Gartner, "DevOps implementations utilize technology, especially automation tools, that can leverage an increasingly programmable and dynamic infrastructure from a life cycle perspective."1  The experience and expertise which the Serena business brings will enable Micro Focus to help its customers develop and release applications and services faster, with greater speed and accuracy. Serena adds capabilities in software application development; software configuration and change management; and business process management to Micro Focus's portfolio of ALM solutions spanning mainframe environments, distributed systems and cloud. The combination of Micro Focus and Serena allows companies to better: Design and build business applications and services with greater accuracy, reliability and predictability; Continuously deploy existing core business applications on a wider variety of platforms to meet changing business needs; and Improve the speed and efficiency of new business services through automated release and deployment solutions. About Serena Software Serena is among the largest Application Lifecycle Management vendors with more than 2,500 enterprise customers. Serena helps the highly regulated large enterprise move fast without breaking things – increasing velocity of the software development lifecycle while enhancing security, compliance, and performance. More information is available at www.serena.com. About Micro Focus Micro Focus (LSE: MCRO.L) is a global enterprise software company helping customers innovate faster with lower risk. Our software helps customers build, operate and secure IT systems that bring together existing business logic and applications with emerging technologies to meet increasingly complex business demands. For more information, visit: www.microfocus.com. 1I&O Must Combine ITIL and DevOps to Deliver Business Value for Bimodal IT," by George Spafford and Ian Head, March 18, 2016.
Hi, I am excited to invite you to subscribe to our new online publication which provides guidance on Configuration Management Best Practices, Agile Application Lifecycle Management (including videos) and, of course DevOps. Our publication explains hands-on best practices required to implement just enough process to ensure that you can build software and systems that are reliable and secure. Based upon our new book, Agile Application Lifecycle Management - Using DevOps to Drive Process Improvement, the Agile ALM DevOps Journal seeks to promote a dialogue that is really needed in the industry today. We will discuss practical approaches to implementing the Agile ALM using DevOps best practices including continuous integration, delivery and deployment. We will also discuss process improvement strategies that work in large organizations that must comply with federal regulatory guidelines, along with smaller teams that may very well grow as they become successful. We are taking this journey together and our goal is to ensure that you have a voice and can share your experiences along with learning from other colleagues too. Enjoy Leslie Sachs's amazing column: Personality Matters and Bob Aiello's column: Behaviorally Speaking. We will also report on major incidents where organizations clearly need to improve on their ability to develop and deliver software effectively, including the recent Southwest systems glitches which resulted in thousands of flights being cancelled and thousands more being delayed. We will also bring you exciting technical product announcements such as jfrog's new xray, which helps to scan your runtime objects, including docker images, for vulnerabilities. This is an exciting time to be in the technology field. Join the revolution! You can submit your articles for publication to share your own knowledge and experience!  Subscribe to receive your copy and register so that you can comment online Bob Aiello http://www.linkedin.com/in/BobAiello @bobaiello, @agilealmdevops, @cmbestpractices This e-mail address is being protected from spambots. You need JavaScript enabled to view it  
Copyright © 2017 CM Best Practices. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.

Product News

Live Online Training