├── .editorconfig ├── runtime ├── fish │ ├── completions │ │ ├── cdp.fish │ │ └── prt.fish │ ├── README.md │ └── functions │ │ └── cdp.fish ├── pkgmk │ ├── README.md │ └── pkgmk ├── bash │ ├── README.md │ └── functions │ │ └── cdp.sh ├── man │ ├── prt-uninstall.md │ ├── prt-pull.md │ ├── prt-diff.md │ ├── prt-sysup.md │ ├── prt-loc.md │ ├── prt-list.md │ ├── prt-prov.md │ ├── prt-info.md │ ├── prt-depends.md │ ├── prt-install.md │ └── prt.md └── config │ └── config.toml ├── .gitignore ├── ports ├── doc.go ├── package.go ├── util.go ├── pkgfile_test.go ├── ports_test.go ├── port_test.go ├── location.go ├── config.go ├── database.go ├── footprint.go ├── permission.go ├── ports.go ├── port.go ├── md5sum.go ├── pkgfile.go └── make.go ├── utils.go ├── tar └── tar.go ├── go.mod ├── uninstall.bak ├── config.go ├── diff.go ├── unpack.go ├── loc.go ├── info.go ├── prov.go ├── download.go ├── pull.go ├── main.go ├── depends.go ├── git └── git.go ├── list.go ├── chart.go ├── README.md ├── go.sum └── LICENSE.md /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | indent_size=4 3 | -------------------------------------------------------------------------------- /runtime/fish/completions/cdp.fish: -------------------------------------------------------------------------------- 1 | complete -c cdp -f -x -a "(prt list)" 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | prt 2 | 3 | Pkgfile 4 | .md5sum 5 | .footprint 6 | .signature 7 | 8 | testfile 9 | testdir 10 | runtime/pkgmk/test 11 | 12 | *.svg 13 | *.dot 14 | -------------------------------------------------------------------------------- /runtime/fish/README.md: -------------------------------------------------------------------------------- 1 | # fish 2 | 3 | Some files that get used by the fish shell are stored here, this 4 | includes completions, and a function that `cd`s to a port. 5 | -------------------------------------------------------------------------------- /ports/doc.go: -------------------------------------------------------------------------------- 1 | // Package ports implements various handy functions to interact with CRUX ports. 2 | // 3 | // This package is a work in progress and EXPERIMENTAL. 4 | package ports 5 | -------------------------------------------------------------------------------- /runtime/pkgmk/README.md: -------------------------------------------------------------------------------- 1 | # pkgmk 2 | 3 | This is a fork of `pkgmk` that gets used solely by `prt`, all (most actually) changes that have been 4 | made are noted with a comment starting with `prt:`. 5 | -------------------------------------------------------------------------------- /utils.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "unicode" 5 | ) 6 | 7 | func capitalize(s string) string { 8 | a := []rune(s) 9 | a[0] = unicode.ToUpper(a[0]) 10 | return string(a) 11 | } 12 | -------------------------------------------------------------------------------- /ports/package.go: -------------------------------------------------------------------------------- 1 | package ports 2 | 3 | // Package is a type describing a package. 4 | type Package struct { 5 | Name string 6 | Version string 7 | Release string 8 | 9 | Files []string 10 | } 11 | -------------------------------------------------------------------------------- /runtime/bash/README.md: -------------------------------------------------------------------------------- 1 | # bash 2 | 3 | Some files that get used by the bash shell are stored here, this 4 | includes completions, and a function that `cd`s to a port. 5 | 6 | Ugh, what a terrible language compared to fish... 7 | -------------------------------------------------------------------------------- /ports/util.go: -------------------------------------------------------------------------------- 1 | package ports 2 | 3 | // Contains tests if a location is in a list of Ports. 4 | func Contains(ports []Port, location Location) bool { 5 | for _, p := range ports { 6 | if p.Location == location { 7 | return true 8 | } 9 | } 10 | 11 | return false 12 | } 13 | -------------------------------------------------------------------------------- /runtime/bash/functions/cdp.sh: -------------------------------------------------------------------------------- 1 | cdp () { 2 | portdir=$(grep 'prtdir.*' /etc/prt/config.toml | cut -d '=' -f 2 | tr -d '" ') 3 | loc=$(prt loc "$argv" 2>/dev/null) 4 | 5 | if [ -n "$loc" ]; then 6 | cd "$portdir/$loc" 7 | else 8 | cd "$portdir" 9 | fi 10 | } 11 | -------------------------------------------------------------------------------- /runtime/fish/functions/cdp.fish: -------------------------------------------------------------------------------- 1 | function cdp 2 | set portdir (cat /etc/prt/config.toml | string match -r 'prtdir.*' | cut -d '=' -f 2 | string trim -c '" ') 3 | set loc (prt loc $argv ^/dev/null) 4 | 5 | if test "$loc" 6 | cd $portdir/$loc 7 | else 8 | cd $portdir 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /ports/pkgfile_test.go: -------------------------------------------------------------------------------- 1 | package ports 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func BenchmarkParse(b *testing.B) { 8 | p := New("/usr/src/prt/core/bash") 9 | 10 | for i := 0; i < b.N; i++ { 11 | p.Pkgfile.Parse() 12 | } 13 | } 14 | 15 | func BenchmarkParseStrict(b *testing.B) { 16 | p := New("/usr/src/prt/core/bash") 17 | 18 | for i := 0; i < b.N; i++ { 19 | p.Pkgfile.Parse(true) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ports/ports_test.go: -------------------------------------------------------------------------------- 1 | package ports 2 | 3 | import "testing" 4 | 5 | func BenchmarkLocate(b *testing.B) { 6 | PrtDir = "/usr/srt/prt" 7 | Order = []string{"opt", "6c37-git", "contrib", "6c37"} 8 | a, _ := All() 9 | 10 | for i := 0; i < b.N; i++ { 11 | Locate(a, "firefox") 12 | } 13 | } 14 | 15 | func BenchmarkAll(b *testing.B) { 16 | PrtDir = "/usr/srt/prt" 17 | 18 | for i := 0; i < b.N; i++ { 19 | All() 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ports/port_test.go: -------------------------------------------------------------------------------- 1 | package ports 2 | 3 | import "testing" 4 | 5 | func TestNew(t *testing.T) { 6 | p := New("/usr/src/prt/opt/firefox") 7 | 8 | got := p.Location 9 | want := Location{"/usr/src/prt", "opt", "firefox"} 10 | if got != want { 11 | t.Errorf("p.Location: Got %s, want %s", got, want) 12 | } 13 | } 14 | 15 | func BenchmarkParseDepends(b *testing.B) { 16 | Order = []string{"punpun", "6c37-dropin", "core", "6c37-git", "6c37-update", 17 | "6c37", "opt", "xorg", "contrib"} 18 | PrtDir = "/usr/src/prt" 19 | p := New("/usr/src/prt/opt/firefox") 20 | a, _ := All() 21 | 22 | p.Pkgfile.Parse() 23 | 24 | for i := 0; i < b.N; i++ { 25 | p.ParseDepends(a, false) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tar/tar.go: -------------------------------------------------------------------------------- 1 | package tar 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "os/exec" 7 | "regexp" 8 | ) 9 | 10 | var formats = regexp.MustCompile(`.*\.tar|.*\.tar\.gz|.*\.tar\.Z|.*\.tgz|.*\.tar\.bz2|.*\.tbz2|.*\.tar\.xz|.*\.txz|.*\.tar\.lzma|.*\.tar\.lz|.*\.zip|.*\.rpm|.*\.7z`) 11 | 12 | func IsArchive(path string) bool { 13 | return formats.MatchString(path) 14 | } 15 | 16 | // Unpack unpacks an archive. 17 | func Unpack(source, target string) error { 18 | cmd := exec.Command("bsdtar", "-p", "-o", "-C", target, "-xf", source) 19 | bb := new(bytes.Buffer) 20 | cmd.Stdout = bb 21 | 22 | if err := cmd.Run(); err != nil { 23 | return fmt.Errorf("tar unpack %s: Something went wrong", source) 24 | } 25 | 26 | return nil 27 | } 28 | -------------------------------------------------------------------------------- /ports/location.go: -------------------------------------------------------------------------------- 1 | package ports 2 | 3 | import "path" 4 | 5 | // A Location describes the location of a port. A port location consist of a 6 | // ports-tree directory, a repo and a port. An example of a valid location would 7 | // be `usr/ports/opt/firefox`. 8 | type Location struct { 9 | Root string 10 | Repo string 11 | Port string 12 | } 13 | 14 | // Base returns the repo and port name. An example of this would be 15 | // `opt/firefox`. 16 | func (l Location) Base() string { 17 | return path.Join(l.Repo, l.Port) 18 | } 19 | 20 | // Full returns the ports-tree directory, the repo and port name. An example of 21 | // this would be `/usr/ports/opt/firefox`. 22 | func (l Location) Full() string { 23 | return path.Join(l.Root, l.Repo, l.Port) 24 | } 25 | -------------------------------------------------------------------------------- /ports/config.go: -------------------------------------------------------------------------------- 1 | package ports 2 | 3 | var ( 4 | // Prtdir defines The root directory of the ports tree. 5 | PrtDir = "/usr/ports" 6 | 7 | // PkgDir defines the directory where created packages get stored. 8 | PkgDir = "." 9 | 10 | // SrcDir defines the directory where downloaded sources get stored. 11 | SrcDir = "." 12 | 13 | // WrkDir defines the root directory where packages get build.. 14 | WrkDir = "." 15 | 16 | // Order gets used to determine how to order multiple ports with the same 17 | // name, but residing in a different repository. The repository found first 18 | // in the Order variable being ordered firt. 19 | Order []string 20 | 21 | // Alias gets used used to alias one port location to another port location. 22 | Aliases [][]Location 23 | ) 24 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/onodera-punpun/prt 2 | 3 | go 1.14 4 | 5 | require ( 6 | github.com/BurntSushi/toml v0.3.1 7 | github.com/ahmetalpbalkan/go-cursor v0.0.0-20131010032410-8136607ea412 8 | github.com/cavaliercoder/grab v2.0.1-0.20191026232651-4bc25e148ae7+incompatible 9 | github.com/dustin/go-humanize v1.0.0 10 | github.com/fatih/color v1.9.0 11 | github.com/go2c/optparse v0.1.0 12 | github.com/hacdias/fileutils v1.0.0 13 | github.com/kr/pretty v0.2.0 // indirect 14 | github.com/kr/text v0.2.0 // indirect 15 | github.com/lucasb-eyer/go-colorful v1.0.3 16 | github.com/mattn/go-colorable v0.1.6 // indirect 17 | github.com/onodera-punpun/go-utils v0.0.0-20180621190137-c8f4b6634a29 18 | golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d // indirect 19 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect 20 | mvdan.cc/sh/v3 v3.0.2 21 | ) 22 | -------------------------------------------------------------------------------- /runtime/man/prt-uninstall.md: -------------------------------------------------------------------------------- 1 | # prt-uninstall 8 "2017-01-02" prt "General Commands Manual" 2 | 3 | ## NAME 4 | 5 | prt-uninstall - uninstall packages 6 | 7 | 8 | ## SYNOPSIS 9 | 10 | prt uninstall [arguments] [packages] 11 | 12 | 13 | ## DESCRIPTION 14 | 15 | prt uninstall uninstalls installed packages, it's just a wrapper for `pkgrm(8)`, but accepts 16 | multiple packages. 17 | 18 | 19 | ## EXAMPLES 20 | 21 | Uninstall mpv and fish: 22 | 23 | ``` 24 | # prt uninstall mpv fish 25 | Uninstalling package 1/2, 6c37-git/mpv. 26 | Uninstalling package 2/2, 6c37-git/fish. 27 | ``` 28 | 29 | 30 | ## AUTHORS 31 | 32 | Camille Scholtz 33 | 34 | 35 | ## SEE ALSO 36 | 37 | `cdp(1)`, `prt(8)`, `prt.toml(5)`, `prt-depends(8)`, `prt-diff(8)`, `prt-info(8)`, `prt-install(8)`, 38 | `prt-list(8)`, `prt-loc(8)`, `prt-prov(8)`, `prt-pull(8)`, `prt-sysup(8), prt-get(8)`, 39 | `pkgmk(8)`, `pkgrm(8)`, `pkgadd(8)`, `ports(8)`, `pkginfo(8)`, `prt-utils(1)` 40 | -------------------------------------------------------------------------------- /runtime/man/prt-pull.md: -------------------------------------------------------------------------------- 1 | # prt-pull 8 "2017-01-02" prt "General Commands Manual" 2 | 3 | ## NAME 4 | 5 | prt-pull - pull in ports 6 | 7 | 8 | ## SYNOPSIS 9 | 10 | prt pull [arguments] [repos] 11 | 12 | 13 | ## DESCRIPTION 14 | 15 | prt pull is pretty much `ports -u`, but it has the ability to pull to a location that is 16 | not `/usr/ports`, it is also possible to only pull in certain repos by specifying them. 17 | 18 | 19 | ## EXAMPLES 20 | 21 | Only pull in punpun and core repos: 22 | 23 | ``` 24 | # prt pull punpun core 25 | Pulling in repo 1/2, core. 26 | Pulling in repo 2/2, punpun. 27 | ``` 28 | 29 | 30 | ## AUTHORS 31 | 32 | Camille Scholtz 33 | 34 | 35 | ## SEE ALSO 36 | 37 | `cdp(1)`, `prt(8)`, `prt.toml(5)`, `prt-depends(8)`, `prt-diff(8)`, `prt-info(8)`, `prt-install(8)`, 38 | `prt-list(8)`, `prt-loc(8)`, `prt-prov(8)`, `prt-sysup(8)`, `prt-uninstall(8), prt-get(8)`, 39 | `pkgmk(8)`, `pkgrm(8)`, `pkgadd(8)`, `ports(8)`, `pkginfo(8)`, `prt-utils(1)` 40 | -------------------------------------------------------------------------------- /ports/database.go: -------------------------------------------------------------------------------- 1 | package ports 2 | 3 | import ( 4 | "bufio" 5 | "os" 6 | ) 7 | 8 | // Database is a type describing the package database file. This file lists all 9 | // installed packages, the version of these packages, and the files these 10 | // packages installed. 11 | type Database struct { 12 | Packages []Package 13 | } 14 | 15 | // Parse parses the `db` file and populates the various fields in the given 16 | // `*Database`. 17 | func (f *Database) Parse() error { 18 | r, err := os.Open("/var/lib/pkg/db") 19 | if err != nil { 20 | return err 21 | } 22 | defer r.Close() 23 | s := bufio.NewScanner(r) 24 | 25 | var blank, file, name bool 26 | var p Package 27 | for s.Scan() { 28 | if blank || !file { 29 | p = Package{} 30 | p.Name = s.Text() 31 | blank, file, name = false, true, true 32 | } else if name { 33 | p.Version = s.Text() 34 | name = false 35 | } else if s.Text() == "" { 36 | f.Packages = append(f.Packages, p) 37 | blank = true 38 | } else { 39 | p.Files = append(p.Files, s.Text()) 40 | } 41 | } 42 | 43 | return nil 44 | } 45 | -------------------------------------------------------------------------------- /runtime/man/prt-diff.md: -------------------------------------------------------------------------------- 1 | # prt-diff 8 "2017-01-02" prt "General Commands Manual" 2 | 3 | ## NAME 4 | 5 | prt-diff - list outdated packages 6 | 7 | 8 | ## SYNOPSIS 9 | 10 | prt diff [arguments] 11 | 12 | 13 | ## DESCRIPTION 14 | 15 | prt diff lists outdated packages, it does does by comparing the version and release of the installed package 16 | against the available version. 17 | 18 | 19 | ## OPTIONS 20 | 21 | `-n` disable aliasing. Without this option ports get aliased using values found in `prt.toml(5)`. Same as `--no-alias` 22 | 23 | `-v` print with version information. Same as `--version` 24 | 25 | 26 | ## EXAMPLES 27 | 28 | List outdated packages with version information: 29 | 30 | ``` 31 | $ prt diff -v 32 | libpng 1.6.26-1 -> 1.6.27-1 33 | fish git-4 -> git-5 34 | ``` 35 | 36 | 37 | ## AUTHORS 38 | 39 | Camille Scholtz 40 | 41 | 42 | ## SEE ALSO 43 | 44 | `cdp(1)`, `prt(8)`, `prt.toml(5)`, `prt-depends(8)`, `prt-info(8)`, `prt-install(8)`, `prt-list(8)`, 45 | `prt-loc(8)`, `prt-prov(8)`, `prt-pull(8)`, `prt-sysup(8)`, `prt-uninstall(8)`, `prt-get(8)`, 46 | `pkgmk(8)`, `pkgrm(8)`, `pkgadd(8)`, `ports(8)`, `pkginfo(8)`, `prt-utils(1)` 47 | -------------------------------------------------------------------------------- /ports/footprint.go: -------------------------------------------------------------------------------- 1 | package ports 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | "path" 8 | "strings" 9 | ) 10 | 11 | // A Footprint describes the `.footprint` file of a port. This file is used for 12 | // regression testing and contains a list of files a package is expected to 13 | // contain once it is built. 14 | // TODO: Handle symlinks (`->`). 15 | type Footprint struct { 16 | *Port 17 | 18 | Files []struct { 19 | Path string 20 | Permission Permission 21 | } 22 | } 23 | 24 | // Parse parses the `.footprint` file of a port and populates the various fields 25 | // in the given `*Footprint`. 26 | func (f *Footprint) Parse() error { 27 | r, err := os.Open(path.Join(f.Location.Full(), ".footprint")) 28 | if err != nil { 29 | return fmt.Errorf("could not open `%s/.footprint`", f.Location.Full()) 30 | } 31 | defer r.Close() 32 | s := bufio.NewScanner(r) 33 | 34 | for s.Scan() { 35 | l := strings.Split(s.Text(), "\t") 36 | f.Files = append(f.Files, struct { 37 | Path string 38 | Permission Permission 39 | }{ 40 | Path: l[2], 41 | Permission: Permission{ 42 | FileMode: toFileMode(l[0]), 43 | Owner: l[1], 44 | }, 45 | }) 46 | } 47 | 48 | return nil 49 | } 50 | -------------------------------------------------------------------------------- /uninstall.bak: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/fatih/color" 8 | "github.com/go2c/optparse" 9 | ) 10 | 11 | // uninstall uninstalls packages. 12 | func uninstall(args []string) { 13 | // Define valid arguments. 14 | o := optparse.New() 15 | argh := o.Bool("help", 'h', false) 16 | 17 | // Parse arguments. 18 | vals, err := o.Parse(args) 19 | if err != nil { 20 | fmt.Fprintln(os.Stderr, "Invaild argument, use -h for a list of arguments!") 21 | os.Exit(1) 22 | } 23 | 24 | // Print help. 25 | if *argh { 26 | fmt.Println("Usage: prt uninstall [arguments] [packages]") 27 | fmt.Println("") 28 | fmt.Println("arguments:") 29 | fmt.Println(" -h, --help print help and exit") 30 | os.Exit(0) 31 | } 32 | 33 | // This command needs a value. 34 | if len(vals) == 0 { 35 | fmt.Fprintln(os.Stderr, "Please specify a package!") 36 | os.Exit(1) 37 | } 38 | 39 | t := len(vals) 40 | for i, p := range vals { 41 | fmt.Printf("Uninstalling package %d/%d, ", i+1, t) 42 | color.Set(config.LightColor) 43 | fmt.Printf(p) 44 | color.Unset() 45 | fmt.Println(".") 46 | 47 | if err := pkgUninstall(p); err != nil { 48 | printe(err.Error()) 49 | continue 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /runtime/man/prt-sysup.md: -------------------------------------------------------------------------------- 1 | # prt-sysup 8 "2017-01-02" prt "General Commands Manual" 2 | 3 | ## NAME 4 | 5 | prt-sysup - update outdated packages 6 | 7 | 8 | ## SYNOPSIS 9 | 10 | prt sysup [arguments] [ports to skip] 11 | 12 | 13 | ## DESCRIPTION 14 | 15 | prt sysup builds and updates outdated packages, these are the same ports as reported 16 | by `prt-diff(8)`. prt sysup also runs pre- and post-install scripts, and reports if the port as a README. 17 | 18 | 19 | ## OPTIONS 20 | 21 | `-v` enable verbose output. Without this option stdout and stderr of `pkgmk(8)` and `pkgadd(8)` will 22 | be redirected to `/dev/null`. Same as `--verbose` 23 | 24 | 25 | ## EXAMPLES 26 | 27 | Update all outdated packages, but not `opt/libpng`: 28 | 29 | ``` 30 | $ prt diff 31 | libpng 32 | zlib 33 | 34 | # prt sysup opt/libpng 35 | Updating package 1/1, core/zlib. 36 | - Downloading sources 37 | - Unpacking sources 38 | - Building package 39 | - Updating package 40 | ``` 41 | 42 | 43 | ## AUTHORS 44 | 45 | Camille Scholtz 46 | 47 | 48 | ## SEE ALSO 49 | 50 | `cdp(1)`, `prt(8)`, `prt.toml(5)`, `prt-depends(8)`, `prt-diff(8)`, `prt-info(8)`, `prt-install(8)`, 51 | `prt-list(8)`, `prt-loc(8)`, `prt-prov(8)`, `prt-pull(8)`, `prt-uninstall(8), prt-get(8)`, 52 | `pkgmk(8)`, `pkgrm(8)`, `pkgadd(8)`, `ports(8)`, `pkginfo(8)`, `prt-utils(1)` 53 | -------------------------------------------------------------------------------- /ports/permission.go: -------------------------------------------------------------------------------- 1 | package ports 2 | 3 | import ( 4 | "os" 5 | ) 6 | 7 | // An Permission is a type describing the permission bits found in the `.md5sum` 8 | // file of a port. 9 | type Permission struct { 10 | FileMode os.FileMode 11 | // TODO: Create a custom type for this. 12 | Owner string 13 | } 14 | 15 | func toFileMode(str string) os.FileMode { 16 | var v os.FileMode 17 | switch str[0:1] { 18 | case "d": 19 | v = os.ModeDir 20 | case "a": 21 | v = os.ModeAppend 22 | case "l": 23 | v = os.ModeExclusive 24 | case "T": 25 | v = os.ModeTemporary 26 | case "L": 27 | v = os.ModeSymlink 28 | case "D": 29 | v = os.ModeDevice 30 | case "p": 31 | v = os.ModeNamedPipe 32 | case "S": 33 | v = os.ModeSocket 34 | case "u": 35 | v = os.ModeSetuid 36 | case "g": 37 | v = os.ModeSetgid 38 | case "c": 39 | v = os.ModeCharDevice 40 | case "t": 41 | v = os.ModeSticky 42 | case "-": 43 | v = 0 44 | } 45 | v |= parseSegment(str[7:10]) 46 | v |= (parseSegment(str[4:7]) << 3) 47 | v |= (parseSegment(str[1:4]) << 6) 48 | 49 | return os.FileMode(v) 50 | } 51 | 52 | func parseSegment(seg string) os.FileMode { 53 | var v os.FileMode 54 | 55 | if seg[0] == 'r' { 56 | v += 4 57 | } 58 | if seg[1] == 'w' { 59 | v += 2 60 | } 61 | if seg[2] == 'x' { 62 | v += 1 63 | } 64 | 65 | return v 66 | } 67 | -------------------------------------------------------------------------------- /runtime/man/prt-loc.md: -------------------------------------------------------------------------------- 1 | # prt-loc 8 "2017-01-02" prt "General Commands Manual" 2 | 3 | ## NAME 4 | 5 | prt-loc - print port locations 6 | 7 | 8 | ## SYNOPSIS 9 | 10 | prt loc [arguments] [ports] 11 | 12 | 13 | ## DESCRIPTION 14 | 15 | prt loc prints the location of a ports, if there are multiple matches (for example 16 | `foo/bar` and `baz/bar`) it will print the most "important" ports using the order 17 | value in `prt.toml(5)`. 18 | 19 | 20 | ## OPTIONS 21 | 22 | `-d` list duplicate as well. Without this flag only the most "important" port will be listed. Same as `--duplicate` 23 | 24 | `-n` disable aliasing. Without this option ports get aliased using values found in `prt.toml(5)`. Same as `--no-alias` 25 | 26 | 27 | ## EXAMPLES 28 | 29 | Get location of `mpv`: 30 | 31 | ``` 32 | $ prt loc mpv 33 | 6c37-git/mpv 34 | ``` 35 | 36 | Get location of `mpv` and `fish`, list duplicate ports as well: 37 | 38 | ``` 39 | $ prt loc -d mpv fish 40 | 6c37-git/mpv 41 | - contrib/mpv 42 | 6c37-git/fish 43 | - 6c37/fish 44 | ``` 45 | 46 | 47 | ## AUTHORS 48 | 49 | Camille Scholtz 50 | 51 | 52 | ## SEE ALSO 53 | 54 | `cdp(1)`, `prt(8)`, `prt.toml(5)`, `prt-depends(8)`, `prt-diff(8)`, `prt-info(8)`, `prt-install(8)`, 55 | `prt-list(8)`, `prt-prov(8)`, `prt-pull(8)`, `prt-sysup(8)`, `prt-uninstall(8), prt-get(8)`, 56 | `pkgmk(8)`, `pkgrm(8)`, `pkgadd(8)`, `ports(8)`, `pkginfo(8)`, `prt-utils(1)` 57 | -------------------------------------------------------------------------------- /runtime/man/prt-list.md: -------------------------------------------------------------------------------- 1 | # prt-list 8 "2017-01-02" prt "General Commands Manual" 2 | 3 | ## NAME 4 | 5 | prt-list - list ports and packages 6 | 7 | 8 | ## SYNOPSIS 9 | 10 | prt list [arguments] 11 | 12 | 13 | ## DESCRIPTION 14 | 15 | prt list lists all ports on the system, or all installed packages. 16 | 17 | 18 | ## OPTIONS 19 | 20 | `-i` only lists installed packages. Without this option only ports that are not yet 21 | installed get listed. Same as `--installed` 22 | 23 | `-r` list with repo information. Same as `--repo` 24 | 25 | `-v` list with version information. Same as `--version` 26 | 27 | 28 | ## EXAMPLES 29 | 30 | List all all ports: 31 | 32 | ``` 33 | $ prt list | head -n 5 34 | abduco 35 | acpiclient 36 | afuse 37 | arandr 38 | artwiz-fonts 39 | ``` 40 | 41 | Only list installed ports, with version and repo information: 42 | 43 | ``` 44 | $ prt list -i -r -v | head -n 5 45 | 6c37-dropin/libressl 1.1.2-1 46 | 6c37-dropin/pkgconf 1.1.1-1 47 | 6c37-git/colorpicker 1.1.2-1 48 | 6c37-git/compton 0.60.6.1-2 49 | 6c37-git/fish 2016.11.20-0-1 50 | ``` 51 | 52 | 53 | ## AUTHORS 54 | 55 | Camille Scholtz 56 | 57 | 58 | ## SEE ALSO 59 | 60 | `cdp(1)`, `prt(8)`, `prt.toml(5)`, `prt-depends(8)`, `prt-diff(8)`, `prt-info(8)`, `prt-install(8)`, 61 | `prt-loc(8)`, `prt-prov(8)`, `prt-pull(8)`, `prt-sysup(8)`, `prt-uninstall(8), prt-get(8)`, 62 | `pkgmk(8)`, `pkgrm(8)`, `pkgadd(8)`, `ports(8)`, `pkginfo(8)`, `prt-utils(1)` 63 | -------------------------------------------------------------------------------- /runtime/config/config.toml: -------------------------------------------------------------------------------- 1 | # Location of the ports tree and pkgutil directories. 2 | prtdir = "/usr/src/prt" 3 | pkgdir = "/usr/src/pkg/pkg" 4 | srcdir = "/usr/src/pkg/src" 5 | wrkdir = "/usr/src/pkg/wrk" 6 | 7 | # Repo order, the port found first is used. 8 | order = [ 9 | "core", 10 | "opt", 11 | "xorg", 12 | "contrib" 13 | ] 14 | 15 | # Alias ports. 16 | aliases = [ 17 | # [ { repo = "core", port = "openssl" }, 18 | # { repo = "6c37-dropin", port = "libressl" } ], 19 | 20 | # [ { repo = "core", port = "pkg-config" }, 21 | # { repo = "6c37-dropin", port = "pkgconf" } ], 22 | ] 23 | 24 | # The amount of files to download concurrently. 25 | concurrentdownloads = 4 26 | 27 | # Characters used for indentation. 28 | indentchar = "- " 29 | 30 | # Characters used for warnings. 31 | warningchar = "! " 32 | 33 | # Color used for indentation, arrows, et cetera. 34 | # See: https://misc.flogisoft.com/bash/tip_colors_and_formatting 35 | darkcolor = 90 36 | 37 | # Color used to highlight repos to pull, ports to install, et cetera. 38 | lightcolor = 93 39 | 40 | # Color used for warnings. 41 | warningcolor = 91 42 | 43 | # Repos to pull. 44 | [repo] 45 | [repo.contrib] 46 | url = "git://crux.nu/ports/contrib" 47 | branch = "3.2" 48 | 49 | [repo.core] 50 | url = "git://crux.nu/ports/core" 51 | branch = "3.2" 52 | 53 | [repo.opt] 54 | url = "git://crux.nu/ports/opt" 55 | branch = "3.2" 56 | 57 | [repo.xorg] 58 | url = "git://crux.nu/ports/xorg" 59 | branch = "3.2" 60 | -------------------------------------------------------------------------------- /runtime/man/prt-prov.md: -------------------------------------------------------------------------------- 1 | # prt-prov 8 "2017-01-02" prt "General Commands Manual" 2 | 3 | ## NAME 4 | 5 | prt-prov - search ports for files 6 | 7 | 8 | ## SYNOPSIS 9 | 10 | prt prov [arguments] [queries] 11 | 12 | 13 | ## DESCRIPTION 14 | 15 | prt prov will search through `/var/lib/pkg/db` or through `.footprint`s of ports for files. 16 | It accepts multiple queries, and has full regex support. 17 | 18 | 19 | ## OPTIONS 20 | 21 | `-i` search in installed ports only, with this flag prov will search through `/var/lib/pkg/db` 22 | insted of `.footprint`s of ports. Same as `--installed` 23 | 24 | 25 | ## EXAMPLES 26 | 27 | Get all installed files that en with `.md`: 28 | 29 | ``` 30 | $ prt prov -i '\.md$' 31 | elementary-icon-theme 32 | - usr/share/icons/elementary/README.md 33 | go 34 | - usr/lib/go/CONTRIBUTING.md 35 | - usr/lib/go/README.md 36 | - usr/lib/go/misc/trace/README.md 37 | - usr/lib/go/src/runtime/HACKING.md 38 | ``` 39 | 40 | Get location of `mpv` and `fish`, list duplicate ports as well: 41 | 42 | ``` 43 | $ prt loc -d mpv fish 44 | 6c37-git/mpv 45 | - contrib/mpv 46 | 6c37-git/fish 47 | - 6c37/fish 48 | ``` 49 | 50 | 51 | ## AUTHORS 52 | 53 | Camille Scholtz 54 | 55 | 56 | ## SEE ALSO 57 | 58 | `cdp(1)`, `prt(8)`, `prt.toml(5)`, `prt-depends(8)`, `prt-diff(8)`, `prt-info(8)`, `prt-install(8)`, 59 | `prt-list(8)`, `prt-loc(8)`, `prt-pull(8)`, `prt-sysup(8)`, `prt-uninstall(8), prt-get(8)`, 60 | `pkgmk(8)`, `pkgrm(8)`, `pkgadd(8)`, `ports(8)`, `pkginfo(8)`, `prt-utils(1)` 61 | -------------------------------------------------------------------------------- /ports/ports.go: -------------------------------------------------------------------------------- 1 | package ports 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "path" 7 | "path/filepath" 8 | ) 9 | 10 | // All lists all ports found in the PrtDir. 11 | func All() ([]Port, error) { 12 | var pl []Port 13 | 14 | err := filepath.Walk(PrtDir, func(p string, i os.FileInfo, 15 | err error) error { 16 | if err != nil { 17 | return err 18 | } 19 | 20 | if !i.IsDir() && i.Name() == "Pkgfile" { 21 | pl = append(pl, New(path.Dir(p))) 22 | } 23 | 24 | return nil 25 | }) 26 | if err != nil { 27 | return pl, err 28 | } 29 | 30 | return pl, nil 31 | } 32 | 33 | // Locate tries to locate a port using a given list of Ports. It returns a list 34 | // with possible ports, sorted according to the order parameter. 35 | func Locate(ports []Port, port string) ([]Port, error) { 36 | // Find matching port names in the `all` list. 37 | var pl []Port 38 | for _, p := range ports { 39 | if p.Location.Port == port { 40 | pl = append(pl, p) 41 | } 42 | } 43 | 44 | // If there have been zero matches return with an error. 45 | if len(pl) == 0 { 46 | return []Port{}, fmt.Errorf("could not find `%s` in the ports tree", 47 | port) 48 | } 49 | 50 | // If there are multiple matches, sort according to the `Order` variable. 51 | if len(pl) > 1 { 52 | var i int 53 | for _, r := range Order { 54 | for j, p := range pl { 55 | if p.Location.Repo == r { 56 | pl[i], pl[j] = pl[j], pl[i] 57 | i++ 58 | } 59 | } 60 | } 61 | 62 | if i != len(pl) { 63 | return []Port{}, fmt.Errorf("could not order `%s`", port) 64 | } 65 | } 66 | 67 | return pl, nil 68 | } 69 | -------------------------------------------------------------------------------- /runtime/man/prt-info.md: -------------------------------------------------------------------------------- 1 | # prt-info 8 "2017-01-02" prt "General Commands Manual" 2 | 3 | ## NAME 4 | 5 | prt-info - print port information 6 | 7 | 8 | ## SYNOPSIS 9 | 10 | prt info [arguments] 11 | 12 | 13 | ## DESCRIPTION 14 | 15 | prt info prinst port information, basically an alias for `grep something Pkgfile`. 16 | 17 | 18 | ## OPTIONS 19 | 20 | `-d` print description. Same as `--description` 21 | 22 | `-u` print url. Same as `--url` 23 | 24 | `-m` print maintainer. Same as `--maintainer` 25 | 26 | `-e` print dependencies. Same as `--depends` 27 | 28 | `-o` print optional dependencies. Same as `--optional` 29 | 30 | `-v` print version. Same as `--version` 31 | 32 | `-r` print release. Same as `--release` 33 | 34 | 35 | ## EXAMPLES 36 | 37 | Print information: 38 | 39 | ``` 40 | $ prt info 41 | Description: CRUX port utils written in Go. 42 | URL: https://github.com/onodera-punpun/prt 43 | Maintainer: onodera, https://github.com/onodera-punpun/crux-ports/issues 44 | Depends on: go 45 | Nice to have: fish 46 | Version: git 47 | Release: 1 48 | ``` 49 | 50 | Only print maintainer, version and release: 51 | 52 | ``` 53 | prt info -r -v -m 54 | Maintainer: onodera, https://github.com/onodera-punpun/crux-ports/issues 55 | Version: git 56 | Release: 1 57 | ``` 58 | 59 | 60 | ## AUTHORS 61 | 62 | Camille Scholtz 63 | 64 | 65 | ## SEE ALSO 66 | 67 | `cdp(1)`, `prt(8)`, `prt.toml(5)`, `prt-depends(8)`, `prt-diff(8)`, `prt-install(8)`, `prt-list(8)`, 68 | `prt-loc(8)`, `prt-prov(8)`, `prt-pull(8)`, `prt-sysup(8)`, `prt-uninstall(8)`, `prt-get(8)`, 69 | `pkgmk(8)`, `pkgrm(8)`, `pkgadd(8)`, `ports(8)`, `pkginfo(8)`, `prt-utils(1)` 70 | -------------------------------------------------------------------------------- /config.go: -------------------------------------------------------------------------------- 1 | // config.go contains functions that interact with the config file, this is a 2 | // file called `config.toml` found in `/etc/prt/`. 3 | 4 | package main 5 | 6 | import ( 7 | "fmt" 8 | 9 | "github.com/BurntSushi/toml" 10 | "github.com/fatih/color" 11 | "github.com/onodera-punpun/prt/ports" 12 | ) 13 | 14 | // config is a stuct with all config values. See `runtime/config/config.toml` 15 | // for more information about these values. 16 | var config struct { 17 | PrtDir string 18 | PkgDir string 19 | SrcDir string 20 | WrkDir string 21 | 22 | Order []string 23 | Aliases [][]ports.Location 24 | 25 | ConcurrentDownloads int 26 | 27 | IndentChar string 28 | WarningChar string 29 | 30 | DarkColor color.Attribute 31 | LightColor color.Attribute 32 | WarningColor color.Attribute 33 | 34 | Repo map[string]repo 35 | } 36 | 37 | // pull is a struct with values related to repos. 38 | type repo struct { 39 | URL string 40 | Branch string 41 | } 42 | 43 | var dark, light, warning func(a ...interface{}) string 44 | 45 | // pareConfig parses a toml config. 46 | func parseConfig() error { 47 | _, err := toml.DecodeFile("/etc/prt/config.toml", &config) 48 | if err != nil { 49 | return fmt.Errorf("config /etc/prt/config.toml: " + err.Error()) 50 | } 51 | 52 | ports.PrtDir = config.PrtDir 53 | ports.PkgDir = config.PkgDir 54 | ports.SrcDir = config.SrcDir 55 | ports.WrkDir = config.WrkDir 56 | 57 | ports.Order = config.Order 58 | ports.Aliases = config.Aliases 59 | 60 | dark = color.New(config.DarkColor).SprintFunc() 61 | light = color.New(config.LightColor).SprintFunc() 62 | warning = color.New(config.WarningColor).SprintFunc() 63 | 64 | return nil 65 | } 66 | -------------------------------------------------------------------------------- /runtime/man/prt-depends.md: -------------------------------------------------------------------------------- 1 | # prt-depends 8 "2017-01-02" prt "General Commands Manual" 2 | 3 | ## NAME 4 | 5 | prt-depends - list dependencies recursively 6 | 7 | 8 | ## SYNOPSIS 9 | 10 | prt depends [arguments] 11 | 12 | 13 | ## DESCRIPTION 14 | 15 | prt depends lists dependencies recursively, it does so by finding the location of a port mentioned in the 16 | `Depends on:` comment in a Pkfile. if there are multiple ports found (for example `foo/bar` and `baz/bar`) 17 | it will choose the most "important" repo using the `prt.toml(5)` order value. 18 | 19 | 20 | ## OPTIONS 21 | 22 | `-a` also list installed dependencies. Without this option only ports that are not yet 23 | installed get listed. Same as `--all` 24 | 25 | `-n` disable aliasing. Without this option ports get aliased using values found in `prt.toml(5)`. Same as `--no-alias` 26 | 27 | `-t` list using tree view. Same as `--tree` 28 | 29 | 30 | ## EXAMPLES 31 | 32 | List all non-installed dependencies: 33 | 34 | ``` 35 | $ prt depends 36 | opt/mplayer 37 | opt/qt4 38 | opt/libmng 39 | ``` 40 | 41 | List all dependencies in tree view: 42 | 43 | ``` 44 | $ prt depends -t -a | head -n 5 45 | opt/mplayer 46 | - opt/expat 47 | - 6c37-dropin/freetype-iu 48 | - - core/zlib 49 | - - opt/libpng 50 | ``` 51 | 52 | List all dependencies in tree view, do not alias ports: 53 | 54 | ``` 55 | $ prt depends -t -a -n | head -n 5 56 | opt/mplayer 57 | - opt/expat 58 | - opt/freetype 59 | - - core/zlib 60 | - - opt/libpng 61 | ``` 62 | 63 | 64 | ## AUTHORS 65 | 66 | Camille Scholtz 67 | 68 | 69 | ## SEE ALSO 70 | 71 | `cdp(1)`, `prt(8)`, `prt.toml(5)`, `prt-diff(8)`, `prt-info(8)`, `prt-install(8)`, `prt-list(8)`, 72 | `prt-loc(8)`, `prt-prov(8)`, `prt-pull(8)`, `prt-sysup(8)`, `prt-uninstall(8)`, `prt-get(8)`, 73 | `pkgmk(8)`, `pkgrm(8)`, `pkgadd(8)`, `ports(8)`, `pkginfo(8)`, `prt-utils(1)` 74 | -------------------------------------------------------------------------------- /runtime/man/prt-install.md: -------------------------------------------------------------------------------- 1 | # prt-install 8 "2017-01-02" prt "General Commands Manual" 2 | 3 | ## NAME 4 | 5 | prt-install - build and install ports and their dependencies 6 | 7 | 8 | ## SYNOPSIS 9 | 10 | prt install [arguments] [ports to skip] 11 | 12 | 13 | ## DESCRIPTION 14 | 15 | prt install builds and installs ports and their uninstalled dependencies, these are the same dependencies as reported 16 | by `prt-depends(8)`. prt install also runs pre- and post-install scripts, and reports if the port as a README. 17 | 18 | If the port is already installed it will force rebuild and reinstall the port. 19 | 20 | 21 | ## OPTIONS 22 | 23 | `-v` enable verbose output. Without this option stdout and stderr of `pkgmk(8)` and `pkgadd(8)` will 24 | be redirected to `/dev/null`. Same as `--verbose` 25 | 26 | 27 | ## EXAMPLES 28 | 29 | Install a port, in this case the port is already installed, so it will force rebuild and reinstall: 30 | 31 | ``` 32 | # prt install 33 | Updating package 1/1, prt. 34 | - Downloading sources 35 | - Unpacking sources 36 | - Building package 37 | - Installing package 38 | ``` 39 | 40 | Install a port and its dependencies, but don't build and install dependency `contrib/boost`: 41 | 42 | ``` 43 | $ prt info -e 44 | Depends on: git ncurses libmpdclient boost taglib 45 | 46 | # prt install contrib/boost 47 | Updating package 1/2, 6c37/mpd. 48 | - Downloading sources 49 | - Unpacking sources 50 | - Building package 51 | - Installing package 52 | Updating package 2/2, 6c37-git/ncmpcpp. 53 | - Downloading sources 54 | - Unpacking sources 55 | - Building package 56 | - Installing package 57 | ``` 58 | 59 | 60 | ## AUTHORS 61 | 62 | Camille Scholtz 63 | 64 | 65 | ## SEE ALSO 66 | 67 | `cdp(1)`, `prt(8)`, `prt.toml(5)`, `prt-depends(8)`, `prt-diff(8)`, `prt-info(8)`, `prt-list(8)`, 68 | `prt-loc(8)`, `prt-prov(8)`, `prt-pull(8)`, `prt-sysup(8)`, `prt-uninstall(8)`, `prt-get(8)`, 69 | `pkgmk(8)`, `pkgrm(8)`, `pkgadd(8)`, `ports(8)`, `pkginfo(8)`, `prt-utils(1)` 70 | -------------------------------------------------------------------------------- /diff.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/go2c/optparse" 8 | "github.com/onodera-punpun/prt/ports" 9 | ) 10 | 11 | // DiffCommand lists outdated packages. 12 | func diffCommand(input []string) error { 13 | // Define valid arguments. 14 | o := optparse.New() 15 | argn := o.Bool("no-alias", 'n', false) 16 | argv := o.Bool("version", 'v', false) 17 | argh := o.Bool("help", 'h', false) 18 | 19 | // Parse arguments. 20 | _, err := o.Parse(input) 21 | if err != nil { 22 | return fmt.Errorf("invaild argument, use `-h` for a list of arguments") 23 | } 24 | 25 | // Print help. 26 | if *argh { 27 | fmt.Println("Usage: prt diff [arguments]") 28 | fmt.Println("") 29 | fmt.Println("arguments:") 30 | fmt.Println(" -n, --no-alias disable aliasing") 31 | fmt.Println(" -v, --version print with version info") 32 | fmt.Println(" -h, --help print help and exit") 33 | 34 | return nil 35 | } 36 | 37 | // Get all ports. 38 | all, err := ports.All() 39 | if err != nil { 40 | return err 41 | } 42 | 43 | // Get installed ports. 44 | var db ports.Database 45 | if err := db.Parse(); err != nil { 46 | return err 47 | } 48 | 49 | for _, n := range db.Packages { 50 | pl, err := ports.Locate(all, n.Name) 51 | if err != nil { 52 | continue 53 | } 54 | p := pl[0] 55 | 56 | // Alias if needed. 57 | if !*argn { 58 | p.Alias() 59 | } 60 | 61 | // Read out Pkgfile. 62 | if err := p.Pkgfile.Parse(); err != nil { 63 | fmt.Fprintf(os.Stderr, "%s%s\n", warning(config.WarningChar), err) 64 | continue 65 | } 66 | 67 | // Get available version and release from Pkgfile. 68 | v := p.Pkgfile.Version + "-" + p.Pkgfile.Release 69 | 70 | // Print if installed and available version don't match. 71 | if v != n.Version { 72 | fmt.Print(p.Pkgfile.Name) 73 | 74 | // Print version information if needed. 75 | if *argv { 76 | fmt.Printf(" %s%s%s", n.Version, dark(" -> "), v) 77 | } 78 | 79 | fmt.Println() 80 | } 81 | } 82 | 83 | return nil 84 | } 85 | -------------------------------------------------------------------------------- /unpack.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "path" 6 | "regexp" 7 | 8 | "github.com/go2c/optparse" 9 | "github.com/hacdias/fileutils" 10 | "github.com/onodera-punpun/prt/ports" 11 | "github.com/onodera-punpun/prt/tar" 12 | ) 13 | 14 | // TODO: Use https://github.com/mholt/archiver. 15 | 16 | // unpackCommand unpacks port sources 17 | func unpackCommand(input []string) error { 18 | // Define valid arguments. 19 | o := optparse.New() 20 | argh := o.Bool("help", 'h', false) 21 | 22 | // Parse arguments. 23 | _, err := o.Parse(input) 24 | if err != nil { 25 | return fmt.Errorf("invaild argument, use `-h` for a list of arguments") 26 | } 27 | 28 | // Print help. 29 | if *argh { 30 | fmt.Println("Usage: prt unpack [arguments]") 31 | fmt.Println("") 32 | fmt.Println("arguments:") 33 | fmt.Println(" -h, --help print help and exit") 34 | 35 | return nil 36 | } 37 | 38 | if err := downloadCommand([]string{}); err != nil { 39 | return err 40 | } 41 | 42 | p := ports.New(".") 43 | if err := p.Pkgfile.Parse(true); err != nil { 44 | return err 45 | } 46 | 47 | // Print a new line if files have been downloaded. 48 | // TODO: Can I simplify this? 49 | var sl = []string{} 50 | r := regexp.MustCompile("^(http|https|ftp|file)://") 51 | for _, s := range p.Pkgfile.Source { 52 | if r.MatchString(s) { 53 | sl = append(sl, s) 54 | } 55 | } 56 | if len(sl) > 0 { 57 | fmt.Println() 58 | } 59 | 60 | if err := p.CreateWrk(); err != nil { 61 | return err 62 | } 63 | 64 | to := path.Join(config.WrkDir, p.Pkgfile.Name, "src") 65 | for i, s := range p.Pkgfile.Source { 66 | f := path.Base(s) 67 | 68 | fmt.Printf("Unpacking source %d/%d, %s.\n", i+1, len(p.Pkgfile.Source), 69 | light(f)) 70 | 71 | if tar.IsArchive(f) { 72 | if err := tar.Unpack(path.Join(config.SrcDir, f), to); err != nil { 73 | return err 74 | } 75 | } else { 76 | if err := fileutils.CopyFile(path.Join(p.Location.Full(), f), 77 | to); err != nil { 78 | return err 79 | } 80 | } 81 | } 82 | 83 | return nil 84 | } 85 | -------------------------------------------------------------------------------- /loc.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | 7 | "github.com/go2c/optparse" 8 | "github.com/onodera-punpun/go-utils/array" 9 | "github.com/onodera-punpun/prt/ports" 10 | ) 11 | 12 | // locCommand prints port locations 13 | func locCommand(input []string) error { 14 | // Define valid arguments. 15 | o := optparse.New() 16 | argd := o.Bool("duplicate", 'd', false) 17 | argn := o.Bool("no-alias", 'n', false) 18 | argh := o.Bool("help", 'h', false) 19 | 20 | // Parse arguments. 21 | vals, err := o.Parse(input) 22 | if err != nil { 23 | return fmt.Errorf("invaild argument, use `-h` for a list of arguments") 24 | } 25 | 26 | // Print help. 27 | if *argh { 28 | fmt.Println("Usage: prt loc [arguments] [ports]") 29 | fmt.Println("") 30 | fmt.Println("arguments:") 31 | fmt.Println(" -d, --duplicate list duplicate ports as well") 32 | fmt.Println(" -n, --no-alias disable aliasing") 33 | fmt.Println(" -h, --help print help and exit") 34 | 35 | return nil 36 | } 37 | 38 | // This command needs a value. 39 | if len(vals) == 0 { 40 | return fmt.Errorf("please specify a port") 41 | } 42 | 43 | // Get all ports. 44 | all, err := ports.All() 45 | if err != nil { 46 | return err 47 | } 48 | 49 | var check []string 50 | var i int 51 | for _, v := range vals { 52 | // Continue if already checked. 53 | if array.ContainsString(check, v) { 54 | continue 55 | } 56 | check = append(check, v) 57 | 58 | pl, err := ports.Locate(all, v) 59 | if err != nil { 60 | return err 61 | } 62 | if !*argd { 63 | pl = []ports.Port{pl[0]} 64 | } 65 | 66 | var op string 67 | for _, p := range pl { 68 | // Alias if needed. 69 | if !*argn { 70 | p.Alias() 71 | } 72 | 73 | // Print duplicate indentation. 74 | if *argd { 75 | // Reset indentation on new port 76 | if p.Location.Port != op { 77 | i = 0 78 | } 79 | op = p.Location.Port 80 | 81 | if i > 0 { 82 | fmt.Print(dark(strings.Repeat(config.IndentChar, i))) 83 | } 84 | i++ 85 | } 86 | 87 | // Finally print the port. 88 | fmt.Println(p.Location.Base()) 89 | } 90 | } 91 | 92 | return nil 93 | } 94 | -------------------------------------------------------------------------------- /ports/port.go: -------------------------------------------------------------------------------- 1 | package ports 2 | 3 | import "path" 4 | 5 | // A Port describes a port. A port is a directory containing the files needed 6 | // for building a package. 7 | type Port struct { 8 | // Location specifies the location of the port, this is used as the "primary 9 | // key" of a port type. 10 | Location Location 11 | 12 | // TODO: Add signature, .nostrip, et cetera. 13 | Footprint Footprint 14 | Md5sum Md5sum 15 | Pkgfile Pkgfile 16 | 17 | // Depends is a "recursive variable" that list all dependencies recursively. 18 | // This 19 | Depends []*Port 20 | } 21 | 22 | // New returns a Port with the Location field populated. Use the various 23 | // `Parse` functions to populate the other fields. 24 | func New(location string) Port { 25 | var p Port 26 | 27 | p.Location = Location{ 28 | Root: path.Dir(path.Dir(location)), 29 | Repo: path.Base(path.Dir(location)), 30 | Port: path.Base(location), 31 | } 32 | 33 | p.Footprint = Footprint{Port: &p} 34 | p.Md5sum = Md5sum{Port: &p} 35 | p.Pkgfile = Pkgfile{Port: &p} 36 | 37 | return p 38 | } 39 | 40 | // Alias aliases ports by using the `Aliases` variable. An example of this would 41 | // be aliasing `core/openssl` to `6c37/libressl`. 42 | func (p *Port) Alias() { 43 | for _, a := range Aliases { 44 | if a[0] == p.Location { 45 | p.Location = a[1] 46 | } 47 | } 48 | } 49 | 50 | // Check used by `ParseDepends()`. 51 | var check []*Port 52 | 53 | // ParseDepends is a function that calculates dependencies recursively and 54 | // populates `Depends`. This function requires `Pkgfile.Parse()` to be run 55 | // prior. 56 | func (p *Port) ParseDepends(ports []Port, alias bool) error { 57 | // Continue if already checked. 58 | for _, c := range check { 59 | if c.Pkgfile.Name == p.Pkgfile.Name { 60 | p.Depends = c.Depends 61 | return nil 62 | } 63 | } 64 | 65 | var err error 66 | for _, n := range p.Pkgfile.Depends { 67 | pl, err := Locate(ports, n) 68 | if err != nil { 69 | return err 70 | } 71 | d := pl[0] 72 | 73 | // Alias ports if needed. 74 | if alias { 75 | d.Alias() 76 | } 77 | 78 | // Read out Pkgfile. 79 | if err = d.Pkgfile.Parse(); err != nil { 80 | return err 81 | } 82 | 83 | // Append to `p.Depends`. 84 | p.Depends = append(p.Depends, &d) 85 | 86 | // Append port to checked ports. 87 | check = append(check, p) 88 | 89 | // Loop. 90 | if err = p.Depends[len(p.Depends)-1].ParseDepends(ports, 91 | alias); err != nil { 92 | return err 93 | } 94 | } 95 | 96 | return err 97 | } 98 | -------------------------------------------------------------------------------- /info.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | 7 | "github.com/go2c/optparse" 8 | "github.com/onodera-punpun/prt/ports" 9 | ) 10 | 11 | // infoCommand prints port information. 12 | func infoCommand(input []string) error { 13 | // Enable all arguments if the user hasn't specified any. 14 | var b bool 15 | if len(input) == 0 { 16 | b = true 17 | } 18 | 19 | // Define valid arguments. 20 | o := optparse.New() 21 | argd := o.Bool("description", 'd', b) 22 | argu := o.Bool("url", 'u', b) 23 | argm := o.Bool("maintainer", 'm', b) 24 | arge := o.Bool("depends", 'e', b) 25 | argo := o.Bool("optional", 'o', b) 26 | argv := o.Bool("version", 'v', b) 27 | argr := o.Bool("release", 'r', b) 28 | args := o.Bool("source", 's', b) 29 | argh := o.Bool("help", 'h', false) 30 | 31 | // Parse arguments. 32 | _, err := o.Parse(input) 33 | if err != nil { 34 | return fmt.Errorf("invaild argument, use `-h` for a list of arguments") 35 | } 36 | 37 | // Print help. 38 | if *argh { 39 | fmt.Println("Usage: prt info [arguments]") 40 | fmt.Println("") 41 | fmt.Println("arguments:") 42 | fmt.Println(" -d, --description print description") 43 | fmt.Println(" -u, --url print url") 44 | fmt.Println(" -m, --maintainer print maintainer") 45 | fmt.Println(" -e, --depends print dependencies") 46 | fmt.Println(" -o, --optional print optional dependencies") 47 | fmt.Println(" -v, --version print version") 48 | fmt.Println(" -r, --release print release") 49 | fmt.Println(" -s, --source print sources") 50 | fmt.Println(" -h, --help print help and exit") 51 | 52 | return nil 53 | } 54 | 55 | // Read out Pkgfile. 56 | p := ports.New(".") 57 | if err := p.Pkgfile.Parse(true); err != nil { 58 | return err 59 | } 60 | 61 | // Print info from Pkgfile. 62 | if *argd { 63 | fmt.Println("Description: " + p.Pkgfile.Description) 64 | } 65 | if *argu { 66 | fmt.Println("URL: " + p.Pkgfile.URL) 67 | } 68 | if *argm { 69 | fmt.Println("Maintainer: " + p.Pkgfile.Maintainer) 70 | } 71 | if *arge { 72 | fmt.Println("Depends on: " + strings.Join(p.Pkgfile.Depends, ", ")) 73 | } 74 | if *argo { 75 | fmt.Println("Nice to have: " + strings.Join(p.Pkgfile.Optional, ", ")) 76 | } 77 | if *argv { 78 | fmt.Println("Version: " + p.Pkgfile.Version) 79 | } 80 | if *argr { 81 | fmt.Println("Release: " + p.Pkgfile.Release) 82 | } 83 | if *args { 84 | fmt.Println("Source: " + strings.Join(p.Pkgfile.Source, ", ")) 85 | } 86 | 87 | return nil 88 | } 89 | -------------------------------------------------------------------------------- /prov.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "regexp" 6 | 7 | "github.com/go2c/optparse" 8 | "github.com/onodera-punpun/prt/ports" 9 | ) 10 | 11 | // provCommand searches ports for files. 12 | func provCommand(input []string) error { 13 | // Define valid arguments. 14 | o := optparse.New() 15 | argi := o.Bool("installed", 'i', false) 16 | argh := o.Bool("help", 'h', false) 17 | 18 | // Parse arguments. 19 | vals, err := o.Parse(input) 20 | if err != nil { 21 | return fmt.Errorf("invaild argument, use `-h` for a list of arguments") 22 | } 23 | 24 | // Print help. 25 | if *argh { 26 | fmt.Println("Usage: prt prov [arguments] [queries]") 27 | fmt.Println("") 28 | fmt.Println("arguments:") 29 | fmt.Println(" -i, --installed search in installed ports") 30 | fmt.Println(" -h, --help print help and exit") 31 | 32 | return nil 33 | } 34 | 35 | // This command needs a value. 36 | if len(vals) == 0 { 37 | return fmt.Errorf("please specify a query") 38 | } 39 | 40 | for _, v := range vals { 41 | if *argi { 42 | var db ports.Database 43 | if err := db.Parse(); err != nil { 44 | return err 45 | } 46 | 47 | for _, p := range db.Packages { 48 | // Search for files. 49 | var fl []string 50 | for _, f := range p.Files { 51 | m, err := regexp.MatchString(v, f) 52 | if err != nil { 53 | return err 54 | } 55 | if m { 56 | fl = append(fl, f) 57 | } 58 | } 59 | 60 | // Print port location. 61 | if len(fl) > 0 { 62 | fmt.Println(p.Name) 63 | } 64 | 65 | // Print matched files. 66 | for _, f := range fl { 67 | fmt.Printf("%s%s\n", dark(config.IndentChar), f) 68 | } 69 | } 70 | } else { 71 | all, err := ports.All() 72 | if err != nil { 73 | return err 74 | } 75 | 76 | for _, p := range all { 77 | if err := p.Footprint.Parse(); err != nil { 78 | continue 79 | } 80 | 81 | // Search for files. 82 | var fl []string 83 | for _, f := range p.Footprint.Files { 84 | m, err := regexp.MatchString(v, f.Path) 85 | if err != nil { 86 | return err 87 | } 88 | if m { 89 | fl = append(fl, f.Path) 90 | } 91 | } 92 | 93 | // Print port location. 94 | if len(fl) > 0 { 95 | fmt.Println(p.Location.Base()) 96 | } 97 | 98 | // Print matched files. 99 | for _, f := range fl { 100 | fmt.Printf("%s%s\n", dark(config.IndentChar), f) 101 | } 102 | } 103 | } 104 | } 105 | 106 | return nil 107 | } 108 | -------------------------------------------------------------------------------- /download.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "path" 6 | "regexp" 7 | "time" 8 | 9 | cursor "github.com/ahmetalpbalkan/go-cursor" 10 | "github.com/cavaliercoder/grab" 11 | humanize "github.com/dustin/go-humanize" 12 | "github.com/go2c/optparse" 13 | "github.com/onodera-punpun/prt/ports" 14 | ) 15 | 16 | // downloadCommand downloads port sources 17 | func downloadCommand(input []string) error { 18 | // Define valid arguments. 19 | o := optparse.New() 20 | argh := o.Bool("help", 'h', false) 21 | 22 | // Parse arguments. 23 | _, err := o.Parse(input) 24 | if err != nil { 25 | return fmt.Errorf("invaild argument, use `-h` for a list of arguments") 26 | } 27 | 28 | // Print help. 29 | if *argh { 30 | fmt.Println("Usage: prt download [arguments]") 31 | fmt.Println("") 32 | fmt.Println("arguments:") 33 | fmt.Println(" -h, --help print help and exit") 34 | 35 | return nil 36 | } 37 | 38 | p := ports.New(".") 39 | if err := p.Pkgfile.Parse(true); err != nil { 40 | return err 41 | } 42 | 43 | var sl = []string{} 44 | r := regexp.MustCompile("^(http|https|ftp|file)://") 45 | for _, s := range p.Pkgfile.Source { 46 | if r.MatchString(s) { 47 | sl = append(sl, s) 48 | } 49 | } 50 | if len(sl) == 0 { 51 | return nil 52 | } 53 | 54 | b, err := grab.GetBatch(config.ConcurrentDownloads, ports.SrcDir, sl...) 55 | if err != nil { 56 | return err 57 | } 58 | 59 | // Monitor downloads. 60 | rl := make([]*grab.Response, 0, len(sl)) 61 | t := time.NewTicker(100 * time.Millisecond) 62 | defer t.Stop() 63 | 64 | // Hide cursor. 65 | fmt.Print(cursor.Hide()) 66 | defer fmt.Print(cursor.Show()) 67 | 68 | // Move the cursor back to the bottom on close. 69 | defer fmt.Print(cursor.MoveDown(len(sl) * 2)) 70 | 71 | var c int 72 | for c != len(sl) { 73 | select { 74 | case r := <-b: 75 | if r != nil { 76 | rl = append(rl, r) 77 | } 78 | case <-t.C: 79 | c = 0 80 | for i, r := range rl { 81 | if r.IsComplete() { 82 | if err := r.Err(); err != nil { 83 | // TODO: A more descriptive error message. 84 | return err 85 | } 86 | 87 | c++ 88 | } 89 | 90 | fmt.Printf("Downloading source %d/%d, %s.\n", i+1, len(rl), 91 | light(path.Base(r.Filename))) 92 | fmt.Printf("%s%s%s of %s\n", cursor.ClearEntireLine(), dark( 93 | config.IndentChar), humanize.Bytes(uint64(r. 94 | BytesComplete())), humanize.Bytes(uint64(r.Size()))) 95 | } 96 | 97 | // Move cursor two lines of for each download. 98 | fmt.Print(cursor.MoveUp(len(rl) * 2)) 99 | } 100 | } 101 | 102 | return nil 103 | } 104 | -------------------------------------------------------------------------------- /pull.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "path" 7 | 8 | "github.com/go2c/optparse" 9 | "github.com/onodera-punpun/go-utils/array" 10 | "github.com/onodera-punpun/prt/git" 11 | ) 12 | 13 | // pullCommand pulls in ports. 14 | func pullCommand(input []string) error { 15 | // Define valid arguments. 16 | o := optparse.New() 17 | argh := o.Bool("help", 'h', false) 18 | 19 | // Parse arguments. 20 | vals, err := o.Parse(input) 21 | if err != nil { 22 | return fmt.Errorf("invaild argument, use `-h` for a list of arguments") 23 | } 24 | 25 | // Print help. 26 | if *argh { 27 | fmt.Println("Usage: prt pull [arguments] [repos]") 28 | fmt.Println("") 29 | fmt.Println("arguments:") 30 | fmt.Println(" -h, --help print help and exit") 31 | 32 | return nil 33 | } 34 | 35 | // Count repos that need to be pulled. 36 | var t int 37 | if len(vals) == 0 { 38 | t = len(config.Repo) 39 | } else { 40 | t = len(vals) 41 | } 42 | 43 | // TODO: Actually learn git and check if all these commands are needed. 44 | var i int 45 | for n, r := range config.Repo { 46 | // Skip repos if needed. 47 | if len(vals) != 0 { 48 | if !array.ContainsString(vals, n) { 49 | continue 50 | } 51 | } 52 | i++ 53 | 54 | fmt.Printf("Pulling in repo %d/%d, %s.\n", i, t, light(n)) 55 | 56 | l := path.Join(config.PrtDir, n) 57 | g := git.Repo{ 58 | Location: l, 59 | URL: r.URL, 60 | Branch: r.Branch, 61 | } 62 | 63 | // Check if location exists, clone if it doesn't. 64 | if _, err := os.Stat(l); err != nil { 65 | if err := g.Clone(); err != nil { 66 | fmt.Fprintf(os.Stderr, "%s%s\n", warning(config.WarningChar), 67 | err) 68 | } 69 | continue 70 | } 71 | 72 | if err := g.Checkout(); err != nil { 73 | fmt.Fprintf(os.Stderr, "%s%s\n", warning(config.WarningChar), err) 74 | continue 75 | } 76 | if err := g.Fetch(); err != nil { 77 | fmt.Fprintf(os.Stderr, "%s%s\n", warning(config.WarningChar), err) 78 | continue 79 | } 80 | 81 | // Print changes. 82 | dl, err := g.Diff() 83 | if err != nil { 84 | fmt.Fprintf(os.Stderr, "%s%s\n", warning(config.WarningChar), err) 85 | continue 86 | } 87 | for _, d := range dl { 88 | fmt.Printf("%s%s\n", dark(config.IndentChar), d) 89 | } 90 | 91 | if err := g.Clean(); err != nil { 92 | fmt.Fprintf(os.Stderr, "%s%s\n", warning(config.WarningChar), err) 93 | continue 94 | } 95 | if err := g.Reset(); err != nil { 96 | fmt.Fprintf(os.Stderr, "%s%s\n", warning(config.WarningChar), err) 97 | continue 98 | } 99 | } 100 | 101 | return nil 102 | } 103 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | if len(os.Args) == 1 { 10 | fmt.Fprintln(os.Stderr, 11 | "Missing command, use help for a list of commands!") 12 | os.Exit(1) 13 | } 14 | 15 | if err := parseConfig(); err != nil { 16 | fmt.Fprintln(os.Stderr, err) 17 | os.Exit(1) 18 | } 19 | 20 | var err error 21 | switch os.Args[1] { 22 | case "help": 23 | fmt.Println("Usage: prt command [arguments]") 24 | fmt.Println("") 25 | fmt.Println("commands:") 26 | fmt.Println(" depends list dependencies recursively") 27 | fmt.Println(" download download port sources") 28 | fmt.Println(" chart generate dependency chart") 29 | fmt.Println(" diff list outdated packages") 30 | fmt.Println(" info print port information") 31 | //fmt.Println(" install build and install ports and their dependencies") 32 | fmt.Println(" list list ports and packages") 33 | fmt.Println(" loc print port locations") 34 | //fmt.Println(" make make package from port") 35 | //fmt.Println(" patch patch ports") 36 | fmt.Println(" prov search ports for files") 37 | fmt.Println(" pull pull in ports") 38 | //fmt.Println(" sysup update outdated packages") 39 | //fmt.Println(" uninstall uninstall packages") 40 | fmt.Println(" unpack unpack port sources") 41 | fmt.Println(" help print help and exit") 42 | case "depends": 43 | err = dependsCommand(os.Args[2:]) 44 | case "download": 45 | err = downloadCommand(os.Args[2:]) 46 | case "diff": 47 | err = diffCommand(os.Args[2:]) 48 | case "chart": 49 | err = chartCommand(os.Args[2:]) 50 | case "info": 51 | err = infoCommand(os.Args[2:]) 52 | //case "install": 53 | // err = installCommand(os.Args[2:]) 54 | case "list": 55 | err = listCommand(os.Args[2:]) 56 | case "loc": 57 | err = locCommand(os.Args[2:]) 58 | //case "make": 59 | // err = makeCommand(os.Args[2:]) 60 | //case "patch": 61 | // err = patchCommand(os.Args[2:]) 62 | case "prov": 63 | err = provCommand(os.Args[2:]) 64 | case "pull": 65 | err = pullCommand(os.Args[2:]) 66 | //case "sysup": 67 | // err = sysupCommand(os.Args[2:]) 68 | //case "uninstall": 69 | // err = uninstallCommand(os.Args[2:]) 70 | case "unpack": 71 | err = unpackCommand(os.Args[2:]) 72 | default: 73 | err = fmt.Errorf("invalid command, use `help` for a list of commands") 74 | } 75 | 76 | if err != nil { 77 | fmt.Fprintf(os.Stderr, "%s!\n", capitalize(err.Error())) 78 | os.Exit(1) 79 | } 80 | os.Exit(0) 81 | } 82 | -------------------------------------------------------------------------------- /depends.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | 7 | "github.com/go2c/optparse" 8 | "github.com/onodera-punpun/prt/ports" 9 | ) 10 | 11 | // dependsCommand lists dependencies recursively. 12 | func dependsCommand(input []string) error { 13 | // Define valid arguments. 14 | o := optparse.New() 15 | arga := o.Bool("all", 'a', false) 16 | argn := o.Bool("no-alias", 'n', false) 17 | argt := o.Bool("tree", 't', false) 18 | argh := o.Bool("help", 'h', false) 19 | 20 | // Parse arguments. 21 | _, err := o.Parse(input) 22 | if err != nil { 23 | return fmt.Errorf("invaild argument, use `-h` for a list of arguments") 24 | } 25 | 26 | // Print help. 27 | if *argh { 28 | fmt.Println("Usage: prt depends [arguments]") 29 | fmt.Println("") 30 | fmt.Println("arguments:") 31 | fmt.Println(" -a, --all also list installed dependencies") 32 | fmt.Println(" -n, --no-alias disable aliasing") 33 | fmt.Println(" -t, --tree list using tree view") 34 | fmt.Println(" -h, --help print help and exit") 35 | 36 | return nil 37 | } 38 | 39 | p := ports.New(".") 40 | if err := p.Pkgfile.Parse(); err != nil { 41 | return err 42 | } 43 | 44 | var db ports.Database 45 | if !*arga { 46 | // Get installed ports. 47 | if err := db.Parse(); err != nil { 48 | return err 49 | } 50 | } 51 | 52 | // Get all ports. 53 | all, err := ports.All() 54 | if err != nil { 55 | return err 56 | } 57 | 58 | if err := p.ParseDepends(all, !*argn); err != nil { 59 | return err 60 | } 61 | 62 | dependsRecurse(&p, db, 0, *argt) 63 | 64 | return nil 65 | } 66 | 67 | var dependsCheck []*ports.Port 68 | var dependsArrow bool 69 | 70 | func dependsRecurse(p *ports.Port, db ports.Database, l int, t bool) { 71 | outer: 72 | for _, d := range p.Depends { 73 | // Continue if installed. 74 | for _, n := range db.Packages { 75 | if d.Pkgfile.Name == n.Name { 76 | continue outer 77 | } 78 | } 79 | 80 | // Continue if already checked. 81 | for _, c := range dependsCheck { 82 | if d.Pkgfile.Name == c.Pkgfile.Name { 83 | if !t { 84 | continue outer 85 | } 86 | 87 | if len(d.Pkgfile.Depends) > 0 { 88 | if !dependsArrow { 89 | fmt.Printf("%s%s%s\n", dark(strings.Repeat(config. 90 | IndentChar, l)), d.Pkgfile.Name, dark(" ->")) 91 | 92 | continue outer 93 | } 94 | 95 | dependsArrow = !dependsArrow 96 | } 97 | } 98 | } 99 | dependsCheck = append(dependsCheck, d) 100 | 101 | if t { 102 | fmt.Print(dark(strings.Repeat(config.IndentChar, l))) 103 | } 104 | fmt.Println(d.Pkgfile.Name) 105 | 106 | dependsRecurse(d, db, l+1, t) 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /git/git.go: -------------------------------------------------------------------------------- 1 | package git 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "os/exec" 7 | "sort" 8 | "strings" 9 | ) 10 | 11 | type Repo struct { 12 | Location string 13 | URL string 14 | Branch string 15 | } 16 | 17 | // Checkout checks out a repo. 18 | func (r Repo) Checkout() error { 19 | cmd := exec.Command("git", "checkout", r.Branch) 20 | cmd.Dir = r.Location 21 | 22 | if err := cmd.Run(); err != nil { 23 | return fmt.Errorf("git checkout %s: Something went wrong", r.Location) 24 | } 25 | 26 | return nil 27 | } 28 | 29 | // Clean cleans a repo. 30 | func (r Repo) Clean() error { 31 | cmd := exec.Command("git", "clean", "-f") 32 | cmd.Dir = r.Location 33 | 34 | if err := cmd.Run(); err != nil { 35 | return fmt.Errorf("git clean %s: Something went wrong", r.Location) 36 | } 37 | 38 | return nil 39 | } 40 | 41 | // Clone clones a repo. 42 | func (r Repo) Clone() error { 43 | cmd := exec.Command("git", "clone", "--depth", "1", "-b", r.Branch, r.URL, 44 | r.Location) 45 | 46 | if err := cmd.Run(); err != nil { 47 | return fmt.Errorf("git clone %s: Something went wrong", r.URL) 48 | } 49 | 50 | return nil 51 | } 52 | 53 | // Diff checks a repo for differences. 54 | func (r Repo) Diff() ([]string, error) { 55 | cmd := exec.Command("git", "diff", "--name-status", "--diff-filter", 56 | "ACDM", "origin/"+r.Branch) 57 | cmd.Dir = r.Location 58 | bb := new(bytes.Buffer) 59 | cmd.Stdout = bb 60 | 61 | if err := cmd.Run(); err != nil { 62 | return []string{}, fmt.Errorf("git diff %s: Something went wrong", r. 63 | Location) 64 | } 65 | 66 | d := bb.String() 67 | if len(d) < 1 { 68 | return []string{}, nil 69 | } 70 | 71 | // Make output pretty. 72 | // TODO: This prints Deleted when it should be Added. 73 | // TODO: Enable Renamed. 74 | d = strings.Replace(d, "A\t", "Added ", -1) 75 | d = strings.Replace(d, "C\t", "Copied ", -1) 76 | d = strings.Replace(d, "D\t", "Deleted ", -1) 77 | d = strings.Replace(d, "M\t", "Modiefied ", -1) 78 | //d = strings.Replace(d, "R\t", "Renamed ", -1) 79 | dl := strings.Split(d, "\n") 80 | sort.Strings(dl) 81 | 82 | return dl[1:], nil 83 | } 84 | 85 | // Fetch fetches a repo. 86 | func (r Repo) Fetch() error { 87 | cmd := exec.Command("git", "fetch", "--depth", "1") 88 | cmd.Dir = r.Location 89 | 90 | if err := cmd.Run(); err != nil { 91 | return fmt.Errorf("git fetch %s: Something went wrong", r.Location) 92 | } 93 | 94 | return nil 95 | } 96 | 97 | // Reset resets a repo. 98 | func (r Repo) Reset() error { 99 | cmd := exec.Command("git", "reset", "--hard", "origin/"+r.Branch) 100 | cmd.Dir = r.Location 101 | 102 | if err := cmd.Run(); err != nil { 103 | return fmt.Errorf("git reset %s: Something went wrong", r.Location) 104 | } 105 | 106 | return nil 107 | } 108 | -------------------------------------------------------------------------------- /list.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "sort" 7 | 8 | "github.com/go2c/optparse" 9 | "github.com/onodera-punpun/prt/ports" 10 | ) 11 | 12 | // listCommand lists ports. 13 | func listCommand(input []string) error { 14 | // Define valid arguments. 15 | o := optparse.New() 16 | argi := o.Bool("installed", 'i', false) 17 | argr := o.Bool("repo", 'r', false) 18 | argv := o.Bool("version", 'v', false) 19 | argh := o.Bool("help", 'h', false) 20 | 21 | // Parse arguments. 22 | _, err := o.Parse(input) 23 | if err != nil { 24 | return fmt.Errorf("invaild argument, use `-h` for a list of arguments") 25 | } 26 | 27 | // Print help. 28 | if *argh { 29 | fmt.Println("Usage: prt list [arguments]") 30 | fmt.Println("") 31 | fmt.Println("arguments:") 32 | fmt.Println(" -i, --installed list installed ports only") 33 | fmt.Println(" -r, --repo list with repo info") 34 | fmt.Println(" -v, --version list with version info") 35 | fmt.Println(" -h, --help print help and exit") 36 | 37 | return nil 38 | } 39 | 40 | // Get all ports. 41 | all, err := ports.All() 42 | if err != nil { 43 | return err 44 | } 45 | 46 | var db ports.Database 47 | if *argi { 48 | // Get installed ports. 49 | if err := db.Parse(); err != nil { 50 | return err 51 | } 52 | 53 | // Get port locations. 54 | var pl []ports.Port 55 | for _, n := range db.Packages { 56 | p, err := ports.Locate(all, n.Name) 57 | if err != nil { 58 | // In case `err` is not `nil` we didn't manage to locate this 59 | // port, this is most likely because the port is not in the 60 | // ports-tree. We append an empty `Port` so that the variable 61 | // `i` in the next for loop increments correctly. 62 | pl = append(pl, ports.Port{}) 63 | } else { 64 | pl = append(pl, p[0]) 65 | } 66 | } 67 | 68 | // I'm using all in the the following for loop, so copy `db` to `all`. 69 | all = pl 70 | } 71 | 72 | var pl []string 73 | for i, p := range all { 74 | // If the Location is empty it means we didn't manage to locate a ports, 75 | if p.Location.Port == "" { 76 | continue 77 | } 78 | 79 | var s string 80 | 81 | if !*argr { 82 | s = p.Location.Port 83 | } else { 84 | s = p.Location.Base() 85 | } 86 | 87 | if *argv { 88 | if *argi { 89 | s += " " + db.Packages[i].Version 90 | } else { 91 | if err := p.Pkgfile.Parse(); err != nil { 92 | fmt.Fprintf(os.Stderr, "%s%s\n", warning(config. 93 | WarningChar), err) 94 | continue 95 | } 96 | s += " " + p.Pkgfile.Version 97 | } 98 | } 99 | 100 | pl = append(pl, s) 101 | } 102 | 103 | sort.Strings(pl) 104 | for _, p := range pl { 105 | fmt.Println(p) 106 | } 107 | 108 | return nil 109 | } 110 | -------------------------------------------------------------------------------- /ports/md5sum.go: -------------------------------------------------------------------------------- 1 | package ports 2 | 3 | import ( 4 | "bufio" 5 | "crypto/md5" 6 | "encoding/hex" 7 | "fmt" 8 | "io" 9 | "os" 10 | "path" 11 | "regexp" 12 | "strings" 13 | ) 14 | 15 | // An Md5sum is a type describing the `.md5sum` file of a port. This file is 16 | // used to validate the sources of a port. 17 | type Md5sum struct { 18 | *Port 19 | 20 | Files []struct { 21 | File string 22 | Hash string 23 | } 24 | } 25 | 26 | // Create creates an `.md5sum` file for a Port. This function requires 27 | // `Pkgfile.Parse(true)` to be run prior. 28 | func (f *Md5sum) Create() error { 29 | nf, err := os.OpenFile(path.Join(f.Location.Full(), ".md5sum"), os.O_CREATE| 30 | os.O_APPEND|os.O_WRONLY, 0666) 31 | if err != nil { 32 | return err 33 | } 34 | defer nf.Close() 35 | 36 | r := regexp.MustCompile("^(http|https|ftp|file)://") 37 | for _, s := range f.Pkgfile.Source { 38 | if r.MatchString(s) { 39 | s = path.Join(SrcDir, path.Base(s)) 40 | } else { 41 | s = path.Join(f.Location.Full(), path.Base(s)) 42 | } 43 | 44 | h, err := hashFromFile(s) 45 | if err != nil { 46 | return err 47 | } 48 | 49 | if _, err := nf.WriteString(h + " " + path.Base(s) + 50 | "\n"); err != nil { 51 | return err 52 | } 53 | } 54 | 55 | return nil 56 | } 57 | 58 | // Parse parses the `.md5sum` file of a port and populates the various fields in 59 | // the given `*Md5sum`. 60 | func (f *Md5sum) Parse() error { 61 | r, err := os.Open(path.Join(f.Location.Full(), ".md5sum")) 62 | if err != nil { 63 | return fmt.Errorf("could not open `%s/.md5sum`", f.Location.Full()) 64 | } 65 | defer r.Close() 66 | s := bufio.NewScanner(r) 67 | 68 | for s.Scan() { 69 | l := strings.Split(s.Text(), " ") 70 | f.Files = append(f.Files, struct { 71 | File string 72 | Hash string 73 | }{ 74 | File: l[1], 75 | Hash: l[0], 76 | }) 77 | } 78 | 79 | return nil 80 | } 81 | 82 | // Validate compares the Ports `.md5sum` file to the hashed source files. This 83 | // function requires `Pkgfile.Parse(true)` and `Md5sum.Parse()` to be run prior. 84 | // TODO: This required some download function to be run. 85 | func (f *Md5sum) Validate() error { 86 | r := regexp.MustCompile("^(http|https|ftp|file)://") 87 | for _, l := range f.Md5sum.Files { 88 | for _, s := range f.Pkgfile.Source { 89 | if r.MatchString(s) { 90 | s = path.Join(SrcDir, path.Base(s)) 91 | } else { 92 | s = path.Join(f.Location.Full(), path.Base(s)) 93 | } 94 | 95 | h, err := hashFromFile(s) 96 | if err != nil { 97 | return err 98 | } 99 | 100 | if l.Hash != h { 101 | return fmt.Errorf("pkgmk md5sum %s:%s: Hash didn't match", f. 102 | Location.Base(), path.Base(s)) 103 | } 104 | } 105 | } 106 | 107 | return nil 108 | } 109 | 110 | func hashFromFile(file string) (string, error) { 111 | hf, err := os.Open(file) 112 | if err != nil { 113 | return "", err 114 | } 115 | defer hf.Close() 116 | 117 | h := md5.New() 118 | if _, err := io.Copy(h, hf); err != nil { 119 | return "", err 120 | } 121 | 122 | return hex.EncodeToString(h.Sum(nil)), nil 123 | } 124 | -------------------------------------------------------------------------------- /runtime/man/prt.md: -------------------------------------------------------------------------------- 1 | # prt 8 "2017-01-02" prt "General Commands Manual" 2 | 3 | ## NAME 4 | 5 | prt - CRUX port utility written in Go, aiming to replace prt-get, ports, and some pkgutils (on my machine) 6 | 7 | 8 | ## SYNOPSIS 9 | 10 | prt command [arguments] 11 | 12 | 13 | ## DESCRIPTION 14 | 15 | prt is like `prt-get(8)` a port/package management utility which provides additional functionality to the 16 | CRUX pkgutils. It works with the local ports tree and is therefore fully compatible with `ports(8)`, `pkgmk(8)`, 17 | `pkgadd(8)` and of course `prt-get(8)`. It offers the following features: 18 | 19 | * listing dependencies of ports recursively, with an optional flag to print using tree view 20 | * listing outdated package, by comparing port versions with the installed version 21 | * easily printing port information such as the maintainer, version, release, et cetera 22 | * install ports and their dependencies with a single command 23 | * list ports, with optional flags to also only list installed ports, print with repo information or to print 24 | with additional version information 25 | * print the location of a port 26 | * searching through files ports provide, with an optional flag to only search through installed ports 27 | * pull in ports using git(1) 28 | * update outdated packages 29 | * uninstall installed packages 30 | 31 | like `prt-get(8)`, prt is basically a wrapper around `pkgmk(8)`/`pkgadd(8)` and provides some nice functionality such as 32 | listing and installing dependencies, getting the location of a port, aliasing ports (for example `core/openssl` 33 | to `6c37-dropin/libressl`), and ordering ports with the same name depending on how "important" the repo is the port resides in. 34 | 35 | There are a few differences though, for example, unlike `prt-get(8)` you need to be in the port's directory for most 36 | commands to work, like how `pkgmk(8)` works. This has a few advantages, for example you can quickly download a port 37 | anywhere on the filesystem, and install it and its dependencies using `prt install`. Because `prt-get depinst` needs 38 | a port name, you can *only* install ports that are located in a predefined `prtdir`. 39 | 40 | Another difference with `prt-get(8)` is that prt does not use a cache file, while still being nearly as fast or faster 41 | in some cases. 42 | 43 | Aliasing is also handeled a bit different. `prt-get(8)` aliases ports based on name, but prt on name and repo. 44 | This makes it possible to alias `foo/bar` to `baz/bar`. 45 | 46 | 47 | ## COMMANDS 48 | 49 | The prt syntax is inspired by `prt-get(8)`, `git(8)` and `go(8)`, and thus uses so called commands which always have to be the first 50 | non-option argument passed. Each command is documented in its own manpage. For example, the install command is documented in 51 | `prt-install(8)`. The commands are: 52 | 53 | `depends` list dependencies recursively, 54 | 55 | `diff` list outdated packages 56 | 57 | `info` print port information 58 | 59 | `install` build and install ports and their dependencies 60 | 61 | `list` list porst and packages 62 | 63 | `loc` print port locations 64 | 65 | `prov` search ports for files 66 | 67 | `pull` pull in ports 68 | 69 | `sysup` update outdated packages 70 | 71 | `uninstall` uninstall packages 72 | 73 | `help` print help and exit 74 | 75 | 76 | ## CONFIGURATION 77 | 78 | See man `prt.toml(5)` 79 | 80 | 81 | ## AUTHORS 82 | 83 | Camille Scholtz 84 | 85 | 86 | ## SEE ALSO 87 | 88 | `cdp(1)`, `prt.toml(5)`, `prt-depends(8)`, `prt-diff(8)`, `prt-info(8)`, `prt-install(8)`, `prt-list(8)`, 89 | `prt-loc(8)`, `prt-prov(8)`, `prt-pull(8)`, `prt-sysup(8)`, `prt-uninstall(8)`, `prt-get(8)`, 90 | `pkgmk(8)`, `pkgrm(8)`, `pkgadd(8)`, `ports(8)`, `pkginfo(8)`, `prt-utils(1)` 91 | -------------------------------------------------------------------------------- /chart.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "os/exec" 7 | 8 | "github.com/go2c/optparse" 9 | colorful "github.com/lucasb-eyer/go-colorful" 10 | "github.com/onodera-punpun/prt/ports" 11 | ) 12 | 13 | // chartCommand generates a dependency grap. 14 | // TODO: Replace current port name "." with the actual name. 15 | func chartCommand(input []string) error { 16 | // Define valid arguments. 17 | o := optparse.New() 18 | //argd := o.Bool("duplicate", 'd', false) 19 | argn := o.Bool("no-alias", 'n', false) 20 | argt := o.String("type", 't', "svg") 21 | argh := o.Bool("help", 'h', false) 22 | 23 | // Parse arguments. 24 | _, err := o.Parse(input) 25 | if err != nil { 26 | return fmt.Errorf("invaild argument, use `-h` for a list of arguments") 27 | } 28 | 29 | // Print help. 30 | if *argh { 31 | fmt.Println("Usage: prt chart [arguments]") 32 | fmt.Println("") 33 | fmt.Println("arguments:") 34 | fmt.Println(" -d, --duplicate display duplicates as well") 35 | fmt.Println(" -n, --no-alias disable aliasing") 36 | fmt.Println(" -t, --type filetype to use") 37 | fmt.Println(" -h, --help print help and exit") 38 | 39 | return nil 40 | } 41 | 42 | p := ports.New(".") 43 | if err := p.Pkgfile.Parse(); err != nil { 44 | return err 45 | } 46 | 47 | // Get all ports. 48 | all, err := ports.All() 49 | if err != nil { 50 | return err 51 | } 52 | 53 | if err := p.ParseDepends(all, !*argn); err != nil { 54 | return err 55 | } 56 | 57 | // Set file to write to. 58 | f, err := os.OpenFile(p.Pkgfile.Name+".dot", os.O_CREATE|os.O_WRONLY, 0666) 59 | if err != nil { 60 | return fmt.Errorf("could not create `%s`", p.Pkgfile.Name+".dot") 61 | } 62 | defer f.Close() 63 | 64 | // Prettify chart. 65 | fmt.Fprintf(f, "digraph G {\n") 66 | fmt.Fprintf(f, "\tgraph [\n") 67 | fmt.Fprintf(f, "\t\t%s=\"%s\"\n", "tcenter", "true") 68 | fmt.Fprintf(f, "\t\t%s=\"%f\"\n", "pad", 2.0) 69 | fmt.Fprintf(f, "\t]\n\n") 70 | 71 | // Prettify nodes. 72 | fmt.Fprint(f, "\tnode [\n") 73 | fmt.Fprintf(f, "\t\t%s=\"%s\"\n", "constraint", "false") 74 | fmt.Fprintf(f, "\t\t%s=\"%s\"\n", "fontcolor", "#111e38") 75 | fmt.Fprintf(f, "\t\t%s=\"%d\"\n", "penwidth", 3) 76 | fmt.Fprintf(f, "\t\t%s=\"%s\"\n", "shape", "box") 77 | fmt.Fprintf(f, "\t]\n\n") 78 | 79 | // Prettify edges. 80 | fmt.Fprintf(f, "\tedge [\n") 81 | fmt.Fprintf(f, "\t\t%s=\"%s\"\n", "arrowhead", "dot") 82 | fmt.Fprintf(f, "\t\t%s=\"%s\"\n", "color", "#cee0e3") 83 | fmt.Fprintf(f, "\t\t%s=\"%s\"\n", "headport", "n") 84 | fmt.Fprintf(f, "\t\t%s=\"%d\"\n", "penwidth", 2) 85 | fmt.Fprintf(f, "\t]\n\n") 86 | 87 | pal, _ := colorful.SoftPalette(128) 88 | chartRecurse(&p, 0, f, pal) 89 | 90 | fmt.Fprintf(f, "}") 91 | 92 | f.Close() 93 | if *argt == "dot" { 94 | return nil 95 | } 96 | 97 | // Convert to chart. 98 | cmd := exec.Command("dot", p.Pkgfile.Name+".dot", "-T", *argt, "-o", p. 99 | Pkgfile.Name+"."+*argt) 100 | if err := cmd.Run(); err != nil { 101 | return fmt.Errorf("something went wrong with GrapViz") 102 | } 103 | 104 | // Remove dot file. 105 | if err := os.Remove(p.Pkgfile.Name + ".dot"); err != nil { 106 | return err 107 | } 108 | 109 | return nil 110 | } 111 | 112 | var chartCheck []*ports.Port 113 | 114 | func chartRecurse(p *ports.Port, l int, f *os.File, pal []colorful.Color) { 115 | outer: 116 | for _, d := range p.Depends { 117 | // Continue if already checked. 118 | for _, c := range chartCheck { 119 | if c.Pkgfile.Name == d.Pkgfile.Name { 120 | continue outer 121 | } 122 | } 123 | chartCheck = append(chartCheck, d) 124 | 125 | fmt.Fprintf(f, "\tnode [color=\"%s\"]\n", pal[l].Hex()) 126 | fmt.Fprintf(f, "\t\"%s\"->\"%s\"\n", p.Location.Base(), d.Location. 127 | Base()) 128 | 129 | chartRecurse(d, l+1, f, pal) 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /runtime/pkgmk/pkgmk: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Based on pkgmk (pkgutils) 5.40.2. 4 | 5 | echoe() { 6 | echo "$1" >&2 7 | } 8 | 9 | get_filename() { 10 | local ABSOLUTE="" 11 | if [ "$1" = "-a" ]; then 12 | ABSOLUTE=1 13 | shift 14 | fi 15 | 16 | if [[ $1 =~ ^(http|https|ftp|file)://.*/(.+) ]]; then 17 | echo "$PKGMK_SOURCE_DIR/${BASH_REMATCH[2]}" 18 | else 19 | if [ "$ABSOLUTE" ]; then 20 | echo $PKGMK_ROOT/$1 21 | else 22 | echo $1 23 | fi 24 | fi 25 | } 26 | 27 | strip_files() { 28 | local FILE FILTER 29 | 30 | cd $PKG 31 | 32 | if [ -f $PKGMK_ROOT/$PKGMK_NOSTRIP ]; then 33 | FILTER="grep -v -f $PKGMK_ROOT/$PKGMK_NOSTRIP" 34 | else 35 | FILTER="cat" 36 | fi 37 | 38 | find . -type f -printf "%P\n" | $FILTER | while read FILE; do 39 | case $(file -b "$FILE") in 40 | *ELF*executable*not\ stripped*) 41 | strip --strip-all "$FILE" 42 | ;; 43 | *ELF*shared\ object*not\ stripped*) 44 | strip --strip-unneeded "$FILE" 45 | ;; 46 | current\ ar\ archive) 47 | strip --strip-debug "$FILE" 48 | esac 49 | done 50 | } 51 | 52 | compress_manpages() { 53 | local FILE DIR TARGET 54 | 55 | cd $PKG 56 | 57 | find . -type f -path "*/man/man*/*" | while read FILE; do 58 | if [ "$FILE" = "${FILE%%.gz}" ]; then 59 | gzip -9 "$FILE" 60 | fi 61 | done 62 | 63 | find . -type l -path "*/man/man*/*" | while read FILE; do 64 | TARGET=`readlink -n "$FILE"` 65 | TARGET="${TARGET##*/}" 66 | TARGET="${TARGET%%.gz}.gz" 67 | rm -f "$FILE" 68 | FILE="${FILE%%.gz}.gz" 69 | DIR=`dirname "$FILE"` 70 | 71 | if [ -e "$DIR/$TARGET" ]; then 72 | ln -sf "$TARGET" "$FILE" 73 | fi 74 | done 75 | } 76 | 77 | build_package() { 78 | local BUILD_SUCCESSFUL="no" 79 | local COMPRESSION 80 | 81 | cd $SRC 82 | (set -e -x ; build) 83 | 84 | if [ $? = 0 ]; then 85 | if [ "$PKGMK_NO_STRIP" = "no" ]; then 86 | strip_files 87 | fi 88 | 89 | compress_manpages 90 | 91 | cd $PKG 92 | info "Build result:" 93 | 94 | case $PKGMK_COMPRESSION_MODE in 95 | gz) COMPRESSION="-z" ;; 96 | bz2) COMPRESSION="-j" ;; 97 | xz) COMPRESSION="-J" ;; 98 | esac 99 | bsdtar -c $COMPRESSION -f $TARGET * && bsdtar -t -v -f $TARGET 100 | 101 | if [ $? = 0 ]; then 102 | BUILD_SUCCESSFUL="yes" 103 | fi 104 | fi 105 | 106 | if [ "$BUILD_SUCCESSFUL" = "no" ]; then 107 | if [ -f $TARGET ]; then 108 | touch -r $PKGMK_ROOT/$PKGMK_PKGFILE $TARGET &> /dev/null 109 | fi 110 | echoe "Building '$TARGET' failed." 111 | exit 1 112 | fi 113 | } 114 | 115 | build_needed() { 116 | local FILE RESULT 117 | 118 | RESULT="yes" 119 | if [ -f $TARGET ]; then 120 | RESULT="no" 121 | for FILE in $PKGMK_PKGFILE ${source[@]}; do 122 | FILE=`get_filename $FILE` 123 | if [ ! -e $FILE ] || [ ! $TARGET -nt $FILE ]; then 124 | RESULT="yes" 125 | break 126 | fi 127 | done 128 | fi 129 | 130 | echo $RESULT 131 | } 132 | 133 | main() { 134 | PKGMK_ARCH=64 135 | if [ -f ".32bit" ]; then 136 | PKGMK_ARCH=32 137 | fi 138 | 139 | local FILE TARGET 140 | 141 | for FILE in $PKGMK_PKGFILE $PKGMK_CONFFILE; do 142 | if [ ! -f $FILE ]; then 143 | error "File '$FILE' not found." 144 | exit 1 145 | fi 146 | . $FILE 147 | done 148 | 149 | case $PKGMK_COMPRESSION_MODE in 150 | gz|bz2|xz) 151 | TARGET="$PKGMK_PACKAGE_DIR/$name#$version-$release.pkg.tar.$PKGMK_COMPRESSION_MODE" 152 | ;; 153 | *) 154 | printe "Compression mode '$PKGMK_COMPRESSION_MODE' not supported" 155 | exit 1 156 | ;; 157 | esac 158 | 159 | export PKG="$PKGMK_WORK_DIR/pkg" 160 | export SRC="$PKGMK_WORK_DIR/src" 161 | 162 | if [ "`build_needed`" = "no" ]; then 163 | info "Package '$TARGET' is up to date." 164 | else 165 | build_package 166 | fi 167 | 168 | exit 0 169 | } 170 | 171 | export LC_ALL=POSIX 172 | 173 | readonly PKGMK_COMMAND="$0" 174 | readonly PKGMK_ROOT="$PWD" 175 | 176 | PKGMK_CONFFILE="/etc/pkgmk.conf" 177 | PKGMK_PKGFILE="Pkgfile" 178 | PKGMK_MD5SUM=".md5sum" 179 | PKGMK_NOSTRIP=".nostrip" 180 | PKGMK_SIGNATURE=".signature" 181 | 182 | PKGMK_SOURCE_DIR="$PWD" 183 | PKGMK_PACKAGE_DIR="$PWD" 184 | PKGMK_WORK_DIR="$PWD/work" 185 | 186 | PKGMK_COMPRESSION_MODE="gz" 187 | 188 | PKGMK_NO_STRIP="no" 189 | 190 | main "$@" 191 | -------------------------------------------------------------------------------- /runtime/fish/completions/prt.fish: -------------------------------------------------------------------------------- 1 | complete -c prt -f -n '__fish_use_subcommand' -a depends -d 'list dependencies recursively' 2 | complete -c prt -f -n '__fish_seen_subcommand_from depends' -o a -l all -d 'also list installed dependencies' 3 | complete -c prt -f -n '__fish_seen_subcommand_from depends' -o n -l no-alias -d 'disable aliasing' 4 | complete -c prt -f -n '__fish_seen_subcommand_from depends' -o t -l tree -d 'list using tree view' 5 | complete -c prt -f -n '__fish_seen_subcommand_from depends' -o h -l help -d 'print help and exit' 6 | 7 | complete -c prt -f -n '__fish_use_subcommand' -a diff -d 'list oudated packages' 8 | complete -c prt -f -n '__fish_seen_subcommand_from diff' -o n -l no-alias -d 'disable aliasing' 9 | complete -c prt -f -n '__fish_seen_subcommand_from diff' -o v -l version -d 'list with version info' 10 | complete -c prt -f -n '__fish_seen_subcommand_from diff' -o h -l help -d 'print help and exit' 11 | 12 | complete -c prt -f -n '__fish_use_subcommand' -a info -d 'print port information' 13 | complete -c prt -f -n '__fish_seen_subcommand_from info' -o d -l description -d 'print description' 14 | complete -c prt -f -n '__fish_seen_subcommand_from info' -o u -l url -d 'print url' 15 | complete -c prt -f -n '__fish_seen_subcommand_from info' -o m -l maintainer -d 'print maintainer' 16 | complete -c prt -f -n '__fish_seen_subcommand_from info' -o e -l depends -d 'print dependencies' 17 | complete -c prt -f -n '__fish_seen_subcommand_from info' -o o -l optional -d 'print optional dependencies' 18 | complete -c prt -f -n '__fish_seen_subcommand_from info' -o v -l version -d 'print version' 19 | complete -c prt -f -n '__fish_seen_subcommand_from info' -o r -l release -d 'print release' 20 | complete -c prt -f -n '__fish_seen_subcommand_from info' -o h -l help -d 'print help and exit' 21 | 22 | complete -c prt -f -n '__fish_use_subcommand' -a install -d 'build and install ports and their dependencies' 23 | complete -c prt -f -n '__fish_seen_subcommand_from install' -a "(prt depends)" 24 | complete -c prt -f -n '__fish_seen_subcommand_from install' -o v -l verbose -d 'enable verbose output' 25 | complete -c prt -f -n '__fish_seen_subcommand_from install' -o h -l help -d 'print help and exit' 26 | 27 | complete -c prt -f -n '__fish_use_subcommand' -a list -d 'list ports and packages' 28 | complete -c prt -f -n '__fish_seen_subcommand_from list' -o i -l installed -d 'list installed ports only' 29 | complete -c prt -f -n '__fish_seen_subcommand_from list' -o r -l repo -d 'list with repo info' 30 | complete -c prt -f -n '__fish_seen_subcommand_from list' -o b -l version -d 'list with version info' 31 | complete -c prt -f -n '__fish_seen_subcommand_from list' -o h -l help -d 'print help and exit' 32 | 33 | complete -c prt -f -n '__fish_use_subcommand' -a loc -d 'prints port locations' 34 | complete -c prt -f -n '__fish_seen_subcommand_from loc' -x -a "(prt list)" 35 | complete -c prt -f -n '__fish_seen_subcommand_from loc' -o d -l duplicate -d 'list duplicate ports as well' 36 | complete -c prt -f -n '__fish_seen_subcommand_from loc' -o n -l no-alias -d 'disable aliasing' 37 | complete -c prt -f -n '__fish_seen_subcommand_from loc' -o h -l help -d 'print help and exit' 38 | 39 | complete -c prt -f -n '__fish_use_subcommand' -a prov -d 'search ports for files' 40 | complete -c prt -f -n '__fish_seen_subcommand_from prov' -o i -l installed -d 'search in installed ports only' 41 | complete -c prt -f -n '__fish_seen_subcommand_from prov' -o h -l help -d 'print help and exit' 42 | 43 | complete -c prt -f -n '__fish_use_subcommand' -a pull -d 'pull in ports' 44 | complete -c prt -f -n '__fish_seen_subcommand_from pull' -a "(ls (cat /etc/prt/config.toml | string match -r 'portdir.*' | cut -d '=' -f 2 | string trim -c '\" '))" 45 | complete -c prt -f -n '__fish_seen_subcommand_from pull' -o h -l help -d 'print help and exit' 46 | 47 | complete -c prt -f -n '__fish_use_subcommand' -a sysup -d 'update outdated packages' 48 | complete -c prt -f -n '__fish_seen_subcommand_from sysup' -a "(prt loc (prt diff))" 49 | complete -c prt -f -n '__fish_seen_subcommand_from sysup' -o v -l verbose -d 'enable verbose output' 50 | complete -c prt -f -n '__fish_seen_subcommand_from sysup' -o h -l help -d 'print help and exit' 51 | 52 | complete -c prt -f -n '__fish_use_subcommand' -a uninstall -d 'uninstall packages' 53 | complete -c prt -f -n '__fish_seen_subcommand_from uninstall' -a "(prt list -i)" 54 | complete -c prt -f -n '__fish_seen_subcommand_from uninstall' -o h -l help -d 'print help and exit' 55 | 56 | complete -c prt -f -n '__fish_use_subcommand' -a help -d 'print help and exit' 57 | -------------------------------------------------------------------------------- /ports/pkgfile.go: -------------------------------------------------------------------------------- 1 | package ports 2 | 3 | import ( 4 | "bufio" 5 | "context" 6 | "fmt" 7 | "io" 8 | "os" 9 | "path" 10 | "strings" 11 | 12 | "mvdan.cc/sh/v3/interp" 13 | "mvdan.cc/sh/v3/syntax" 14 | ) 15 | 16 | // A Pkgfile is a type describing the `Pkgfile` file of a port. This file 17 | // contains information about the package (such as `name`, `version`, et cetera) 18 | // and the commands that should be executed in order to compile the package in 19 | // question. 20 | type Pkgfile struct { 21 | *Port 22 | 23 | // Comments with various information that isn't strictly needed in order to 24 | // build a package. 25 | Description string 26 | URL string 27 | Maintainer string 28 | 29 | // Comments with information about dependencies. These need some more 30 | // parsing because some `Pkgfile`s use commas to separate dependencies, and 31 | // others use spaces. 32 | Depends []string 33 | Optional []string 34 | 35 | // BASH variables with various information that is required in order to 36 | // build a package. 37 | Name string 38 | Version string 39 | Release string 40 | 41 | // A BASH array with the sources needed to build a package. We probably need 42 | // to parse this by actually using `source(1)` because `Pkgfile`s often use 43 | // BASH variables (such as `$name` or `$version`) and bashisms in the source 44 | // variable. 45 | Source []string 46 | } 47 | 48 | // Parse parses the `Pkgfile` file of a port and populates the various fields in 49 | // the given `*Pkgfile`. Keep in mind that this does not expand BASH ariables by 50 | // default. so `$version` will just be a literal string. Nor does this parse the 51 | // `source` field of a `Pkgfile` because it often uses variables in the string 52 | // and because it's simply too hard too parse. 53 | // 54 | // If you want to expand BASH variables pass a bool as a parameter. This will 55 | // force the use of a bash interpreter to get the variables in `Pkgfile`, this 56 | // is relatively slow. 57 | func (f *Pkgfile) Parse(strict ...bool) error { 58 | r, err := os.Open(path.Join(f.Location.Full(), "Pkgfile")) 59 | if err != nil { 60 | return fmt.Errorf("could not open `%s/Pkgfile`", f.Location.Full()) 61 | } 62 | defer r.Close() 63 | s := bufio.NewScanner(r) 64 | 65 | for s.Scan() { 66 | i := s.Text() 67 | 68 | if strings.HasPrefix(i, "#") { 69 | kv := strings.SplitN(i, ":", 2) 70 | 71 | switch kv[0] { 72 | case "# Description": 73 | f.Description = strings.TrimSpace(kv[1]) 74 | case "# URL": 75 | f.URL = strings.TrimSpace(kv[1]) 76 | case "# Maintainer": 77 | f.Maintainer = strings.TrimSpace(kv[1]) 78 | case "# Depends on": 79 | f.Depends = strings.Fields(strings.Replace(strings.TrimSpace( 80 | kv[1]), ",", "", -1)) 81 | case "# Optional": 82 | case "# Nice to have": 83 | f.Optional = strings.Fields(strings.Replace(strings.TrimSpace( 84 | kv[1]), ",", "", -1)) 85 | } 86 | } else { 87 | if len(strict) > 0 { 88 | break 89 | } 90 | 91 | kv := strings.SplitN(i, "=", 2) 92 | 93 | switch kv[0] { 94 | case "name": 95 | f.Name = strings.TrimSpace(kv[1]) 96 | case "version": 97 | f.Version = strings.TrimSpace(kv[1]) 98 | case "release": 99 | f.Release = strings.TrimSpace(kv[1]) 100 | 101 | // Since `release` should be the last meaningfull value in a 102 | // `Pkgfile`, we will stop walking. There is `source` as well 103 | // hover, we will only parse this if the `strict` parameter has 104 | // been given. 105 | return nil 106 | } 107 | } 108 | } 109 | 110 | // We will only end up here if the `strict` paramenter has been given. We 111 | // will parse the `Pkgfile` using a bash interpreter. 112 | r.Seek(0, io.SeekStart) 113 | p, err := syntax.NewParser().Parse(r, path.Join(f.Location.Full(), 114 | "Pkgfile")) 115 | if err != nil { 116 | return fmt.Errorf("could not interpret `%s/Pkgfile`", f.Location.Full()) 117 | } 118 | i, _ := interp.New() 119 | if err := i.Run(context.TODO(), p); err != nil { 120 | return fmt.Errorf("could not interpret `%s/Pkgfile`", f.Location.Full()) 121 | } 122 | 123 | f.Name = i.Vars["name"].Str 124 | f.Version = i.Vars["version"].Str 125 | f.Release = i.Vars["release"].Str 126 | f.Source = i.Vars["source"].List 127 | 128 | return nil 129 | } 130 | 131 | // Validate checks if all required variables and functions are in a `Pkgfile` 132 | // file. 133 | // TODO: Check for `build()` function 134 | func (f *Pkgfile) Validate() error { 135 | if f.Name == "" { 136 | return fmt.Errorf("pkgfile %s: Name variable is empty", f.Location. 137 | Base()) 138 | } 139 | if f.Version == "" { 140 | return fmt.Errorf("pkgfile %s: Version variable is empty", f.Location. 141 | Base()) 142 | } 143 | if f.Release == "" { 144 | return fmt.Errorf("pkgfile %s: Release variable is empty", f.Location. 145 | Base()) 146 | } 147 | 148 | return nil 149 | } 150 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Go Report Card](https://goreportcard.com/badge/github.com/onodera-punpun/prt)](https://goreportcard.com/report/github.com/onodera-punpun/prt) 2 | 3 | *This project is currently in early alpha stage!* 4 | 5 | prt - CRUX port utility written in Go, aiming to replace prt-get, ports, and 6 | some pkgutils (on my machine) 7 | 8 | 9 | ## SYNOPSIS 10 | 11 | prt command [arguments] 12 | 13 | 14 | ## DESCRIPTION 15 | 16 | prt is like `prt-get(8)` a port/package management utility which provides 17 | additional functionality to the CRUX pkgutils. In addition to that it also 18 | strives to replace the CRUX pkgutils in Go. It works with the local ports tree 19 | and is therefore fully compatible with `ports(8)`, `pkgmk(8)`, `pkgadd(8)` and 20 | of course `prt-get(8)`. It offers the following features: 21 | 22 | * Listing dependencies of ports recursively, with an optional flag to print 23 | using tree view. 24 | * Generating graphs of port dependencies 25 | * Listing outdated package, by comparing port versions with the installed 26 | version 27 | * Easily printing port information such as the maintainer, version, release, et 28 | cetera 29 | * Install ports and their dependencies with a single command 30 | * List ports, with optional flags to also only list installed ports, print with 31 | repo information or to print with additional version information 32 | * Print the location of a port 33 | * Searching through files ports provide, with an optional flag to only search 34 | through installed ports 35 | * Pull in ports using `git(1)` 36 | * Update outdated packages 37 | * Uninstall installed packages 38 | 39 | Like said before, unlike `prt-get(8)`, prt reimplements `pkgmk(8)`/`pkgadd(8)` 40 | fully in Go. This is mostly for more control. Like `prt-get` it does provide 41 | some nice extra functionality such as listing and installing dependencies, 42 | getting the location of a port, aliasing ports (for example `core/openssl` to 43 | `6c37-dropin/libressl`), and ordering ports with the same name depending on how 44 | "important" the repo is the port resides in. 45 | 46 | There are a few differences, for example, unlike `prt-get(8)` you need to be in 47 | the port's directory for most commands to work, like how `pkgmk(8)` works. This 48 | has a few advantages, for example you can quickly download a port anywhere on 49 | the filesystem, and install it and its dependencies using `prt install`. Because 50 | `prt-get depinst` needs a port name, you can *only* install ports that are 51 | located in a predefined `prtdir`. 52 | 53 | Another difference with `prt-get(8)` is that prt does not use a cache file, 54 | while still being nearly as fast or faster in some cases. 55 | 56 | Aliasing is also handeled a bit different. `prt-get(8)` aliases ports based on 57 | name, but prt on name and repo. This makes it possible to alias `foo/bar` to 58 | `baz/bar`. 59 | 60 | 61 | ## COMMANDS 62 | 63 | The prt syntax is inspired by `prt-get(8)`, `git(8)` and `go(8)`, and thus uses 64 | so called commands which always have to be the first non-option argument passed. 65 | The commands are: 66 | 67 | `depends` list dependencies recursively, 68 | 69 | `diff` list outdated packages 70 | 71 | `info` print port information 72 | 73 | `install` build and install ports and their dependencies 74 | 75 | `list` list porst and packages 76 | 77 | `loc` print port locations 78 | 79 | `prov` search ports for files 80 | 81 | `pull` pull in ports 82 | 83 | `sysup` update outdated packages 84 | 85 | `uninstall` uninstall packages 86 | 87 | `help` print help and exit 88 | 89 | 90 | ## INSTALLATION 91 | 92 | https://github.com/onodera-punpun/crux-ports/blob/master/prt/Pkgfile 93 | 94 | Make sure to check `/etc/prt/config.toml` after installation and edit values to 95 | fit your needs and setup. 96 | 97 | If you use `fish` a `cd` wrapper for `prt loc` will also be installed, and some 98 | handy completions. 99 | 100 | 101 | ## TODO 102 | 103 | - [x] Implement `depends` command. 104 | - [x] Implement `diff` command. 105 | - [x] Implement `info` command. *(This always prints something, even when not in 106 | a port directory...)* 107 | - [x] Implement `graph` command. 108 | - [ ] Implement `install` command. 109 | - [x] Implement `list` command. 110 | - [x] Implement `loc` command. 111 | - [ ] Implement `patch` command. 112 | - [x] Implement `prov` command. 113 | - [x] Implement `pull` command. 114 | - [ ] Implement `sysup` command. 115 | - [ ] Implement `uninstall` command. 116 | 117 | --- 118 | 119 | - [x] Convert `pkgmk` `get_filename` function to Go. *(so uhh, `pkgmk` does 120 | something with "absolute paths", do I need this as well?)* 121 | - [x] Convert `pkgmk` `get_basename` function to Go. 122 | - [x] Convert `pkgmk` `check_pkgfile` function to Go. 123 | - [x] Convert `pkgmk` `check_directory` function to Go. 124 | - [x] Convert `pkgmk` `check_file` function to Go. 125 | - [x] Convert `pkgmk` `download_file` function to Go. *(`curl` is still used, is 126 | there some pure Go implementation?)* 127 | - [x] Convert `pkgmk` `download_source` function to Go. 128 | - [x] Convert `pkgmk` `unpack_source` function to Go. *(some `Pkgfile`s create 129 | their own unpack functions, I still need to detect and use those.)* 130 | - [x] Convert `pkgmk` `make_md5sum` function to Go. 131 | - [ ] Convert `pkgmk` `make_footprint` function to Go. 132 | - [x] Convert `pkgmk` `check_md5sum` function to Go. 133 | - [x] Convert `pkgmk` `check_signature` function to Go. *(`signify` is still 134 | used, is there some pure Go implementation?)* 135 | - [ ] Convert `pkgmk` `make_signature` function to Go. 136 | - [ ] Convert `pkgmk` `strip_files` function to Go. 137 | - [ ] Convert `pkgmk` `compress_manpages` function to Go. 138 | - [ ] Convert `pkgmk` `check_footprint` function to Go. 139 | - [x] Convert `pkgmk` `make_work_dir` function to Go. 140 | - [x] Convert `pkgmk` `remove_work_dir` function to Go. 141 | - [ ] Convert `pkgmk` `install_package` function to Go. 142 | - [x] Convert `pkgmk` `clean` function to Go. *(not going to implement, there is 143 | `rm`)* 144 | 145 | --- 146 | 147 | - [x] Write fish `cdp` function. 148 | - [x] Write bash `cdp` function. *(need to actually test this)* 149 | - [x] Write fish completions. 150 | - [ ] Write bash completions. 151 | 152 | --- 153 | 154 | - [ ] Write tests. 155 | - [ ] Make errors pretty and consistent. 156 | - [ ] Test environment variables. 157 | - [x] Write README and man pages. *(needs some updates with changes)* 158 | - [ ] Check for missing config values. 159 | 160 | 161 | ## AUTHORS 162 | 163 | Camille Scholtz 164 | -------------------------------------------------------------------------------- /ports/make.go: -------------------------------------------------------------------------------- 1 | package ports 2 | 3 | import ( 4 | "os" 5 | "path" 6 | ) 7 | 8 | // TODO: Move Download function from prt. 9 | // TODO: Move Unpack function from prt. 10 | 11 | // CreateWrk creates the necessary WrkDir directories. 12 | func (p Port) CreateWrk() error { 13 | if err := os.MkdirAll(path.Join(WrkDir, p.Pkgfile.Name, "pkg"), 14 | 0777); err != nil { 15 | return err 16 | } 17 | if err := os.MkdirAll(path.Join(WrkDir, p.Pkgfile.Name, "src"), 18 | 0777); err != nil { 19 | return err 20 | } 21 | 22 | return nil 23 | } 24 | 25 | // CleanWrk removes the necessary WrkDir directories. 26 | /*func (p Port) CleanWrk() error { 27 | if err := os.RemoveAll(path.Join(config.WrkDir, 28 | p.Pkgfile.Name)); err != nil { 29 | return err 30 | } 31 | 32 | // Temp directory used by some functions. 33 | if err := os.RemoveAll("/tmp/prt"); err != nil { 34 | return err 35 | } 36 | 37 | return nil 38 | }*/ 39 | 40 | /* 41 | // checkSignature checks the .signature file. 42 | // TODO: Rewrite this. 43 | func (p Port) checkSignature() error { 44 | sl := p.Pkgfile.Source 45 | sort.Sort(byBase(sl)) 46 | 47 | // Prepend Pkgfile and .footprint to sources. 48 | sl = append([]string{"Pkgfile", ".footprint"}, sl...) 49 | 50 | for _, s := range sl { 51 | r := regexp.MustCompile("^(http|https|ftp|file)://") 52 | if r.MatchString(s) { 53 | s = path.Join(config.SrcDir, path.Base(s)) 54 | } else { 55 | s = path.Join(p.Location, path.Base(s)) 56 | } 57 | 58 | if err := os.Symlink(s, path.Join("/tmp/prt/"+path.Base(s))); err != 59 | nil { 60 | return err 61 | } 62 | } 63 | 64 | // TODO: Do this in Go. 65 | cmd := exec.Command("signify", "-q", "-C", "-x", path.Join(p.Location, 66 | ".signature")) 67 | cmd.Dir = "/tmp/prt" 68 | var b bytes.Buffer 69 | cmd.Stderr = &b 70 | 71 | if err := cmd.Run(); err != nil { 72 | for _, l := range strings.Split(b.String(), "\n") { 73 | if len(l) == 0 { 74 | continue 75 | } 76 | 77 | printe("Mismatch " + strings.Trim(l, ": FAIL")) 78 | } 79 | return fmt.Errorf("pkgmk signature %s: verification failed", 80 | p.getBaseDir()) 81 | } 82 | 83 | return nil 84 | } 85 | 86 | // install installs a package. 87 | func (p port) install(v bool) error { 88 | cmd := exec.Command("/usr/share/prt/pkgmk", "-io") 89 | cmd.Dir = p.Location 90 | if v { 91 | cmd.Stdout = os.Stdout 92 | cmd.Stderr = os.Stderr 93 | } 94 | 95 | if err := cmd.Run(); err != nil { 96 | return fmt.Errorf("install %s: Something went wrong", p.getBaseDir()) 97 | } 98 | 99 | return nil 100 | } 101 | 102 | // md5sum checks the .md5sum file. 103 | func (p port) md5sum() error { 104 | // Only check md5sum if there is no signature. 105 | // TODO 106 | //if p.Signature != nil { 107 | // return nil 108 | //} 109 | 110 | // Check .md5sum if it exists, else create it. 111 | if _, err := os.Stat(path.Join(p.Location, 112 | ".md5sum")); err == nil { 113 | printi("Checking md5sum") 114 | if err := p.checkMd5sum(); err != nil { 115 | return err 116 | } 117 | } else { 118 | printi("Creating md5sum") 119 | if err := p.createMd5sum(p.Location); err != nil { 120 | return err 121 | } 122 | } 123 | 124 | return nil 125 | } 126 | 127 | // post runs a pre-install scripts. 128 | func (p port) post(v bool) error { 129 | if _, err := os.Stat(path.Join(p.Location, 130 | "post-install")); err != nil { 131 | return nil 132 | } 133 | 134 | cmd := exec.Command("bash", "./post-install") 135 | cmd.Dir = p.Location 136 | if v { 137 | cmd.Stdout = os.Stdout 138 | cmd.Stderr = os.Stderr 139 | } 140 | 141 | printi("Running post-install") 142 | if err := cmd.Run(); err != nil { 143 | return fmt.Errorf( 144 | "pkgmk post %s: Something went wrong", p.getBaseDir()) 145 | } 146 | 147 | return nil 148 | } 149 | 150 | // pre runs a pre-install scripts. 151 | func (p port) pre(v bool) error { 152 | if _, err := os.Stat(path.Join(p.Location, "pre-install")); err != nil { 153 | return nil 154 | } 155 | 156 | cmd := exec.Command("bash", "./pre-install") 157 | cmd.Dir = p.Location 158 | if v { 159 | cmd.Stdout = os.Stdout 160 | cmd.Stderr = os.Stderr 161 | } 162 | 163 | printi("Running pre-install") 164 | if err := cmd.Run(); err != nil { 165 | return fmt.Errorf( 166 | "pkgmk pre %s: Something went wrong", p.getBaseDir()) 167 | } 168 | 169 | return nil 170 | } 171 | 172 | // uninstall uninstalls a package. 173 | // TODO: Rewrite this. 174 | func pkgUninstall(todo string) error { 175 | cmd := exec.Command("pkgrm", todo) 176 | 177 | if err := cmd.Run(); err != nil { 178 | return fmt.Errorf( 179 | "pkgmk uninstall %s: Something went wrong", todo) 180 | } 181 | 182 | return nil 183 | } 184 | 185 | // unpack unpacks a port sources. 186 | // TODO: Don't run this if the Pkgfile has its own unpack function. 187 | // TODO: Or should I, it's a lot of added complexity for basically just 188 | // the Go port, I could try to rewrite that port. 189 | func (p port) unpack() error { 190 | sl := p.Pkgfile.Source 191 | sort.Sort(byBase(sl)) 192 | 193 | // Unpack sources. 194 | for _, s := range sl { 195 | printi("Unpacking " + path.Base(s)) 196 | 197 | for _, ff := range archiver.SupportedFormats { 198 | if !ff.Match(path.Base(s)) { 199 | continue 200 | } 201 | 202 | if err := ff.Open(path.Join(config.SrcDir, path.Base(s)), path.Join(config.WrkDir, path.Base(p.Location), "src")); err != nil { 203 | return err 204 | } 205 | continue 206 | } 207 | 208 | // TODO: Make this missing. 209 | f, _ := os.Open(path.Join(p.Location, path.Base(s))) 210 | defer f.Close() 211 | 212 | d, err := os.Create(path.Join(path.Join(config.WrkDir, path.Base(p.Location), "src"), path.Base(s))) 213 | if err != nil { 214 | return err 215 | } 216 | 217 | io.Copy(d, f) 218 | d.Close() 219 | } 220 | 221 | return nil 222 | } 223 | 224 | // update updates a package. 225 | func (p port) update(v bool) error { 226 | cmd := exec.Command("/usr/share/prt/pkgmk", "-uo") 227 | cmd.Dir = p.Location 228 | if v { 229 | cmd.Stdout = os.Stdout 230 | cmd.Stderr = os.Stderr 231 | } 232 | 233 | if err := cmd.Run(); err != nil { 234 | return fmt.Errorf( 235 | "update %s: Something went wrong", p.getBaseDir()) 236 | } 237 | 238 | return nil 239 | } 240 | 241 | // pkgmk is a wrapper for all the functions in pkgmk.go. 242 | func (p port) pkgmk(inst []string, v bool) error { 243 | if err := checkDir(); err != nil { 244 | return err 245 | } 246 | if err := p.checkPkgfile(); err != nil { 247 | return err 248 | } 249 | if err := p.createWrk(); err != nil { 250 | return err 251 | } 252 | defer p.cleanWrk() 253 | if err := p.pre(v); err != nil { 254 | return err 255 | } 256 | if err := p.download(v); err != nil { 257 | return err 258 | } 259 | if err := p.md5sum(); err != nil { 260 | return err 261 | } 262 | /* 263 | if err := p.unpack(); err != nil { 264 | return err 265 | } 266 | if !stringInList(path.Base(p.Location), inst) { 267 | if err := p.build(v); err != nil { 268 | return err 269 | } 270 | } 271 | if stringInList(path.Base(p.Location), inst) { 272 | printi("Updating package") 273 | if err := p.update(v); err != nil { 274 | return err 275 | } 276 | } else { 277 | printi("Installing package") 278 | if err := p.install(v); err != nil { 279 | return err 280 | } 281 | } 282 | if err := p.post(v); err != nil { 283 | return err 284 | } 285 | */ 286 | /* 287 | return nil 288 | } 289 | */ 290 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= 2 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 3 | github.com/ahmetalpbalkan/go-cursor v0.0.0-20131010032410-8136607ea412 h1:vOVO0ypMfTt6tZacyI0kp+iCZb1XSNiYDqnzBWYgfe4= 4 | github.com/ahmetalpbalkan/go-cursor v0.0.0-20131010032410-8136607ea412/go.mod h1:AI9hp1tkp10pAlK5TCwL+7yWbRgtDm9jhToq6qij2xs= 5 | github.com/cavaliercoder/grab v1.0.0 h1:H6VQ1NiLO7AvXM6ZyaInnoZrRLeo2FoUTQEcXln4bvQ= 6 | github.com/cavaliercoder/grab v2.0.0+incompatible h1:wZHbBQx56+Yxjx2TCGDcenhh3cJn7cCLMfkEPmySTSE= 7 | github.com/cavaliercoder/grab v2.0.0+incompatible/go.mod h1:tTBkfNqSBfuMmMBFaO2phgyhdYhiZQ/+iXCZDzcDsMI= 8 | github.com/cavaliercoder/grab v2.0.1-0.20191026232651-4bc25e148ae7+incompatible h1:H9GnHTWAp9pi05PNR93PcQ6zp/SBFAgi96jxlzPkk9Q= 9 | github.com/cavaliercoder/grab v2.0.1-0.20191026232651-4bc25e148ae7+incompatible/go.mod h1:tTBkfNqSBfuMmMBFaO2phgyhdYhiZQ/+iXCZDzcDsMI= 10 | github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= 11 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 12 | github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= 13 | github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= 14 | github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= 15 | github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= 16 | github.com/go2c/optparse v0.1.0 h1:JnZxpex05iIRq/byON8X22sN2WIEnIo9lTk8r8dP6+I= 17 | github.com/go2c/optparse v0.1.0/go.mod h1:ePMw9vqVohKMXeXPiAn/OIkA2nOU36Rj3919EtWbkTU= 18 | github.com/hacdias/fileutils v1.0.0 h1:wMcgj/wlNGWdfQtQxTp2kHO1MBVZq+u+7Iu1QCYMU+Y= 19 | github.com/hacdias/fileutils v1.0.0/go.mod h1:UuwDYEj+fnZ43U+ac40q16vXiWO7vehkiKOQGOgRpGg= 20 | github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= 21 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 22 | github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= 23 | github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= 24 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 25 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= 26 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 27 | github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 28 | github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 29 | github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac= 30 | github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= 31 | github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= 32 | github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= 33 | github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE= 34 | github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= 35 | github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= 36 | github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM= 37 | github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= 38 | github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= 39 | github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= 40 | github.com/onodera-punpun/go-utils v0.0.0-20180621190137-c8f4b6634a29 h1:BPYMZwN82xeV5rY+3RrSzdUJkQ1VftgwS5sfdVKc0bU= 41 | github.com/onodera-punpun/go-utils v0.0.0-20180621190137-c8f4b6634a29/go.mod h1:lm1rKj/E44gY5yXovfmcOShvKKrDmyviPQXG/a9Zrz0= 42 | github.com/pkg/diff v0.0.0-20190930165518-531926345625/go.mod h1:kFj35MyHn14a6pIgWhm46KVjJr5CHys3eEYxkuKD1EI= 43 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 44 | github.com/rogpeppe/go-internal v1.5.0/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= 45 | github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= 46 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 47 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 48 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 49 | golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc h1:c0o/qxkaO2LF5t6fQrT4b5hzyggAkLLlCUjqfRxd8Q4= 50 | golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 51 | golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d h1:1ZiEyfaQIg3Qh0EoqpwAakHVhecoE5wlSg5GjnafJGw= 52 | golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 53 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 54 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= 55 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 56 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 57 | golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 58 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 59 | golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 60 | golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4= 61 | golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 62 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 63 | golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8= 64 | golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 65 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 66 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA= 67 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 68 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= 69 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 70 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 71 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 72 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 73 | gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= 74 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 75 | mvdan.cc/editorconfig v0.1.1-0.20191109213504-890940e3f00e/go.mod h1:Ge4atmRUYqueGppvJ7JNrtqpqokoJEFxYbP0Z+WeKS8= 76 | mvdan.cc/sh v1.3.1 h1:UxMLpJPEnVj8hmGWCD3kgC5Toem3A3VuDliExsENI7E= 77 | mvdan.cc/sh v2.6.4+incompatible h1:eD6tDeh0pw+/TOTI1BBEryZ02rD2nMcFsgcvde7jffM= 78 | mvdan.cc/sh/v3 v3.0.2 h1:NU+UpTZHRdIZ9igRo8zi/7+5/NpetYlhlyDhz1/AdMM= 79 | mvdan.cc/sh/v3 v3.0.2/go.mod h1:rBIndNJFYPp8xSppiZcGIk6B5d1g3OEARxEaXjPxwVI= 80 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | ### GNU GENERAL PUBLIC LICENSE 2 | 3 | Version 3, 29 June 2007 4 | 5 | Copyright (C) 2007 Free Software Foundation, Inc. 6 | 7 | 8 | Everyone is permitted to copy and distribute verbatim copies of this 9 | license document, but changing it is not allowed. 10 | 11 | ### Preamble 12 | 13 | The GNU General Public License is a free, copyleft license for 14 | software and other kinds of works. 15 | 16 | The licenses for most software and other practical works are designed 17 | to take away your freedom to share and change the works. By contrast, 18 | the GNU General Public License is intended to guarantee your freedom 19 | to share and change all versions of a program--to make sure it remains 20 | free software for all its users. We, the Free Software Foundation, use 21 | the GNU General Public License for most of our software; it applies 22 | also to any other work released this way by its authors. You can apply 23 | it to your programs, too. 24 | 25 | When we speak of free software, we are referring to freedom, not 26 | price. Our General Public Licenses are designed to make sure that you 27 | have the freedom to distribute copies of free software (and charge for 28 | them if you wish), that you receive source code or can get it if you 29 | want it, that you can change the software or use pieces of it in new 30 | free programs, and that you know you can do these things. 31 | 32 | To protect your rights, we need to prevent others from denying you 33 | these rights or asking you to surrender the rights. Therefore, you 34 | have certain responsibilities if you distribute copies of the 35 | software, or if you modify it: responsibilities to respect the freedom 36 | of others. 37 | 38 | For example, if you distribute copies of such a program, whether 39 | gratis or for a fee, you must pass on to the recipients the same 40 | freedoms that you received. You must make sure that they, too, receive 41 | or can get the source code. And you must show them these terms so they 42 | know their rights. 43 | 44 | Developers that use the GNU GPL protect your rights with two steps: 45 | (1) assert copyright on the software, and (2) offer you this License 46 | giving you legal permission to copy, distribute and/or modify it. 47 | 48 | For the developers' and authors' protection, the GPL clearly explains 49 | that there is no warranty for this free software. For both users' and 50 | authors' sake, the GPL requires that modified versions be marked as 51 | changed, so that their problems will not be attributed erroneously to 52 | authors of previous versions. 53 | 54 | Some devices are designed to deny users access to install or run 55 | modified versions of the software inside them, although the 56 | manufacturer can do so. This is fundamentally incompatible with the 57 | aim of protecting users' freedom to change the software. The 58 | systematic pattern of such abuse occurs in the area of products for 59 | individuals to use, which is precisely where it is most unacceptable. 60 | Therefore, we have designed this version of the GPL to prohibit the 61 | practice for those products. If such problems arise substantially in 62 | other domains, we stand ready to extend this provision to those 63 | domains in future versions of the GPL, as needed to protect the 64 | freedom of users. 65 | 66 | Finally, every program is threatened constantly by software patents. 67 | States should not allow patents to restrict development and use of 68 | software on general-purpose computers, but in those that do, we wish 69 | to avoid the special danger that patents applied to a free program 70 | could make it effectively proprietary. To prevent this, the GPL 71 | assures that patents cannot be used to render the program non-free. 72 | 73 | The precise terms and conditions for copying, distribution and 74 | modification follow. 75 | 76 | ### TERMS AND CONDITIONS 77 | 78 | #### 0. Definitions. 79 | 80 | "This License" refers to version 3 of the GNU General Public License. 81 | 82 | "Copyright" also means copyright-like laws that apply to other kinds 83 | of works, such as semiconductor masks. 84 | 85 | "The Program" refers to any copyrightable work licensed under this 86 | License. Each licensee is addressed as "you". "Licensees" and 87 | "recipients" may be individuals or organizations. 88 | 89 | To "modify" a work means to copy from or adapt all or part of the work 90 | in a fashion requiring copyright permission, other than the making of 91 | an exact copy. The resulting work is called a "modified version" of 92 | the earlier work or a work "based on" the earlier work. 93 | 94 | A "covered work" means either the unmodified Program or a work based 95 | on the Program. 96 | 97 | To "propagate" a work means to do anything with it that, without 98 | permission, would make you directly or secondarily liable for 99 | infringement under applicable copyright law, except executing it on a 100 | computer or modifying a private copy. Propagation includes copying, 101 | distribution (with or without modification), making available to the 102 | public, and in some countries other activities as well. 103 | 104 | To "convey" a work means any kind of propagation that enables other 105 | parties to make or receive copies. Mere interaction with a user 106 | through a computer network, with no transfer of a copy, is not 107 | conveying. 108 | 109 | An interactive user interface displays "Appropriate Legal Notices" to 110 | the extent that it includes a convenient and prominently visible 111 | feature that (1) displays an appropriate copyright notice, and (2) 112 | tells the user that there is no warranty for the work (except to the 113 | extent that warranties are provided), that licensees may convey the 114 | work under this License, and how to view a copy of this License. If 115 | the interface presents a list of user commands or options, such as a 116 | menu, a prominent item in the list meets this criterion. 117 | 118 | #### 1. Source Code. 119 | 120 | The "source code" for a work means the preferred form of the work for 121 | making modifications to it. "Object code" means any non-source form of 122 | a work. 123 | 124 | A "Standard Interface" means an interface that either is an official 125 | standard defined by a recognized standards body, or, in the case of 126 | interfaces specified for a particular programming language, one that 127 | is widely used among developers working in that language. 128 | 129 | The "System Libraries" of an executable work include anything, other 130 | than the work as a whole, that (a) is included in the normal form of 131 | packaging a Major Component, but which is not part of that Major 132 | Component, and (b) serves only to enable use of the work with that 133 | Major Component, or to implement a Standard Interface for which an 134 | implementation is available to the public in source code form. A 135 | "Major Component", in this context, means a major essential component 136 | (kernel, window system, and so on) of the specific operating system 137 | (if any) on which the executable work runs, or a compiler used to 138 | produce the work, or an object code interpreter used to run it. 139 | 140 | The "Corresponding Source" for a work in object code form means all 141 | the source code needed to generate, install, and (for an executable 142 | work) run the object code and to modify the work, including scripts to 143 | control those activities. However, it does not include the work's 144 | System Libraries, or general-purpose tools or generally available free 145 | programs which are used unmodified in performing those activities but 146 | which are not part of the work. For example, Corresponding Source 147 | includes interface definition files associated with source files for 148 | the work, and the source code for shared libraries and dynamically 149 | linked subprograms that the work is specifically designed to require, 150 | such as by intimate data communication or control flow between those 151 | subprograms and other parts of the work. 152 | 153 | The Corresponding Source need not include anything that users can 154 | regenerate automatically from other parts of the Corresponding Source. 155 | 156 | The Corresponding Source for a work in source code form is that same 157 | work. 158 | 159 | #### 2. Basic Permissions. 160 | 161 | All rights granted under this License are granted for the term of 162 | copyright on the Program, and are irrevocable provided the stated 163 | conditions are met. This License explicitly affirms your unlimited 164 | permission to run the unmodified Program. The output from running a 165 | covered work is covered by this License only if the output, given its 166 | content, constitutes a covered work. This License acknowledges your 167 | rights of fair use or other equivalent, as provided by copyright law. 168 | 169 | You may make, run and propagate covered works that you do not convey, 170 | without conditions so long as your license otherwise remains in force. 171 | You may convey covered works to others for the sole purpose of having 172 | them make modifications exclusively for you, or provide you with 173 | facilities for running those works, provided that you comply with the 174 | terms of this License in conveying all material for which you do not 175 | control copyright. Those thus making or running the covered works for 176 | you must do so exclusively on your behalf, under your direction and 177 | control, on terms that prohibit them from making any copies of your 178 | copyrighted material outside their relationship with you. 179 | 180 | Conveying under any other circumstances is permitted solely under the 181 | conditions stated below. Sublicensing is not allowed; section 10 makes 182 | it unnecessary. 183 | 184 | #### 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 185 | 186 | No covered work shall be deemed part of an effective technological 187 | measure under any applicable law fulfilling obligations under article 188 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 189 | similar laws prohibiting or restricting circumvention of such 190 | measures. 191 | 192 | When you convey a covered work, you waive any legal power to forbid 193 | circumvention of technological measures to the extent such 194 | circumvention is effected by exercising rights under this License with 195 | respect to the covered work, and you disclaim any intention to limit 196 | operation or modification of the work as a means of enforcing, against 197 | the work's users, your or third parties' legal rights to forbid 198 | circumvention of technological measures. 199 | 200 | #### 4. Conveying Verbatim Copies. 201 | 202 | You may convey verbatim copies of the Program's source code as you 203 | receive it, in any medium, provided that you conspicuously and 204 | appropriately publish on each copy an appropriate copyright notice; 205 | keep intact all notices stating that this License and any 206 | non-permissive terms added in accord with section 7 apply to the code; 207 | keep intact all notices of the absence of any warranty; and give all 208 | recipients a copy of this License along with the Program. 209 | 210 | You may charge any price or no price for each copy that you convey, 211 | and you may offer support or warranty protection for a fee. 212 | 213 | #### 5. Conveying Modified Source Versions. 214 | 215 | You may convey a work based on the Program, or the modifications to 216 | produce it from the Program, in the form of source code under the 217 | terms of section 4, provided that you also meet all of these 218 | conditions: 219 | 220 | - a) The work must carry prominent notices stating that you modified 221 | it, and giving a relevant date. 222 | - b) The work must carry prominent notices stating that it is 223 | released under this License and any conditions added under 224 | section 7. This requirement modifies the requirement in section 4 225 | to "keep intact all notices". 226 | - c) You must license the entire work, as a whole, under this 227 | License to anyone who comes into possession of a copy. This 228 | License will therefore apply, along with any applicable section 7 229 | additional terms, to the whole of the work, and all its parts, 230 | regardless of how they are packaged. This License gives no 231 | permission to license the work in any other way, but it does not 232 | invalidate such permission if you have separately received it. 233 | - d) If the work has interactive user interfaces, each must display 234 | Appropriate Legal Notices; however, if the Program has interactive 235 | interfaces that do not display Appropriate Legal Notices, your 236 | work need not make them do so. 237 | 238 | A compilation of a covered work with other separate and independent 239 | works, which are not by their nature extensions of the covered work, 240 | and which are not combined with it such as to form a larger program, 241 | in or on a volume of a storage or distribution medium, is called an 242 | "aggregate" if the compilation and its resulting copyright are not 243 | used to limit the access or legal rights of the compilation's users 244 | beyond what the individual works permit. Inclusion of a covered work 245 | in an aggregate does not cause this License to apply to the other 246 | parts of the aggregate. 247 | 248 | #### 6. Conveying Non-Source Forms. 249 | 250 | You may convey a covered work in object code form under the terms of 251 | sections 4 and 5, provided that you also convey the machine-readable 252 | Corresponding Source under the terms of this License, in one of these 253 | ways: 254 | 255 | - a) Convey the object code in, or embodied in, a physical product 256 | (including a physical distribution medium), accompanied by the 257 | Corresponding Source fixed on a durable physical medium 258 | customarily used for software interchange. 259 | - b) Convey the object code in, or embodied in, a physical product 260 | (including a physical distribution medium), accompanied by a 261 | written offer, valid for at least three years and valid for as 262 | long as you offer spare parts or customer support for that product 263 | model, to give anyone who possesses the object code either (1) a 264 | copy of the Corresponding Source for all the software in the 265 | product that is covered by this License, on a durable physical 266 | medium customarily used for software interchange, for a price no 267 | more than your reasonable cost of physically performing this 268 | conveying of source, or (2) access to copy the Corresponding 269 | Source from a network server at no charge. 270 | - c) Convey individual copies of the object code with a copy of the 271 | written offer to provide the Corresponding Source. This 272 | alternative is allowed only occasionally and noncommercially, and 273 | only if you received the object code with such an offer, in accord 274 | with subsection 6b. 275 | - d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | - e) Convey the object code using peer-to-peer transmission, 288 | provided you inform other peers where the object code and 289 | Corresponding Source of the work are being offered to the general 290 | public at no charge under subsection 6d. 291 | 292 | A separable portion of the object code, whose source code is excluded 293 | from the Corresponding Source as a System Library, need not be 294 | included in conveying the object code work. 295 | 296 | A "User Product" is either (1) a "consumer product", which means any 297 | tangible personal property which is normally used for personal, 298 | family, or household purposes, or (2) anything designed or sold for 299 | incorporation into a dwelling. In determining whether a product is a 300 | consumer product, doubtful cases shall be resolved in favor of 301 | coverage. For a particular product received by a particular user, 302 | "normally used" refers to a typical or common use of that class of 303 | product, regardless of the status of the particular user or of the way 304 | in which the particular user actually uses, or expects or is expected 305 | to use, the product. A product is a consumer product regardless of 306 | whether the product has substantial commercial, industrial or 307 | non-consumer uses, unless such uses represent the only significant 308 | mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to 312 | install and execute modified versions of a covered work in that User 313 | Product from a modified version of its Corresponding Source. The 314 | information must suffice to ensure that the continued functioning of 315 | the modified object code is in no case prevented or interfered with 316 | solely because modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or 331 | updates for a work that has been modified or installed by the 332 | recipient, or for the User Product in which it has been modified or 333 | installed. Access to a network may be denied when the modification 334 | itself materially and adversely affects the operation of the network 335 | or violates the rules and protocols for communication across the 336 | network. 337 | 338 | Corresponding Source conveyed, and Installation Information provided, 339 | in accord with this section must be in a format that is publicly 340 | documented (and with an implementation available to the public in 341 | source code form), and must require no special password or key for 342 | unpacking, reading or copying. 343 | 344 | #### 7. Additional Terms. 345 | 346 | "Additional permissions" are terms that supplement the terms of this 347 | License by making exceptions from one or more of its conditions. 348 | Additional permissions that are applicable to the entire Program shall 349 | be treated as though they were included in this License, to the extent 350 | that they are valid under applicable law. If additional permissions 351 | apply only to part of the Program, that part may be used separately 352 | under those permissions, but the entire Program remains governed by 353 | this License without regard to the additional permissions. 354 | 355 | When you convey a copy of a covered work, you may at your option 356 | remove any additional permissions from that copy, or from any part of 357 | it. (Additional permissions may be written to require their own 358 | removal in certain cases when you modify the work.) You may place 359 | additional permissions on material, added by you to a covered work, 360 | for which you have or can give appropriate copyright permission. 361 | 362 | Notwithstanding any other provision of this License, for material you 363 | add to a covered work, you may (if authorized by the copyright holders 364 | of that material) supplement the terms of this License with terms: 365 | 366 | - a) Disclaiming warranty or limiting liability differently from the 367 | terms of sections 15 and 16 of this License; or 368 | - b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | - c) Prohibiting misrepresentation of the origin of that material, 372 | or requiring that modified versions of such material be marked in 373 | reasonable ways as different from the original version; or 374 | - d) Limiting the use for publicity purposes of names of licensors 375 | or authors of the material; or 376 | - e) Declining to grant rights under trademark law for use of some 377 | trade names, trademarks, or service marks; or 378 | - f) Requiring indemnification of licensors and authors of that 379 | material by anyone who conveys the material (or modified versions 380 | of it) with contractual assumptions of liability to the recipient, 381 | for any liability that these contractual assumptions directly 382 | impose on those licensors and authors. 383 | 384 | All other non-permissive additional terms are considered "further 385 | restrictions" within the meaning of section 10. If the Program as you 386 | received it, or any part of it, contains a notice stating that it is 387 | governed by this License along with a term that is a further 388 | restriction, you may remove that term. If a license document contains 389 | a further restriction but permits relicensing or conveying under this 390 | License, you may add to a covered work material governed by the terms 391 | of that license document, provided that the further restriction does 392 | not survive such relicensing or conveying. 393 | 394 | If you add terms to a covered work in accord with this section, you 395 | must place, in the relevant source files, a statement of the 396 | additional terms that apply to those files, or a notice indicating 397 | where to find the applicable terms. 398 | 399 | Additional terms, permissive or non-permissive, may be stated in the 400 | form of a separately written license, or stated as exceptions; the 401 | above requirements apply either way. 402 | 403 | #### 8. Termination. 404 | 405 | You may not propagate or modify a covered work except as expressly 406 | provided under this License. Any attempt otherwise to propagate or 407 | modify it is void, and will automatically terminate your rights under 408 | this License (including any patent licenses granted under the third 409 | paragraph of section 11). 410 | 411 | However, if you cease all violation of this License, then your license 412 | from a particular copyright holder is reinstated (a) provisionally, 413 | unless and until the copyright holder explicitly and finally 414 | terminates your license, and (b) permanently, if the copyright holder 415 | fails to notify you of the violation by some reasonable means prior to 416 | 60 days after the cessation. 417 | 418 | Moreover, your license from a particular copyright holder is 419 | reinstated permanently if the copyright holder notifies you of the 420 | violation by some reasonable means, this is the first time you have 421 | received notice of violation of this License (for any work) from that 422 | copyright holder, and you cure the violation prior to 30 days after 423 | your receipt of the notice. 424 | 425 | Termination of your rights under this section does not terminate the 426 | licenses of parties who have received copies or rights from you under 427 | this License. If your rights have been terminated and not permanently 428 | reinstated, you do not qualify to receive new licenses for the same 429 | material under section 10. 430 | 431 | #### 9. Acceptance Not Required for Having Copies. 432 | 433 | You are not required to accept this License in order to receive or run 434 | a copy of the Program. Ancillary propagation of a covered work 435 | occurring solely as a consequence of using peer-to-peer transmission 436 | to receive a copy likewise does not require acceptance. However, 437 | nothing other than this License grants you permission to propagate or 438 | modify any covered work. These actions infringe copyright if you do 439 | not accept this License. Therefore, by modifying or propagating a 440 | covered work, you indicate your acceptance of this License to do so. 441 | 442 | #### 10. Automatic Licensing of Downstream Recipients. 443 | 444 | Each time you convey a covered work, the recipient automatically 445 | receives a license from the original licensors, to run, modify and 446 | propagate that work, subject to this License. You are not responsible 447 | for enforcing compliance by third parties with this License. 448 | 449 | An "entity transaction" is a transaction transferring control of an 450 | organization, or substantially all assets of one, or subdividing an 451 | organization, or merging organizations. If propagation of a covered 452 | work results from an entity transaction, each party to that 453 | transaction who receives a copy of the work also receives whatever 454 | licenses to the work the party's predecessor in interest had or could 455 | give under the previous paragraph, plus a right to possession of the 456 | Corresponding Source of the work from the predecessor in interest, if 457 | the predecessor has it or can get it with reasonable efforts. 458 | 459 | You may not impose any further restrictions on the exercise of the 460 | rights granted or affirmed under this License. For example, you may 461 | not impose a license fee, royalty, or other charge for exercise of 462 | rights granted under this License, and you may not initiate litigation 463 | (including a cross-claim or counterclaim in a lawsuit) alleging that 464 | any patent claim is infringed by making, using, selling, offering for 465 | sale, or importing the Program or any portion of it. 466 | 467 | #### 11. Patents. 468 | 469 | A "contributor" is a copyright holder who authorizes use under this 470 | License of the Program or a work on which the Program is based. The 471 | work thus licensed is called the contributor's "contributor version". 472 | 473 | A contributor's "essential patent claims" are all patent claims owned 474 | or controlled by the contributor, whether already acquired or 475 | hereafter acquired, that would be infringed by some manner, permitted 476 | by this License, of making, using, or selling its contributor version, 477 | but do not include claims that would be infringed only as a 478 | consequence of further modification of the contributor version. For 479 | purposes of this definition, "control" includes the right to grant 480 | patent sublicenses in a manner consistent with the requirements of 481 | this License. 482 | 483 | Each contributor grants you a non-exclusive, worldwide, royalty-free 484 | patent license under the contributor's essential patent claims, to 485 | make, use, sell, offer for sale, import and otherwise run, modify and 486 | propagate the contents of its contributor version. 487 | 488 | In the following three paragraphs, a "patent license" is any express 489 | agreement or commitment, however denominated, not to enforce a patent 490 | (such as an express permission to practice a patent or covenant not to 491 | sue for patent infringement). To "grant" such a patent license to a 492 | party means to make such an agreement or commitment not to enforce a 493 | patent against the party. 494 | 495 | If you convey a covered work, knowingly relying on a patent license, 496 | and the Corresponding Source of the work is not available for anyone 497 | to copy, free of charge and under the terms of this License, through a 498 | publicly available network server or other readily accessible means, 499 | then you must either (1) cause the Corresponding Source to be so 500 | available, or (2) arrange to deprive yourself of the benefit of the 501 | patent license for this particular work, or (3) arrange, in a manner 502 | consistent with the requirements of this License, to extend the patent 503 | license to downstream recipients. "Knowingly relying" means you have 504 | actual knowledge that, but for the patent license, your conveying the 505 | covered work in a country, or your recipient's use of the covered work 506 | in a country, would infringe one or more identifiable patents in that 507 | country that you have reason to believe are valid. 508 | 509 | If, pursuant to or in connection with a single transaction or 510 | arrangement, you convey, or propagate by procuring conveyance of, a 511 | covered work, and grant a patent license to some of the parties 512 | receiving the covered work authorizing them to use, propagate, modify 513 | or convey a specific copy of the covered work, then the patent license 514 | you grant is automatically extended to all recipients of the covered 515 | work and works based on it. 516 | 517 | A patent license is "discriminatory" if it does not include within the 518 | scope of its coverage, prohibits the exercise of, or is conditioned on 519 | the non-exercise of one or more of the rights that are specifically 520 | granted under this License. You may not convey a covered work if you 521 | are a party to an arrangement with a third party that is in the 522 | business of distributing software, under which you make payment to the 523 | third party based on the extent of your activity of conveying the 524 | work, and under which the third party grants, to any of the parties 525 | who would receive the covered work from you, a discriminatory patent 526 | license (a) in connection with copies of the covered work conveyed by 527 | you (or copies made from those copies), or (b) primarily for and in 528 | connection with specific products or compilations that contain the 529 | covered work, unless you entered into that arrangement, or that patent 530 | license was granted, prior to 28 March 2007. 531 | 532 | Nothing in this License shall be construed as excluding or limiting 533 | any implied license or other defenses to infringement that may 534 | otherwise be available to you under applicable patent law. 535 | 536 | #### 12. No Surrender of Others' Freedom. 537 | 538 | If conditions are imposed on you (whether by court order, agreement or 539 | otherwise) that contradict the conditions of this License, they do not 540 | excuse you from the conditions of this License. If you cannot convey a 541 | covered work so as to satisfy simultaneously your obligations under 542 | this License and any other pertinent obligations, then as a 543 | consequence you may not convey it at all. For example, if you agree to 544 | terms that obligate you to collect a royalty for further conveying 545 | from those to whom you convey the Program, the only way you could 546 | satisfy both those terms and this License would be to refrain entirely 547 | from conveying the Program. 548 | 549 | #### 13. Use with the GNU Affero General Public License. 550 | 551 | Notwithstanding any other provision of this License, you have 552 | permission to link or combine any covered work with a work licensed 553 | under version 3 of the GNU Affero General Public License into a single 554 | combined work, and to convey the resulting work. The terms of this 555 | License will continue to apply to the part which is the covered work, 556 | but the special requirements of the GNU Affero General Public License, 557 | section 13, concerning interaction through a network will apply to the 558 | combination as such. 559 | 560 | #### 14. Revised Versions of this License. 561 | 562 | The Free Software Foundation may publish revised and/or new versions 563 | of the GNU General Public License from time to time. Such new versions 564 | will be similar in spirit to the present version, but may differ in 565 | detail to address new problems or concerns. 566 | 567 | Each version is given a distinguishing version number. If the Program 568 | specifies that a certain numbered version of the GNU General Public 569 | License "or any later version" applies to it, you have the option of 570 | following the terms and conditions either of that numbered version or 571 | of any later version published by the Free Software Foundation. If the 572 | Program does not specify a version number of the GNU General Public 573 | License, you may choose any version ever published by the Free 574 | Software Foundation. 575 | 576 | If the Program specifies that a proxy can decide which future versions 577 | of the GNU General Public License can be used, that proxy's public 578 | statement of acceptance of a version permanently authorizes you to 579 | choose that version for the Program. 580 | 581 | Later license versions may give you additional or different 582 | permissions. However, no additional obligations are imposed on any 583 | author or copyright holder as a result of your choosing to follow a 584 | later version. 585 | 586 | #### 15. Disclaimer of Warranty. 587 | 588 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 589 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 590 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT 591 | WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT 592 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 593 | A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND 594 | PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE 595 | DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR 596 | CORRECTION. 597 | 598 | #### 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR 602 | CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 603 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES 604 | ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT 605 | NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR 606 | LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM 607 | TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER 608 | PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 609 | 610 | #### 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | ### How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these 626 | terms. 627 | 628 | To do so, attach the following notices to the program. It is safest to 629 | attach them to the start of each source file to most effectively state 630 | the exclusion of warranty; and each file should have at least the 631 | "copyright" line and a pointer to where the full notice is found. 632 | 633 | 634 | Copyright (C) 635 | 636 | This program is free software: you can redistribute it and/or modify 637 | it under the terms of the GNU General Public License as published by 638 | the Free Software Foundation, either version 3 of the License, or 639 | (at your option) any later version. 640 | 641 | This program is distributed in the hope that it will be useful, 642 | but WITHOUT ANY WARRANTY; without even the implied warranty of 643 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 644 | GNU General Public License for more details. 645 | 646 | You should have received a copy of the GNU General Public License 647 | along with this program. If not, see . 648 | 649 | Also add information on how to contact you by electronic and paper 650 | mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands \`show w' and \`show c' should show the 661 | appropriate parts of the General Public License. Of course, your 662 | program's commands might be different; for a GUI interface, you would 663 | use an "about box". 664 | 665 | You should also get your employer (if you work as a programmer) or 666 | school, if any, to sign a "copyright disclaimer" for the program, if 667 | necessary. For more information on this, and how to apply and follow 668 | the GNU GPL, see . 669 | 670 | The GNU General Public License does not permit incorporating your 671 | program into proprietary programs. If your program is a subroutine 672 | library, you may consider it more useful to permit linking proprietary 673 | applications with the library. If this is what you want to do, use the 674 | GNU Lesser General Public License instead of this License. But first, 675 | please read . 676 | --------------------------------------------------------------------------------