Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backport] PR #7510 to 4.x #7683

Merged
merged 1 commit into from
Jul 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions tasks/build/package_scripts/post_install.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
#!/bin/sh
set -e

user_check() {
getent passwd "$1" > /dev/null 2>&1
}
case $1 in
# Debian
configure)
if ! getent group "<%= group %>" >/dev/null; then
addgroup --quiet --system "<%= group %>"
fi

user_create() {
# Create a system user. A system user is one within the system uid range and
# has no expiration
useradd -r "$1"
}
if ! getent passwd "<%= user %>" >/dev/null; then
adduser --quiet --system --no-create-home --disabled-password \
--ingroup "<%= group %>" --shell /bin/false "<%= user %>"
fi
;;
abort-deconfigure|abort-upgrade|abort-remove)
;;

# Red Hat
1|2)
if ! getent group "<%= group %>" >/dev/null; then
groupadd -r "<%= group %>"
fi

if ! getent passwd "<%= user %>" >/dev/null; then
useradd -r -g "<%= group %>" -M -s /sbin/nologin \
-c "kibana service user" "<%= user %>"
fi
;;

*)
echo "post install script called with unknown argument \`$1'" >&2
exit 1
;;
esac

if ! user_check "<%= user %>" ; then
user_create "<%= user %>"
fi
chown -R <%= user %>:<%= group %> <%= optimizeDir %>
chown <%= user %>:<%= group %> <%= dataDir %>
chown <%= user %>:<%= group %> <%= pluginsDir %>
24 changes: 10 additions & 14 deletions tasks/build/package_scripts/post_remove.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
#!/bin/sh
set -e

user_check() {
getent passwd "$1" > /dev/null 2>&1
}

user_remove() {
userdel "$1"
}

REMOVE_USER=false
REMOVE_USER_AND_GROUP=false
REMOVE_DIRS=false

case $1 in
# Includes cases for all valid arguments, exit 1 otherwise
# Debian
purge)
REMOVE_USER=true
REMOVE_USER_AND_GROUP=true
REMOVE_DIRS=true
;;
remove)
Expand All @@ -28,7 +20,7 @@ case $1 in

# Red Hat
0)
REMOVE_USER=true
REMOVE_USER_AND_GROUP=true
REMOVE_DIRS=true
;;

Expand All @@ -41,9 +33,13 @@ case $1 in
;;
esac

if [ "$REMOVE_USER" = "true" ]; then
if user_check "<%= user %>" ; then
user_remove "<%= user %>"
if [ "$REMOVE_USER_AND_GROUP" = "true" ]; then
if getent passwd "<%= user %>" >/dev/null; then
userdel "<%= user %>"
fi

if getent group "<%= group %>" >/dev/null; then
groupdel "<%= group %>"
fi
fi

Expand Down