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:
|
||||
- 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
|
||||
image: golangci/golangci-lint:latest
|
||||
commands:
|
||||
- make lint
|
||||
depends_on:
|
||||
- go-bindata
|
||||
|
||||
- name: test
|
||||
image: golang:latest
|
||||
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
|
||||
image: goreleaser/goreleaser:latest
|
||||
@ -25,14 +44,14 @@ steps:
|
||||
path: /var/run
|
||||
environment:
|
||||
commands:
|
||||
- (cd /tmp; go get -u github.com/go-bindata/go-bindata/...)
|
||||
- make build
|
||||
when:
|
||||
event:
|
||||
exclude:
|
||||
- tag
|
||||
depends_on:
|
||||
- lint
|
||||
- test
|
||||
- clean
|
||||
|
||||
- name: release
|
||||
image: goreleaser/goreleaser:latest
|
||||
@ -43,13 +62,13 @@ steps:
|
||||
GITEA_TOKEN:
|
||||
from_secret: gitea_token
|
||||
commands:
|
||||
- make release
|
||||
- (cd /tmp; go get -u github.com/go-bindata/go-bindata/...)
|
||||
- goreleaser release --rm-dist --parallelism=1
|
||||
when:
|
||||
event:
|
||||
- tag
|
||||
depends_on:
|
||||
- lint
|
||||
- test
|
||||
- clean
|
||||
|
||||
services:
|
||||
- name: docker
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -80,7 +80,6 @@ fabric.properties
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
# OWN
|
||||
wg-quicker
|
||||
assets/*
|
||||
dist/*
|
||||
bin/*
|
||||
|
@ -1,5 +1,7 @@
|
||||
---
|
||||
project_name: wg-quicker
|
||||
gitea_urls:
|
||||
api: https://git.xsfx.dev/api/v1/
|
||||
builds:
|
||||
- main: ./cmd/wg-quicker/main.go
|
||||
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)
|
||||
|
||||
@ -6,24 +6,24 @@ wg-quick like library in go for embedding
|
||||
|
||||
# Roadmap
|
||||
|
||||
* [x] full wg-quick feature parity
|
||||
* [x] PreUp
|
||||
* [x] PostUp
|
||||
* [x] PreDown
|
||||
* [x] PostDown
|
||||
* [x] DNS
|
||||
* [x] MTU
|
||||
* [x] Save --> Use MarshallText interface to save config
|
||||
* [x] Sync
|
||||
* [x] Up
|
||||
* [x] Down
|
||||
* [x] MarshallText
|
||||
* [x] UnmarshallText
|
||||
* [x] Minimal test
|
||||
* [ ] Integration tests ((TODO; have some virtual machines/kvm and wreck havoc :) ))
|
||||
- [x] full wg-quick feature parity
|
||||
- [x] PreUp
|
||||
- [x] PostUp
|
||||
- [x] PreDown
|
||||
- [x] PostDown
|
||||
- [x] DNS
|
||||
- [x] MTU
|
||||
- [x] Save --> Use MarshallText interface to save config
|
||||
- [x] Sync
|
||||
- [x] Up
|
||||
- [x] Down
|
||||
- [x] MarshallText
|
||||
- [x] UnmarshallText
|
||||
- [x] Minimal test
|
||||
- [ ] Integration tests ((TODO; have some virtual machines/kvm and wreck havoc :) ))
|
||||
|
||||
# Caveats
|
||||
|
||||
* Endpoints DNS MarshallText is unsupported
|
||||
* 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)).
|
||||
- Endpoints DNS MarshallText is unsupported
|
||||
- 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)).
|
||||
|
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