\_SB_.PCI0.S17_
      ˆ¾‘äÇò 8àFÌ¬ÈôƒßÏÃƒh¹ÂÁÀ      auto
  7   	ˆl–Ü4ý('ÜZÔâ€vàZ¸ÓJbÑ¿�þY+ÅYÆÈÜ�¸Û£¤þÄ„€_ÃÂÁ >Ž    	#!/bin/bash
#
# packager.io postinstall script functions
#

function debug() {
  if [ "${DEBUG}" == "yes" ]; then
    echo "DEBUG MODE ON"
    set -ex
  fi
}

function detect_os () {
  . /etc/os-release

  if [ "${ID}" == "debian" ] || [ "${ID}" == "ubuntu" ]; then
    OS="DEBIAN"
  elif [ "${ID}" == "centos" ] || [ "${ID}" == "fedora" ] || [ "${ID}" == "rhel" ]; then
    OS="REDHAT"
  elif [[ "${ID}" =~ suse|sles ]]; then
    OS="SUSE"
  else
    OS="UNKNOWN"
  fi

  if [ "${DEBUG}" == "yes" ]; then
    echo "OS is ${OS} based"
  fi
}

function detect_docker() {
  if [ -n "$(grep docker < /proc/1/cgroup)" ]; then
    DOCKER="yes"
  else
    DOCKER="no"
  fi

  if [ "${DEBUG}" == "yes" ]; then
    echo "os runs in docker container = ${DOCKER}"
  fi
}

function detect_initcmd () {
  if command -v systemctl > /dev/null 2>&1; then
    INIT_CMD="systemctl"
  elif command -v initctl > /dev/null 2>&1; then
    INIT_CMD="initctl"
  else
    function sysvinit () {
      service $2 $1
    }
    INIT_CMD="sysvinit"
  fi

  if [ "${DOCKER}" == "yes" ]; then
    INIT_CMD="initctl"
  fi

  if [ "${DEBUG}" == "yes" ]; then
    echo "INIT CMD = ${INIT_CMD}"
  fi
}

function detect_webserver () {
  if command -v nginx > /dev/null 2>&1; then
    WEBSERVER="nginx"
    WEBSERVER_CMD="nginx"
    if [ "${OS}" == "DEBIAN" ]; then
      WEBSERVER_CONF="/etc/nginx/sites-available/zammad.conf"
    elif [ "${OS}" == "REDHAT" ]; then
      WEBSERVER_CONF="/etc/nginx/conf.d/zammad.conf"
    elif [ "${OS}" == "SUSE" ]; then
      WEBSERVER_CONF="/etc/nginx/vhosts.d/zammad.conf"
    fi
  elif command -v apache2 > /dev/null 2>&1; then
    WEBSERVER="apache2"
    WEBSERVER_CMD="apache2"
    if [ "${OS}" == "DEBIAN" ]; then
      WEBSERVER_CONF="/etc/apache2/sites-available/zammad.conf"
    fi
  elif command -v httpd > /dev/null 2>&1; then
    WEBSERVER="apache2"
    WEBSERVER_CMD="httpd"
    if [ "${OS}" == "REDHAT" ]; then
      WEBSERVER_CONF="/etc/httpd/conf.d/zammad.conf"
    elif [ "${OS}" == "SUSE" ]; then
      WEBSERVER_CONF="/etc/apache2/vhosts.d/zammad.conf"
    fi
  fi

  if [ "${DEBUG}" == "yes" ]; then
    echo "Webserver is ${WEBSERVER_CMD}"
  fi
}

function create_initscripts () {
  echo "# (Re)creating init scripts"
  zammad scale web="${ZAMMAD_WEBS}" websocket="${ZAMMAD_WEBSOCKETS}" worker="${ZAMMAD_WORKERS}"

  echo "# Enabling Zammad on boot"
  ${INIT_CMD} enable zammad
}

function start_zammad () {
  echo "# Starting Zammad"
  ${INIT_CMD} start zammad
}

function stop_zammad () {
  echo "# Stopping Zammad"
  ${INIT_CMD} stop zammad
}

function create_database_password () {
  DB_PASS="$(tr -dc A-Za-z0-9 < /dev/urandom | head -c10)"
}

function create_postgresql_db () {
  if command -v postgresql-setup > /dev/null 2>&1; then
    echo "# Preparing postgresql server"

    # postgresql-setup --initdb uses 'systemctl cat postgresql.service' to look up
    # PGDATA, which requires the unit to already be registered with systemd. When
    # postgresql-server is installed in the same DNF transaction as Zammad, systemd
    # has not yet loaded the new unit (daemon-reload has not run and may not be
    # callable from a postinstall context), so postgresql-setup fails with
    # "FATAL: no db datadir (PGDATA) configured". Work around this by reading
    # PGDATA directly from the unit file on disk and calling initdb ourselves.
    local pg_service=/usr/lib/systemd/system/postgresql.service
    local pgdata
    pgdata="$(grep 'Environment=PGDATA=' "${pg_service}" 2>/dev/null | sed 's/.*PGDATA=//' | cut -d' ' -f1)"
    pgdata="${pgdata:-/var/lib/pgsql/data}"
    mkdir -p "${pgdata}"
    chown postgres:postgres "${pgdata}"
    chmod 700 "${pgdata}"
    runuser -u postgres -- initdb -D "${pgdata}"
  fi

  echo "# Creating postgresql bootstart"
  ${INIT_CMD} enable postgresql.service

  echo "# Restarting postgresql server"

  # Ensure the PostgreSQL socket directory exists. On RHEL/CentOS it lives under
  # 