#!/usr/bin/env bash

. /usr/share/dosis2/bin/shell-support-functions

systemtype="$1"

if [ "${systemtype}" = "site-server" ] || [ "${systemtype}" = "standalone" ]; then
    ln -vsfT "/usr/share/dosis2/bin/dosis-backup" "/etc/cron.daily/z50-dosis-backup"
    ln -vsfT "/usr/share/dosis2/bin/reindex-database" "/etc/cron.monthly/z52-dosis-reindex-database"
    ln -vsfT "/usr/share/dosis2/bin/dosis-cups-cleanup" "/etc/cron.daily/z90-dosis-cups-cleanup"
    ln -vsfT "/usr/share/dosis2/bin/dosis-system-query" "/etc/cron.daily/z10-dosis-system-query"
    ln -vsfT "/usr/share/dosis2/bin/update-ppk-recommend" "/etc/cron.hourly/z93-update-ppk-recommend"
    rm -vf "/etc/cron.daily/z93-update-ppk-recommend"
    ln -vsfT "/usr/share/dosis2/bin/update-ppk-snapshot" "/etc/cron.hourly/z94-update-ppk-snapshot"
    ln -vsfT "/usr/share/dosis2/bin/download-drug-exception-list" "/etc/cron.daily/z96-import-drug-exceptions"
else
    rm -vf "/etc/cron.daily/z50-dosis-backup"
    rm -vf "/etc/cron.monthly/z52-dosis-reindex-database"
    rm -vf "/etc/cron.daily/z90-dosis-cups-cleanup"
    rm -vf "/etc/cron.daily/z61-dosis-refresh-cold-storage-views"
    rm -vf "/etc/cron.daily/z22-dosis-refresh-ai-issue-list"
    rm -vf "/etc/cron.daily/z93-update-ppk-recommend"
    rm -vf "/etc/cron.hourly/z93-update-ppk-recommend"
    rm -vf "/etc/cron.hourly/z94-update-ppk-snapshot"
    rm -vf "/etc/cron.daily/z96-import-drug-exceptions"
    ln -vsfT "/usr/share/dosis2/bin/dosis-system-query" "/etc/cron.daily/z10-dosis-system-query"
fi
