File: /var/lib/dpkg/info/opensearch-dashboards.postinst
#!/bin/bash
# Copyright OpenSearch Contributors
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
# deb opensearch-dashboards postinst script
set -e
echo "Running OpenSearch-Dashboards Post-Installation Script"
product_dir=/usr/share/opensearch-dashboards
config_dir=/etc/opensearch-dashboards
data_dir=/var/lib/opensearch-dashboards
log_dir=/var/log/opensearch-dashboards
pid_dir=/var/run/opensearch-dashboards
# Reload systemctl daemon
if command -v systemctl > /dev/null; then
    systemctl daemon-reload
fi
# Reload other configs
if command -v systemd-tmpfiles > /dev/null; then
    systemd-tmpfiles --create opensearch-dashboards.conf
fi
# Restart the service after an upgrade
if [ "$1" = "configure" ] && [ -n "$2" ]; then
    if command -v systemctl >/dev/null && systemctl is-enabled opensearch-dashboards.service >/dev/null; then
        echo "Restarting opensearch-dashboards.service after upgrade"
        systemctl start opensearch-dashboards.service
    fi
else
    # Messages
    echo "### NOT starting on installation, please execute the following statements to configure opensearch-dashboards service to start automatically using systemd"
    echo " sudo systemctl daemon-reload"
    echo " sudo systemctl enable opensearch-dashboards.service"
    echo "### You can start opensearch-dashboards service by executing"
    echo " sudo systemctl start opensearch-dashboards.service"
fi
echo "### Breaking change in packaging since 2.13.0"
echo " In 2.13.0 and later releases of OpenSearch Dashboards, we have changed the permissions associated with access to installed files"
echo " If you are configuring tools that require read access to the OpenSearch Dashboards configuration files, we recommend you add the user that runs these tools to the 'opensearch-dashboards' group"
echo " For more information, see https://github.com/opensearch-project/opensearch-build/pull/4043"
# Set ownership and permissions
chown -R root:opensearch-dashboards ${config_dir}
chmod -R u=rwX,g=rX,o= ${config_dir}
chown -R opensearch-dashboards:adm ${log_dir}
chmod 750 ${log_dir}
chown -R opensearch-dashboards:opensearch-dashboards ${data_dir}
chmod 750 ${data_dir}
chown -R opensearch-dashboards:opensearch-dashboards ${pid_dir}
exit 0