Skip to content

Commit

Permalink
Create /etc/sql_exporter in postinstall
Browse files Browse the repository at this point in the history
This fixes install error:
cp: cannot create regular file '/etc/sql_exporter/sql_exporter.yml': No such file or directory

Also fix indent
  • Loading branch information
dupondje committed May 11, 2023
1 parent 3386c93 commit 7ab2cc7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 48 deletions.
49 changes: 25 additions & 24 deletions packaging/deb/postinstall
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,31 @@ set -e
IS_UPGRADE=false

case "$1" in
configure)
[ -z "$SQL_EXPORTER_USER" ] && SQL_EXPORTER_USER="sql_exporter"
[ -z "$SQL_EXPORTER_GROUP" ] && SQL_EXPORTER_GROUP="sql_exporter"
if ! getent group "$SQL_EXPORTER_GROUP" > /dev/null 2>&1 ; then
addgroup --system "$SQL_EXPORTER_GROUP" --quiet
fi
if ! id $SQL_EXPORTER_USER > /dev/null 2>&1 ; then
adduser --system --home /usr/share/sql_exporter \
--ingroup "$SQL_EXPORTER_GROUP" --disabled-password --shell /bin/false \
"$SQL_EXPORTER_USER"
fi
configure)
[ -z "$SQL_EXPORTER_USER" ] && SQL_EXPORTER_USER="sql_exporter"
[ -z "$SQL_EXPORTER_GROUP" ] && SQL_EXPORTER_GROUP="sql_exporter"
if ! getent group "$SQL_EXPORTER_GROUP" >/dev/null 2>&1; then
addgroup --system "$SQL_EXPORTER_GROUP" --quiet
fi
if ! id $SQL_EXPORTER_USER >/dev/null 2>&1; then
adduser --system --home /usr/share/sql_exporter \
--ingroup "$SQL_EXPORTER_GROUP" --disabled-password --shell /bin/false \
"$SQL_EXPORTER_USER"
fi

# copy user config files
if [ ! -f $CONF_FILE ]; then
CONF_PATH=$(dirname "$CONF_FILE")
cp /usr/share/sql_exporter/sql_exporter.yml $CONF_FILE
cp /usr/share/sql_exporter/mssql_example.collector.yml $CONF_PATH
fi

# configuration files should not be modifiable by sql_exporter user, as this can be a security issue
chown -Rh root:$SQL_EXPORTER_GROUP /etc/sql_exporter/
chmod 755 /etc/sql_exporter
find /etc/sql_exporter -type f -exec chmod 640 {} ';'
find /etc/sql_exporter -type d -exec chmod 755 {} ';'
if [ ! -f $CONF_FILE ]; then
CONF_PATH=$(dirname "$CONF_FILE")
mkdir -p $CONF_PATH
cp /usr/share/sql_exporter/sql_exporter.yml $CONF_FILE
cp /usr/share/sql_exporter/mssql_example.collector.yml $CONF_PATH
fi

# configuration files should not be modifiable by sql_exporter user, as this can be a security issue
chown -Rh root:$SQL_EXPORTER_GROUP /etc/sql_exporter/
chmod 755 /etc/sql_exporter
find /etc/sql_exporter -type f -exec chmod 640 {} ';'
find /etc/sql_exporter -type d -exec chmod 755 {} ';'

# If $1=configure and $2 is set, this is an upgrade
if [ "$2" != "" ]; then
Expand All @@ -55,6 +56,6 @@ case "$1" in
fi
echo " OK"

fi
;;
fi
;;
esac
49 changes: 25 additions & 24 deletions packaging/rpm/postinstall
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,31 @@ set -e
IS_UPGRADE=false

case "$1" in
configure)
[ -z "$SQL_EXPORTER_USER" ] && SQL_EXPORTER_USER="sql_exporter"
[ -z "$SQL_EXPORTER_GROUP" ] && SQL_EXPORTER_GROUP="sql_exporter"
if ! getent group "$SQL_EXPORTER_GROUP" > /dev/null 2>&1 ; then
groupadd -r "$SQL_EXPORTER_GROUP"
fi
if ! getent passwd $SQL_EXPORTER_USER > /dev/null 2>&1 ; then
useradd -r -d /usr/share/sql_exporter \
-g "$SQL_EXPORTER_GROUP" -s /sbin/nologin \
"$SQL_EXPORTER_USER"
fi
configure)
[ -z "$SQL_EXPORTER_USER" ] && SQL_EXPORTER_USER="sql_exporter"
[ -z "$SQL_EXPORTER_GROUP" ] && SQL_EXPORTER_GROUP="sql_exporter"
if ! getent group "$SQL_EXPORTER_GROUP" >/dev/null 2>&1; then
groupadd -r "$SQL_EXPORTER_GROUP"
fi
if ! getent passwd $SQL_EXPORTER_USER >/dev/null 2>&1; then
useradd -r -d /usr/share/sql_exporter \
-g "$SQL_EXPORTER_GROUP" -s /sbin/nologin \
"$SQL_EXPORTER_USER"
fi

# copy user config files
if [ ! -f $CONF_FILE ]; then
CONF_PATH=$(dirname "$CONF_FILE")
cp /usr/share/sql_exporter/sql_exporter.yml "$CONF_FILE"
cp /usr/share/sql_exporter/mssql_example.collector.yml "$CONF_PATH"
fi

# configuration files should not be modifiable by sql_exporter user, as this can be a security issue
chown -Rh root:$SQL_EXPORTER_GROUP /etc/sql_exporter/
chmod 755 /etc/sql_exporter
find /etc/sql_exporter -type f -exec chmod 640 {} ';'
find /etc/sql_exporter -type d -exec chmod 755 {} ';'
if [ ! -f $CONF_FILE ]; then
CONF_PATH=$(dirname "$CONF_FILE")
mkdir -p $CONF_PATH
cp /usr/share/sql_exporter/sql_exporter.yml "$CONF_FILE"
cp /usr/share/sql_exporter/mssql_example.collector.yml "$CONF_PATH"
fi

# configuration files should not be modifiable by sql_exporter user, as this can be a security issue
chown -Rh root:$SQL_EXPORTER_GROUP /etc/sql_exporter/
chmod 755 /etc/sql_exporter
find /etc/sql_exporter -type f -exec chmod 640 {} ';'
find /etc/sql_exporter -type d -exec chmod 755 {} ';'

# If $1=configure and $2 is set, this is an upgrade
if [ "$2" != "" ]; then
Expand All @@ -55,6 +56,6 @@ case "$1" in
fi
echo " OK"

fi
;;
fi
;;
esac

0 comments on commit 7ab2cc7

Please sign in to comment.