post_install() {
  log() {
    echo "$@" 
  }

  log "info" "Configuring portmaster.service to launch at boot"
    systemctl enable portmaster.service

  #
  # Prepare the installation directory tree
  #
  /opt/safing/portmaster/portmaster-start --data /opt/safing/portmaster clean-structure

  #
  # Finally, trigger downloading modules. As this requires internet access
  # it is more likely to fail and is thus the last thing we do.
  #
  log "Downloading portmaster modules. This may take a while ..."
  /opt/safing/portmaster/portmaster-start --data /opt/safing/portmaster update 2>/dev/null >/dev/null || (
    log "error" "Failed to download modules"
    log "error" "Please run '/opt/safing/portmaster/portmaster-start --data /opt/safing/portmaster update' manually.\n"
  )
}

pre_remove() {
  log() {
    echo "$@" 
  }

  # stop the portmaster service and disable it if it's enabled.
    if (systemctl -q is-active portmaster.service); then
      log "info" "Stopping portmaster.service"
      systemctl stop portmaster.service
    fi
    if (systemctl -q is-enabled portmaster.service); then
      log "info" "Disabling portmaster.service to launch at boot"
      systemctl disable portmaster.service
    fi
}

post_remove() {
  rm -rf /opt/safing
}
