Files
SideStore/update_apps.py

121 lines
3.6 KiB
Python
Raw Normal View History

2024-12-18 12:09:53 +05:30
#!/usr/bin/env python3
import os
import json
import sys
2025-02-08 04:45:22 +05:30
# SIDESTORE_BUNDLE_ID = "com.SideStore.SideStore"
2024-12-18 12:09:53 +05:30
# Set environment variables with default values
VERSION_IPA = os.getenv("VERSION_IPA")
VERSION_DATE = os.getenv("VERSION_DATE")
2025-02-08 04:45:22 +05:30
IS_BETA = os.getenv("IS_BETA")
SIZE = os.getenv("SIZE")
SHA256 = os.getenv("SHA256")
LOCALIZED_DESCRIPTION = os.getenv("LOCALIZED_DESCRIPTION")
DOWNLOAD_URL = os.getenv("DOWNLOAD_URL")
2025-02-08 04:45:22 +05:30
BUNDLE_IDENTIFIER = os.getenv("BUNDLE_IDENTIFIER")
# Uncomment to debug/test by simulating dummy input locally
# VERSION_IPA = os.getenv("VERSION_IPA", "0.0.0")
# VERSION_DATE = os.getenv("VERSION_DATE", "2000-12-18T00:00:00Z")
# SIZE = int(os.getenv("SIZE", "0")) # Convert to integer
# SHA256 = os.getenv("SHA256", "")
# LOCALIZED_DESCRIPTION = os.getenv("LOCALIZED_DESCRIPTION", "Invalid Update")
# DOWNLOAD_URL = os.getenv("DOWNLOAD_URL", "https://github.com/SideStore/SideStore/releases/download/0.0.0/SideStore.ipa")
2024-12-18 12:09:53 +05:30
# Check if input file is provided
if len(sys.argv) < 2:
print("Usage: python3 update_apps.py <input_file>")
sys.exit(1)
input_file = sys.argv[1]
print(f"Input File: {input_file}")
# Debugging the environment variables
print(" ====> Required parameter list <====")
2025-02-08 04:45:22 +05:30
print("Bundle Identifier:", BUNDLE_IDENTIFIER)
2024-12-18 12:09:53 +05:30
print("Version:", VERSION_IPA)
print("Version Date:", VERSION_DATE)
2025-02-08 04:45:22 +05:30
print("IsBeta:", IS_BETA)
2024-12-18 12:09:53 +05:30
print("Size:", SIZE)
print("Sha256:", SHA256)
print("Localized Description:", LOCALIZED_DESCRIPTION)
print("Download URL:", DOWNLOAD_URL)
2025-02-08 04:45:22 +05:30
if IS_BETA is None:
print("Setting IS_BETA = False since no value was provided")
IS_BETA = False
if str(IS_BETA).lower() in ["true", "1", "yes"]:
IS_BETA = True
2024-12-18 12:09:53 +05:30
# Read the input JSON file
try:
with open(input_file, "r") as file:
data = json.load(file)
except Exception as e:
print(f"Error reading the input file: {e}")
sys.exit(1)
2025-02-08 04:45:22 +05:30
if (not BUNDLE_IDENTIFIER or
not VERSION_IPA or
not VERSION_DATE or
not SIZE or
not SHA256 or
not LOCALIZED_DESCRIPTION or
not DOWNLOAD_URL):
print("One or more required parameter(s) were not defined as environment variable(s)")
sys.exit(1)
# Convert to integer
SIZE = int(SIZE)
2025-02-08 04:45:22 +05:30
# Process the JSON data
updated = False
apps = data.get("apps", [])
appsToUpdate = [app for app in apps if app.get("bundleIdentifier") == BUNDLE_IDENTIFIER]
if len(appsToUpdate) == 0:
print("No app with the specified bundle identifier found.")
sys.exit(1)
2025-02-08 04:45:22 +05:30
if len(appsToUpdate) > 1:
print(f"Multiple apps with same `bundleIdentifier` = ${BUNDLE_IDENTIFIER} are not allowed!")
sys.exit(1)
2025-02-08 04:45:22 +05:30
app = appsToUpdate[0]
# Update app-level metadata for store front page
app.update({
"beta": IS_BETA,
})
versions = app.get("versions", [])
versionIfExists = [version for version in versions if version == VERSION_IPA]
if versionIfExists: # current version is a duplicate, so reject it
print(f"`version` = ${VERSION_IPA} already exists!, new build cannot have an existing version, Aborting!")
2024-12-18 12:09:53 +05:30
sys.exit(1)
2025-02-08 04:45:22 +05:30
# create an entry and keep ready
new_version = {
"version": VERSION_IPA,
"date": VERSION_DATE,
"localizedDescription": LOCALIZED_DESCRIPTION,
"downloadURL": DOWNLOAD_URL,
"size": SIZE,
"sha256": SHA256,
}
versions.insert(0, new_version)
2024-12-18 12:09:53 +05:30
# Save the updated JSON to the input file
try:
print("\nUpdated Sources File:\n")
print(json.dumps(data, indent=2, ensure_ascii=False))
with open(input_file, "w", encoding="utf-8") as file:
json.dump(data, file, indent=2, ensure_ascii=False)
print("JSON successfully updated.")
except Exception as e:
print(f"Error writing to the file: {e}")
sys.exit(1)