#!/bin/bash

source debian/vars.sh

# Clean the build root first
rm -rf $buildroot
# Installing directories
install -d -m 755 $buildroot/etc
install -d -m 755 $buildroot/etc/cron.d
install -d -m 755 $buildroot/usr
install -d -m 755 $buildroot/usr/local
install -d -m 755 $buildroot/usr/local/cpanel
install -d -m 755 $buildroot/usr/local/cpanel/whostmgr
install -d -m 755 $buildroot/usr/local/cpanel/whostmgr/cgi
install -d -m 755 $buildroot/usr/local/cpanel/whostmgr/cgi/comet-backup
install -d -m 755 $buildroot/usr/local/cpanel/whostmgr/docroot
install -d -m 755 $buildroot/usr/local/cpanel/whostmgr/docroot/templates
install -d -m 755 $buildroot/usr/local/cpanel/whostmgr/docroot/templates/comet-backup
install -d -m 755 $buildroot/usr/local/cpanel/whostmgr/docroot/templates/comet-backup/spa
install -d -m 755 $buildroot/var
install -d -m 755 $buildroot/var/cpanel
install -d -m 755 $buildroot/var/cpanel/plugins
install -d -m 755 $buildroot/var/cpanel/plugins/comet-backup
install -d -m 755 $buildroot/var/cpanel/plugins/comet-backup/locale
# Installing source files
install -D -m 644 $SOURCE5 $buildroot/etc/cron.d/backup_jobs_helper
install -D -m 644 $SOURCE6 $buildroot/etc/cron.d/comet_license_sync
install -D -m 644 $SOURCE7 $buildroot/usr/local/cpanel/Cpanel/Server/Handlers/CometWebProsCallback.pm
install -D -m 644 $SOURCE8 $buildroot/usr/local/cpanel/Cpanel/Server/Handlers/CometWebProsOAuthCallback.pm
install -D -m 644 $SOURCE9 $buildroot/usr/local/cpanel/Cpanel/Server/Handlers/OpenIdConnect/CometIntercept.pm
install -D -m 644 $SOURCE10 $buildroot/usr/local/cpanel/Whostmgr/API/1/CometBackup.pm
install -D -m 644 $SOURCE11 $buildroot/usr/local/cpanel/Whostmgr/CometBackup/AgentManager.pm
install -D -m 644 $SOURCE12 $buildroot/usr/local/cpanel/Whostmgr/CometBackup/BackupJobs.pm
install -D -m 644 $SOURCE13 $buildroot/usr/local/cpanel/Whostmgr/CometBackup/BackupRunLogs.pm
install -D -m 644 $SOURCE14 $buildroot/usr/local/cpanel/Whostmgr/CometBackup/CometBackupAPI.pm
install -D -m 644 $SOURCE15 $buildroot/usr/local/cpanel/Whostmgr/CometBackup/CometBackupAPI/ProtectedItemBatch.pm
install -D -m 644 $SOURCE16 $buildroot/usr/local/cpanel/Whostmgr/CometBackup/CometBackupAPI/ProtectedItemRestore.pm
install -D -m 644 $SOURCE17 $buildroot/usr/local/cpanel/Whostmgr/CometBackup/Config.pm
install -D -m 644 $SOURCE18 $buildroot/usr/local/cpanel/Whostmgr/CometBackup/Constants.pm
install -D -m 644 $SOURCE19 $buildroot/usr/local/cpanel/Whostmgr/CometBackup/DeletedUsers.pm
install -D -m 644 $SOURCE20 $buildroot/usr/local/cpanel/Whostmgr/CometBackup/Hooks/AccountsRemove.pm
install -D -m 644 $SOURCE21 $buildroot/usr/local/cpanel/Whostmgr/CometBackup/Logger.pm
install -D -m 644 $SOURCE22 $buildroot/usr/local/cpanel/Whostmgr/CometBackup/ProtectedItemMap.pm
install -D -m 644 $SOURCE23 $buildroot/usr/local/cpanel/Whostmgr/CometBackup/RestoreRunLogs.pm
install -D -m 644 $SOURCE24 $buildroot/usr/local/cpanel/Whostmgr/CometBackup/Scheduling.pm
install -D -m 644 $SOURCE25 $buildroot/usr/local/cpanel/Whostmgr/CometBackup/Setup.pm
install -D -m 644 $SOURCE26 $buildroot/usr/local/cpanel/Whostmgr/CometBackup/WebProsAuth.pm
install -D -m 755 $SOURCE27 $buildroot/usr/local/cpanel/bin/comet_backup_runner
install -D -m 755 $SOURCE28 $buildroot/usr/local/cpanel/bin/comet_reset_protected_items
install -D -m 755 $SOURCE29 $buildroot/usr/local/cpanel/bin/sync_comet_protected_items
install -D -m 755 $SOURCE30 $buildroot/usr/local/cpanel/scripts/backup_jobs_helper
install -D -m 755 $SOURCE31 $buildroot/usr/local/cpanel/scripts/call_pkgacct
install -D -m 755 $SOURCE32 $buildroot/usr/local/cpanel/scripts/comet_license_registration_sync
install -D -m 755 $SOURCE33 $buildroot/usr/local/cpanel/scripts/comet_protected_item_maintenance
install -D -m 755 $SOURCE34 $buildroot/usr/local/cpanel/scripts/initialize_comet_backup
install -D -m 755 $SOURCE35 $buildroot/usr/local/cpanel/scripts/process_cpmove
install -D -m 644 $SOURCE36 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup.t
install -D -m 644 $SOURCE37 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_cancel_running_backup_job.t
install -D -m 644 $SOURCE38 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_create_backup_job.t
install -D -m 644 $SOURCE39 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_create_local_storage.t
install -D -m 644 $SOURCE40 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_delete_backup_job.t
install -D -m 644 $SOURCE41 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_disable_backup_job.t
install -D -m 644 $SOURCE42 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_disable_comet_backup.t
install -D -m 644 $SOURCE43 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_download_backup_job_log.t
install -D -m 644 $SOURCE44 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_download_restore_job_log.t
install -D -m 644 $SOURCE45 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_duplicate_backup_job.t
install -D -m 644 $SOURCE46 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_enable_backup_job.t
install -D -m 644 $SOURCE47 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_enable_comet_backup.t
install -D -m 644 $SOURCE48 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_get_backup_destinations.t
install -D -m 644 $SOURCE49 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_get_backup_jobs.t
install -D -m 644 $SOURCE50 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_get_comet_backup_configuration_status.t
install -D -m 644 $SOURCE51 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_get_restore_log.t
install -D -m 644 $SOURCE52 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_is_comet_backup_enabled.t
install -D -m 644 $SOURCE53 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_list_accounts_for_restore.t
install -D -m 644 $SOURCE54 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_list_backup_run_history.t
install -D -m 644 $SOURCE55 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_list_backups_for_user.t
install -D -m 644 $SOURCE56 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_list_restore_history.t
install -D -m 644 $SOURCE57 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_modify_backup_job.t
install -D -m 644 $SOURCE58 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_register_server_with_comet_backup.t
install -D -m 644 $SOURCE59 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_run_backup_job.t
install -D -m 644 $SOURCE60 $buildroot/usr/local/cpanel/t/small/Whostmgr-API-1-CometBackup_run_restore_job.t
install -D -m 644 $SOURCE61 $buildroot/usr/local/cpanel/t/small/Whostmgr-CometBackup-AgentManager.t
install -D -m 644 $SOURCE62 $buildroot/usr/local/cpanel/t/small/Whostmgr-CometBackup-BackupJobs.t
install -D -m 644 $SOURCE63 $buildroot/usr/local/cpanel/t/small/Whostmgr-CometBackup-BackupRunLogs.t
install -D -m 644 $SOURCE64 $buildroot/usr/local/cpanel/t/small/Whostmgr-CometBackup-CometBackupAPI-ProtectedItemBatch.t
install -D -m 644 $SOURCE65 $buildroot/usr/local/cpanel/t/small/Whostmgr-CometBackup-CometBackupAPI-ProtectedItemRestore.t
install -D -m 644 $SOURCE66 $buildroot/usr/local/cpanel/t/small/Whostmgr-CometBackup-CometBackupAPI.t
install -D -m 644 $SOURCE67 $buildroot/usr/local/cpanel/t/small/Whostmgr-CometBackup-Config.t
install -D -m 644 $SOURCE68 $buildroot/usr/local/cpanel/t/small/Whostmgr-CometBackup-Constants.t
install -D -m 644 $SOURCE69 $buildroot/usr/local/cpanel/t/small/Whostmgr-CometBackup-DeletedUsers.t
install -D -m 644 $SOURCE70 $buildroot/usr/local/cpanel/t/small/Whostmgr-CometBackup-Hooks-AccountsRemove.t
install -D -m 644 $SOURCE71 $buildroot/usr/local/cpanel/t/small/Whostmgr-CometBackup-Logger.t
install -D -m 644 $SOURCE72 $buildroot/usr/local/cpanel/t/small/Whostmgr-CometBackup-ProtectedItemMap.t
install -D -m 644 $SOURCE73 $buildroot/usr/local/cpanel/t/small/Whostmgr-CometBackup-RestoreRunLogs.t
install -D -m 644 $SOURCE74 $buildroot/usr/local/cpanel/t/small/Whostmgr-CometBackup-Scheduling.t
install -D -m 644 $SOURCE75 $buildroot/usr/local/cpanel/t/small/Whostmgr-CometBackup-Setup.t
install -D -m 755 $SOURCE76 $buildroot/usr/local/cpanel/whostmgr/docroot/cgi/comet-backup/comet-backup.cgi
install -D -m 644 $SOURCE77 $buildroot/usr/local/cpanel/whostmgr/docroot/templates/comet-backup/comet-backup.tmpl
install -D -m 644 $SOURCE78 $buildroot/usr/local/cpanel/whostmgr/docroot/templates/comet-backup/spa/assets/activation-modal-banner-bg-1mTKQR4E.png
install -D -m 644 $SOURCE79 $buildroot/usr/local/cpanel/whostmgr/docroot/templates/comet-backup/spa/assets/comet-bg-CRUnuPq2.svg
install -D -m 644 $SOURCE80 $buildroot/usr/local/cpanel/whostmgr/docroot/templates/comet-backup/spa/assets/default-EHwmsrMW.png
install -D -m 644 $SOURCE81 $buildroot/usr/local/cpanel/whostmgr/docroot/templates/comet-backup/spa/assets/filtered-E_wy3Kf4.png
install -D -m 644 $SOURCE82 $buildroot/usr/local/cpanel/whostmgr/docroot/templates/comet-backup/spa/assets/index-BX1eVgAj.css
install -D -m 644 $SOURCE83 $buildroot/usr/local/cpanel/whostmgr/docroot/templates/comet-backup/spa/assets/index-ChJJHETZ.js
install -D -m 644 $SOURCE84 $buildroot/usr/local/cpanel/whostmgr/docroot/templates/comet-backup/spa/assets/symbols-DGjW64mN.svg
install -D -m 644 $SOURCE85 $buildroot/usr/local/cpanel/whostmgr/docroot/templates/comet-backup/spa/index.html.tt
install -D -m 644 $SOURCE86 $buildroot/usr/local/cpanel/whostmgr/docroot/templates/comet-backup/spa/vite.svg
install -D -m 644 $SOURCE87 $buildroot/var/cpanel/plugins/comet-backup/README.md
install -D -m 644 $SOURCE88 $buildroot/var/cpanel/plugins/comet-backup/clean_snapshot
install -D -m 644 $SOURCE89 $buildroot/var/cpanel/plugins/comet-backup/comet-backup.svg
install -D -m 644 $SOURCE90 $buildroot/var/cpanel/plugins/comet-backup/comet_backup.json
install -D -m 644 $SOURCE91 $buildroot/var/cpanel/plugins/comet-backup/config.yaml
install -D -m 755 $SOURCE92 $buildroot/var/cpanel/plugins/comet-backup/install.sh
install -D -m 644 $SOURCE93 $buildroot/var/cpanel/plugins/comet-backup/locale/ar.yaml
install -D -m 644 $SOURCE94 $buildroot/var/cpanel/plugins/comet-backup/locale/de.yaml
install -D -m 644 $SOURCE95 $buildroot/var/cpanel/plugins/comet-backup/locale/es.yaml
install -D -m 644 $SOURCE96 $buildroot/var/cpanel/plugins/comet-backup/locale/es_419.yaml
install -D -m 644 $SOURCE97 $buildroot/var/cpanel/plugins/comet-backup/locale/es_es.yaml
install -D -m 644 $SOURCE98 $buildroot/var/cpanel/plugins/comet-backup/locale/fr.yaml
install -D -m 644 $SOURCE99 $buildroot/var/cpanel/plugins/comet-backup/locale/id.yaml
install -D -m 644 $SOURCE100 $buildroot/var/cpanel/plugins/comet-backup/locale/ja.yaml
install -D -m 644 $SOURCE101 $buildroot/var/cpanel/plugins/comet-backup/locale/pt.yaml
install -D -m 644 $SOURCE102 $buildroot/var/cpanel/plugins/comet-backup/locale/pt_br.yaml
install -D -m 644 $SOURCE103 $buildroot/var/cpanel/plugins/comet-backup/locale/tr.yaml
install -D -m 755 $SOURCE104 $buildroot/var/cpanel/plugins/comet-backup/uninstall.sh
install -D -m 644 $SOURCE105 $buildroot/var/cpanel/plugins/comet-backup/whm-comet-backup.conf
echo "Tree for buildroot: $buildroot"
tree $buildroot
