2023-02-12 20:59:55 +00:00
|
|
|
//go:build mage
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/magefile/mage/sh"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2023-02-24 18:07:08 +00:00
|
|
|
configFile string = "./config/services.json"
|
|
|
|
rootBuildDir string = "./build"
|
|
|
|
templateExtension string = ".gotmpl"
|
|
|
|
rootTemplatesDir string = "./templates"
|
2023-02-12 20:59:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Clean cleans the workspace.
|
|
|
|
func Clean() error {
|
|
|
|
buildDir := "./build"
|
|
|
|
|
|
|
|
objects, err := os.ReadDir(buildDir)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range objects {
|
|
|
|
name := objects[i].Name()
|
|
|
|
|
|
|
|
if name != ".gitkeep" {
|
|
|
|
if err := sh.Rm(buildDir + "/" + name); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-02-26 17:14:39 +00:00
|
|
|
// Download downloads the binaries for a given service.
|
2023-02-25 21:16:20 +00:00
|
|
|
func Download(name string) error {
|
2023-02-12 20:59:55 +00:00
|
|
|
cfg, err := newConfig(configFile)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("unable to load the configuration; %v", err)
|
|
|
|
}
|
|
|
|
|
2023-02-26 17:14:39 +00:00
|
|
|
switch name {
|
|
|
|
case "forgejo":
|
2023-02-25 21:16:20 +00:00
|
|
|
if err := downloadForgejo(cfg.Forgejo.Version); err != nil {
|
|
|
|
return fmt.Errorf("an error occurred whilst getting the forgejo binary; %w", err)
|
|
|
|
}
|
2023-02-26 17:14:39 +00:00
|
|
|
case "gotosocial":
|
|
|
|
if err := downloadGoToSocial(cfg.GoToSocial.Version); err != nil {
|
|
|
|
return fmt.Errorf("an error occurred whilst getting the packages for GoToSocial; %w", err)
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
fmt.Printf("'%s' has no files to download.\n", name)
|
2023-02-12 20:59:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|