#!/bin/bash
GPG_KEY="3CE1F7C9015A9450D6D6906004AFD16F1DE3C455"
#search_string="./pool/"
#replace_string="https://frcoal.cfd/pool/"

script_full_path=$(dirname "$0")
cd $script_full_path/.. || exit 1

rm InRelease Packages Packages.bz2 Packages.xz Packages.zst Release Release.gpg Packages.zip Packages.lz4 Packages.lzma

#echo "[Repository] Proxying frcoal.cfd..."
#rm proxy_pkg
#curl -L https://frcoal.cfd/Packages -o proxy_pkg
#sed -i 's|./pool/|https://frcoal.cfd/pool/|g' proxy_pkg
#cat proxy_pkg-nofrcoal >> proxy_pkg

echo "[Repository] Generating Packages..."
apt-ftparchive packages ./debs > Packages
#echo >> Packages
#cat proxy_pkg >> Packages
zstd -q -c19 Packages > Packages.zst
xz -c9 Packages > Packages.xz
bzip2 -c9 Packages > Packages.bz2
lzma -c9 Packages > Packages.lzma
lz4 -c9 Packages > Packages.lz4
zip -r Packages.zip Packages

echo "[Repository] Generating Release..."
apt-ftparchive \
		-o APT::FTPArchive::Release::Origin="azaz's repo" \
		-o APT::FTPArchive::Release::Label="azaz's repo" \
		-o APT::FTPArchive::Release::Suite="stable" \
		-o APT::FTPArchive::Release::Version="1488" \
		-o APT::FTPArchive::Release::Codename="eyeOS" \
		-o APT::FTPArchive::Release::Architectures="iphoneos-arm iphoneos-arm64" \
		-o APT::FTPArchive::Release::Components="main" \
		-o APT::FTPArchive::Release::Description="cydia thats about it" \
		release . > Release

echo "[Repository] Signing Release using Azreal's GPG Key..."
gpg -abs -u $GPG_KEY -o Release.gpg Release
gpg -abs -u $GPG_KEY --clearsign -o InRelease Release

echo "[Repository] Finished"
#curl -X POST https://api.cloudflare.com/client/v4/zones/543ec7410e0c8700cc705f983d77d6ef/purge_cache -H 'Authorization: Bearer -Hf4yfv0AnWRuvCDzWH71GlGRQyeTW3Sdgu8JdVq' -H 'Content-Type: application/json' --data '{"purge_everything": true}'
#sudo rm -rf ../modiverse-dark/debs
#sudo rm ../modiverse-dark/Package*
#sudo rm ../modiverse-dark/Releas* ../modiverse-dark/InRelease
#sudo cp -r ./debs/ ../modiverse-dark/
#sudo cp Package* ../modiverse-dark/
#udo cp Releas* ../modiverse-dark/
#sudo cp InRelease ../modiverse-dark/
