getting drone to work
This commit is contained in:
parent
2fb6cbcaf1
commit
167c003387
31
.drone.yml
31
.drone.yml
@ -8,15 +8,34 @@ steps:
|
|||||||
commands:
|
commands:
|
||||||
- git fetch --tags
|
- git fetch --tags
|
||||||
|
|
||||||
|
- name: go-bindata
|
||||||
|
image: golang:latest
|
||||||
|
commands:
|
||||||
|
- (cd /tmp; go get -u github.com/go-bindata/go-bindata/...)
|
||||||
|
- go-bindata -pkg assets -o assets/bindata.go -nomemcopy /bin/true
|
||||||
|
|
||||||
- name: lint
|
- name: lint
|
||||||
image: golangci/golangci-lint:latest
|
image: golangci/golangci-lint:latest
|
||||||
commands:
|
commands:
|
||||||
- make lint
|
- make lint
|
||||||
|
depends_on:
|
||||||
|
- go-bindata
|
||||||
|
|
||||||
- name: test
|
- name: test
|
||||||
image: golang:latest
|
image: golang:latest
|
||||||
commands:
|
commands:
|
||||||
- make lint
|
- make test
|
||||||
|
depends_on:
|
||||||
|
- go-bindata
|
||||||
|
|
||||||
|
- name: clean
|
||||||
|
image: golang:latest
|
||||||
|
commands:
|
||||||
|
- make clean
|
||||||
|
- git checkout -- .
|
||||||
|
depends_on:
|
||||||
|
- lint
|
||||||
|
- test
|
||||||
|
|
||||||
- name: build
|
- name: build
|
||||||
image: goreleaser/goreleaser:latest
|
image: goreleaser/goreleaser:latest
|
||||||
@ -25,14 +44,14 @@ steps:
|
|||||||
path: /var/run
|
path: /var/run
|
||||||
environment:
|
environment:
|
||||||
commands:
|
commands:
|
||||||
|
- (cd /tmp; go get -u github.com/go-bindata/go-bindata/...)
|
||||||
- make build
|
- make build
|
||||||
when:
|
when:
|
||||||
event:
|
event:
|
||||||
exclude:
|
exclude:
|
||||||
- tag
|
- tag
|
||||||
depends_on:
|
depends_on:
|
||||||
- lint
|
- clean
|
||||||
- test
|
|
||||||
|
|
||||||
- name: release
|
- name: release
|
||||||
image: goreleaser/goreleaser:latest
|
image: goreleaser/goreleaser:latest
|
||||||
@ -43,13 +62,13 @@ steps:
|
|||||||
GITEA_TOKEN:
|
GITEA_TOKEN:
|
||||||
from_secret: gitea_token
|
from_secret: gitea_token
|
||||||
commands:
|
commands:
|
||||||
- make release
|
- (cd /tmp; go get -u github.com/go-bindata/go-bindata/...)
|
||||||
|
- goreleaser release --rm-dist --parallelism=1
|
||||||
when:
|
when:
|
||||||
event:
|
event:
|
||||||
- tag
|
- tag
|
||||||
depends_on:
|
depends_on:
|
||||||
- lint
|
- clean
|
||||||
- test
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
- name: docker
|
- name: docker
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -80,7 +80,6 @@ fabric.properties
|
|||||||
.idea/caches/build_file_checksums.ser
|
.idea/caches/build_file_checksums.ser
|
||||||
|
|
||||||
# OWN
|
# OWN
|
||||||
wg-quicker
|
|
||||||
assets/*
|
assets/*
|
||||||
dist/*
|
dist/*
|
||||||
bin/*
|
bin/*
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
---
|
---
|
||||||
project_name: wg-quicker
|
project_name: wg-quicker
|
||||||
|
gitea_urls:
|
||||||
|
api: https://git.xsfx.dev/api/v1/
|
||||||
builds:
|
builds:
|
||||||
- main: ./cmd/wg-quicker/main.go
|
- main: ./cmd/wg-quicker/main.go
|
||||||
env:
|
env:
|
||||||
|
38
README.md
38
README.md
@ -1,4 +1,4 @@
|
|||||||
# wg-quick-go
|
# wg-quicker
|
||||||
|
|
||||||
[![Build Status](https://gitlab.com/neven-miculinic/wg-quick-go/badges/master/pipeline.svg)](https://gitlab.com/neven-miculinic/wg-quick-go/pipelines) [![GoDoc](https://godoc.org/github.com/nmiculinic/wireguardctrl?status.svg)](https://godoc.org/github.com/nmiculinic/wg-quick-go) [![Go Report Card](https://goreportcard.com/badge/github.com/nmiculinic/wg-quick-go)](https://goreportcard.com/report/github.com/nmiculinic/wg-quick-go)
|
[![Build Status](https://gitlab.com/neven-miculinic/wg-quick-go/badges/master/pipeline.svg)](https://gitlab.com/neven-miculinic/wg-quick-go/pipelines) [![GoDoc](https://godoc.org/github.com/nmiculinic/wireguardctrl?status.svg)](https://godoc.org/github.com/nmiculinic/wg-quick-go) [![Go Report Card](https://goreportcard.com/badge/github.com/nmiculinic/wg-quick-go)](https://goreportcard.com/report/github.com/nmiculinic/wg-quick-go)
|
||||||
|
|
||||||
@ -6,24 +6,24 @@ wg-quick like library in go for embedding
|
|||||||
|
|
||||||
# Roadmap
|
# Roadmap
|
||||||
|
|
||||||
* [x] full wg-quick feature parity
|
- [x] full wg-quick feature parity
|
||||||
* [x] PreUp
|
- [x] PreUp
|
||||||
* [x] PostUp
|
- [x] PostUp
|
||||||
* [x] PreDown
|
- [x] PreDown
|
||||||
* [x] PostDown
|
- [x] PostDown
|
||||||
* [x] DNS
|
- [x] DNS
|
||||||
* [x] MTU
|
- [x] MTU
|
||||||
* [x] Save --> Use MarshallText interface to save config
|
- [x] Save --> Use MarshallText interface to save config
|
||||||
* [x] Sync
|
- [x] Sync
|
||||||
* [x] Up
|
- [x] Up
|
||||||
* [x] Down
|
- [x] Down
|
||||||
* [x] MarshallText
|
- [x] MarshallText
|
||||||
* [x] UnmarshallText
|
- [x] UnmarshallText
|
||||||
* [x] Minimal test
|
- [x] Minimal test
|
||||||
* [ ] Integration tests ((TODO; have some virtual machines/kvm and wreck havoc :) ))
|
- [ ] Integration tests ((TODO; have some virtual machines/kvm and wreck havoc :) ))
|
||||||
|
|
||||||
# Caveats
|
# Caveats
|
||||||
|
|
||||||
* Endpoints DNS MarshallText is unsupported
|
- Endpoints DNS MarshallText is unsupported
|
||||||
* Pre/Post Up/Down doesn't support escaped `%i`, that is all `%i` are expanded to interface name.
|
- Pre/Post Up/Down doesn't support escaped `%i`, that is all `%i` are expanded to interface name.
|
||||||
* SaveConfig in config is only a placeholder (( since there's no reading/writing from files )). Use Unmarshall/Marshall Text to save/load config (( you're responsible for IO)).
|
- SaveConfig in config is only a placeholder (( since there's no reading/writing from files )). Use Unmarshall/Marshall Text to save/load config (( you're responsible for IO)).
|
||||||
|
94
cmd/wg-quicker/main.go
Normal file
94
cmd/wg-quicker/main.go
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
// nolint: gomnd
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
wgquick "go.xsfx.dev/wg-quicker"
|
||||||
|
)
|
||||||
|
|
||||||
|
func printHelp() {
|
||||||
|
fmt.Print("wg-quick [flags] [ up | down | sync ] [ config_file | interface ]\n\n") // nolint: forbidigo
|
||||||
|
flag.Usage()
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// nolint: funlen
|
||||||
|
func main() {
|
||||||
|
flag.String("iface", "", "interface")
|
||||||
|
verbose := flag.Bool("v", false, "verbose")
|
||||||
|
protocol := flag.Int("route-protocol", 0, "route protocol to use for our routes")
|
||||||
|
metric := flag.Int("route-metric", 0, "route metric to use for our routes")
|
||||||
|
flag.Parse()
|
||||||
|
args := flag.Args()
|
||||||
|
|
||||||
|
if len(args) != 2 {
|
||||||
|
printHelp()
|
||||||
|
}
|
||||||
|
|
||||||
|
if *verbose {
|
||||||
|
logrus.SetLevel(logrus.DebugLevel)
|
||||||
|
}
|
||||||
|
|
||||||
|
iface := flag.Lookup("iface").Value.String()
|
||||||
|
log := logrus.WithField("iface", iface)
|
||||||
|
|
||||||
|
cfg := args[1]
|
||||||
|
|
||||||
|
_, err := os.Stat(cfg)
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case err == nil:
|
||||||
|
case os.IsNotExist(err):
|
||||||
|
if iface == "" {
|
||||||
|
iface = cfg
|
||||||
|
log = logrus.WithField("iface", iface)
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg = "/etc/wireguard/" + cfg + ".conf"
|
||||||
|
|
||||||
|
_, err = os.Stat(cfg)
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).Errorln("cannot find config file")
|
||||||
|
printHelp()
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
logrus.WithError(err).Errorln("error while reading config file")
|
||||||
|
printHelp()
|
||||||
|
}
|
||||||
|
|
||||||
|
b, err := ioutil.ReadFile(cfg)
|
||||||
|
if err != nil {
|
||||||
|
logrus.WithError(err).Fatalln("cannot read file")
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &wgquick.Config{}
|
||||||
|
|
||||||
|
if err := c.UnmarshalText(b); err != nil {
|
||||||
|
logrus.WithError(err).Fatalln("cannot parse config file")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.RouteProtocol = *protocol
|
||||||
|
c.RouteMetric = *metric
|
||||||
|
|
||||||
|
switch args[0] {
|
||||||
|
case "up":
|
||||||
|
if err := wgquick.Up(c, iface, log); err != nil {
|
||||||
|
logrus.WithError(err).Errorln("cannot up interface")
|
||||||
|
}
|
||||||
|
case "down":
|
||||||
|
if err := wgquick.Down(c, iface, log); err != nil {
|
||||||
|
logrus.WithError(err).Errorln("cannot down interface")
|
||||||
|
}
|
||||||
|
case "sync":
|
||||||
|
if err := wgquick.Sync(c, iface, log); err != nil {
|
||||||
|
logrus.WithError(err).Errorln("cannot sync interface")
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
printHelp()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user