Files
autopkg/main.py
phantom 70f64f1766
All checks were successful
Build Docker Image / build (push) Successful in 36s
v1.0.0b2
2025-11-28 04:51:21 -06:00

71 lines
1.6 KiB
Python

import os
import logging
import configparser
import requests
from logger import setup_log
from package import pkg
## Autopkg Apps
apps = {
"bitcoinknots": "https://api.github.com/repos/bitcoinknots/bitcoin/releases/latest",
"electrs": "https://api.github.com/repos/romanz/electrs/releases/latest"
}
def main():
# Handle apps (get versions)
for app, url in apps.items():
ini_version = data["Versions"][app] # Version previously packaged from data.ini
response = requests.get(url)
# Parse through JSON data
if response.status_code == 200:
json = response.json()
version = json["id"]
ini_version = str(version)
# Package new versions if available
if version != ini_version:
logging.info(f"Found new version ({version}) for {app}, packaging..")
pkg(app, version)
# Write changes
with open("data.ini", "w") as datafile:
data.write(datafile)
# Main Application
if __name__ == "__main__":
# Logging Setup
setup_log()
logging.info("Running Autopkg (c) 2025 phantom <phantom@shadeouts.net> https://shadeouts.net/")
# Environment Setup
target = os.getenv("APKG_TARGET")
if target == "prod":
datafile = "/etc/autopkg/data.ini"
elif target == "test" or None:
logging.warning("Running autopkg in testing mode!")
datafile = "test/data.ini"
## Config File Setup
data = configparser.ConfigParser()
data.read(datafile)
## Setup file if not present
if "Versions" not in data:
data["Versions"] = {}
# Call main function
main()