OpenStack Orchestration (Heat)
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.

install.sh 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/bin/bash
  2. if [[ $EUID -ne 0 ]]; then
  3. echo "This script must be run as root" >&2
  4. exit 1
  5. fi
  6. # Install prefix for config files (e.g. "/usr/local").
  7. # Leave empty to install into /etc
  8. CONF_PREFIX=""
  9. LOG_DIR=/var/log/heat
  10. install -d $LOG_DIR
  11. detect_rabbit() {
  12. PKG_CMD="rpm -q"
  13. RABBIT_PKG="rabbitmq-server"
  14. QPID_PKG="qpid-cpp-server"
  15. # Detect OS type
  16. # Ubuntu has an lsb_release command which allows us to detect if it is Ubuntu
  17. if lsb_release -i 2>/dev/null | grep -iq ubuntu
  18. then
  19. PKG_CMD="dpkg -s"
  20. QPID_PKG="qpidd"
  21. fi
  22. if $PKG_CMD $RABBIT_PKG > /dev/null 2>&1
  23. then
  24. if ! $PKG_CMD $QPID_PKG > /dev/null 2>&1
  25. then
  26. return 0
  27. fi
  28. fi
  29. return 1
  30. }
  31. # Determinate is the given option present in the INI file
  32. # ini_has_option config-file section option
  33. function ini_has_option() {
  34. local file=$1
  35. local section=$2
  36. local option=$3
  37. local line
  38. line=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ p; }" "$file")
  39. [ -n "$line" ]
  40. }
  41. # Set an option in an INI file
  42. # iniset config-file section option value
  43. function iniset() {
  44. local file=$1
  45. local section=$2
  46. local option=$3
  47. local value=$4
  48. if ! grep -q "^\[$section\]" "$file"; then
  49. # Add section at the end
  50. echo -e "\n[$section]" >>"$file"
  51. fi
  52. if ! ini_has_option "$file" "$section" "$option"; then
  53. # Add it
  54. sed -i -e "/^\[$section\]/ a\\
  55. $option = $value
  56. " "$file"
  57. else
  58. # Replace it
  59. sed -i -e "/^\[$section\]/,/^\[.*\]/ s|^\($option[ \t]*=[ \t]*\).*$|\1$value|" "$file"
  60. fi
  61. }
  62. basic_configuration() {
  63. conf_path=$1
  64. if echo $conf_path | grep ".conf$" >/dev/null 2>&1
  65. then
  66. iniset $target DEFAULT auth_encryption_key `hexdump -n 16 -v -e '/1 "%02x"' /dev/random`
  67. iniset $target database connection "mysql+pymysql://heat:heat@localhost/heat"
  68. BRIDGE_IP=127.0.0.1
  69. iniset $target DEFAULT heat_metadata_server_url "http://${BRIDGE_IP}:8000/"
  70. if detect_rabbit
  71. then
  72. echo "rabbitmq detected, configuring $conf_path for rabbit" >&2
  73. iniset $conf_path DEFAULT rpc_backend kombu
  74. iniset $conf_path oslo_messaging_rabbit rabbit_password guest
  75. else
  76. echo "qpid detected, configuring $conf_path for qpid" >&2
  77. iniset $conf_path DEFAULT rpc_backend qpid
  78. fi
  79. fi
  80. }
  81. install_dir() {
  82. local dir=$1
  83. local prefix=$2
  84. for fn in $(ls $dir); do
  85. f=$dir/$fn
  86. target=$prefix/$f
  87. if [ $fn = 'heat.conf.sample' ]; then
  88. target=$prefix/$dir/heat.conf
  89. fi
  90. if [ -d $f ]; then
  91. [ -d $target ] || install -d $target
  92. install_dir $f $prefix
  93. elif [ -f $target ]; then
  94. echo "NOT replacing existing config file $target" >&2
  95. diff -u $target $f
  96. else
  97. echo "Installing $fn in $prefix/$dir" >&2
  98. install -m 664 $f $target
  99. if [ $fn = 'heat.conf.sample' ]; then
  100. basic_configuration $target
  101. fi
  102. fi
  103. done
  104. }
  105. install_dir etc $CONF_PREFIX
  106. python setup.py install >/dev/null
  107. rm -rf build heat.egg-info