modified version of jenkins debian glue (https://github.com/mika/jenkins-debian-glue) for devuan
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

110 lines
3.9 KiB

  1. #!/bin/bash
  2. start_seconds=$(cut -d . -f 1 /proc/uptime)
  3. [ -n "$start_seconds" ] && SECONDS="$[$(cut -d . -f 1 /proc/uptime)-$start_seconds]" || SECONDS="unknown"
  4. if [ -r /var/lib/jenkins/config.xml ] ; then
  5. echo "Configuration file /var/lib/jenkins/config.xml exists already." >&2
  6. echo "Exiting to avoid possible data loss." >&2
  7. exit 1
  8. fi
  9. if [ $# -lt 1 ] ; then
  10. echo "Usage: $0 <password> [<http://path/to/some/puppetfile.pp>]" >&2
  11. exit 1
  12. fi
  13. SEED=$(head -c 12 /dev/urandom | base64)
  14. if [ -z "$SEED" ] ; then
  15. echo "Error calculating seed. :(" >&2
  16. exit 1
  17. fi
  18. PASSWORD_HASH=$(echo -n "${1}"{"${SEED}"} | sha256sum | awk '{print $1}')
  19. if [ -z "$PASSWORD_HASH" ] ; then
  20. echo "Error calculating password hash. :(" >&2
  21. exit 1
  22. fi
  23. if [ -n "$2" ] ; then
  24. if [ -r jenkins_debian_glue.pp ] ; then
  25. echo "Error: file jenkins_debian_glue.pp exists already. Exiting to avoid possible data loss." >&2
  26. exit 1
  27. else
  28. echo "Retrieving $2 and storing as jenkins_debian_glue.pp"
  29. wget -O jenkins_debian_glue.pp --no-check-certificate "$2"
  30. fi
  31. else
  32. if ! [ -r jenkins_debian_glue.pp ] ; then
  33. wget --no-check-certificate https://raw.github.com/mika/jenkins-debian-glue/master/puppet/jenkins_debian_glue.pp
  34. fi
  35. fi
  36. if ! grep -q PASSWORD_HASH_TO_BE_ADJUSTED jenkins_debian_glue.pp ; then
  37. echo "################################################################################"
  38. echo "Warning: string PASSWORD_HASH_TO_BE_ADJUSTED not found in jenkins_debian_glue.pp"
  39. echo "Notice that rerunning $0 with a different password might not work as expected."
  40. echo "To make sure adjusting the password works please execute:
  41. rm jenkins_debian_glue.pp
  42. $0 <your_password> https://raw.github.com/mika/jenkins-debian-glue/master/puppet/jenkins_debian_glue.pp"
  43. echo
  44. echo "################################################################################"
  45. else
  46. printf "Adjusting password in jenkins_debian_glue.pp: "
  47. sed -i "s;PASSWORD_HASH_TO_BE_ADJUSTED;$PASSWORD_HASH;" jenkins_debian_glue.pp || exit 1
  48. sed -i "s;SEED_TO_BE_ADJUSTED;$SEED;" jenkins_debian_glue.pp || exit 1
  49. echo OK
  50. fi
  51. if ! [ -r jenkins_debian_glue.pp ] ; then
  52. echo "Error: can not find jenkins_debian_glue.pp." >&2
  53. echo "Either manually grab https://raw.github.com/mika/jenkins-debian-glue/master/puppet/jenkins_debian_glue.pp" >&2
  54. echo " or run $0 <http://path/to/some/puppetfile.pp>" >&2
  55. exit 1
  56. fi
  57. if ! type puppet &>/dev/null ; then
  58. apt-get update
  59. apt-get -y install puppet || exit 1
  60. fi
  61. # Amazon EC2 returns the internal IP by default, so ask about the public one
  62. IP=$(facter ec2_public_ipv4 2>/dev/null) # curl http://169.254.169.254/latest/meta-data/public-ipv4
  63. # 'facter ec2_public_ipv4' returns nothing on Debian's AMI :(
  64. if [ -z "$IP" ] ; then
  65. IP=$(wget --quiet --tries=3 --timeout=3 -O - http://169.254.169.254/latest/meta-data/public-ipv4 2>/dev/null)
  66. fi
  67. # try Google Compute Engine
  68. if [ -z "$IP" ] ; then
  69. IP=$(wget --quiet --tries=3 --timeout=3 -O - "http://metadata/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip" --header "X-Google-Metadata-Request: True" 2>/dev/null)
  70. fi
  71. # neither using EC2 nor GCE? use a fallback then
  72. if [ -z "$IP" ] ; then
  73. IP=$(ip addr show dev $(route -n | awk '/^0\.0\.0\.0/{print $NF}') | awk '/inet / {print $2}' | head -1 |sed "s;/.*;;")
  74. fi
  75. if [[ $(facter fqdn) == "" ]] ; then
  76. echo "Error: please make sure you have a valid FQDN configured in /etc/hosts" >&2
  77. echo "NOTE: Something like adding the following snippet to /etc/hosts might help:
  78. $IP $(hostname).example.org $(hostname)
  79. "
  80. exit 1
  81. fi
  82. if puppet apply jenkins_debian_glue.pp ; then
  83. [ -n "$start_seconds" ] && SECONDS="$[$(cut -d . -f 1 /proc/uptime)-$start_seconds]" || SECONDS="unknown"
  84. echo "jenkins-debian-glue deployment finished after ${SECONDS} seconds."
  85. else
  86. echo "Fatal error during puppet run. :(" >&2
  87. exit 1
  88. fi
  89. echo "Now point your browser to http://${IP}:8080"