summaryrefslogtreecommitdiff
blob: 29678309f4114bf1d5721c149363abb53399ee92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*-eselect-*-  vim: ft=eselect
# Copyright 2005-2017 Gentoo Foundation
# Distributed under the terms of the GNU GPL version 2 or later

DESCRIPTION="Manage user installed plugins of logstash"
MAINTAINER="hydrapolic@gmail.com"

PLUGINS="/var/lib/logstash/plugins-list.txt"
LS_INSTALL_DIR="/opt/logstash"

ls_plugin_wrapper() {
  JARS_SKIP=true "${LS_INSTALL_DIR}/bin/logstash-plugin" "${1}" "${2}" || die
}

### install action
describe_install() {
  echo "Install plugin"
}

describe_install_parameters() {
  echo "<plugin>"
}

do_install() {
  [[ ${#} -lt 1 ]] && die "Please specify at least one plugin"

  local plugin
  for plugin; do
    ls_plugin_wrapper install "${plugin}"
    echo "${plugin}" >> "${PLUGINS}" || die
  done

  sort -u "${PLUGINS}" > "${PLUGINS}.tmp" || die
  mv "${PLUGINS}.tmp" "${PLUGINS}" || die
}

### list action
describe_list() {
  echo "List user installed plugins"
}

do_list() {
  if [[ -f "${PLUGINS}" ]]; then
    write_list_start "Installed plugins:"

    local plugin
    while read -r plugin; do
      write_kv_list_entry "${plugin}"
    done < "${PLUGINS}"
  fi
}

### reinstall action
describe_reinstall() {
  echo "Reinstall plugins"
}

do_reinstall() {
  if [[ -f "${PLUGINS}" ]]; then
    local plugin
    while read -r plugin; do
      ls_plugin_wrapper install "${plugin}"
    done < "${PLUGINS}"
  fi
}

### uninstall action
describe_uninstall() {
  echo "Uninstall plugin"
}

describe_uninstall_parameters() {
  echo "<plugin>"
}

do_uninstall() {
  if [[ -f "${PLUGINS}" ]]; then
    local plugin
    for plugin; do
      grep "^${plugin}\$" "${PLUGINS}" || write_warning_msg "Plugin ${plugin} not recorded"
      sed -i "/^${plugin}\$/d" "${PLUGINS}" || die
      ls_plugin_wrapper remove "${plugin}"
    done
  fi
}