Skip to content

Commit

Permalink
Remove sqlite
Browse files Browse the repository at this point in the history
- Move all source code to main.go
- Restore .goreleaser.yml
  • Loading branch information
fabiocody committed Jan 2, 2022
1 parent ba7ca67 commit 9dd6658
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 121 deletions.
47 changes: 20 additions & 27 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
before:
hooks:
- go mod tidy
- go mod download

builds:
- id: linux
ldflags:
- -s -w -extldflags=-static
binary: ovh-ddns-update
goos:
- linux
goarch:
- amd64
- 386
- arm
- arm64
goarm:
- 5
- 6
- 7

- id: macos
ldflags:
- -s -w
binary: ovh-ddns-update
goos:
- darwin
goarch:
- amd64
- arm64
build:
ldflags:
- -s -w
binary: ovh-ddns-update
goos:
- darwin
- linux
goarch:
- amd64
- 386
- arm
- arm64
goarm:
- 5
- 6
- 7
ignore:
- goos: darwin
goarch: 386

archives:
- name_template: '{{ .Binary }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ Positional arguments:
OVHPASSWORD OVH DynHost identifier password
Options:
--database DATABASE database file [default: .ovh-ddns-update.sqlite3]
--database DATABASE database file [default: .ovh-ddns-update.db]
--help, -h display this help and exit
```
10 changes: 0 additions & 10 deletions args.go

This file was deleted.

10 changes: 0 additions & 10 deletions errors.go

This file was deleted.

7 changes: 1 addition & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@ require (
github.com/alexflint/go-arg v1.4.2
github.com/glendc/go-external-ip v0.1.0
github.com/sirupsen/logrus v1.8.1
gorm.io/driver/sqlite v1.2.6
gorm.io/gorm v1.22.4
)

require (
github.com/alexflint/go-scalar v1.0.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.4 // indirect
github.com/mattn/go-sqlite3 v1.14.9 // indirect
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect
)
24 changes: 2 additions & 22 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,15 @@ github.com/alexflint/go-arg v1.4.2 h1:lDWZAXxpAnZUq4qwb86p/3rIJJ2Li81EoMbTMujhVa
github.com/alexflint/go-arg v1.4.2/go.mod h1:9iRbDxne7LcR/GSvEr7ma++GLpdIU1zrghf2y2768kM=
github.com/alexflint/go-scalar v1.0.0 h1:NGupf1XV/Xb04wXskDFzS0KWOLH632W/EO4fAFi+A70=
github.com/alexflint/go-scalar v1.0.0/go.mod h1:GpHzbCOZXEKMEcygYQ5n/aa4Aq84zbxjy3MxYW0gjYw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/glendc/go-external-ip v0.1.0 h1:iX3xQ2Q26atAmLTbd++nUce2P5ht5P4uD4V7caSY/xg=
github.com/glendc/go-external-ip v0.1.0/go.mod h1:CNx312s2FLAJoWNdJWZ2Fpf5O4oLsMFwuYviHjS4uJE=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.3/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.4 h1:tHnRBy1i5F2Dh8BAFxqFzxKqqvezXrL2OW1TnX+Mlas=
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/mattn/go-sqlite3 v1.14.9 h1:10HX2Td0ocZpYEjhilsuo6WWtUqttj2Kb0KtD86/KYA=
github.com/mattn/go-sqlite3 v1.14.9/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d h1:FjkYO/PPp4Wi0EAUOVLxePm7qVW4r4ctbWpURyuOD0E=
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/sqlite v1.2.6 h1:SStaH/b+280M7C8vXeZLz/zo9cLQmIGwwj3cSj7p6l4=
gorm.io/driver/sqlite v1.2.6/go.mod h1:gyoX0vHiiwi0g49tv+x2E7l8ksauLK0U/gShcdUsjWY=
gorm.io/gorm v1.22.3/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=
gorm.io/gorm v1.22.4 h1:8aPcyEJhY0MAt8aY6Dc524Pn+pO29K+ydu+e/cXSpQM=
gorm.io/gorm v1.22.4/go.mod h1:1aeVC+pe9ZmvKZban/gW4QPra7PRoTEssyc922qCAkk=
36 changes: 35 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,27 @@ import (
"github.com/alexflint/go-arg"
externalip "github.com/glendc/go-external-ip"
log "github.com/sirupsen/logrus"
"io/fs"
"net/http"
"os"
)

type ArgsType struct {
Database string `default:".ovh-ddns-update.db" help:"database file"`
Domain string `arg:"positional,required" help:"OVH DynHost domain"`
OvhId string `arg:"positional,required" help:"OVH DynHost identifier"`
OvhPassword string `arg:"positional,required" help:"OVH DynHost identifier password"`
}

var Args ArgsType

func main() {
arg.MustParse(&Args)
log.SetFormatter(&log.TextFormatter{
ForceColors: true,
FullTimestamp: true,
})
log.SetLevel(log.InfoLevel)
SetupDB()
currentIP := GetCurrentIP()
previousIP := GetPreviousIP()
if currentIP != previousIP {
Expand All @@ -35,9 +45,33 @@ func GetCurrentIP() string {
return ip.String()
}

func GetPreviousIP() string {
data, err := os.ReadFile(Args.Database)
_, ok := err.(*fs.PathError)
if ok {
log.Warn("Previous IP not found")
return "not_found"
} else {
HandleError(err)
}
return string(data)
}

func UpdateDDNS(ip string) {
url := fmt.Sprintf("https://%s:%s@www.ovh.com/nic/update?system=dyndns&hostname=%s&myip=%s", Args.OvhId, Args.OvhPassword, Args.Domain, ip)
_, err := http.Get(url)
HandleError(err)
log.Infof("IP updated (%s)", ip)
}

func SaveCurrentIP(ip string) {
err := os.WriteFile(Args.Database, []byte(ip), 0644)
HandleError(err)
}

func HandleError(err error) {
if err != nil {
log.SetReportCaller(true)
log.Fatal(err)
}
}
44 changes: 0 additions & 44 deletions model.go

This file was deleted.

0 comments on commit 9dd6658

Please sign in to comment.