@@ -27,6 +27,48 @@ echo_red() { printf "\033[1;31m$*\033[m\n"; }
2727echo_green () { printf " \033[1;32m$* \033[m\n" ; }
2828echo_blue () { printf " \033[1;34m$* \033[m\n" ; }
2929
30+ backtrace () {
31+ # shell backtraces only work on bash
32+ if [ ! -z " ${BASH} " ] ; then
33+ local i=
34+ i=${# FUNCNAME[@]}
35+ (( -- i))
36+
37+ while (( i >= 0 ))
38+ do
39+ echo " ${BASH_SOURCE[$i]} :${BASH_LINENO[$i]} .${FUNCNAME[$i]} ()"
40+ i=$(( i - 1 ))
41+ done
42+ fi
43+ }
44+
45+ add_python_path () {
46+ echo " adding Python to the path"
47+ if [ -d " $HOME /.pyenv/bin" -a " $( echo " $PATH " | grep .pyenv/bin | wc -c) " -eq " 0" ] ; then
48+ echo " adding $HOME /.pyenv/bin to path"
49+ export PATH=" $HOME /.pyenv/bin:$PATH "
50+ fi
51+ if [ -z " ${PYENV_SHELL} " ] ; then
52+ echo init pyenv
53+ eval " $( pyenv init -) "
54+ fi
55+ if [ -d /opt/pyenv/versions/3.6.3/bin -a " $( echo " $PATH " | grep opt/pyenv/versions | wc -c) " -eq " 0" ] ; then
56+ echo adding python on opt to PATH
57+ export PATH=" /opt/pyenv/versions/3.6.3/bin:$PATH "
58+ fi
59+ if [ -d /root/.pyenv/versions/3.6.3/bin -a " $( echo " $PATH " | grep root/.pyenv/versions | wc -c) " -eq " 0" ] ; then
60+ echo adding python on root/.pyenv to PATH
61+ export PATH=" /root/.pyenv/versions/3.6.3/bin:$PATH "
62+ fi
63+ if ! command_exists python ; then
64+ echo No python on path
65+ echo " $PATH "
66+ else
67+ python --version
68+ command -v python
69+ fi
70+ }
71+
3072get_script_path () {
3173 local script=" $1 "
3274
@@ -180,14 +222,30 @@ brew_install_if_not_exists() {
180222}
181223
182224sftp_cmd_pipe () {
183- sftp " ${EXTRA_SSH} " " ${SSHUSER} @${SSHHOST} "
225+ sftp -o " StrictHostKeyChecking no" " ${EXTRA_SSH} " " ${SSHUSER} @${SSHHOST} "
226+ }
227+
228+ sftp_run_cmds () {
229+ local x=5
230+ while [ " ${x} " -gt " 0" ] ; do
231+ sftp -o " StrictHostKeyChecking no" " ${EXTRA_SSH} " " ${SSHUSER} @${SSHHOST} " 0< " $1 " && break ;
232+ echo_red " failed to ssh, trying again"
233+ x=$(( x - 1 ))
234+ sleep 10
235+ done
236+ if [ " ${x} " -eq " 0" ] ; then
237+ echo_red " failed to upload files"
238+ return 1;
239+ fi
240+ return 0
184241}
185242
186243sftp_rm_artifact () {
187244 local artifact=" $1 "
188245 sftp_cmd_pipe << -EOF
189246 cd ${DEPLOY_TO}
190247 rm ${artifact}
248+ bye
191249 EOF
192250}
193251
@@ -196,16 +254,26 @@ sftp_upload() {
196254 local TO=" $2 "
197255 local LATE=" $3 "
198256
199- sftp_cmd_pipe << -EOF
200- cd ${DEPLOY_TO}
257+ if [ -n " ${LATE} " ] ; then
258+ sftp_cmd_pipe << -EOF
259+ cd ${DEPLOY_TO}
201260
202- put ${FROM} ${TO}
203- ls -l ${TO}
261+ put ${FROM} ${TO}
262+ ls -l ${TO}
204263
205- symlink ${TO} ${LATE}
206- ls -l ${LATE}
207- bye
208- EOF
264+ symlink ${TO} ${LATE}
265+ ls -l ${LATE}
266+ bye
267+ EOF
268+ else
269+ sftp_cmd_pipe << -EOF
270+ cd ${DEPLOY_TO}
271+
272+ put ${FROM} ${TO}
273+ ls -l ${TO}
274+ bye
275+ EOF
276+ fi
209277}
210278
211279upload_file_to_swdownloads () {
@@ -245,26 +313,106 @@ upload_file_to_swdownloads() {
245313 echo and " ${branch} _${LIBNAME}${LDIST}${EXT} "
246314 ssh -V
247315
248- for rmf in ${TO} ${LATE} ; do
249- sftp_rm_artifact " ${rmf} " || \
250- echo_blue " Could not delete ${rmf} "
251- done
316+ local tmpfl=$( mktemp)
317+ echo " cd ${DEPLOY_TO} " > " ${tmpfl} "
318+ echo " rm ${TO} " >> " ${tmpfl} "
319+ echo " rm ${LATE} " >> " ${tmpfl} "
320+ echo " put ${FROM} ${TO} " >> " ${tmpfl} "
321+ echo " symlink ${TO} ${LATE} " >> " ${tmpfl} "
322+ echo " ls -l ${TO} " >> " ${tmpfl} "
323+ echo " ls -l ${LATE} " >> " ${tmpfl} "
324+ echo " bye" >> " ${tmpfl} "
252325
253- sftp_upload " ${FROM} " " ${TO} " " ${LATE} " || {
254- echo_red " Failed to upload artifact from '${FROM} ', to '${TO} ', symlink '${LATE} '"
255- return 1
256- }
326+ sftp_run_cmds " ${tmpfl} "
327+ rm " ${tmpfl} "
328+
329+ return 0
330+ }
257331
332+ remove_old_pkgs () {
258333 # limit things to a few files, so things don't grow forever
259- if [ " ${EXT} " = " .deb" ] ; then
260- for files in $( ssh " ${EXTRA_SSH} " " ${SSHUSER} @${SSHHOST} " \
334+ # we only do this on one build so simultaneous builds don't clobber each other
335+ if [ -z " ${GH_DOC_TOKEN} " ] ; then
336+ return 0
337+ fi
338+
339+ if [ -z " ${TRAVIS_BUILD_DIR} " ] ; then
340+ echo " TRAVIS_BUILD_DIR not set"
341+ return 0
342+ fi
343+
344+ if [ ! -d " ${TRAVIS_BUILD_DIR} /.git" ] ; then
345+ echo " No ${TRAVIS_BUILD_DIR} /.git to operate git on"
346+ return 0
347+ fi
348+
349+ local LIBNAME=$1
350+ local old=
351+
352+ echo " Remove old packages from ${LIBNAME} "
353+
354+ if [ -n " $TRAVIS_PULL_REQUEST_BRANCH " ] ; then
355+ local branch=" $TRAVIS_PULL_REQUEST_BRANCH "
356+ else
357+ local branch=" $TRAVIS_BRANCH "
358+ fi
359+
360+ local GLOB=${DEPLOY_TO} /${branch} _${LIBNAME} -*
361+
362+ # putting everything into a file, and connecting once decreases the chances
363+ # for ssh issues, connections happen once, not every single file
364+ local tmpfl=$( mktemp)
365+ echo " cd ${DEPLOY_TO} " > " ${tmpfl} "
366+ for files in $( ssh -o " StrictHostKeyChecking no" " ${EXTRA_SSH} " " ${SSHUSER} @${SSHHOST} " \
261367 " ls -lt ${GLOB} " | tail -n +100 | awk ' {print $NF}' )
262- do
263- ssh " ${EXTRA_SSH} " " ${SSHUSER} @${SSHHOST} " \
264- " rm ${DEPLOY_TO} /${files} " || \
265- return 1
266- done
368+ do
369+ echo " rm ${files} " >> " ${tmpfl} "
370+ done
371+ echo " bye" >> " ${tmpfl} "
372+ # if it is only cd & bye, skip it
373+ if [ " $( wc -l " ${tmpfl} " | awk ' {print $1}' ) " -gt " 2" ] ; then
374+ sftp_run_cmds " ${tmpfl} "
267375 fi
376+ rm " ${tmpfl} "
377+ # provide an index so people can find files.
378+ ssh -o " StrictHostKeyChecking no" " ${EXTRA_SSH} " " ${SSHUSER} @${SSHHOST} " \
379+ " ls -lt ${DEPLOY_TO} " | grep " ${LIBNAME} " > " ${LIBNAME} _index.html"
380+ echo " ls captured"
381+
382+ echo " cd ${DEPLOY_TO} " > " ${tmpfl} "
383+ # prune old / removed branches, leave things are are tags/branches
384+ for old in $( sed ' s/-> .*$//' libiio_index.html | \
385+ awk ' {print $NF}' | grep -v master | sort | \
386+ sed " s/_libiio-0.[0-9][0-9].g[a-z0-9]*-/ %% /" | \
387+ grep " %%" | awk ' {print $1}' | sort -u)
388+ do
389+ if [ " $( git --git-dir " ${TRAVIS_BUILD_DIR} /.git" ls-remote --heads origin " ${old} " | wc -l) " -ne " 0" ] ; then
390+ echo " ${old} is a branch"
391+ else
392+ if [ " $( git --git-dir " ${TRAVIS_BUILD_DIR} /.git" ls-remote --tags origin " ${old} " | wc -l) " -ne " 0" ] ; then
393+ echo " ${old} is a tag"
394+ else
395+ echo " ${old} can be removed"
396+ echo " rm ${old} _${LIBNAME} -*" >> " ${tmpfl} "
397+ echo " rm ${old} _latest_${LIBNAME} -*" >> " ${tmpfl} "
398+ echo " rm ${old} _lastest_${LIBNAME} -*" >> " ${tmpfl} "
399+ fi
400+ fi
401+ done
402+ # cap things at 15, so we don't exceed the time
403+ sed -i 16q " ${tmpfl} "
404+ echo " bye" >> " ${tmpfl} "
405+ # if it is only cd & bye, skip it
406+ if [ " $( wc -l " ${tmpfl} " | awk ' {print $1}' ) " -gt " 2" ] ; then
407+ sftp_run_cmds " ${tmpfl} "
408+ fi
409+ rm " ${tmpfl} "
410+
411+ # Now that we removed things, do it again
412+ rm " ${LIBNAME} _index.html"
413+ ssh -o " StrictHostKeyChecking no" " ${EXTRA_SSH} " " ${SSHUSER} @${SSHHOST} " \
414+ " ls -lt ${DEPLOY_TO} " | grep " ${LIBNAME} " > " ${LIBNAME} _index.html"
415+ sftp_upload " ${LIBNAME} _index.html" " ${LIBNAME} _index.html"
268416
269417 return 0
270418}
@@ -347,6 +495,11 @@ is_centos_at_least_ver() {
347495 version_ge " $( get_version) " " $1 "
348496}
349497
498+ is_arm () {
499+ [ " $( dpkg --print-architecture) " = " armhf" ] || return 1
500+ test " $( dpkg --print-architecture) " = " armhf"
501+ }
502+
350503print_github_api_rate_limits () {
351504 # See https://developer.github.com/v3/rate_limit/
352505 # Note: Accessing this endpoint does not count against your REST API rate limit.
0 commit comments