forked from RedHatSatellite/soe-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuppetbuild.sh
executable file
·72 lines (63 loc) · 2.28 KB
/
puppetbuild.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
# Search for Puppet module directories
#
# e.g. ${WORKSPACE}/scripts/puppetbuilder.sh ${WORKSPACE}/soe/puppet/
#
. ${WORKSPACE}/scripts/common.sh
function build_puppetmodule {
if [[ -e "$1" ]]
then
git_commit=$(git log --format="%H" -1 $(pwd))
if ! [[ ${git_commit} == $(cat .puppetbuild-hash) ]]
then
MODULEDIR=$(dirname ${METADATA})
if [[ $(basename ${METADATA}) = 'metadata.json' ]] ; then
modname=$(IGNORECASE=1 awk -F \" '/name/ {print $4;exit;}' ${METADATA} | awk -F \- '{print $2}')
modversion=$(IGNORECASE=1 awk -F \" '/version/ {print $4;exit;}' ${METADATA})
elif [[ $(basename ${METADATA}) = 'Modulefile' ]] ; then
modname=$(IGNORECASE=1 awk -F \' '/^name/ {print $2}' ${METADATA})
modversion=$(IGNORECASE=1 awk -F \' '/^version/ {print $2}' ${METADATA})
else
echo "Could not parse module name and/or module version using ${METADATA}"
exit 1
fi
modarchive=${modname}-${modversion}.tar.gz
# build the archive
puppet module build ${MODULEDIR}
RETVAL=$?
if [[ ${RETVAL} != 0 ]]
then
echo "Could not build puppet module ${modname} using ${METADATA}"
exit ${MODBUILD_ERR}
fi
mv ${MODULEDIR}/pkg/${modarchive} ${PUPPET_REPO}
echo ${git_commit} > .puppetbuild-hash
else
echo "No changes since last build - skipping ${METADATA}"
fi
fi
}
if [[ -z "$1" ]] || [[ ! -d "$1" ]]
then
echo "Usage: $0 <directory containing puppet module directories>"
exit ${NOARGS}
fi
workdir=$1
if [[ -z ${WORKSPACE} ]] || [[ ! -w ${WORKSPACE} ]]
then
echo "WORKSPACE not set or not found"
exit ${WORKSPACE_ERR}
fi
# Traverse directories looking for Modulefiles
cd ${workdir}
for I in $(ls -d */ )
do
METADATA=""
pushd ${I}
# find Modulefiles
METADATA=$(find $(pwd) -maxdepth 1 -name 'metadata.json')
# look for deprecated Modulefile if there is no metadata.json
if [[ -z ${METADATA} ]] ; then METADATA=$(find $(pwd) -maxdepth 1 -name 'Modulefile') ; fi
if [[ -n ${METADATA} ]] ; then build_puppetmodule ${METADATA} ; fi
popd
done