Forum: CFEngine Help
Subject: Re: SVN tricks
Author: [email protected]
Link to topic: https://cfengine.com/forum/read.php?3,24395,24422#msg-24422
This script is utterly disgusting, but it gets the job done. Anytime I add a
new file into my SVN tree (new policy, new config, etc) I run this script over
the whole base "cfengine directory"
So, my SVN tree looks like this:
svn-tree ----> cfengine ----> branch
-----> trunk
-----> tags
The script gets executed from the "svn-tree" level, so it crawls over every
file under branch, trunk and tags. Note, that I skip over the
/var/cfengine/modules directory. I ship some binary executable files to my
clients, and applying the SVN headers breaks binaries. This is why there are
multiple svn propset commands. I basically have to hit every directory in my
tree other than the modules to make sure that the SVN properties aren't applied
to the binaries.
Also, the "find" statement at the beginning allows me to put in things that I
want to skip -- like /etc/motd or .xml files where this header would break
things. If I detect that the file is a bash / perl / python / ksh / sh / etc.
script, I insert these headers at line 2 to preserve the shebang.
Again, its really ugly, but it does the job. Every single file that is
Cfengine maintained under my tree gets these SVN properties applied
automatically.
msvoboda-4-mn:sysops-svn msvoboda$ cat find-not-svn-tagged.sh
#!/bin/bash
# This is a basic script that will find anything under the cfengine root SVN
directory (both branches and trunk) and will tag
# the configs / scripts with the SVN keywords which will expand on commit.
# Find everything, then remove stuff based off of filename or extension.
find ./cfengine -path \*.svn -prune \
-o -name \*.rpm -prune \
-o -name \*.pkg -prune \
-o -name \*.xml -prune \
-o -name motd -prune \
-o -name issue -prune \
-o -name lshw\* -prune \
-o -name \*modules -prune \
-o -name \*coreadm\* -prune \
-o -path \*solaris_hardware_verification\* -prune \
-o -type f -print > check_svn_files_for_tags
for file in `cat check_svn_files_for_tags`
do
MODIFIED="false"
grep HeadURL $file > /dev/null
# If we dont find HeadURL, then the file doesn't have the SVN headers
applied.
if [ $? -eq 1 ]
then
MODIFIED="true"
# Test to see if the file is some sort of script.
IS_SCRIPT=`head -1 ${file} | egrep
'bash|ksh|dtrace|perl|python|sh'`
if [ "${IS_SCRIPT}" != "" ]
then
# The file was some sort of script. Insert at line 2+.
Preserve the shebang.
echo "(+) Found script ${file} not tagged"
head -1 ${file} > tmp
echo '# filesource \$HeadURL$' >> tmp
echo '# version \$Revision$' >> tmp
echo '# modifiedby \$LastChangedBy$' >> tmp
echo '# lastmodified \$Date$' >> tmp
# Print everything in the file excempt for line 1.
We've already captured that.
sed '1d' ${file} >> tmp
else
# Not a script.
echo "found $file not tagged"
echo '# filesource \$HeadURL$' > tmp
echo '# version \$Revision$' >> tmp
echo '# modifiedby \$LastChangedBy$' >> tmp
echo '# lastmodified \$Date$' >> tmp
cat ${file} >> tmp
fi # End if not a script
fi # End check for HeadURL (is the file actually tagged)
if [ "$MODIFIED" == "true" ]
then
# Continue processing file as something we haven't SVN tagged
yet.
mv tmp ${file}
SVNSTATUS=`svn stat ${file} | awk '{print $1}'`
# A ? status in SVN means that the file hasn't been added to
the repository. Add it. The file
# doesn't actually transfer until you perform the commit.
if [ "$SVNSTATUS" == "?" ]
then
echo "(+) Adding ${file} into the SVN repository. It
will be uploaded on the commit"
svn add ${file}
fi
# Apply the SVN properties on all directories, except for the
modules, regardless if they have the tags or not.
# The modules directory contains binaries, and setting the
svn:keywords on them can corrput the binaries
# This means that tags in the module directories need to be
manually applied.
svn propset --recursive svn:keywords "HeadURL Revision
LastChangedBy Date Id" ./cfengine/branches/esv4-cfe-test.corp/CORP > /dev/null
2>&1
svn propset --recursive svn:keywords "HeadURL Revision
LastChangedBy Date Id" ./cfengine/branches/esv4-cfe-test.corp/PROD > /dev/null
2>&1
svn propset --recursive svn:keywords "HeadURL Revision
LastChangedBy Date Id" ./cfengine/branches/esv4-cfe-test.corp/HADOOP >
/dev/null 2>&1
svn propset --recursive svn:keywords "HeadURL Revision
LastChangedBy Date Id" ./cfengine/branches/esv4-cfe-test.corp/STG > /dev/null
2>&1
svn propset --recursive svn:keywords "HeadURL Revision
LastChangedBy Date Id"
./cfengine/branches/esv4-cfe-test.corp/generic_cf-agent_policies > /dev/null
2>&1
svn propset --recursive svn:keywords "HeadURL Revision
LastChangedBy Date Id"
./cfengine/branches/esv4-cfe-test.corp/generic_cf-serverd_policies > /dev/null
2>&1
svn propset --recursive svn:keywords "HeadURL Revision
LastChangedBy Date Id" ./cfengine/trunk/CORP > /dev/null 2>&1
svn propset --recursive svn:keywords "HeadURL Revision
LastChangedBy Date Id" ./cfengine/trunk/PROD > /dev/null 2>&1
svn propset --recursive svn:keywords "HeadURL Revision
LastChangedBy Date Id" ./cfengine/trunk/HADOOP > /dev/null 2>&1
svn propset --recursive svn:keywords "HeadURL Revision
LastChangedBy Date Id" ./cfengine/trunk/STG > /dev/null 2>&1
svn propset --recursive svn:keywords "HeadURL Revision
LastChangedBy Date Id" ./cfengine/trunk/generic_cf-agent_policies > /dev/null
2>&1
svn propset --recursive svn:keywords "HeadURL Revision
LastChangedBy Date Id" ./cfengine/trunk/generic_cf-serverd_policies > /dev/null
2>&1
# Print out a SVN stat so we can see what we touched.
echo "(+) Adding / tagging the following files:"
svn stat
fi
done
echo "(+) Execution complete. Manually svn commit when ready"
rm check_svn_files_for_tags
It produces the following below. The HeadURL is like a breadcrumb. Anyone
wondering if the config is under Cfengine, or where the config lives -- they
can immediately find its location in the SVN tree.
$ cat /etc/resolv.conf
# filesource \$HeadURL:
svn+ssh://[email protected]/export/content/sysops-svn/cfengine/branches/esv4-cfe-test.corp/STG/ESV4/cf-agent/config-general/check_resolv/resolv.conf
$
# version \$Revision: 1121 $
# modifiedby \$LastChangedBy: msvoboda $
# lastmodified \$Date: 2010-10-12 14:08:50 -0700 (Tue, 12 Oct 2010) $
domain stg.linkedin.com
search stg.linkedin.com linkedin.com
...
....
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine