note() {
  all_off="$(tput sgr0)"
  bold="${all_off}$(tput bold)"
  blue="${bold}$(tput setaf 4)"
  yellow="${bold}$(tput setaf 3)"
  echo "${blue}==>${yellow} NOTE:${bold} ${1}${all_off}"
}

post_install() {
  note '****************************************************************************************'
  note 'Default admin login is at localhost:8080/admin with user = admin and password = abc123.'
  note 'It is highly recommended to change this from the default.'
  note ''
  note "Owncast's webroot (front-end) is /usr/share/webapps/owncast"
  note ''
  note "The backend service can be enabled (and started) by: systemctl enable --now start owncast"
  note ''
  note 'for production environments use a proper webserver for the front-end (ie. apache/nginx)'
  note 'a sample nginx config file is at /usr/share/owncast/nginx.sample.conf'
  note ''
  note 'for documentation, visit https://owncast.online/docs/'
  note '****************************************************************************************'
}

post_upgrade() {
  post_install
}

pre_upgrade() {
  #old files from 0.2.1 rel 2/3
  if [ -d /usr/share/webapps/owncast/static ]; then
    rm -rf /usr/share/webapps/owncast/static
  fi
  if [ -d /usr/share/webapps/owncast/web ]; then
    rm -rf /usr/share/webapps/owncast/web
  fi
}

post_remove() {
  # Check if the /var/lib/owncast/web directory exists
  if [ -d /usr/share/webapps/owncast ]; then
    note 'automatically removing /usr/share/webapps/owncast files'
    rm -rf /usr/share/webapps/owncast # remove some stray npm files
  fi
  if [ -d /var/lib/owncast ]; then
    if [ -d /var/lib/owncast/.npm ]; then
      note 'found and removing owncast .npm files '
      rm -rf /var/lib/owncast/.npm # remove some stray npm files
    fi
    note 'owncast data still exists in /var/lib/owncast'
    note 'to remove this, run: sudo rm -rf /var/lib/owncast '
  fi
}
