Move from adduser to user add and slightly fix postinst script

This commit is contained in:
alesapin 2020-01-10 13:19:59 +03:00
parent 05a36ec05c
commit 44625faa1f
2 changed files with 13 additions and 18 deletions

View File

@ -23,12 +23,13 @@ CLICKHOUSE_DATADIR=/var/lib/clickhouse
if [ -d "/var/lock" ]; then if [ -d "/var/lock" ]; then
LOCALSTATEDIR=/var/lock LOCALSTATEDIR=/var/lock
else else
if [ -d "/var/run" ]; then LOCALSTATEDIR=/run/lock
LOCALSTATEDIR=/var/run
else
LOCALSTATEDIR=/run/lock
fi
fi fi
if [ ! -d "$LOCALSTATEDIR" ]; then
mkdir -p "$LOCALSTATEDIR"
fi
CLICKHOUSE_BINDIR=/usr/bin CLICKHOUSE_BINDIR=/usr/bin
CLICKHOUSE_CRONFILE=/etc/cron.d/clickhouse-server CLICKHOUSE_CRONFILE=/etc/cron.d/clickhouse-server
CLICKHOUSE_CONFIG=$CLICKHOUSE_CONFDIR/config.xml CLICKHOUSE_CONFIG=$CLICKHOUSE_CONFDIR/config.xml

View File

@ -13,19 +13,14 @@ CLICKHOUSE_GENERIC_PROGRAM=${CLICKHOUSE_GENERIC_PROGRAM:=clickhouse}
EXTRACT_FROM_CONFIG=${CLICKHOUSE_GENERIC_PROGRAM}-extract-from-config EXTRACT_FROM_CONFIG=${CLICKHOUSE_GENERIC_PROGRAM}-extract-from-config
CLICKHOUSE_CONFIG=$CLICKHOUSE_CONFDIR/config.xml 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 /usr/share/debconf/confmodule ] && . /usr/share/debconf/confmodule
[ -f /etc/default/clickhouse ] && . /etc/default/clickhouse [ -f /etc/default/clickhouse ] && . /etc/default/clickhouse
if [ "$OS" = "rhel" ] || [ "$OS" = "centos" ] || [ "$OS" = "fedora" ] || [ "$OS" = "CentOS" ] || [ "$OS" = "Fedora" ] || [ "$OS" = "ol" ]; then if [ ! -f "/etc/debian_version" ]; then
is_rh=1 not_deb_os=1
fi 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 [ -x "/bin/systemctl" ] && [ -f /etc/systemd/system/clickhouse-server.service ] && [ -d /run/systemd/system ]; then
# if old rc.d service present - remove it # if old rc.d service present - remove it
if [ -x "/etc/init.d/clickhouse-server" ] && [ -x "/usr/sbin/update-rc.d" ]; then 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 # Make sure the administrative user exists
if ! getent passwd ${CLICKHOUSE_USER} > /dev/null; then if ! getent passwd ${CLICKHOUSE_USER} > /dev/null; then
if [ -n "$is_rh" ]; then if [ -n "$not_deb_os" ]; then
adduser --system --no-create-home --home /nonexistent \ useradd -r -s /bin/false --home-dir /nonexistent ${CLICKHOUSE_USER} > /dev/null
--shell /bin/false ${CLICKHOUSE_USER} > /dev/null
else else
adduser --system --disabled-login --no-create-home --home /nonexistent \ adduser --system --disabled-login --no-create-home --home /nonexistent \
--shell /bin/false --group --gecos "ClickHouse server" ${CLICKHOUSE_USER} > /dev/null --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 the user was created manually, make sure the group is there as well
if ! getent group ${CLICKHOUSE_GROUP} > /dev/null; then if ! getent group ${CLICKHOUSE_GROUP} > /dev/null; then
addgroup --system ${CLICKHOUSE_GROUP} > /dev/null groupadd -r ${CLICKHOUSE_GROUP} > /dev/null
fi fi
# make sure user is in the correct group # make sure user is in the correct group
if ! id -Gn ${CLICKHOUSE_USER} | grep -qw ${CLICKHOUSE_USER}; then 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 fi
# check validity of user and group # check validity of user and group