tar.bash 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/bash
  2. # This file contains some utilities to test the elasticsearch scripts,
  3. # the .deb/.rpm packages and the SysV/Systemd scripts.
  4. # WARNING: This testing file must be executed as root and can
  5. # dramatically change your system. It removes the 'elasticsearch'
  6. # user/group and also many directories. Do not execute this file
  7. # unless you know exactly what you are doing.
  8. # Licensed to Elasticsearch under one or more contributor
  9. # license agreements. See the NOTICE file distributed with
  10. # this work for additional information regarding copyright
  11. # ownership. Elasticsearch licenses this file to you under
  12. # the Apache License, Version 2.0 (the "License"); you may
  13. # not use this file except in compliance with the License.
  14. # You may obtain a copy of the License at
  15. #
  16. # http://www.apache.org/licenses/LICENSE-2.0
  17. #
  18. # Unless required by applicable law or agreed to in writing,
  19. # software distributed under the License is distributed on an
  20. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21. # KIND, either express or implied. See the License for the
  22. # specific language governing permissions and limitations
  23. # under the License.
  24. # Install the tar.gz archive
  25. install_archive() {
  26. export ESHOME=${1:-/tmp/elasticsearch}
  27. echo "Unpacking tarball to $ESHOME"
  28. rm -rf /tmp/untar
  29. mkdir -p /tmp/untar
  30. tar -xzpf elasticsearch*.tar.gz -C /tmp/untar
  31. find /tmp/untar -depth -type d -name 'elasticsearch*' -exec mv {} "$ESHOME" \; > /dev/null
  32. # ES cannot run as root so create elasticsearch user & group if needed
  33. if ! getent group "elasticsearch" > /dev/null 2>&1 ; then
  34. if is_dpkg; then
  35. addgroup --system "elasticsearch"
  36. else
  37. groupadd -r "elasticsearch"
  38. fi
  39. fi
  40. if ! id "elasticsearch" > /dev/null 2>&1 ; then
  41. if is_dpkg; then
  42. adduser --quiet --system --no-create-home --ingroup "elasticsearch" --disabled-password --shell /bin/false "elasticsearch"
  43. else
  44. useradd --system -M --gid "elasticsearch" --shell /sbin/nologin --comment "elasticsearch user" "elasticsearch"
  45. fi
  46. fi
  47. chown -R elasticsearch:elasticsearch "$ESHOME"
  48. export_elasticsearch_paths
  49. }
  50. # Move the unzipped tarball to another location.
  51. move_elasticsearch() {
  52. local oldhome="$ESHOME"
  53. export ESHOME="$1"
  54. rm -rf "$ESHOME"
  55. mv "$oldhome" "$ESHOME"
  56. export_elasticsearch_paths
  57. }
  58. # Export some useful paths.
  59. export_elasticsearch_paths() {
  60. export ESMODULES="$ESHOME/modules"
  61. export ESPLUGINS="$ESHOME/plugins"
  62. export ESCONFIG="$ESHOME/config"
  63. export ESSCRIPTS="$ESCONFIG/scripts"
  64. export ESDATA="$ESHOME/data"
  65. export ESLOG="$ESHOME/logs"
  66. }
  67. # Checks that all directories & files are correctly installed
  68. # after a archive (tar.gz/zip) install
  69. verify_archive_installation() {
  70. assert_file "$ESHOME" d elasticsearch elasticsearch 755
  71. assert_file "$ESHOME/bin" d elasticsearch elasticsearch 755
  72. assert_file "$ESHOME/bin/elasticsearch" f elasticsearch elasticsearch 755
  73. assert_file "$ESHOME/bin/elasticsearch.in.sh" f elasticsearch elasticsearch 755
  74. assert_file "$ESHOME/bin/elasticsearch-plugin" f elasticsearch elasticsearch 755
  75. assert_file "$ESHOME/bin/elasticsearch-translog" f elasticsearch elasticsearch 755
  76. assert_file "$ESCONFIG" d elasticsearch elasticsearch 755
  77. assert_file "$ESCONFIG/elasticsearch.yml" f elasticsearch elasticsearch 660
  78. assert_file "$ESCONFIG/jvm.options" f elasticsearch elasticsearch 660
  79. assert_file "$ESCONFIG/log4j2.properties" f elasticsearch elasticsearch 660
  80. assert_file "$ESPLUGINS" d elasticsearch elasticsearch 755
  81. assert_file "$ESHOME/lib" d elasticsearch elasticsearch 755
  82. assert_file "$ESHOME/NOTICE.txt" f elasticsearch elasticsearch 644
  83. assert_file "$ESHOME/LICENSE.txt" f elasticsearch elasticsearch 644
  84. assert_file "$ESHOME/README.textile" f elasticsearch elasticsearch 644
  85. }