-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (44 loc) · 966 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"runtime"
)
func main() {
fmt.Printf("Prism Installer for %s (%s)\n\n", runtime.GOOS, runtime.GOARCH)
fmt.Println("Installing...")
file, err := DownloadFile()
if err != nil {
panic(err)
}
os.Chmod(file, os.FileMode(int(0777)))
fmt.Println("Done.")
}
func DownloadFile() (string, error) {
var file string
url := "https://github.com/PrismLang/binaries/raw/master/prism-" + runtime.GOOS + "-" + runtime.GOARCH
switch runtime.GOOS {
case "windows":
url += ".exe"
installDir := os.Getenv("SYSTEMROOT")
file = filepath.Join(installDir, "prism.exe")
default:
installDir := "/usr/local/bin"
file = filepath.Join(installDir, "prism")
}
resp, err := http.Get(url)
if err != nil {
return file, err
}
defer resp.Body.Close()
out, err := os.Create(file)
if err != nil {
return file, err
}
defer out.Close()
_, err = io.Copy(out, resp.Body)
return file, err
}