#!/bin/bash


INSTALL_DIR=$(pwd)

# Check for root privileges
if [[ $EUID -ne 0 ]]; then
  echo "This script must be run as root." >&2
  exit 1
fi

mkdir -p /home/backup/
mkdir -p /home/backup/db
mkdir -p /home/backup/files
mkdir -p /home/backup/maildir
mkdir -p /home/backup/public_html
mkdir -p /home/backup/public_ftp
mkdir -p /home/backup/repos
mkdir -p /home/backup/repository
mkdir -p /home/backup/users

mkdir -p /etc/backup

chmod g-rwx,o-rwx -R /home/backup/*
chown postgres -R /home/backup/db

  cp -vp $INSTALL_DIR'/lib/backup/backup_db.sh' /etc/backup/
  cp -vp $INSTALL_DIR'/lib/backup/backup_repos.sh' /etc/backup/
  cp -vp $INSTALL_DIR'/lib/backup/backup_files.sh' /etc/backup/
  cp -vp $INSTALL_DIR'/lib/backup/backup_publichtml.sh' /etc/backup/
  cp -vp $INSTALL_DIR'/lib/backup/backup_repository.sh' /etc/backup/
  cp -vp $INSTALL_DIR'/lib/backup/clear_edok_var.sh' /etc/backup/
  cp -vp $INSTALL_DIR'/lib/backup/maildrop_clear.sh' /etc/backup/
  cp -vp $INSTALL_DIR'/lib/backup/update_test.sh' /etc/backup/
  cp -vp $INSTALL_DIR'/lib/backup/clean_logs_backproc.sh' /etc/backup/
  cp -vp $INSTALL_DIR'/lib/backup/exclude_test.conf' /etc/backup
  cp -vp $INSTALL_DIR'/lib/backup/backproc_watchdog.sh' /etc/backup

  # Ustawienie uprawnień dla skryptów backupu tylko root
  chmod 755  /etc/backup
  chmod 700  /etc/backup/*.sh

  # Ustawienie uprawnień dla katalogu backup tylko root
  chmod 711 /home/backup


  # Logrotate configuration dla logów
  cp -vp $INSTALL_DIR'/conf/etc/logrotate.d/edokumenty_logrot' /etc/logrotate.d/

  # Ustawienie uprawnień dla pliku logrotate
  chmod 644 /etc/logrotate.d/edokumenty_logrot