-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
203 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
version: 2.1 | ||
|
||
jobs: | ||
build: | ||
docker: | ||
- image: cimg/go:1.20 | ||
steps: | ||
- run: | ||
name: Install upx | ||
command: sudo apt update && sudo apt install upx -y | ||
- checkout | ||
- restore_cache: | ||
keys: | ||
- go-mod-v1-{{ checksum "go.sum" }} | ||
- go-mod-v1 | ||
- run: | ||
name: Install Dependencies | ||
command: go get ./... | ||
- save_cache: | ||
key: go-mod-v1-{{ checksum "go.sum" }} | ||
paths: | ||
- "/go/pkg/mod" | ||
- run: | ||
name: Build | ||
command: go build -C cmd/gowake/ -v -ldflags="-w -s" | ||
- run: | ||
name: Upx | ||
command: upx ./cmd/gowake/gowake | ||
- persist_to_workspace: | ||
root: ~/project | ||
paths: | ||
- cmd/gowake/gowake | ||
release: | ||
docker: | ||
- image: cimg/base:current | ||
steps: | ||
- attach_workspace: | ||
at: ./ | ||
- run: | ||
name: Package | ||
command: tar cvfz ${CIRCLE_PROJECT_REPONAME}_${CIRCLE_TAG}_linux_amd64.tar.gz cmd/${CIRCLE_PROJECT_REPONAME}/${CIRCLE_PROJECT_REPONAME} | ||
- run: | ||
name: Release | ||
command: | | ||
curl -v \ | ||
-X POST \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer ${GITHUB_TOKEN}" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
https://api.github.com/repos/lupinelab/${CIRCLE_PROJECT_REPONAME}/releases \ | ||
-d '{"tag_name":"'$CIRCLE_TAG'","draft":false,"prerelease":false}' | ||
RELEASE_ID=$(curl -s \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer ${GITHUB_TOKEN}" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
https://api.github.com/repos/lupinelab/${CIRCLE_PROJECT_REPONAME}/releases/tags/${CIRCLE_TAG} \ | ||
| jq '.id') | ||
curl -v \ | ||
-X POST \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer $GITHUB_TOKEN"\ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
-H "Content-Type: $(file -b --mime-type ${CIRCLE_PROJECT_REPONAME}_${CIRCLE_TAG}_linux_amd64.tar.gz)" \ | ||
https://uploads.github.com/repos/lupinelab/${CIRCLE_PROJECT_REPONAME}/releases/$RELEASE_ID/assets?name=$(basename ${CIRCLE_PROJECT_REPONAME}_${CIRCLE_TAG}_linux_amd64.tar.gz) \ | ||
--data-binary @${CIRCLE_PROJECT_REPONAME}_${CIRCLE_TAG}_linux_amd64.tar.gz | ||
workflows: | ||
build_and_release: | ||
jobs: | ||
- build: | ||
filters: | ||
tags: | ||
only: /v\d+\.\d+\.\d+/ | ||
- release: | ||
context: | ||
- github | ||
requires: | ||
- build | ||
filters: | ||
branches: | ||
ignore: /.*/ | ||
tags: | ||
only: /v\d+\.\d+\.\d+/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
gowake | ||
./gowake |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
module github.com/lupinelab/gowake | ||
|
||
go 1.19 | ||
go 1.20 | ||
|
||
require github.com/spf13/cobra v1.5.0 | ||
require github.com/spf13/cobra v1.7.0 | ||
|
||
require ( | ||
github.com/inconshreveable/mousetrap v1.0.1 // indirect | ||
github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= | ||
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= | ||
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= | ||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= | ||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= | ||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU= | ||
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM= | ||
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= | ||
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= | ||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= | ||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package gowake | ||
|
||
import ( | ||
"net" | ||
) | ||
|
||
func Listen(port int) (*net.UDPAddr, string, error) { | ||
addr := net.UDPAddr{ | ||
IP: net.ParseIP("0.0.0.0"), | ||
Port: port, | ||
} | ||
|
||
listener, err := net.ListenUDP("udp", &addr) | ||
if err != nil { | ||
return nil, "", err | ||
} | ||
defer listener.Close() | ||
|
||
magicPacket := MagicPacket{} | ||
remote := &net.UDPAddr{} | ||
for { | ||
_, remote, err = listener.ReadFromUDP(magicPacket[:]) | ||
if err != nil { | ||
return remote, "", err | ||
} else { | ||
return remote, net.HardwareAddr.String(magicPacket[96:]), err | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package gowake | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
) | ||
|
||
type MagicPacket [102]byte | ||
|
||
func NewMagicPacket(mac string) (mp *MagicPacket, err error) { | ||
// Parse mac address | ||
hwAddr, err := net.ParseMAC(mac) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if len(hwAddr) != 6 { | ||
return nil, fmt.Errorf("invalid EUI-48 MAC address") | ||
} | ||
|
||
// Build magicpacket | ||
magicPacket := MagicPacket{} | ||
copy(magicPacket[:], []byte{255, 255, 255, 255, 255, 255}) | ||
|
||
offset := 6 | ||
for i := 0; i < 16; i++ { | ||
copy(magicPacket[offset:], hwAddr[:]) | ||
offset += 6 | ||
} | ||
|
||
return &magicPacket, err | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.