Skip to content

Commit 5456aad

Browse files
committed
Initial commit
0 parents  commit 5456aad

8 files changed

+955
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dh-make-golang

LICENSE

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright © 2015 Michael Stapelberg and contributors
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above copyright
11+
notice, this list of conditions and the following disclaimer in the
12+
documentation and/or other materials provided with the distribution.
13+
14+
* Neither the name of Michael Stapelberg nor the
15+
names of contributors may be used to endorse or promote products
16+
derived from this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY Michael Stapelberg ''AS IS'' AND ANY
19+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL Michael Stapelberg BE LIABLE FOR ANY
22+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

filter-packages.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/zsh
2+
mkdir -p /home/stapelberg/public_html/dh-make-golang
3+
TEMPFILE=$(mktemp)
4+
wget -q -O- http://httpredir.debian.org/debian/dists/sid/main/binary-amd64/Packages.gz | zgrep '^Package: golang-' | uniq > "${TEMPFILE}"
5+
if [ -s "${TEMPFILE}" ]; then
6+
chmod o+r "${TEMPFILE}"
7+
mv "${TEMPFILE}" /home/stapelberg/public_html/dh-make-golang/binary-amd64-grep-golang
8+
else
9+
rm "${TEMPFILE}"
10+
fi

license.go

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"net/http"
6+
"strings"
7+
)
8+
9+
type licensesReply struct {
10+
Key string `json:"key"`
11+
Name string `json:"name"`
12+
URL string `json:"url"`
13+
Featured bool `json:"featured"`
14+
}
15+
16+
type repositoryReply struct {
17+
License licensesReply `json:"license"`
18+
}
19+
20+
type licenseReply struct {
21+
Body string `json:"body"`
22+
}
23+
24+
// To update, use:
25+
// curl -s -H 'Accept: application/vnd.github.drax-preview+json' https://api.github.com/licenses | jq '.[].key'
26+
// then compare with https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/#license-specification
27+
var githubLicenseToDebianLicense = map[string]string{
28+
//"agpl-3.0" (not in debian?)
29+
"apache-2.0": "Apache-2.0",
30+
"artistic-2.0": "Artistic-2.0",
31+
"bsd-2-clause": "BSD-2-clause",
32+
"bsd-3-clause": "BSD-3-clause",
33+
"cc0-1.0": "CC0-1.0",
34+
//"epl-1.0" (eclipse public license)
35+
"gpl-2.0": "GPL-2.0", // TODO: is this GPL-2.0+?
36+
"gpl-3.0": "GPL-3.0",
37+
"isc": "ISC",
38+
"lgpl-2.1": "LGPL-2.1",
39+
"lgpl-3.0": "LGPL-3.0",
40+
//"mit" - expat?
41+
//"mpl-2.0" (only 1.1 is in debian)
42+
//"unlicense" (not in debian)
43+
}
44+
45+
var debianLicenseText = map[string]string{
46+
"Apache-2.0": ` Licensed under the Apache License, Version 2.0 (the "License");
47+
you may not use this file except in compliance with the License.
48+
You may obtain a copy of the License at
49+
.
50+
http://www.apache.org/licenses/LICENSE-2.0
51+
.
52+
Unless required by applicable law or agreed to in writing, software
53+
distributed under the License is distributed on an "AS IS" BASIS,
54+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
55+
See the License for the specific language governing permissions and
56+
limitations under the License.
57+
.
58+
On Debian systems, the complete text of the Apache version 2.0 license
59+
can be found in "/usr/share/common-licenses/Apache-2.0".
60+
`,
61+
}
62+
63+
func getLicenseForGopkg(gopkg string) (string, string, error) {
64+
if !strings.HasPrefix(gopkg, "github.com/") {
65+
return "", "", nil
66+
}
67+
req, err := http.NewRequest("GET", "https://api.github.com/repos/"+gopkg[len("github.com/"):], nil)
68+
if err != nil {
69+
return "", "", err
70+
}
71+
req.Header.Set("Accept", "application/vnd.github.drax-preview+json")
72+
resp, err := http.DefaultClient.Do(req)
73+
if err != nil {
74+
return "", "", err
75+
}
76+
defer resp.Body.Close()
77+
var r repositoryReply
78+
if err := json.NewDecoder(resp.Body).Decode(&r); err != nil {
79+
return "", "", err
80+
}
81+
if deblicense, ok := githubLicenseToDebianLicense[r.License.Key]; ok {
82+
fulltext := debianLicenseText[deblicense]
83+
if fulltext == "" {
84+
fulltext = "TODO"
85+
}
86+
return deblicense, fulltext, nil
87+
} else {
88+
return "TODO", "TODO", nil
89+
}
90+
}

0 commit comments

Comments
 (0)