functions 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. # common functions
  2. # get_file <base_url> <file> <dir>
  3. # downlaods file from $base_url/$file into directory $dir
  4. function get_file() {
  5. local base_url=$1
  6. local file=$2
  7. local dir=$3
  8. if [ ! -e $dir ]; then
  9. mkdir $dir
  10. fi
  11. if [ -e $dir/$file ]; then
  12. rm $dir/$file
  13. fi
  14. pushd $dir > /dev/null
  15. wget --no-check-certificate $base_url/$file
  16. popd > /dev/null
  17. }
  18. # setup_artifacts <tag> <suffix>
  19. # downloads artifacts to build installer:
  20. # 1. geoserver bin artifact
  21. # 2. installer specific artifact specified by <suffix>
  22. # files are unpacked into tmp directory
  23. function setup_artifacts() {
  24. local tag=$1
  25. local suf=$2
  26. local gs_artifact=geoserver-$tag-bin.zip
  27. local installer_artifact=geoserver-$tag-$suf.zip
  28. if [ -z $SKIP_DOWNLOAD ]; then
  29. get_file $DIST_URL/$tag $gs_artifact files
  30. get_file $DIST_URL/$tag $installer_artifact files
  31. fi
  32. # unpack the artifacts
  33. if [ -e tmp ]; then
  34. rm -rf tmp
  35. fi
  36. mkdir -p tmp
  37. unzip -d tmp files/$installer_artifact
  38. unzip -d tmp files/$gs_artifact
  39. }
  40. # upload_installer <tag> <file>
  41. # uploads file <file> to distribution server under tag <tag>
  42. function upload_installer() {
  43. local tag=$1
  44. local file=$2
  45. local ssh_opts="-i $DIST_PK -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
  46. if [ -z $SKIP_UPLOAD ]; then
  47. echo "uploading $file"
  48. # add an extra / to beginning of file path to overcome issue with MinGW text substitution
  49. # where the :/ remote path is converted to ;z: (and connection fails to resolve hostname)
  50. # http://www.mingw.org/wiki/Posix_path_conversion
  51. echo "scp $ssh_opts -P $DIST_PORT $file $DIST_USER@$DIST_HOST:/$DIST_PATH/$tag"
  52. scp $ssh_opts -P $DIST_PORT $file $DIST_USER@$DIST_HOST:/$DIST_PATH/$tag
  53. # set access permissions for www
  54. echo "ssh $ssh_opts -p $DIST_PORT $DIST_USER@$DIST_HOST \"chmod 0644 '$DIST_PATH/$tag/$file'\""
  55. ssh $ssh_opts -p $DIST_PORT $DIST_USER@$DIST_HOST "chmod 0644 '$DIST_PATH/$tag/$file'"
  56. fi
  57. }
  58. # start_installer_job <hudson_url> <user> <key> <tag>
  59. # starts a hudson installer job
  60. function start_installer_job() {
  61. local job_url="$1/job/geoserver-installer/buildWithParameters?TAG=$4&token=buildme"
  62. local creds=$2:$3
  63. echo "executing installer job $job_url with credentials $creds"
  64. curl -k --connect-timeout 10 --user $creds $job_url
  65. }
  66. function is_primary_branch_num() {
  67. local str=$1
  68. if [ "$( echo $str | egrep "[0-9]+\.x" )" == "$str" ] || [ "master" == "$str" ]; then
  69. echo "1"
  70. else
  71. echo "0"
  72. fi
  73. }
  74. # is_version_nuym <str>
  75. # tests a string to see if it is a x.y.z or x.y-z style version number
  76. function is_version_num() {
  77. local str=$1
  78. if [ "$( echo $str | egrep "[0-9]+\.[0-9]+((\.|-).*)?" )" == "$str" ]; then
  79. echo "1"
  80. else
  81. if [ "$( echo $str | egrep "[0-9]+-.*" )" == "$str" ]; then
  82. echo "1"
  83. else
  84. echo "0"
  85. fi
  86. fi
  87. }
  88. # get_pom_version <pom>
  89. # gets the version declared in a pom file
  90. function get_pom_version() {
  91. local pom=$1
  92. echo `grep "<version>" $pom | head -n 1 | sed 's/<.*>\(.*\)<\/.*>/\1/g' | sed 's/ //g'`
  93. }
  94. # get_jira_id <tag>
  95. # gets the jira id for a version named <tag>
  96. function get_jira_id() {
  97. local tag=$1
  98. local jira_id=`curl -s -G $JIRA_REST/project/$JIRA_PROJ/versions | tr "{" "\n" | grep -F "\"$tag\"" | tr "," "\n" | grep "\"id\"" | sed 's/"id": *"\([0-9]\+\).*/\1/g'`
  99. #sed 's/"id": *\([0-9]*\).*/\1/g'`
  100. if [ ! -z $jira_id ]; then
  101. echo $jira_id
  102. fi
  103. }
  104. # init_git <user> <emai>
  105. # sets up git config for user/email
  106. function init_git() {
  107. # setup the author, for some reason I can;t for the life of me get to this
  108. # to work properly from a script using the --author option to git commit
  109. git config user.name $1
  110. git config user.email $2
  111. }