updated APPINDEX
This commit is contained in:
parent
3545a5f73b
commit
2bb34d2f5c
3 changed files with 214 additions and 111 deletions
|
@ -11,20 +11,38 @@ import (
|
|||
)
|
||||
|
||||
// Package the APPINDEX update process
|
||||
func PackageAPPINDEX(name, release, version, arch, size, installedSize, description, url, license, origin, maintainer, dependencies, platform string) error {
|
||||
// Mock package file name
|
||||
pkgFile := fmt.Sprintf("%s-%s", name, version)
|
||||
func PackageAPPINDEX(
|
||||
name, // e.g. "spitfire-browser"
|
||||
release, // e.g. "nightly"
|
||||
version, // e.g. "2024.12.21"
|
||||
arch, // e.g. "amd64"
|
||||
size, // e.g. "838205457" (compressed size)
|
||||
installedSize, // e.g. "3595495684" (uncompressed size)
|
||||
description, // e.g. "Spitfire build"
|
||||
url, // e.g. "https://spitfirebrowser.xyz/"
|
||||
license, // e.g. "AGPL-3.0"
|
||||
origin, // e.g. "browser"
|
||||
maintainer, // e.g. "Internet Addict"
|
||||
dependencies, // usually blank ..."
|
||||
platform, // e.g. "linux"
|
||||
remoteDir string, // e.g. "nightly/linux/amd64"
|
||||
) error {
|
||||
|
||||
// Calculate checksums
|
||||
checksum := calcChecksum(pkgFile)
|
||||
contentChecksum := calcChecksum(pkgFile)
|
||||
// Construct a filename that matches what you compress & upload
|
||||
// Adjust this naming convention to match your compress step exactly!
|
||||
// Example: "spitfire-browser-nightly-amd64-linux.tar.gz"
|
||||
fileName := fmt.Sprintf("%s-%s-%s-%s.tar.gz", origin, arch, release, platform)
|
||||
|
||||
// Timestamp
|
||||
timestamp := time.Now().Unix()
|
||||
// If you have a real file on disk, you might call `calcChecksum(fileName)`.
|
||||
// For demo, we call `calcChecksum` with a mock package name.
|
||||
checksum := calcChecksum(fileName)
|
||||
|
||||
// Remove existing entry based on P, R, A, and o fields
|
||||
// Remove existing entry based on P, R, A, o (if you want to deduplicate).
|
||||
removeExistingEntry(name, release, arch, origin)
|
||||
|
||||
// Use current Unix timestamp
|
||||
timestamp := time.Now().Unix()
|
||||
|
||||
// Open or create the APPINDEX file for appending
|
||||
file, err := os.OpenFile("./APPINDEX", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
|
@ -32,30 +50,42 @@ func PackageAPPINDEX(name, release, version, arch, size, installedSize, descript
|
|||
}
|
||||
defer file.Close()
|
||||
|
||||
// Write the new entry
|
||||
// Build the SourceForge-based download URL:
|
||||
// https://downloads.sourceforge.net/project/spitfire-browser/<remoteDir>/<fileName>
|
||||
downloadURL := fmt.Sprintf("https://downloads.sourceforge.net/project/spitfire-browser/%s/%s", remoteDir, fileName)
|
||||
|
||||
// Format the entry.
|
||||
entry := fmt.Sprintf(`
|
||||
C:%s
|
||||
P:%s
|
||||
R:%s
|
||||
V:%s
|
||||
A:%s
|
||||
S:%s
|
||||
I:%s
|
||||
T:%s
|
||||
U:%s
|
||||
L:%s
|
||||
o:%s
|
||||
m:%s
|
||||
t:%d
|
||||
c:%s
|
||||
D:%s
|
||||
p:%s
|
||||
q:
|
||||
Z:%s
|
||||
C:%s
|
||||
P:%s
|
||||
R:%s
|
||||
V:%s
|
||||
A:%s
|
||||
S:%s
|
||||
I:%s
|
||||
T:%s
|
||||
U:%s
|
||||
L:%s
|
||||
o:%s
|
||||
m:%s
|
||||
t:%d
|
||||
D:%s
|
||||
p:%s
|
||||
q:
|
||||
d:%s
|
||||
I:https://weforge.xyz/Spitfire/Branding/raw/branch/main/active/browser/icon.svg
|
||||
S:https://spitfirebrowser.xyz/static/images/screenshots/1.png
|
||||
T:browser,experimental,testing
|
||||
r: Automated Nightly build of Spitfire
|
||||
c:%s
|
||||
`, checksum, name, release, version, arch, size, installedSize,
|
||||
description, url, license, origin, maintainer, timestamp, dependencies,
|
||||
platform, downloadURL, checksum)
|
||||
|
||||
`, checksum, name, release, version, arch, size, installedSize, description, url, license, origin, maintainer, timestamp, contentChecksum, dependencies, platform, checksum)
|
||||
// Trim leading newline to keep it clean
|
||||
entry = strings.TrimPrefix(entry, "\n")
|
||||
|
||||
if _, err := file.WriteString(entry); err != nil {
|
||||
if _, err := file.WriteString(entry + "\n"); err != nil {
|
||||
log.Fatalf("Failed to write to APPINDEX file: %v", err)
|
||||
}
|
||||
|
||||
|
@ -70,7 +100,7 @@ func calcChecksum(input string) string {
|
|||
return fmt.Sprintf("%x", h.Sum(nil))
|
||||
}
|
||||
|
||||
// removeExistingEntry removes an existing entry from APPINDEX based on P, R, A, and o fields
|
||||
// removeExistingEntry removes an existing entry from APPINDEX if it matches P, R, A, and o fields.
|
||||
func removeExistingEntry(name, release, arch, origin string) {
|
||||
// Read file contents
|
||||
content, err := os.ReadFile("./APPINDEX")
|
||||
|
@ -81,39 +111,78 @@ func removeExistingEntry(name, release, arch, origin string) {
|
|||
log.Fatalf("Failed to read APPINDEX: %v", err)
|
||||
}
|
||||
|
||||
// Remove lines matching the package with the same P, R, A, and o fields
|
||||
lines := strings.Split(string(content), "\n")
|
||||
|
||||
var newLines []string
|
||||
remove := false
|
||||
var currentEntry []string
|
||||
|
||||
inEntry := false // true when we're reading lines for a single entry
|
||||
|
||||
// Use these to store the P, R, A, o values within the current entry
|
||||
var pVal, rVal, aVal, oVal string
|
||||
|
||||
for _, line := range lines {
|
||||
// Detect start of an entry by matching on P, R, A, and o
|
||||
if strings.HasPrefix(line, "P:"+name) {
|
||||
remove = true
|
||||
}
|
||||
if remove && strings.HasPrefix(line, "R:"+release) {
|
||||
remove = true
|
||||
}
|
||||
if remove && strings.HasPrefix(line, "A:"+arch) {
|
||||
remove = true
|
||||
}
|
||||
if remove && strings.HasPrefix(line, "o:"+origin) {
|
||||
remove = true
|
||||
trimmed := strings.TrimSpace(line)
|
||||
|
||||
// Detect the start of an entry (a line that starts with "C:")
|
||||
if strings.HasPrefix(trimmed, "C:") {
|
||||
// If we were in an entry previously, check if it should be removed or kept
|
||||
if inEntry && len(currentEntry) > 0 {
|
||||
// Decide whether to keep the previous entry
|
||||
if !(pVal == name && rVal == release && aVal == arch && oVal == origin) {
|
||||
newLines = append(newLines, currentEntry...)
|
||||
newLines = append(newLines, "") // Blank line to separate entries
|
||||
}
|
||||
}
|
||||
|
||||
// Start a new entry
|
||||
currentEntry = []string{trimmed}
|
||||
inEntry = true
|
||||
|
||||
// Reset these values for the new entry
|
||||
pVal, rVal, aVal, oVal = "", "", "", ""
|
||||
continue
|
||||
}
|
||||
|
||||
// Stop removal at the end of an entry
|
||||
if remove && line == "" {
|
||||
remove = false
|
||||
continue // Skip the line
|
||||
}
|
||||
if inEntry {
|
||||
// Collect lines for this entry
|
||||
currentEntry = append(currentEntry, trimmed)
|
||||
|
||||
// Append lines that are not part of the matching entry
|
||||
if !remove {
|
||||
newLines = append(newLines, line)
|
||||
// Extract P, R, A, o for matching later
|
||||
switch {
|
||||
case strings.HasPrefix(trimmed, "P:"):
|
||||
pVal = strings.TrimPrefix(trimmed, "P:")
|
||||
case strings.HasPrefix(trimmed, "R:"):
|
||||
rVal = strings.TrimPrefix(trimmed, "R:")
|
||||
case strings.HasPrefix(trimmed, "A:"):
|
||||
aVal = strings.TrimPrefix(trimmed, "A:")
|
||||
case strings.HasPrefix(trimmed, "o:"):
|
||||
oVal = strings.TrimPrefix(trimmed, "o:")
|
||||
}
|
||||
} else {
|
||||
// Lines outside of entries just get appended directly
|
||||
// (e.g. if there's extraneous text before the first "C:" or after the last)
|
||||
if trimmed != "" {
|
||||
newLines = append(newLines, trimmed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Write the updated contents back to the file
|
||||
err = os.WriteFile("./APPINDEX", []byte(strings.Join(newLines, "\n")), 0644)
|
||||
// Handle the last entry if we ended inEntry
|
||||
if inEntry && len(currentEntry) > 0 {
|
||||
// Decide whether to keep the final entry
|
||||
if !(pVal == name && rVal == release && aVal == arch && oVal == origin) {
|
||||
newLines = append(newLines, currentEntry...)
|
||||
}
|
||||
}
|
||||
|
||||
// Join everything back and ensure at least one trailing newline
|
||||
finalContent := strings.Join(newLines, "\n")
|
||||
if !strings.HasSuffix(finalContent, "\n") {
|
||||
finalContent += "\n"
|
||||
}
|
||||
|
||||
err = os.WriteFile("./APPINDEX", []byte(finalContent), 0644)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to update APPINDEX: %v", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue