-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.sh
executable file
·160 lines (139 loc) · 4.37 KB
/
build.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
#!/bin/bash
##
## Deployment script for MadeiraCloud OpsAgent
## @author: Thibault BRONCHAIN
##
## (c) 2014 MadeiraCloud LTD.
##
USAGE="$0 tree|release"
GPG_PRIVATE_PATH=${HOME}/.ssh/keys/madeira.gpg.private.key
SCRIPTS_DIR=scripts
CONF_DIR=conf
LIBS_DIR=libs
SOURCES_DIR=sources
BUILD_DIR=build
RELEASE_DIR=release
OPSAGENT_DIR=opsagent
MISC_DIR=misc
function tree() {
# Clear (if any) and create build directory
rm -rf ${BUILD_DIR}
# Create agent build/release directory
mkdir -p ${BUILD_DIR}/${OPSAGENT_DIR}/{$SCRIPTS_DIR,$CONF_DIR,$LIBS_DIR,$SOURCES_DIR}
# Move to build directory
cd ${BUILD_DIR}
# Add License
cp ../LICENSE ${OPSAGENT_DIR}/
# Copy bootstrap scripts
cp ../${SCRIPTS_DIR}/{bootstrap.sh,daemon.sh,kill.sh,update.sh} ${OPSAGENT_DIR}/${SCRIPTS_DIR}/
# Copy standalone scripts
cp ../${SCRIPTS_DIR}/{init.sh,userdata.sh,clean.sh,ud_init.sh,manual_update.sh} ./
cp -f ../${SCRIPTS_DIR}/ud_init.sh ./userdata.sh
if [ "${1}" != "" ]; then
sed "s/OA_VERSION=.*/OA_VERSION='${1}'/" < ../${SCRIPTS_DIR}/init.sh > ./init.sh
else
cp ../${SCRIPTS_DIR}/init.sh ./
fi
# Copy service launcher
cp ../${SCRIPTS_DIR}/daemon.sh ${OPSAGENT_DIR}/${SCRIPTS_DIR}/
# Copy EPEL installer
cp -r ../${LIBS_DIR}/epel ${OPSAGENT_DIR}/${LIBS_DIR}/
# Copy virtualenv
cp -r ../${LIBS_DIR}/virtualenv ${OPSAGENT_DIR}/${LIBS_DIR}/
# Copy ws4py sources
cp -r ../${LIBS_DIR}/ws4py ${OPSAGENT_DIR}/${LIBS_DIR}/
# Copy salt dependencies
cp -r ../${LIBS_DIR}/{requests,msgpack,yaml,jinja2,markupsafe} ${OPSAGENT_DIR}/${LIBS_DIR}/
# Copy opsagent sources
for file in `find ../${SOURCES_DIR}/opsagent -type f -name '*.py'`
do
dir=`echo ${file} | rev | cut -d '/' -f 2-100 | rev | cut -d '/' -f 3-100 -s`
mkdir -p ${OPSAGENT_DIR}/${SOURCES_DIR}/${dir}
cp -f ${file} "${OPSAGENT_DIR}/${SOURCES_DIR}/${dir}"
done
# Copy launcher script
if [ "${1}" != "" ]; then
sed "s/VERSION_NBR=.*/VERSION_NBR='${1}'/" < ../${SOURCES_DIR}/opsagent.py > ${OPSAGENT_DIR}/${SCRIPTS_DIR}/opsagent
sed "s/VERSION=.*/VERSION='${1}'/" < ../${SCRIPTS_DIR}/init.sh > ${OPSAGENT_DIR}/${SCRIPTS_DIR}/init.sh
else
cp ../${SOURCES_DIR}/opsagent.py ${OPSAGENT_DIR}/${SCRIPTS_DIR}/opsagent
fi
# create tarball
cd ${OPSAGENT_DIR}
tar cvfz ../opsagent.tgz *
cd -
}
function publish() {
echo "${1}" > curent
rm -rf ${RELEASE_DIR}
mkdir -p ${RELEASE_DIR}
cp ${BUILD_DIR}/{clean.sh,init.sh,ud_init.sh,opsagent.tgz,userdata.sh,manual_update.sh} ${RELEASE_DIR}/
# GPG
gpg --allow-secret-key-import --import ${GPG_PRIVATE_PATH}
cd ${BUILD_DIR}
gpg --sign init.sh
gpg --sign ud_init.sh
gpg --sign opsagent.tgz
gpg --sign userdata.sh
cd -
cp -f ${BUILD_DIR}/{init.sh.gpg,opsagent.tgz.gpg,ud_init.sh.gpg,userdata.sh.gpg} ${RELEASE_DIR}/
cd ${RELEASE_DIR}
cksum clean.sh > clean.sh.cksum
cksum manual_update.sh > manual_update.sh.cksum
cksum userdata.sh > userdata.sh.cksum
cksum userdata.sh.gpg > userdata.sh.gpg.cksum
cksum init.sh > init.sh.cksum
cksum init.sh.gpg > init.sh.gpg.cksum
cksum ud_init.sh > ud_init.sh.cksum
cksum ud_init.sh.gpg > ud_init.sh.gpg.cksum
cksum opsagent.tgz > opsagent.tgz.cksum
cksum opsagent.tgz.gpg > opsagent.tgz.gpg.cksum
cd -
cp ${MISC_DIR}/madeira.gpg.public.key ${RELEASE_DIR}/madeira.gpg.public.key
git add . -A
git commit -m "v${1}"
git push
}
function update() {
git add . -A
git commit -m "${1}"
git pull
}
function merge() {
git checkout master
git pull origin master
git merge develop
git push origin master
git checkout develop
}
case $1 in
tree)
tree
;;
release)
git status
echo
echo
echo -n "Please input commit message then [ENTER]: "
read COMMIT
echo -n "Please input release number [ENTER]: "
read RELEASE_NAME
ROOT=${PWD}
update "${COMMIT}"
cd ${ROOT}
tree "${RELEASE_NAME}"
cd ${ROOT}
publish "${RELEASE_NAME}"
echo -n "Merge to master? [y/N]: "
read MERGE
if [ "$MERGE" = "y" ]; then
merge
else
echo "No"
fi
echo "Done."
;;
*)
echo -e "syntax error\nusage: $USAGE"
;;
esac