forked from OpenNebula/addon-context-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.sh
executable file
·182 lines (154 loc) · 5.67 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
if [ -z "${TARGET}" ]; then
echo 'Error: env. variable TARGET not set' >&2
exit 1
fi
set -e
source targets.sh
set +e
###
if [ -z "${RELEASE}" ]; then
if git describe --contains $(git rev-parse HEAD) &>/dev/null; then
RELEASE=1
else
DATE=${DATE:-$(date +%Y%m%d)}
GIT=$(git rev-parse --short HEAD)
RELEASE="0.${DATE}git${GIT}"
fi
fi
###
VERSION=${VERSION:-5.4.2}
RELEASE=${RELEASE:-1}
MAINTAINER=${MAINTAINER:-OpenNebula Systems <[email protected]>}
LICENSE=${LICENSE:-Apache 2.0}
VENDOR=${VENDOR:-OpenNebula Systems}
SUMMARY="OpenNebula Contextualization Package"
DESC="
This package prepares a VM image for OpenNebula:
* Disables udev net and cd persistent rules
* Deletes udev net and cd persistent rules
* Unconfigures the network
* Adds OpenNebula contextualization scripts to startup
* Configure network
* Configure dns (from DNS and ETH*_DNS context variables)
* Set root authorized keys (from SSH_PUBLIC_KEY and EC2_PUBLIC_KEY)
* Add onegate tool (NEEDS RUBY AND JSON GEM TO WORK)
* Resize root filesystem
* Generate host ssh keys in debian distributions
To get support check the OpenNebula web page:
http://OpenNebula.org
"
DESCRIPTION=${DESCRIPTION:-$DESC}
URL=${URL:-http://opennebula.org}
RELEASE_FULL="${RELEASE}${RELSUFFIX}"
if [ "${TYPE}" = 'deb' ]; then
FILENAME="${NAME}_${VERSION}-${RELEASE_FULL}.${TYPE}"
elif [ "${TYPE}" = 'apk' ]; then
RELEASE_FULL="r${RELEASE_FULL}"
FILENAME="${NAME}-${VERSION}-${RELEASE_FULL}.${TYPE}"
elif [ "${TYPE}" = 'iso' ]; then
LABEL="${NAME}-${VERSION}"
FILENAME="${NAME}-${VERSION}-${RELEASE_FULL}.${TYPE}"
else
FILENAME="${NAME}-${VERSION}-${RELEASE_FULL}.noarch.${TYPE}"
fi
###
set -e
BUILD_DIR=$(mktemp -d)
_POSTIN=$(mktemp)
_PREUN=$(mktemp)
_POSTUN=$(mktemp)
_POSTUP=$(mktemp)
trap "rm -rf ${BUILD_DIR} ${_POSTIN} ${_PREUN} ${_POSTUN} ${_POSTUP}" EXIT
while IFS= read -r -d $'\0' SRC; do
F_TAGS=${SRC##*##}
if [ "x${SRC}" != "x${F_TAGS}" ]; then
for F_TAG in $(echo ${F_TAGS} | sed -e 's/\./ /g'); do
for TAG in ${TAGS}; do
if [ "${F_TAG}" = "${TAG}" ]; then
continue 2 # tag matches, continue with next tag
fi
done
continue 2 # tags not maching, skip this file
done
fi
# file matches
DST=${SRC%##*} #strip tags
mkdir -p "${BUILD_DIR}/$(dirname "${DST}")"
cp "src/${SRC}" "${BUILD_DIR}/${DST}"
done < <(cd src/ && find . -type f -print0)
for F in $@; do
cp -r "$F" "${BUILD_DIR}/"
done
# fix permissions and set umask for fpm
find "${BUILD_DIR}/" -perm -u+r -exec chmod go+r {} \;
find "${BUILD_DIR}/" -perm -u+x -exec chmod go+x {} \;
umask 0022
# cleanup
if [ -z "${OUT}" ]; then
OUT="out/${FILENAME}"
mkdir -p $(dirname "${OUT}")
rm -rf "${OUT}"
fi
if [ "${TYPE}" = 'dir' ]; then
cp -rT "${BUILD_DIR}" "${OUT}"
elif [ "${TYPE}" = 'iso' ]; then
mkisofs -J -R -input-charset utf8 \
-m '*.iso' \
-V "${LABEL}" \
-o "${OUT}" \
$(dirname "${OUT}")
else
CONFIG_FILES=$(cd "${BUILD_DIR}" && \
find etc/ \
! -path 'etc/one-context.d/*' \
! -path 'etc/init*' \
-type f -printf '--config-files %p ')
# concatenate pre/postinstall scripts
if [ -n "${POSTIN}" ]; then
cat ${POSTIN} >"${_POSTIN}"
fi
if [ -n "${PREUN}" ]; then
cat ${PREUN} >"${_PREUN}"
fi
if [ -n "${POSTUN}" ]; then
cat ${POSTUN} >"${_POSTUN}"
fi
if [ -n "${POSTUP}" ]; then
cat ${POSTUP} >"${_POSTUP}"
fi
fpm --name "${NAME}" --version "${VERSION}" --iteration "${RELEASE_FULL}" \
--architecture all --license "${LICENSE}" \
--vendor "${VENDOR}" --maintainer "${MAINTAINER}" \
--description "${DESCRIPTION}" --url "${URL}" \
--output-type "${TYPE}" --input-type dir --chdir "${BUILD_DIR}" \
${POSTIN:+ --after-install ${_POSTIN}} \
${POSTUP:+ --after-upgrade ${_POSTUP}} \
${PREUN:+ --before-remove ${_PREUN}} \
${POSTUN:+ --after-remove ${_POSTUN}} \
--rpm-os linux \
--rpm-summary "${SUMMARY}" \
${DEPENDS:+ --depends ${DEPENDS// / --depends }} \
${REPLACES:+ --replaces ${REPLACES// / --replaces }} \
${CONFLICTS:+ --conflicts ${CONFLICTS// / --conflicts }} \
${PROVIDES:+ --provides ${PROVIDES// / --provides }} \
--deb-no-default-config-files \
${CONFIG_FILES} \
--package "${OUT}"
fi
echo $(basename ${OUT})