This commit is contained in:
Henrique Dias 2016-06-07 19:00:07 +01:00
parent 4cd72ca58d
commit 078cbb2e1b
2 changed files with 64 additions and 34 deletions

25
tools/installer/hashes.go Normal file
View File

@ -0,0 +1,25 @@
package installer
var (
sha256Hash = map[string]string{
"hugo_0.16_darwin-arm32.tgz": "683d5d4b4e0ac03a183ca5eb9019981ba696569445c7d6d1efc7e6706bd273a5",
"hugo_0.16_dragonfly-64bit.tgz": "63a3ee9a36d4d2166c77b96bb8bf39b2239affe118e44a83b3d0a44374a8921d",
"hugo_0.16_freebsd-32bit.tgz": "ea3f84900feeeb9d89573dea49a4349753116e70de561eeec4858f7ffc74f8f9",
"hugo_0.16_freebsd-64bit.tgz": "8d9320bb660090a77a4f922ca30b1582593bc6d87c3fd8bd6f5ecbe49cf1d2f2",
"hugo_0.16_freebsd-arm32.tgz": "b4c21296e01ea68709ac50d7eb1d314b738f1c8408ff2be223d06ae76604dbea",
"hugo_0.16_linux-32bit.tgz": "aed82d156f01a4562c39bd1af41aa81699009140da965e0369c370ba874725c9",
"hugo_0.16_linux-64bit.tgz": "13e299dc45bea4fad5bdf8c2640305a5926e2acd02c3aa03b7864403e513920e",
"hugo_0.16_linux-arm32.tgz": "bc836def127d93e2457da9994f9c09b0100523e46d61074cd724ef092b11714f",
"hugo_0.16_linux-arm64.tgz": "d04486918f43f89f1e0359eebedd8a05d96f7ca40f93e7fd8d7c3f2dac115a8d",
"hugo_0.16_netbsd-32bit.tgz": "cb578eebec5b6364b0afd5bb208d94317acab0a3e033b81f04b1511af0669b63",
"hugo_0.16_netbsd-64bit.tgz": "d3c766d9800d7fdd268ffd2f28b7af451f13a4de63901bfdae2ee5c96528b8cc",
"hugo_0.16_netbsd-arm32.tgz": "51162b2637e71b786582af715a44b778f62bdc62a9a354ccc4a7c8384afe194c",
"hugo_0.16_openbsd-32bit.tgz": "2d1e112a7346850897ea77da868c0d987ef90efb7f49c917659437a5a67f89f8",
"hugo_0.16_openbsd-64bit.tgz": "7b33ff2565df5a6253c3e4308813d947e34af04c633fb4e01cac83751066e16e",
"hugo_0.16_osx-32bit.tgz": "6155dda548bbd1e26c26a4a00472e4c0e55fad9fcd46991ce90987385bd5fd0a",
"hugo_0.16_osx-64bit.tgz": "b0cba8f6996946ef34a664184d6461567d79fc2a3e793145d34379902eda0ad9",
"hugo_0.16_solaris-64bit.tgz": "af9557403af5e16eb7faf965c04540417a70699efbbbc4e0a7ae4c4703ad1ae8",
"hugo_0.16_windows-32bit.zip": "1c72d06843fe02cb62348660d87a523c885ed684a683271fc8762e7234c4210b",
"hugo_0.16_windows-64bit.zip": "a3fda0bd30592e4eb3bdde85c8a8ce23a7433073536466d16fd0e97bf7794067",
}
)

View File

@ -11,6 +11,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"regexp"
"runtime" "runtime"
"github.com/hacdias/caddy-hugo/tools/files" "github.com/hacdias/caddy-hugo/tools/files"
@ -19,31 +20,11 @@ import (
) )
const ( const (
version = "0.15" version = "0.16"
baseurl = "https://github.com/spf13/hugo/releases/download/v" + version + "/" baseurl = "https://github.com/spf13/hugo/releases/download/v" + version + "/"
) )
var ( var caddy, bin, temp, hugo, tempfile, zipname, exename string
caddy, bin, temp, hugo, tempfile, zipname, exename string
sha256Hash = map[string]string{
"hugo_0.15_darwin_386.zip": "f9b7353f9b64e7aece5f7981e5aa97dc4b31974ce76251edc070e77691bc03e2",
"hugo_0.15_darwin_amd64.zip": "aeecd6a12d86ab920f5b04e9486474bbe478dc246cdc2242799849b84c61c6f1",
"hugo_0.15_dragonfly_amd64.zip": "e380343789f2b2e0c366c8e1eeb251ccd90eea53dac191ff85d8177b130e53bc",
"hugo_0.15_freebsd_386.zip": "98f9210bfa3dcb48bd154879ea1cfe1b0ed8a3d891fdeacbdb4c3fc69b72aac4",
"hugo_0.15_freebsd_amd64.zip": "aa6a3028899e76e6920b9b5a64c29e14017ae34120efa67276e614e3a69cb100",
"hugo_0.15_freebsd_arm.zip": "de52e1b07caf778bdc3bdb07f39119cd5a1739c8822ebe311cd4f667c43588ac",
"hugo_0.15_linux_386.tar.gz": "af28c4cbb16db765535113f361a38b2249c634ce2d3798dcf5b795de6e4b7ecf",
"hugo_0.15_linux_amd64.tar.gz": "32a6335bd76f72867efdec9306a8a7eb7b9498a2e0478105efa96c1febadb09b",
"hugo_0.15_linux_arm.tar.gz": "886dd1a843c057a46c541011183dd558469250580e81450eedbd1a4d041e9234",
"hugo_0.15_netbsd_386.zip": "6245f5db16b33a09466f149d5b7b68a7899d6d624903de9e7e70c4b6ea869a72",
"hugo_0.15_netbsd_amd64.zip": "103ea8d81d2a3d707c05e3dd68c98fcf8146ddd36b49bf0e65d9874cee230c88",
"hugo_0.15_netbsd_arm.zip": "9c9b5cf4ea3b6169be1b5fc924251a247d9c140dd8a45aa5175031878585ff0a",
"hugo_0.15_openbsd_386.zip": "81dfdb3048a27a61b249650241fe4e8da1eda31a3a7311c615eb419f1cdd06b1",
"hugo_0.15_openbsd_amd64.zip": "e7447cde0dd7628b05b25b86938018774d8db8156ab1330b364e0e2c6501ad87",
"hugo_0.15_windows_386_32-bit-only.zip": "0a72f9a1a929f36c0e52fb1c6272b4d37a2bd1a6bd19ce57a6e7b6803b434756",
"hugo_0.15_windows_amd64.zip": "9f03602e48ae2199e06431d7436fb3b9464538c0d44aac9a76eb98e1d4d5d727",
}
)
// GetPath retrives the Hugo path for the user or install it if it's not found // GetPath retrives the Hugo path for the user or install it if it's not found
func GetPath() string { func GetPath() string {
@ -53,12 +34,16 @@ func GetPath() string {
// Check if Hugo is already on $PATH // Check if Hugo is already on $PATH
if hugo, err = exec.LookPath("hugo"); err == nil { if hugo, err = exec.LookPath("hugo"); err == nil {
return hugo if checkVersion() {
return hugo
}
} }
// Check if Hugo is on $HOME/.caddy/bin // Check if Hugo is on $HOME/.caddy/bin
if _, err = os.Stat(hugo); err == nil { if _, err = os.Stat(hugo); err == nil {
return hugo if checkVersion() {
return hugo
}
} }
fmt.Println("Unable to find Hugo on your computer.") fmt.Println("Unable to find Hugo on your computer.")
@ -125,8 +110,25 @@ func GetPath() string {
} }
func initializeVariables() { func initializeVariables() {
exename = "hugo_" + version + "_" + runtime.GOOS + "_" + runtime.GOARCH var arch string
zipname = exename switch runtime.GOARCH {
case "amd64":
arch = "64bit"
case "386":
arch = "32bit"
case "arm":
arch = "arm32"
default:
arch = runtime.GOARCH
}
var ops = runtime.GOOS
if runtime.GOOS == "darwin" && runtime.GOARCH != "arm" {
ops = "osx"
}
exename = "hugo"
zipname = "hugo_" + version + "_" + ops + "-" + arch
homedir, err := homedir.Dir() homedir, err := homedir.Dir()
if err != nil { if err != nil {
@ -139,22 +141,25 @@ func initializeVariables() {
hugo = filepath.Join(bin, "hugo") hugo = filepath.Join(bin, "hugo")
switch runtime.GOOS { switch runtime.GOOS {
case "darwin":
zipname += ".zip"
case "windows": case "windows":
// At least for v0.15 version
if runtime.GOARCH == "386" {
zipname += "32-bit-only"
}
zipname += ".zip" zipname += ".zip"
exename += ".exe" exename += ".exe"
hugo += ".exe" hugo += ".exe"
default: default:
zipname += ".tar.gz" zipname += ".tgz"
} }
} }
func checkVersion() bool {
out, _ := exec.Command("hugo", "version").Output()
r := regexp.MustCompile(`v\d\.\d{2}`)
v := r.FindStringSubmatch(string(out))[0]
v = v[1:len(v)]
return (v == version)
}
func downloadHugo() { func downloadHugo() {
tempfile = filepath.Join(temp, zipname) tempfile = filepath.Join(temp, zipname)