update upgrade script
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
module github.com/mattn/go-sqlite3/upgrade
|
||||
|
||||
go 1.19
|
||||
|
||||
require github.com/PuerkitoBio/goquery v1.7.1 // indirect
|
||||
@@ -1,12 +0,0 @@
|
||||
github.com/PuerkitoBio/goquery v1.7.1 h1:oE+T06D+1T7LNrn91B4aERsRIeCLJ/oPSa6xB9FPnz4=
|
||||
github.com/PuerkitoBio/goquery v1.7.1/go.mod h1:XY0pP4kfraEmmV1O7Uf6XyjoslwsneBbgeDjLYuN8xY=
|
||||
github.com/andybalholm/cascadia v1.2.0 h1:vuRCkM5Ozh/BfmsaTm26kbjm0mIOM3yS5Ek/F5h18aE=
|
||||
github.com/andybalholm/cascadia v1.2.0/go.mod h1:YCyR8vOZT9aZ1CHEd8ap0gMVm2aFgxBp0T0eFw1RUQY=
|
||||
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q=
|
||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
@@ -1,5 +0,0 @@
|
||||
// Package upgrade is a dummy package to ensure package can be loaded
|
||||
//
|
||||
// This file is to avoid the following error:
|
||||
// can't load package: package go-sqlite3/upgrade: build constraints exclude all Go files in go-sqlite3\upgrade
|
||||
package upgrade
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"archive/zip"
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@@ -15,36 +16,49 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
)
|
||||
|
||||
func download(prefix string) (url string, content []byte, err error) {
|
||||
year := time.Now().Year()
|
||||
|
||||
site := "https://www.sqlite.org/download.html"
|
||||
//fmt.Printf("scraping %v\n", site)
|
||||
doc, err := goquery.NewDocument(site)
|
||||
resp, err := http.Get("https://www.sqlite.org/download.html")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return "", nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
doc.Find("a").Each(func(_ int, s *goquery.Selection) {
|
||||
if strings.HasPrefix(s.Text(), prefix) {
|
||||
url = fmt.Sprintf("https://www.sqlite.org/%d/", year) + s.Text()
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
html := string(b)
|
||||
start := strings.Index(html, `<!-- Download product data for scripts to read`)
|
||||
if start == -1 {
|
||||
return "", nil, errors.New("Unable to find download section on sqlite.org")
|
||||
}
|
||||
html = html[start:]
|
||||
end := strings.Index(html, `-->`)
|
||||
if end == -1 {
|
||||
return "", nil, errors.New("Unable to find download section on sqlite.org")
|
||||
}
|
||||
html = html[:end]
|
||||
for _, line := range strings.Split(html, "\n") {
|
||||
if strings.Contains(line, prefix) {
|
||||
if tok := strings.Split(line, ","); len(tok) >= 5 {
|
||||
url = fmt.Sprintf("https://www.sqlite.org/%s", tok[2])
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if url == "" {
|
||||
return "", nil, fmt.Errorf("Unable to find prefix '%s' on sqlite.org", prefix)
|
||||
}
|
||||
|
||||
fmt.Printf("Downloading %v\n", url)
|
||||
resp, err := http.Get(url)
|
||||
resp, err = http.Get(url)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
// Ready Body Content
|
||||
@@ -98,13 +112,13 @@ func mergeFile(src string, dst string) error {
|
||||
func main() {
|
||||
fmt.Println("Go-SQLite3 Upgrade Tool")
|
||||
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
_, file, _, ok := runtime.Caller(0)
|
||||
if !ok {
|
||||
log.Fatal("could not get current file info")
|
||||
}
|
||||
if filepath.Base(wd) != "upgrade" {
|
||||
log.Printf("Current directory is %q but should run in upgrade directory", wd)
|
||||
os.Exit(1)
|
||||
err := os.Chdir(filepath.Dir(filepath.Dir(file)))
|
||||
if err != nil {
|
||||
log.Fatalf("could not change directory: %s", err)
|
||||
}
|
||||
|
||||
// Download Amalgamation
|
||||
|
||||
Reference in New Issue
Block a user