added automatic mozilla-release download
This commit is contained in:
parent
e5c95924d5
commit
a13f43086f
6 changed files with 477 additions and 194 deletions
|
@ -26,52 +26,57 @@ type Config struct {
|
|||
|
||||
// Load the SourceForge configuration from a file
|
||||
func LoadConfig() (*Config, error) {
|
||||
fmt.Println("🔑 Loading SourceForge configuration...")
|
||||
|
||||
file, err := os.Open("sourceforge_config.json")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open config file: %v", err)
|
||||
return nil, fmt.Errorf("❌ failed to open config file: %v", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
config := &Config{}
|
||||
if err := json.NewDecoder(file).Decode(config); err != nil {
|
||||
return nil, fmt.Errorf("failed to decode config file: %v", err)
|
||||
return nil, fmt.Errorf("❌ failed to decode config file: %v", err)
|
||||
}
|
||||
|
||||
// Expand tilde manually
|
||||
fmt.Println("🔍 Expanding SSH key path...")
|
||||
expandedPath, err := homedir.Expand(config.SFKeyPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed expanding key path: %v", err)
|
||||
return nil, fmt.Errorf("❌ failed expanding key path: %v", err)
|
||||
}
|
||||
config.SFKeyPath = filepath.Clean(expandedPath)
|
||||
|
||||
// Validate that the key file exists
|
||||
fmt.Println("🔐 Validating SSH key...")
|
||||
if _, err := os.Stat(config.SFKeyPath); os.IsNotExist(err) {
|
||||
return nil, fmt.Errorf("SSH key file not found at path: %s", config.SFKeyPath)
|
||||
return nil, fmt.Errorf("❌ SSH key file not found at path: %s", config.SFKeyPath)
|
||||
} else if err != nil {
|
||||
return nil, fmt.Errorf("error accessing SSH key file: %v", err)
|
||||
return nil, fmt.Errorf("❌ error accessing SSH key file: %v", err)
|
||||
}
|
||||
|
||||
fmt.Println("✅ Configuration loaded successfully")
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// CompressDirectory compresses the build directory to a tar.gz file using PAX format for large file support
|
||||
func CompressDirectory(srcDir, dstFile string) error {
|
||||
// Create the destination file
|
||||
fmt.Printf("🗜️ Compressing directory: %s → %s\n", srcDir, dstFile)
|
||||
|
||||
fmt.Println("📄 Creating destination file...")
|
||||
f, err := os.Create(dstFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create file %s: %v", dstFile, err)
|
||||
return fmt.Errorf("❌ could not create file %s: %v", dstFile, err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// Create a new gzip writer
|
||||
fmt.Println("📦 Initializing gzip writer...")
|
||||
gw := gzip.NewWriter(f)
|
||||
defer gw.Close()
|
||||
|
||||
// Create a new tar writer with PAX format for large file support
|
||||
fmt.Println("📦 Initializing tar writer (PAX format)...")
|
||||
tw := tar.NewWriter(gw)
|
||||
defer tw.Close()
|
||||
|
||||
// Walk through the source directory and add files to the tar archive
|
||||
fmt.Println("🔍 Walking directory structure...")
|
||||
err = filepath.Walk(srcDir, func(file string, fi os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -130,46 +135,58 @@ func CompressDirectory(srcDir, dstFile string) error {
|
|||
})
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("error walking the source directory %s: %v", srcDir, err)
|
||||
return fmt.Errorf("❌ error walking the source directory %s: %v", srcDir, err)
|
||||
}
|
||||
|
||||
fmt.Println("✅ Compression completed successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Upload the file to SourceForge, ensuring the local directory structure is created and uploaded
|
||||
func Upload(config *Config, buildPath, remoteDir string) error {
|
||||
fmt.Println("📤 Starting upload process...")
|
||||
|
||||
// Generate a random hash for the temp directory name
|
||||
fmt.Println("🔒 Generating random hash for temp directory...")
|
||||
randomHash, err := generateRandomHash(8) // 8 bytes = 16 hex characters
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to generate random hash: %v", err)
|
||||
return fmt.Errorf("❌ failed to generate random hash: %v", err)
|
||||
}
|
||||
|
||||
// Create a temporary directory with the random hash appended
|
||||
fmt.Printf("📂 Creating temporary directory with hash: %s...\n", randomHash)
|
||||
tmpDir, err := os.MkdirTemp("", "spitfire-upload-"+randomHash)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create temporary directory: %v", err)
|
||||
return fmt.Errorf("❌ failed to create temporary directory: %v", err)
|
||||
}
|
||||
|
||||
// Create the required local directory structure inside the temporary directory
|
||||
fmt.Printf("📁 Creating local directory structure: %s...\n", remoteDir)
|
||||
localDir := filepath.Join(tmpDir, remoteDir)
|
||||
err = os.MkdirAll(localDir, os.ModePerm)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create local directory structure: %v", err)
|
||||
return fmt.Errorf("❌ failed to create local directory structure: %v", err)
|
||||
}
|
||||
|
||||
// Move the build file to the local directory structure
|
||||
fmt.Printf("📦 Copying build file to temp location: %s...\n", filepath.Base(buildPath))
|
||||
destinationFile := filepath.Join(localDir, filepath.Base(buildPath))
|
||||
err = copyFile(buildPath, destinationFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to copy file to local directory structure: %v", err)
|
||||
return fmt.Errorf("❌ failed to copy file to local directory structure: %v", err)
|
||||
}
|
||||
|
||||
// Upload the entire local directory structure to the remote directory
|
||||
fmt.Printf("Uploading file %s to %s on SourceForge...\n", buildPath, remoteDir)
|
||||
fmt.Printf("🚀 Uploading %s to SourceForge (%s)...\n", filepath.Base(buildPath), remoteDir)
|
||||
scpCmd := exec.Command("scp", "-i", config.SFKeyPath, "-r", tmpDir+"/.", fmt.Sprintf("%s@%s:%s", config.SFUser, config.SFHost, "/"))
|
||||
scpCmd.Stdout = os.Stdout
|
||||
scpCmd.Stderr = os.Stderr
|
||||
return scpCmd.Run()
|
||||
if err := scpCmd.Run(); err != nil {
|
||||
return fmt.Errorf("❌ upload failed: %v", err)
|
||||
}
|
||||
|
||||
fmt.Println("✅ Upload completed successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Helper function to generate a random hash
|
||||
|
@ -206,7 +223,7 @@ func copyFile(src, dst string) error {
|
|||
|
||||
// Download the APPINDEX file from SourceForge
|
||||
func DownloadAPPINDEX(config *Config, remoteDir string) error {
|
||||
fmt.Println("Downloading APPINDEX from SourceForge...")
|
||||
fmt.Println("📥 Downloading APPINDEX from SourceForge...")
|
||||
|
||||
// Construct the correct path without double slashes
|
||||
remoteAPPINDEXPath := filepath.Join(remoteDir, "APPINDEX")
|
||||
|
@ -220,23 +237,27 @@ func DownloadAPPINDEX(config *Config, remoteDir string) error {
|
|||
if err != nil {
|
||||
// Check if the error is due to the file not existing
|
||||
if strings.Contains(err.Error(), "No such file or directory") {
|
||||
fmt.Println("APPINDEX file not found on the server. A new one will be created.")
|
||||
fmt.Println("ℹ️ APPINDEX file not found - will create new one")
|
||||
return nil // Continue without failing if the APPINDEX is missing
|
||||
}
|
||||
return fmt.Errorf("failed to download APPINDEX: %v", err) // Fail for other types of errors
|
||||
return fmt.Errorf("❌ failed to download APPINDEX: %v", err) // Fail for other types of errors
|
||||
}
|
||||
|
||||
fmt.Println("APPINDEX downloaded successfully.")
|
||||
fmt.Println("✅ APPINDEX downloaded successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Upload the updated APPINDEX file to SourceForge
|
||||
func UploadAPPINDEX(config *Config, remoteDir string) error {
|
||||
fmt.Println("Uploading updated APPINDEX to SourceForge...")
|
||||
fmt.Println("📤 Uploading updated APPINDEX to SourceForge...")
|
||||
cmd := exec.Command("scp", "-i", config.SFKeyPath, "./APPINDEX", fmt.Sprintf("%s@%s:%s", config.SFUser, config.SFHost, remoteDir))
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
return cmd.Run()
|
||||
if err := cmd.Run(); err != nil {
|
||||
return fmt.Errorf("❌ failed to upload APPINDEX: %v", err)
|
||||
}
|
||||
fmt.Println("✅ APPINDEX uploaded successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetDirectorySize calculates the total size of all files in a directory
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue