Skip to content
This repository was archived by the owner on Mar 6, 2020. It is now read-only.

Commit 1056260

Browse files
committed
Add required jenkins script
Script used in Jenkins for upload of generated manual-pages package Signed-off-by: Mick <arceye@mgware.co.uk>
1 parent 8e4b140 commit 1056260

1 file changed

Lines changed: 171 additions & 0 deletions

File tree

.jenkins/manual_upload.sh

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
#!/bin/bash -e
2+
#
3+
# Usage:
4+
# manual_upload.sh -i <import dir> -d <debian suite> \
5+
# -u <sftp username> \
6+
# -w <sftp password> -p <sftp port> <sftp host>
7+
#
8+
# ./manual_upload.sh -i /home/mah/hello -d jessie -w PASSWORD HOST
9+
#
10+
# The default arguments are:
11+
#
12+
# username: mkjail
13+
# sftp port: 9422
14+
#
15+
#
16+
# Note that all the files under the <import dir>
17+
# will be uploaded to the sftp server
18+
#
19+
20+
if ! uuidgen >/dev/null 2>&1; then
21+
echo "uuidgen not found - please apt-get install uuid-runtime"
22+
exit 1
23+
fi
24+
25+
IMPORT=`uuidgen`
26+
27+
28+
while [[ $# > 1 ]]
29+
do
30+
key="$1"
31+
32+
case $key in
33+
-i|--import)
34+
DIR="$2"
35+
shift
36+
;;
37+
-w|--pass)
38+
export SSHPASS="$2"
39+
shift
40+
;;
41+
-d|--distribution)
42+
DIST="$2"
43+
shift
44+
;;
45+
-u|--user)
46+
SFTP_USER="$2"
47+
shift
48+
;;
49+
-p|--port)
50+
PORT="$2"
51+
shift
52+
;;
53+
esac
54+
shift
55+
done
56+
57+
if [ -z "${1}" ]; then
58+
echo sftp host argument missing!
59+
exit 1
60+
fi
61+
62+
if [ -z "${DIST}" ]; then
63+
echo Debian distribution missing! Use -d/--distribution argument
64+
exit 1
65+
fi
66+
67+
if [ -z "${DIR}" ]; then
68+
echo No import directory specified! Use -i/--import argument
69+
exit 1
70+
fi
71+
72+
if [ ! -d "${DIR}" ]; then
73+
echo Import directory ${DIR} does not exists!
74+
exit 1
75+
fi
76+
77+
x=$(find $DIR -mindepth 1 -print -quit -name '*.dsc' -o -name '*.deb')
78+
if [ -z "${x}" ]; then
79+
echo The import directory ${DIR} does not contain any debian packages!
80+
exit 1
81+
fi
82+
83+
if [ -z "${SSHPASS}" ]; then
84+
echo no password given - use --pass
85+
exit 1
86+
fi
87+
88+
89+
TMPDIR=`mktemp -d ` && cd $TEMPDIR
90+
91+
# deletes the temp directory
92+
function cleanup {
93+
rm -f ${TMPDIR}/{sftp_cmds,${IMPORT}*}
94+
echo "Deleted temp working directory $TMPDIR"
95+
}
96+
97+
# register the cleanup function to be called on the EXIT signal
98+
trap cleanup EXIT
99+
100+
101+
# test sftp connection
102+
cat >${TMPDIR}/sftp_cmds <<EOF
103+
bye
104+
EOF
105+
106+
SFTP_ARGS="-oStrictHostKeyChecking=no -oBatchMode=no -b ${TMPDIR}/sftp_cmds"
107+
108+
if [ ! -z "${PORT}" ]; then
109+
SFTP_ARGS+=" -P ${PORT}"
110+
else
111+
SFTP_ARGS+=" -P 9422"
112+
fi
113+
114+
if [ ! -z "${SFTP_USER}" ]; then
115+
SFTP_ARGS+=" ${SFTP_USER}@${1}"
116+
else
117+
SFTP_ARGS+=" mkjail@${1}"
118+
fi
119+
120+
connect_sftp() {
121+
err=0
122+
sshpass -e sftp ${SFTP_ARGS} || err=$?
123+
124+
if [ $err -ne 0 ]; then
125+
rm -f ${TMPDIR}/{sftp_cmds,${IMPORT}*}
126+
echo Error connecting with sftp. Exit code: ${err}
127+
exit 1
128+
fi
129+
}
130+
131+
# check connection
132+
connect_sftp
133+
134+
rm -f ${TMPDIR}/sftp_cmds
135+
# tar payload
136+
tar czf ${TMPDIR}/${IMPORT}.1.tgz -C ${DIR} . 2>/dev/null || true
137+
138+
if [ ! -f ${TMPDIR}/${IMPORT}.1.tgz ]; then
139+
echo Error creating ${TMPDIR}/${IMPORT}.1.tgz file!
140+
exit 1
141+
fi
142+
143+
# create status file
144+
cat >${TMPDIR}/${IMPORT} <<EOF
145+
CMD=run_tests
146+
EOF
147+
148+
cat >${TMPDIR}/${IMPORT}.1 <<EOF
149+
TAG=${DIST}-xxx
150+
EOF
151+
152+
# create result file
153+
touch ${TMPDIR}/${IMPORT}_passed
154+
touch ${TMPDIR}/${IMPORT}.1_passed
155+
156+
cat >${TMPDIR}/sftp_cmds <<EOF
157+
cd shared/incoming
158+
put ${TMPDIR}/${IMPORT}.1.tgz
159+
cd ../info
160+
put ${TMPDIR}/${IMPORT}
161+
put ${TMPDIR}/${IMPORT}_passed
162+
! sleep 2
163+
put ${TMPDIR}/${IMPORT}.1
164+
put ${TMPDIR}/${IMPORT}.1_passed
165+
bye
166+
EOF
167+
168+
# upload
169+
connect_sftp
170+
171+
cleanup

0 commit comments

Comments
 (0)