mirror of
https://github.com/EnumeratedDev/bpm-utils.git
synced 2026-09-16 11:06:11 +00:00
Move package recipes to separate directory
This commit is contained in:
+28
-25
@@ -26,7 +26,6 @@ var keepCompilationFiles = flag.BoolP("keep", "k", false, "Keep compilation file
|
|||||||
var installDepends = flag.BoolP("depends", "d", false, "Install package dependencies for compilation")
|
var installDepends = flag.BoolP("depends", "d", false, "Install package dependencies for compilation")
|
||||||
var installPackage = flag.BoolP("install", "i", false, "Install compiled BPM package after compilation finishes")
|
var installPackage = flag.BoolP("install", "i", false, "Install compiled BPM package after compilation finishes")
|
||||||
var compilationJobs = flag.IntP("jobs", "j", 0, "Set the amount of concurrent processes to use for source package compilation")
|
var compilationJobs = flag.IntP("jobs", "j", 0, "Set the amount of concurrent processes to use for source package compilation")
|
||||||
var moveToBinaryDir = flag.BoolP("move", "m", false, "Move output packages to the current repository's binary directory")
|
|
||||||
var updateInfo = flag.BoolP("update-info", "u", false, "Update the pkg.info file")
|
var updateInfo = flag.BoolP("update-info", "u", false, "Update the pkg.info file")
|
||||||
var signPackage = flag.BoolP("sign", "s", false, "Sign package using GPG")
|
var signPackage = flag.BoolP("sign", "s", false, "Sign package using GPG")
|
||||||
var yesAll = flag.BoolP("yes", "y", false, "Accept all confirmation prompts")
|
var yesAll = flag.BoolP("yes", "y", false, "Accept all confirmation prompts")
|
||||||
@@ -44,6 +43,10 @@ func main() {
|
|||||||
if *compile {
|
if *compile {
|
||||||
compilePackage(outputFile)
|
compilePackage(outputFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if repo := bpmutilsshared.GetRepository(); repo != "" {
|
||||||
|
bpmutilsshared.UpdateDatabases(repo)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func runChecks() {
|
func runChecks() {
|
||||||
@@ -138,32 +141,35 @@ func createArchive() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove old BPM archives in current directory
|
// Remove old package from source dir
|
||||||
oldArchives, err := filepath.Glob("*.bpm")
|
if repo := bpmutilsshared.GetRepository(); repo != "" {
|
||||||
if err != nil {
|
if database, err := bpmutilsshared.ReadDatabase(path.Join(repo, "source/database.bpmdb")); err == nil {
|
||||||
log.Printf("Warning: could not search for old BPM archives: %s", err)
|
if entry, ok := database.Entries[pkgInfo.Name]; ok {
|
||||||
}
|
pkgFilepath := path.Join(repo, "source", entry.Filepath)
|
||||||
for _, bpmArchive := range oldArchives {
|
err := os.Remove(pkgFilepath)
|
||||||
err = os.Remove(bpmArchive)
|
if err != nil {
|
||||||
if err != nil {
|
log.Printf("Warning: could not remove old source package (%s): %s", pkgFilepath, err)
|
||||||
log.Printf("Warning: could not remove old BPM archive (%s): %s", bpmArchive, err)
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove old BPM archive signatures in current directory
|
// Remove package signature
|
||||||
oldSignatures, err := filepath.Glob("*.sig")
|
if _, err := os.Stat(pkgFilepath + ".sig"); err == nil {
|
||||||
if err != nil {
|
err := os.Remove(pkgFilepath + ".sig")
|
||||||
log.Printf("Warning: could not search for old BPM archive signatures: %s", err)
|
if err != nil {
|
||||||
}
|
log.Printf("Warning: could not remove old source package signature (%s): %s", pkgFilepath+".str", err)
|
||||||
for _, signature := range oldSignatures {
|
}
|
||||||
err = os.Remove(signature)
|
}
|
||||||
if err != nil {
|
}
|
||||||
log.Printf("Warning: could not remove old BPM archive signature (%s): %s", signature, err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create filename
|
// Create filename
|
||||||
filename := fmt.Sprintf("%s-%s-%d-%s-src.bpm", pkgInfo.Name, pkgInfo.Version, pkgInfo.Revision, pkgInfo.Arch)
|
filename := fmt.Sprintf("%s-%s-%d-%s-src.bpm", pkgInfo.Name, pkgInfo.Version, pkgInfo.Revision, pkgInfo.Arch)
|
||||||
|
if repo := bpmutilsshared.GetRepository(); repo != "" {
|
||||||
|
// Create source directory
|
||||||
|
os.MkdirAll(path.Join(repo, "source", pkgInfo.Arch), 0755)
|
||||||
|
|
||||||
|
filename = path.Join(repo, "source", pkgInfo.Arch, filename)
|
||||||
|
}
|
||||||
|
|
||||||
// Create archive using tar
|
// Create archive using tar
|
||||||
args := make([]string, 0)
|
args := make([]string, 0)
|
||||||
@@ -263,7 +269,7 @@ func compilePackage(archive string) {
|
|||||||
// Read generated package info
|
// Read generated package info
|
||||||
pkgInfo, err := bpmutilsshared.ReadPacakgeInfoFromTarball(line)
|
pkgInfo, err := bpmutilsshared.ReadPacakgeInfoFromTarball(line)
|
||||||
|
|
||||||
if repo := bpmutilsshared.GetRepository(); repo != "" && *moveToBinaryDir {
|
if repo := bpmutilsshared.GetRepository(); repo != "" {
|
||||||
// Remove old package from binary dir
|
// Remove old package from binary dir
|
||||||
if database, err := bpmutilsshared.ReadDatabase(path.Join(repo, "binary/database.bpmdb")); err == nil {
|
if database, err := bpmutilsshared.ReadDatabase(path.Join(repo, "binary/database.bpmdb")); err == nil {
|
||||||
if entry, ok := database.Entries[pkgInfo.Name]; ok {
|
if entry, ok := database.Entries[pkgInfo.Name]; ok {
|
||||||
@@ -296,9 +302,6 @@ func compilePackage(archive string) {
|
|||||||
outputPkgs[pkgInfo.Name] = line
|
outputPkgs[pkgInfo.Name] = line
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if repo := bpmutilsshared.GetRepository(); repo != "" && *moveToBinaryDir {
|
|
||||||
bpmutilsshared.UpdateDatabases(repo)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sign package
|
// Sign package
|
||||||
if *signPackage {
|
if *signPackage {
|
||||||
|
|||||||
+72
-63
@@ -147,7 +147,7 @@ func createRepository(name, description string) {
|
|||||||
log.Fatalf("Error: could not write to file: %s", err)
|
log.Fatalf("Error: could not write to file: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.Mkdir(path.Join(name, "source"), 0755)
|
err = os.Mkdir(path.Join(name, "recipes"), 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error: could not create directory: %s", err)
|
log.Fatalf("Error: could not create directory: %s", err)
|
||||||
}
|
}
|
||||||
@@ -185,14 +185,14 @@ func checkVersionsFunc(repo string) {
|
|||||||
directories := make([]string, 0)
|
directories := make([]string, 0)
|
||||||
if currentFlagSet.NArg() > 0 {
|
if currentFlagSet.NArg() > 0 {
|
||||||
for _, dir := range currentFlagSet.Args() {
|
for _, dir := range currentFlagSet.Args() {
|
||||||
if _, err := os.Stat(path.Join(repo, "source", dir, "pkg.info")); err != nil {
|
if _, err := os.Stat(path.Join(repo, "recipes", dir, "pkg.info")); err != nil {
|
||||||
log.Fatalf("Error: could not find pkg.info file in directory (%s): %s", dir, err)
|
log.Fatalf("Error: could not find pkg.info file in directory (%s): %s", dir, err)
|
||||||
}
|
}
|
||||||
directories = append(directories, path.Join(repo, "source", dir))
|
directories = append(directories, path.Join(repo, "recipes", dir))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Loop through each directory with a 'pkg.info' file
|
// Loop through each directory with a 'pkg.info' file
|
||||||
err := filepath.Walk(path.Join(repo, "source"), func(path string, info fs.FileInfo, err error) error {
|
err := filepath.Walk(path.Join(repo, "recipes"), func(path string, info fs.FileInfo, err error) error {
|
||||||
if filepath.Base(path) == "pkg.info" {
|
if filepath.Base(path) == "pkg.info" {
|
||||||
directories = append(directories, filepath.Dir(path))
|
directories = append(directories, filepath.Dir(path))
|
||||||
}
|
}
|
||||||
@@ -375,7 +375,7 @@ func holdPackage(repo string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ensure package exists
|
// Ensure package exists
|
||||||
if _, err := os.Stat(path.Join(repo, "source", pkgName, "pkg.info")); err != nil {
|
if _, err := os.Stat(path.Join(repo, "recipes", pkgName, "pkg.info")); err != nil {
|
||||||
log.Fatalf("Error: could not find pkg.info file in directory (%s): %s", pkgName, err)
|
log.Fatalf("Error: could not find pkg.info file in directory (%s): %s", pkgName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -435,44 +435,40 @@ func holdPackage(repo string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func listPackagesFunc(repo string) {
|
func listPackagesFunc(repo string) {
|
||||||
|
// Read package recipes
|
||||||
|
pkgs := bpmutilsshared.ReadRepositoryRecipes(repo)
|
||||||
|
|
||||||
// Read databases
|
// Read databases
|
||||||
sourceDatabase, err := bpmutilsshared.ReadDatabase(path.Join(repo, "source/database.bpmdb"))
|
sourceDatabase, _ := bpmutilsshared.ReadDatabase(path.Join(repo, "source/database.bpmdb"))
|
||||||
if err != nil {
|
binaryDatabase, _ := bpmutilsshared.ReadDatabase(path.Join(repo, "binary/database.bpmdb"))
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
binaryDatabase, err := bpmutilsshared.ReadDatabase(path.Join(repo, "binary/database.bpmdb"))
|
for _, pkg := range pkgs {
|
||||||
if err != nil {
|
fmt.Printf("%s (%s):\n", pkg.Name, pkg.Version)
|
||||||
binaryDatabase = &bpmutilsshared.BPMDatabase{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort database entries
|
// Show source package version
|
||||||
entriesSorted := slices.Collect(maps.Values(sourceDatabase.Entries))
|
if sourceDatabase != nil {
|
||||||
sort.Slice(entriesSorted, func(i, j int) bool {
|
if entry, ok := sourceDatabase.Entries[pkg.Name]; ok {
|
||||||
return entriesSorted[i].PackageInfo.Name < entriesSorted[j].PackageInfo.Name
|
if entry.PackageInfo.Version == pkg.Version {
|
||||||
})
|
fmt.Printf(" Source package: %s\n", entry.PackageInfo.Version)
|
||||||
|
} else {
|
||||||
// Loop through each entry
|
fmt.Printf(" Source package: %s ≠ %s (Version mismatch)\n", entry.PackageInfo.Version, pkg.Version)
|
||||||
for _, entry := range entriesSorted {
|
|
||||||
if len(entry.PackageInfo.SplitPackages) > 0 {
|
|
||||||
for _, splitPkg := range entry.PackageInfo.SplitPackages {
|
|
||||||
// Handle split packages
|
|
||||||
additionalText := ""
|
|
||||||
if binaryEntry, ok := binaryDatabase.Entries[splitPkg.Name]; !ok {
|
|
||||||
additionalText += "(Binary package missing) "
|
|
||||||
} else if fmt.Sprintf("%s-%d", binaryEntry.PackageInfo.Version, binaryEntry.PackageInfo.Revision) != fmt.Sprintf("%s-%d", entry.PackageInfo.Version, entry.PackageInfo.Revision) {
|
|
||||||
additionalText += "(Binary package version mismatch) "
|
|
||||||
}
|
}
|
||||||
fmt.Printf("%s %s-%d %s\n", splitPkg.Name, entry.PackageInfo.Version, entry.PackageInfo.Revision, additionalText)
|
} else {
|
||||||
|
fmt.Println(" Source package not found!")
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
additionalText := ""
|
|
||||||
if binaryEntry, ok := binaryDatabase.Entries[entry.PackageInfo.Name]; !ok {
|
// Show binary package version
|
||||||
additionalText += "(Binary package missing) "
|
if binaryDatabase != nil {
|
||||||
} else if fmt.Sprintf("%s-%d", binaryEntry.PackageInfo.Version, binaryEntry.PackageInfo.Revision) != fmt.Sprintf("%s-%d", entry.PackageInfo.Version, entry.PackageInfo.Revision) {
|
if entry, ok := binaryDatabase.Entries[pkg.Name]; ok {
|
||||||
additionalText += "(Binary package version mismatch) "
|
if entry.PackageInfo.Version == pkg.Version {
|
||||||
|
fmt.Printf(" Binary package: %s\n", entry.PackageInfo.Version)
|
||||||
|
} else {
|
||||||
|
fmt.Printf(" Binary package: %s ≠ %s (Version mismatch)\n", entry.PackageInfo.Version, pkg.Version)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Println(" Binary package not found!")
|
||||||
}
|
}
|
||||||
fmt.Printf("%s %s-%d %s\n", entry.PackageInfo.Name, entry.PackageInfo.Version, entry.PackageInfo.Revision, additionalText)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -489,27 +485,22 @@ func compileAllPackagesFunc(repo string) {
|
|||||||
log.Fatalf("Error: failed to read config: %s", err)
|
log.Fatalf("Error: failed to read config: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure database is updated
|
// Read package recipes
|
||||||
bpmutilsshared.UpdateDatabases(repo)
|
pkgs := bpmutilsshared.ReadRepositoryRecipes(repo)
|
||||||
|
pkgsMap := make(map[string]bpmutilsshared.PackageInfo)
|
||||||
|
for _, pkg := range pkgs {
|
||||||
|
pkgsMap[pkg.Name] = pkg
|
||||||
|
}
|
||||||
|
|
||||||
// Read databases
|
// Read databases
|
||||||
sourceDatabase, err := bpmutilsshared.ReadDatabase(path.Join(repo, "source/database.bpmdb"))
|
sourceDatabase, err := bpmutilsshared.ReadDatabase(path.Join(repo, "source/database.bpmdb"))
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Error: could not read source database: %s", err)
|
|
||||||
}
|
|
||||||
binaryDatabase, _ := bpmutilsshared.ReadDatabase(path.Join(repo, "binary/database.bpmdb"))
|
binaryDatabase, _ := bpmutilsshared.ReadDatabase(path.Join(repo, "binary/database.bpmdb"))
|
||||||
|
|
||||||
// Get all packages from database entries
|
|
||||||
packages := slices.Collect(maps.Values(sourceDatabase.Entries))
|
|
||||||
sort.Slice(packages, func(a, b int) bool {
|
|
||||||
return packages[a].PackageInfo.Name < packages[b].PackageInfo.Name
|
|
||||||
})
|
|
||||||
|
|
||||||
// Toposort packages using Depth-first search algorithm
|
// Toposort packages using Depth-first search algorithm
|
||||||
sorted := make([]bpmutilsshared.PackageInfo, 0)
|
sorted := make([]bpmutilsshared.PackageInfo, 0)
|
||||||
marked := make(map[string]int) // 0 = Unmarked, 1 = Temporary mark, 2 = Permanent mark
|
marked := make(map[string]int) // 0 = Unmarked, 1 = Temporary mark, 2 = Permanent mark
|
||||||
var visit func(pkgInfo *bpmutilsshared.PackageInfo) error
|
var visit func(pkgInfo bpmutilsshared.PackageInfo) error
|
||||||
visit = func(pkgInfo *bpmutilsshared.PackageInfo) error {
|
visit = func(pkgInfo bpmutilsshared.PackageInfo) error {
|
||||||
if mark, _ := marked[pkgInfo.Name]; mark == 2 {
|
if mark, _ := marked[pkgInfo.Name]; mark == 2 {
|
||||||
return nil
|
return nil
|
||||||
} else if mark == 1 {
|
} else if mark == 1 {
|
||||||
@@ -524,12 +515,12 @@ func compileAllPackagesFunc(repo string) {
|
|||||||
|
|
||||||
for _, depend := range depends {
|
for _, depend := range depends {
|
||||||
// Find package in repository
|
// Find package in repository
|
||||||
dependEntry, ok := sourceDatabase.Entries[depend]
|
dependInfo, ok := pkgsMap[depend]
|
||||||
if !ok {
|
if !ok {
|
||||||
// Search for virtual package
|
// Search for virtual package
|
||||||
for _, entry := range sourceDatabase.Entries {
|
for _, pkg := range pkgsMap {
|
||||||
if slices.Contains(entry.PackageInfo.Provides, depend) {
|
if slices.Contains(pkg.Provides, depend) {
|
||||||
dependEntry = entry
|
dependInfo = pkg
|
||||||
ok = true
|
ok = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -540,30 +531,48 @@ func compileAllPackagesFunc(repo string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err := visit(dependEntry.PackageInfo)
|
err := visit(dependInfo)
|
||||||
if err != nil && verbose {
|
if err != nil && verbose {
|
||||||
fmt.Printf("Circular dependency found! (%s -> %s)\n", pkgInfo.Name, dependEntry.PackageInfo.Name)
|
fmt.Printf("Circular dependency found! (%s -> %s)\n", pkgInfo.Name, dependInfo.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
marked[pkgInfo.Name] = 2
|
marked[pkgInfo.Name] = 2
|
||||||
sorted = append(sorted, *pkgInfo)
|
sorted = append(sorted, pkgInfo)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, entry := range packages {
|
for _, pkg := range pkgsMap {
|
||||||
if mark, _ := marked[entry.PackageInfo.Name]; mark != 2 {
|
if mark, _ := marked[pkg.Name]; mark != 2 {
|
||||||
visit(entry.PackageInfo)
|
visit(pkg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compile all packages in order
|
// Compile all packages in order
|
||||||
for _, pkgInfo := range sorted {
|
for _, pkgInfo := range sorted {
|
||||||
if modifiedOnly && binaryDatabase != nil {
|
skip := false
|
||||||
if binaryPkgInfo, ok := binaryDatabase.Entries[pkgInfo.Name]; ok && binaryPkgInfo.PackageInfo.GetFullVersion() == pkgInfo.GetFullVersion() {
|
|
||||||
continue
|
if modifiedOnly {
|
||||||
|
skip = true
|
||||||
|
|
||||||
|
// Check if source database entry is not synced
|
||||||
|
if sourceDatabase != nil {
|
||||||
|
if sourcePkgInfo, ok := sourceDatabase.Entries[pkgInfo.Name]; !ok || sourcePkgInfo.PackageInfo.GetFullVersion() != pkgInfo.GetFullVersion() {
|
||||||
|
skip = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if binary database entry is not synced
|
||||||
|
if binaryDatabase != nil {
|
||||||
|
if binaryPkgInfo, ok := binaryDatabase.Entries[pkgInfo.Name]; !ok || binaryPkgInfo.PackageInfo.GetFullVersion() != pkgInfo.GetFullVersion() {
|
||||||
|
skip = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if skip {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if showOrder {
|
if showOrder {
|
||||||
|
|||||||
+40
-27
@@ -10,14 +10,12 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
flag "github.com/spf13/pflag"
|
flag "github.com/spf13/pflag"
|
||||||
yaml "gopkg.in/yaml.v3"
|
yaml "gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var directory = flag.StringP("directory", "D", "", "Path to package directory")
|
|
||||||
var name = flag.StringP("name", "n", "", "Set the package name")
|
var name = flag.StringP("name", "n", "", "Set the package name")
|
||||||
var description = flag.StringP("description", "d", "Default Package Description", "Set the description")
|
var description = flag.StringP("description", "d", "Default Package Description", "Set the description")
|
||||||
var version = flag.StringP("version", "v", "1.0", "Set the package version")
|
var version = flag.StringP("version", "v", "1.0", "Set the package version")
|
||||||
@@ -26,20 +24,35 @@ var license = flag.StringP("license", "l", "", "Set the package licenses")
|
|||||||
var template = flag.StringP("template", "t", "gnu-configure", "Set the package template")
|
var template = flag.StringP("template", "t", "gnu-configure", "Set the package template")
|
||||||
var git = flag.BoolP("git", "g", true, "Create git repository")
|
var git = flag.BoolP("git", "g", true, "Create git repository")
|
||||||
|
|
||||||
|
var directory = ""
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Setup flags and help
|
// Setup flags and help
|
||||||
setupFlagsAndHelp("bpm-setup <options>", "Sets up files and directories for BPM source package creation")
|
setupFlagsAndHelp("bpm-setup <options>", "Sets up files and directories for BPM source package creation")
|
||||||
|
|
||||||
|
// Trim package name
|
||||||
|
*name = strings.TrimSpace(*name)
|
||||||
|
|
||||||
// Show command help if no directory name is given
|
// Show command help if no directory name is given
|
||||||
if *directory == "" {
|
if *name == "" {
|
||||||
log.Println("Error: directory flag is required")
|
log.Println("Error: name flag is required")
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set package name to directory name if empty
|
// Get current repository
|
||||||
if *name == "" {
|
repo := bpmutilsshared.GetRepository()
|
||||||
*name = filepath.Base(*directory)
|
|
||||||
|
// Set directory
|
||||||
|
if repo != "" {
|
||||||
|
directory = path.Join(repo, "recipes", *name)
|
||||||
|
} else {
|
||||||
|
workDir, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Error: could not get working directory")
|
||||||
|
}
|
||||||
|
|
||||||
|
directory = path.Join(workDir, *name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// run checks
|
// run checks
|
||||||
@@ -62,25 +75,29 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runChecks() {
|
func runChecks() {
|
||||||
if strings.TrimSpace(*directory) == "" {
|
// Check if package name is valid
|
||||||
log.Fatalf("No directory was specified!")
|
if *name == "" {
|
||||||
|
log.Fatalf("Error: no package name was specified!")
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.TrimSpace(*name) == "" {
|
// Check if parent directory is valid
|
||||||
log.Fatalf("No package name was specified!")
|
if _, err := os.Stat(path.Dir(directory)); err != nil {
|
||||||
|
log.Fatalf("Error: %s is not a valid directory: %s", path.Dir(directory), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if package directory exists
|
||||||
|
if _, err := os.Stat(directory); err == nil {
|
||||||
|
log.Fatalf("Error: %s already exists", directory)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if template file is valid
|
||||||
if stat, err := os.Stat(path.Join("/etc/bpm-utils/templates/", *template)); err != nil || stat.IsDir() {
|
if stat, err := os.Stat(path.Join("/etc/bpm-utils/templates/", *template)); err != nil || stat.IsDir() {
|
||||||
log.Fatalf("%s is not a valid template file!", *template)
|
log.Fatalf("Error: '%s' is not a valid template file!", *template)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func showSummary() {
|
func showSummary() {
|
||||||
absPath, err := filepath.Abs(strings.TrimSpace(*directory))
|
fmt.Printf("Setting up package directory at %s with the following information:\n", directory)
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to determine absolute path: %s", err)
|
|
||||||
}
|
|
||||||
fmt.Printf("Setting up package directory at %s with the following information:\n", absPath)
|
|
||||||
fmt.Printf("Package name: %s\n", strings.TrimSpace(*name))
|
fmt.Printf("Package name: %s\n", strings.TrimSpace(*name))
|
||||||
fmt.Printf("Package description: %s\n", *description)
|
fmt.Printf("Package description: %s\n", *description)
|
||||||
fmt.Printf("Package version: %s\n", *version)
|
fmt.Printf("Package version: %s\n", *version)
|
||||||
@@ -114,12 +131,8 @@ func createDirectory() {
|
|||||||
log.Fatalf("Error: failed to read config: %s", err)
|
log.Fatalf("Error: failed to read config: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trim spaces
|
|
||||||
*directory = strings.TrimSpace(*directory)
|
|
||||||
*name = strings.TrimSpace(*name)
|
|
||||||
|
|
||||||
// Create directory
|
// Create directory
|
||||||
err = os.Mkdir(*directory, 0755)
|
err = os.Mkdir(directory, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error: could not create directory: %s", err)
|
log.Fatalf("Error: could not create directory: %s", err)
|
||||||
}
|
}
|
||||||
@@ -153,13 +166,13 @@ func createDirectory() {
|
|||||||
encoder.Encode(&pkgInfo)
|
encoder.Encode(&pkgInfo)
|
||||||
|
|
||||||
// Write package info to file
|
// Write package info to file
|
||||||
err = os.WriteFile(path.Join(*directory, "pkg.info"), buffer.Bytes(), 0644)
|
err = os.WriteFile(path.Join(directory, "pkg.info"), buffer.Bytes(), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not write to pkg.info: %s", err)
|
log.Fatalf("Could not write to pkg.info: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create source-files directory
|
// Create source-files directory
|
||||||
err = os.Mkdir(path.Join(*directory, "source-files"), 0755)
|
err = os.Mkdir(path.Join(directory, "source-files"), 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error: could not create directory: %s", err)
|
log.Fatalf("Error: could not create directory: %s", err)
|
||||||
}
|
}
|
||||||
@@ -174,7 +187,7 @@ func createDirectory() {
|
|||||||
// Replace variables in template file
|
// Replace variables in template file
|
||||||
input = []byte(replaceVariables(string(input)))
|
input = []byte(replaceVariables(string(input)))
|
||||||
|
|
||||||
err = os.WriteFile(path.Join(*directory, "source.sh"), input, 0644)
|
err = os.WriteFile(path.Join(directory, "source.sh"), input, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error: could not write to source file: %s", err)
|
log.Fatalf("Error: could not write to source file: %s", err)
|
||||||
return
|
return
|
||||||
@@ -182,7 +195,7 @@ func createDirectory() {
|
|||||||
|
|
||||||
// Create git repository
|
// Create git repository
|
||||||
if git != nil && *git {
|
if git != nil && *git {
|
||||||
err = exec.Command("git", "init", *directory).Run()
|
err = exec.Command("git", "init", directory).Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error: could not initialize git repository: %s", err)
|
log.Fatalf("Error: could not initialize git repository: %s", err)
|
||||||
}
|
}
|
||||||
@@ -193,7 +206,7 @@ func createDirectory() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer defaultGitignoreFile.Close()
|
defer defaultGitignoreFile.Close()
|
||||||
newGitignoreFile, err := os.OpenFile(path.Join(*directory, ".gitignore"), os.O_CREATE|os.O_WRONLY, 0644)
|
newGitignoreFile, err := os.OpenFile(path.Join(directory, ".gitignore"), os.O_CREATE|os.O_WRONLY, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error: could not create .gitignore file: %s", err)
|
log.Fatalf("Error: could not create .gitignore file: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package bpm_utils_shared
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetRepository() string {
|
func GetRepository() string {
|
||||||
@@ -23,3 +24,31 @@ func GetRepository() string {
|
|||||||
}
|
}
|
||||||
return dir
|
return dir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ReadRepositoryRecipes(repository string) []PackageInfo {
|
||||||
|
// Read package recipes
|
||||||
|
recipeDirs, err := os.ReadDir(path.Join(repository, "recipes"))
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
pkgs := make([]PackageInfo, 0)
|
||||||
|
for _, dir := range recipeDirs {
|
||||||
|
pkgInfoPath := path.Join(repository, "recipes", dir.Name(), "pkg.info")
|
||||||
|
if _, err := os.Stat(pkgInfoPath); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
pkgInfo, err := ReadPacakgeInfoFromFile(pkgInfoPath)
|
||||||
|
if err == nil {
|
||||||
|
pkgs = append(pkgs, *pkgInfo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort package recipes
|
||||||
|
sort.Slice(pkgs, func(i, j int) bool {
|
||||||
|
return pkgs[i].Name < pkgs[j].Name
|
||||||
|
})
|
||||||
|
|
||||||
|
return pkgs
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user