commit | author | age
|
f90860
|
1 |
#!/bin/ksh |
TW |
2 |
# 2021-04-07 Olaf Bohlen <olbohlen@eenfach.de> |
|
3 |
# instead of putting all this into the Jenkinsfile I decided to put the actual code in this script |
|
4 |
|
|
5 |
# global config |
|
6 |
HTTPCONF="/etc/apache2/2.4/conf.d/pkgdepotd.conf" |
|
7 |
|
|
8 |
# just run prepare once to initially set up the environment |
|
9 |
# this must be run as root |
|
10 |
prepare() { |
|
11 |
echo "jenkinshelper: preparing..." |
|
12 |
pkg install web/server/apache-24 |
|
13 |
mkdir -p /etc/apache2/2.4/conf.d && chown root:sys /etc/apache2/2.4/conf.d |
|
14 |
grep "#ProxyPassMatch /default/(.*)\$ http://127.0.0.1:10000/\$1 nocanon max=200" "${HTTPCONF}" >/dev/null 2>&1 |
|
15 |
if [ $? -gt 0 ]; then |
|
16 |
echo "jenkinshelper: Initializing a new apache config at ${HTTPCONF}" |
|
17 |
echo "#ProxyPassMatch /default/(.*)\$ http://127.0.0.1:10000/\$1 nocanon max=200" >"${HTTPCONF}" |
|
18 |
else |
|
19 |
echo "jenkinshelper: Preserving an existing ${HTTPCONF}" |
|
20 |
fi |
|
21 |
|
|
22 |
cat >/etc/apache2/2.4/conf.d/00-proxy.conf <<EOF |
|
23 |
LoadModule proxy_module libexec/mod_proxy.so |
|
24 |
LoadModule proxy_connect_module libexec/mod_proxy_connect.so |
|
25 |
LoadModule proxy_ftp_module libexec/mod_proxy_ftp.so |
|
26 |
LoadModule proxy_http_module libexec/mod_proxy_http.so |
|
27 |
LoadModule proxy_ajp_module libexec/mod_proxy_ajp.so |
|
28 |
|
|
29 |
ProxyRequests Off |
|
30 |
ProxyVia Off |
|
31 |
ProxyPreserveHost on |
|
32 |
RequestHeader unset Origin |
|
33 |
AllowEncodedSlashes NoDecode |
|
34 |
EOF |
|
35 |
|
|
36 |
chown root:builders "${HTTPCONF}" |
|
37 |
chmod 664 "${HTTPCONF}" |
|
38 |
svcadm enable svc:/network/http:apache24 |
|
39 |
} |
|
40 |
|
|
41 |
# setup oi-userland |
|
42 |
stage_setup() { |
|
43 |
if [ ! -f /etc/apache2/2.4/conf.d/00-proxy.conf ]; then |
|
44 |
echo "jenkinshelper: aborting, please run \"jenkinshelper -p\" initially as root on this jenkins instance once" |
|
45 |
exit 1 |
|
46 |
fi |
|
47 |
echo "jenkinshelper: running gmake setup" |
|
48 |
gmake setup |
|
49 |
} |
|
50 |
|
|
51 |
# scan the git log for changed components |
|
52 |
# we try to be smart and assume that all updates will always touch |
|
53 |
# the components Makefile also (to update COMPONENT_REVISION, etc) |
|
54 |
stage_build_changed() { |
|
55 |
for f in $(git diff --name-only HEAD..origin/oi/hipster | grep Makefile); do |
|
56 |
echo "jenkinshelper: building for ${f%/*}..." |
|
57 |
curpwd=$(pwd) |
|
58 |
cd "${f%/*}" && gmake publish |
|
59 |
rc=$? |
|
60 |
cd "${curpwd}" |
|
61 |
echo "jenkinshelper: done with ${f%/*} return code ${rc}" |
|
62 |
done |
|
63 |
} |
|
64 |
|
|
65 |
# prepare the pkg.depotd server instance, if an instance already |
|
66 |
# exists for this branch, we will use that - otherwise create a |
|
67 |
# fresh one |
|
68 |
stage_prepare_pkgdepotd() |
|
69 |
{ |
|
70 |
# we need the platform for the path to the repo |
|
71 |
platform=$(uname -p) |
|
72 |
|
|
73 |
# check if we already have this branch set up as a pkg.depotd: |
|
74 |
if ! "svcs pkg/server:${BRANCH_NAME}" >/dev/null 2>&1; then |
|
75 |
|
|
76 |
# get highest port from ${HTTPCONF} to figure out the next free one |
|
77 |
nextport=$(( $(nawk -F '[/:]' '{ print $7 }' < "${HTTPCONF}" | sort -n | tail -1) + 1 )) |
|
78 |
|
|
79 |
# set-up a new pkg/server instance |
|
80 |
svccfg -s pkg/server <<EOF |
|
81 |
add ${BRANCH_NAME} |
|
82 |
select ${BRANCH_NAME} |
|
83 |
addpg pkg application |
|
84 |
setprop pkg/port=${nextport} |
|
85 |
setprop pkg/readonly=true |
|
86 |
setprop pkg/pkg_root=/ |
|
87 |
setprop pkg/inst_root=${WORKSPACE}/${platform}/repo |
|
88 |
setprop pkg/proxy_base=${JENKINS_URL%:[0-9]*/}/${BRANCH_NAME}/ |
|
89 |
end |
|
90 |
EOF |
|
91 |
|
|
92 |
# enable the new pkg/server instance |
|
93 |
svcadm enable pkg/server:${BRANCH_NAME} |
|
94 |
|
|
95 |
# add the new proxy rule to our apache config |
|
96 |
echo "ProxyPassMatch /${BRANCH_NAME}/(.*)\$ http://127.0.0.1:${nextport}/\$1 nocanon max=200" >> "${HTTPCONF}" |
|
97 |
|
|
98 |
fi |
|
99 |
|
|
100 |
# we need to refresh the repo: |
|
101 |
pkgrepo refresh -s ${WORKSPACE}/${platform}/repo |
|
102 |
|
|
103 |
# also restarting pkg.depotd does not hurt |
|
104 |
svcadm restart pkg/server:${BRANCH_NAME} |
|
105 |
|
|
106 |
# graceful restart apache to reload config |
|
107 |
svcadm refresh svc:/network/http:apache24 |
|
108 |
} |
|
109 |
|
|
110 |
usage() { |
|
111 |
cat <<EOF |
|
112 |
Usage: |
|
113 |
jenkinshelper.ksh [ -h | -p | -s <stage> ] |
|
114 |
-h show this help |
|
115 |
-p run only ONCE to initialize your environment |
|
116 |
-s followed by the stage to run, currently: |
|
117 |
setup, build_changed, prepare_pkgdepotd |
|
118 |
EOF |
|
119 |
exit 0 |
|
120 |
} |
|
121 |
|
|
122 |
## MAIN ## |
|
123 |
# call this script with the stage as an argument to -s |
|
124 |
|
|
125 |
while getopts s:hp argv |
|
126 |
do |
|
127 |
case ${argv} in |
|
128 |
s) stage="stage_${OPTARG}";; |
|
129 |
p) stage="prepare";; |
|
130 |
h) usage;; |
|
131 |
esac |
|
132 |
done |
|
133 |
shift `expr ${OPTIND} - 1` |
|
134 |
|
|
135 |
# run requested stage |
|
136 |
rt=0 |
|
137 |
${stage} || rt=$? |
|
138 |
|
|
139 |
# we are done |
|
140 |
exit ${rt} |