~dricottone/simple-builder

ref: 5efee8c6bb548138cfb63a24ed7c7747d366486a simple-builder/cli.go -rw-r--r-- 1.3 KiB
5efee8c6Dominic Ricottone Update 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main

import (
	"fmt"
	"path/filepath"
	"regexp"
	"strings"
)

// Clean up -source SRCDIR.
func clean_source(srcdir string) string {
	src, err := filepath.Abs(srcdir)
	if (err != nil) {
		panic(err)
	}
	return src
}

// Clean up -destination PKGDIR
func clean_destination(pkgdir string) string {
	dest, err := filepath.Abs(pkgdir)
	if (err != nil) {
		panic(err)
	}
	return dest
}

// Clean up -repository CONNECTION
func clean_repository(connection string) string {
	repo := strings.TrimSpace(connection)

	// To obtain a directory listing, the connection string must end in a
	// forward slash.
	if (strings.HasSuffix(repo, "/") == false) {
		repo += "/"
	}

	pattern, err := regexp.Compile(`^(([A-Za-z0-9][A-Za-z0-9._-]*@)?([A-Za-z0-9._-]+):)?(/[A-Za-z0-9._-]+)+/$`)
	if (err != nil) {
		panic(err)
	}
	match := pattern.FindStringSubmatch(repo)
	if (match == nil) || (match[4] == "") {
		panic(fmt.Sprintf("Connection string %s seems invalid", repo))
	}

	return repo
}

// Clean up -arch ARCH
func clean_architecture(arch, repo string) string {
	if (arch == "amd64" ) || (arch == "arm64") {
		return arch
	}

	if (strings.Contains(repo, "x86_64")) {
		return "amd64"
	} else if (strings.Contains(repo, "aarch64")) {
		return "arm64"
	}

	panic("Not a valid architecture")
}