This repository has been archived by the owner on Sep 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
puppetbuild.sh
executable file
·91 lines (81 loc) · 3.06 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
# Search for Puppet module directories and build any modules found
#
# e.g. ${WORKSPACE}/scripts/puppetbuilder.sh ${WORKSPACE}/soe/puppet/
#
# Load common parameter variables
. $(dirname "${0}")/common.sh
function build_puppetmodule {
if [[ -e "$1" ]]
then
git_commit=$(git log --format="%H" -1 $(pwd))
if [[ ! -e .puppetbuild-hash ]] || [[ ! ${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})
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
err "Could not parse module name and/or module version using ${METADATA}"
exit 1
fi
modarchive=${modname}-${modversion}.tar.gz
if [ -f "${PUPPET_REPO}/${modarchive}" ]
then
warn "Puppet module '${modarchive}' already in repository," \
"You might have forgotten to increase the version" \
"after doing changes. Skipping ${MODULEFILE}."
else
# build the archive
puppet module build ${MODULEDIR}
RETVAL=$?
if [[ ${RETVAL} != 0 ]]
then
err "Could not build puppet module ${modname} using ${METADATA}."
exit ${MODBUILD_ERR}
fi
mv -nv ${MODULEDIR}/pkg/${modarchive} ${PUPPET_REPO} # don't overwrite
restorecon -F ${PUPPET_REPO}/*
fi
# Something has changed, track it for build and for tests
echo ${git_commit} > .puppetbuild-hash
echo "#${modname}#" >> "${MODIFIED_CONTENT_FILE}"
echo "${modname}" >> "${MODIFIED_PUPPET_FILE}"
else
inform "No changes since last build - skipping ${METADATA}"
fi
fi
}
if [[ -z "$1" ]] || [[ ! -d "$1" ]]
then
usage "$0 <directory containing puppet module directories>"
exit ${NOARGS}
fi
workdir=$1
if [[ -z ${WORKSPACE} ]] || [[ ! -w ${WORKSPACE} ]]
then
err "Environment variable '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}
else
err "Could not find puppet metadata file for puppet module ${I}"
exit 1
fi
popd
done