-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate.sh
executable file
·117 lines (99 loc) · 2.63 KB
/
generate.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash -e
#
# Copyright 2015 North Development AB
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Author: Ilja Bobkevic <[email protected]>
#
###
### FUNCTIONS LOGGING
###
msg() {
local level="${1}"
local msg="${2}"
local output_code="${3:-1}"
echo >&$output_code "${level} $(date '+%Y-%m-%d %H:%M:%S') - ${msg}"
}
info() {
msg "INFO " "${1}"
}
warn() {
msg "WARN " "${1}"
}
debug() {
if [ "x" != "x${DEBUG}" ]; then
msg "DEBUG" "${1}"
fi
}
error() {
msg "ERROR" "${1}" 2
}
###
### FUNCTIONS MISC
###
realpath() { echo $(cd $(dirname $1); pwd)/$(basename $1); }
verify_variable_set() {
local variable="${1}"
if [ -z "${!variable}" ]; then
error "Environment variable ${variable} not set"
exit 2
fi
}
###
### VARIABLES
###
MODULE_AUTHOR=${MODULE_AUTHOR:-"unibet"}
GITHUB_ORG=$(echo ${GITHUB_ORG:-"unibet"} |tr '[:upper:]' '[:lower:]')
PROJECT_URL=${PROJECT_URL:-"https://github.com/${GITHUB_ORG}/puppet-${MODULE_NAME}"}
SOURCE_URL=${SOURCE_URL:-"${PROJECT_URL}.git"}
ISSUES_URL=${ISSUES_URL:-"${PROJECT_URL}/issues"}
MODULE_SUMMARY=${MODULE_SUMMARY:-"Unibet ${MODULE_NAME} puppet module"}
MODULE_PATH=$(dirname ${BASH_SOURCE[0]})
###
### PREREQUISITES
###
for V in "MODULE_NAME FORGE_USER FORGE_PASSWORD"; do
verify_variable_set $V
done
set +e
TRAVIS=$(which travis)
if [ ! -x "${TRAVIS}" ]; then
error "Travis command is not available. Consider running 'gem install travis'"
exit 3
fi
set -e
###
### MAIN
###
cd $MODULE_PATH
FILES=(.fixtures.yml metadata.json README.md manifests/init.pp manifests/params.pp spec/classes/init_spec.rb test/integration/default/puppet/manifests/site.pp tests/init.pp)
set +e
# gsed if available
SED=$(which gsed)
set -e
if [ ! -x "${SED}" ]; then
SED=$(which sed)
fi
for V in MODULE_NAME MODULE_AUTHOR SOURCE_URL PROJECT_URL ISSUES_URL MODULE_SUMMARY; do
for F in "${FILES[@]}"; do
info "Setting ${V} to '${!V}' in ${F}..."
$SED -i -e "s|__${V}__|${!V}|g" $F
done
done
info "Adding encrypted credentials for travis"
$TRAVIS encrypt "${FORGE_USER}" --add deploy.user
$TRAVIS encrypt "${FORGE_PASSWORD}" --add deploy.password
cd -
info "Removing myself..."
rm -f ${BASH_SOURCE[0]}