From 44625faa1f27eb383a8b031bea4f68c0e6fcb34e Mon Sep 17 00:00:00 2001 From: alesapin Date: Fri, 10 Jan 2020 13:19:59 +0300 Subject: [PATCH] Move from adduser to user add and slightly fix postinst script --- debian/clickhouse-server.init | 11 ++++++----- debian/clickhouse-server.postinst | 20 +++++++------------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/debian/clickhouse-server.init b/debian/clickhouse-server.init index e716fe06754..a150275cb78 100755 --- a/debian/clickhouse-server.init +++ b/debian/clickhouse-server.init @@ -23,12 +23,13 @@ CLICKHOUSE_DATADIR=/var/lib/clickhouse if [ -d "/var/lock" ]; then LOCALSTATEDIR=/var/lock else - if [ -d "/var/run" ]; then - LOCALSTATEDIR=/var/run - else - LOCALSTATEDIR=/run/lock - fi + LOCALSTATEDIR=/run/lock fi + +if [ ! -d "$LOCALSTATEDIR" ]; then + mkdir -p "$LOCALSTATEDIR" +fi + CLICKHOUSE_BINDIR=/usr/bin CLICKHOUSE_CRONFILE=/etc/cron.d/clickhouse-server CLICKHOUSE_CONFIG=$CLICKHOUSE_CONFDIR/config.xml diff --git a/debian/clickhouse-server.postinst b/debian/clickhouse-server.postinst index 052c2552b47..81a9582c063 100644 --- a/debian/clickhouse-server.postinst +++ b/debian/clickhouse-server.postinst @@ -13,19 +13,14 @@ CLICKHOUSE_GENERIC_PROGRAM=${CLICKHOUSE_GENERIC_PROGRAM:=clickhouse} EXTRACT_FROM_CONFIG=${CLICKHOUSE_GENERIC_PROGRAM}-extract-from-config CLICKHOUSE_CONFIG=$CLICKHOUSE_CONFDIR/config.xml -OS=${OS=`lsb_release -is 2>/dev/null ||:`} -[ -z "$OS" ] && [ -f /etc/os-release ] && . /etc/os-release && OS=$ID -[ -z "$OS" ] && [ -f /etc/centos-release ] && OS=centos -[ -z "$OS" ] && OS=`uname -s ||:` - [ -f /usr/share/debconf/confmodule ] && . /usr/share/debconf/confmodule [ -f /etc/default/clickhouse ] && . /etc/default/clickhouse -if [ "$OS" = "rhel" ] || [ "$OS" = "centos" ] || [ "$OS" = "fedora" ] || [ "$OS" = "CentOS" ] || [ "$OS" = "Fedora" ] || [ "$OS" = "ol" ]; then - is_rh=1 +if [ ! -f "/etc/debian_version" ]; then + not_deb_os=1 fi -if [ "$1" = configure ] || [ -n "$is_rh" ]; then +if [ "$1" = configure ] || [ -n "$not_deb_os" ]; then if [ -x "/bin/systemctl" ] && [ -f /etc/systemd/system/clickhouse-server.service ] && [ -d /run/systemd/system ]; then # if old rc.d service present - remove it if [ -x "/etc/init.d/clickhouse-server" ] && [ -x "/usr/sbin/update-rc.d" ]; then @@ -48,9 +43,8 @@ if [ "$1" = configure ] || [ -n "$is_rh" ]; then # Make sure the administrative user exists if ! getent passwd ${CLICKHOUSE_USER} > /dev/null; then - if [ -n "$is_rh" ]; then - adduser --system --no-create-home --home /nonexistent \ - --shell /bin/false ${CLICKHOUSE_USER} > /dev/null + if [ -n "$not_deb_os" ]; then + useradd -r -s /bin/false --home-dir /nonexistent ${CLICKHOUSE_USER} > /dev/null else adduser --system --disabled-login --no-create-home --home /nonexistent \ --shell /bin/false --group --gecos "ClickHouse server" ${CLICKHOUSE_USER} > /dev/null @@ -59,12 +53,12 @@ if [ "$1" = configure ] || [ -n "$is_rh" ]; then # if the user was created manually, make sure the group is there as well if ! getent group ${CLICKHOUSE_GROUP} > /dev/null; then - addgroup --system ${CLICKHOUSE_GROUP} > /dev/null + groupadd -r ${CLICKHOUSE_GROUP} > /dev/null fi # make sure user is in the correct group if ! id -Gn ${CLICKHOUSE_USER} | grep -qw ${CLICKHOUSE_USER}; then - adduser ${CLICKHOUSE_USER} ${CLICKHOUSE_GROUP} > /dev/null + usermod -a -G ${CLICKHOUSE_GROUP} ${CLICKHOUSE_USER} > /dev/null fi # check validity of user and group