-
Notifications
You must be signed in to change notification settings - Fork 0
/
updater.go
817 lines (707 loc) · 21 KB
/
updater.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
package main
import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"os/exec"
"regexp"
"runtime"
"strings"
"sync"
"time"
"github.com/kardianos/osext"
"github.com/donomii/goof"
"github.com/probandula/figlet4go"
"github.com/donomii/goof"
)
var wg sync.WaitGroup
var installDir = "installs"
var goExe = "installs/go/bin/go"
var cpanExe = "installs/strawberry-perl/perl/bin/cpan"
var gitExe = "installs/PortableGit-2.15.0"
var tempDir = "temp"
var noGcc = false
var noGo = false
var noGit = false
var noInstall = false
var develMode = false
var oneFile = ""
var subPaths []string = []string{
"installs/PortableGit-2.15.0/bin",
"installs/PortableGit-2.15.0/usr/bin",
"installs/go/bin",
"7zip",
"installs/components-15.3.7/bin",
"installs/strawberry/perl/site/bin",
"installs/strawberry-perl/perl/bin",
"installs/strawberry-perl/c/bin",
"langlibs/gopath/bin",
}
func MoveFile(sourcePath, destPath string) error {
inputFile, err := os.Open(sourcePath)
if err != nil {
return fmt.Errorf("Couldn't open source file: %s", err)
}
outputFile, err := os.Create(destPath)
if err != nil {
inputFile.Close()
return fmt.Errorf("Couldn't open dest file: %s", err)
}
defer outputFile.Close()
_, err = io.Copy(outputFile, inputFile)
inputFile.Close()
if err != nil {
return fmt.Errorf("Writing to output file failed: %s", err)
}
// The copy was successful, so now delete the original file
err = os.Remove(sourcePath)
if err != nil {
return fmt.Errorf("Failed removing original file: %s", err)
}
return nil
}
func downloadFile(tempPath, finalfilepath string, url string) (err error) {
fmt.Printf("I> Downloading %v to %v\n", url, tempPath)
if _, err := os.Stat(finalfilepath); os.IsNotExist(err) {
// Get the data
resp, err := http.Get(url)
if err != nil {
fmt.Printf("E> %v\n", err)
return err
}
defer resp.Body.Close()
// Create the file
out, err := os.Create(tempPath)
if err != nil {
fmt.Printf("E> %v\n", err)
return err
}
// Writer the body to file
_, err = io.Copy(out, resp.Body)
if err != nil {
fmt.Printf("E> %v\n", err)
return err
}
defer out.Close()
MoveFile(tempPath, finalfilepath)
}
return nil
}
func doCommand(cmd string, args []string) string {
if noInstall {
return ""
}
fmt.Println("C>", cmd, args)
out, err := exec.Command(cmd, args...).CombinedOutput()
if err != nil {
fmt.Fprintf(os.Stderr, "IO> %v\n", string(out))
fmt.Fprintf(os.Stderr, "E> %v\n", err)
//os.Exit(1)
}
if string(out) != "" {
fmt.Fprintf(os.Stderr, "O> %v\n\n", string(out))
}
return string(out)
}
func copyFile(source, target string) {
doCommand("/bin/cp", []string{"-r", source, target})
}
//Takes a path to a dmg file, mounts it, then return the mount point and device path
func attachDMG(path string) (string, string) {
if goof.Exists(path) {
results := doCommand("/usr/bin/hdiutil", []string{"attach", path})
r := regexp.MustCompile(`(/dev/\S+)\s+Apple_HFS\s+(.*)`)
b := r.FindStringSubmatch(results)
if len(b) > 0 {
s := regexp.MustCompile(`\s+`)
bits := s.Split(b[0], 3)
//fmt.Println(bits)
if len(bits) == 3 {
device := string(bits[0])
mountpoint := string(bits[2])
fmt.Printf("\n!!!device: %v, mountpoint: %v\n", device, mountpoint)
return mountpoint, device
}
}
} else {
log.Printf("File not found: %v\n", path)
}
return "",""
}
func detachDMG(device string) {
doCommand("/usr/bin/hdiutil", []string{"detach", device})
}
func buildGithub(repo string) {
cmd := goExe
args := []string{"build", repo}
fmt.Printf("I> Building %v\n", repo)
doCommand(cmd, args)
}
func installGoGithub(repo string) {
cmd := goExe
args := []string{"get", "-u", repo}
fmt.Printf("I> Installing %v\n", repo)
doCommand(cmd, args)
}
func installGithub(repo string) {
cmd := gitExe
args := []string{"clone", repo}
fmt.Printf("I> Cloning %v\n", repo)
doCommand(cmd, args)
}
func installCpan(repo string) {
cmd := force_winpath(cpanExe)
args := []string{repo}
fmt.Printf("I> Installing %v\n", repo)
doCommand(cmd, args)
}
func loadRepos(filename string) []string {
content, err := ioutil.ReadFile(filename)
if err != nil {
//Do something
}
lines1 := strings.Split(string(content), "\r\n")
lines2 := strings.Split(string(content), "\n")
if len(lines1) > len(lines2) {
return lines1
} else {
return lines2
}
}
func printEnv() {
fmt.Println("I> GOROOT_BOOTSTRAP", os.Getenv("GOROOT_BOOTSTRAP"))
fmt.Println("I> GOPATH", os.Getenv("GOPATH"))
fmt.Println("I> PATH", os.Getenv("PATH"))
fmt.Println("I> GOROOT", runtime.GOROOT())
}
func figlet(s string) string {
ascii := figlet4go.NewAsciiRender()
// Adding the colors to RenderOptions
options := figlet4go.NewRenderOptions()
if runtime.GOOS == "darwin" || runtime.GOOS == "linux" {
options.FontColor = []figlet4go.Color{
// Colors can be given by default ansi color codes...
figlet4go.ColorGreen,
figlet4go.ColorYellow,
figlet4go.ColorCyan,
// ...or by an hex string...
//figlet4go.NewTrueColorFromHexString("885DBA"),
// ...or by an TrueColor object with rgb values
//figlet4go.TrueColor{136, 93, 186},
}
}
renderStr, _ := ascii.RenderOpts(s, options)
return renderStr
}
func makeWith(optName, srcDir, libName string) string {
return fmt.Sprintf("--with-%v=%v/%v", optName, srcDir, libName)
}
func makeOpt(optName, optVal string) string {
return fmt.Sprintf("--%v=%v", optName, optVal)
}
func unTar(b Config, zipPath string) {
zipPath = strings.ReplaceAll(zipPath, "\\", "/")
splits := strings.Split(zipPath, "/")
fname := splits[len(splits)-1]
if _, err := os.Stat(zipPath); err == nil {
unSevenZ(b, zipPath)
doCommand("tar", []string{"-xzvf", zipPath, "--force-local"})
doCommand("tar", []string{"-xjvf", zipPath, "--force-local"})
} else {
log.Println("Could not find ", fname)
}
}
func unTgzLib(b Config, zipPath string) {
p2 := strings.Replace(zipPath, ".gz", "", -1)
splits := strings.Split(p2, "/")
fname := splits[len(splits)-1]
if _, err := os.Stat(zipPath); err == nil {
if isWindows() {
unSevenZ(b, zipPath)
//unSevenZ(b, fname)
} else {
doCommand("tar", []string{"-xzvf", zipPath, "--force-local"})
doCommand("tar", []string{"-xjvf", zipPath, "--force-local"})
}
} else {
log.Println("Could not extract ", fname)
}
}
func unBzLib(b Config, lib string) {
path := fmt.Sprintf("%v/%v.tar.bz2", b.ZipDir, lib)
if _, err := os.Stat(path); err == nil {
if isWindows() {
unSevenZ(b, path)
} else {
doCommand("tar", []string{"-xjvf", path})
}
}
}
func recurseRemove(path string) {
os.RemoveAll(path)
}
func chmod(perms, path string) {
if !isWindows() {
doCommand("chmod", []string{perms, path})
}
}
func standardConfigureBuild(b Config, name, buildDir string, args []string) {
cwd, _ := os.Getwd()
configurePath := fmt.Sprintf("%v/%v/%v", cwd, name, "configure")
unBzLib(b, name)
unTgzLib(b, name)
os.Chdir(name)
os.Chdir(buildDir)
chmod("a+rwx", "configure")
doCommand(configurePath, args)
doCommand("make", []string{})
doCommand("make", []string{"install"})
os.Chdir(cwd)
recurseRemove(name)
}
func buildGcc(b Config, path string) {
arch := "x86_64"
targetDir := fmt.Sprintf("%v/%v", path, installDir)
//srcDir := fmt.Sprintf("%v/src", path)
os.Chdir(path)
fmt.Println(figlet("GMP"))
//doCommand("git", []string{"clone", "https://github.com/bw-oss/gmp"})
gmpName := "gmp-6.1.2"
mpfrName := "mpfr-3.1.5"
mpcName := "mpc-1.0.3"
gccName := "gcc-6.3.0"
islName := "isl-0.15"
standardConfigureBuild(b, gmpName, ".", []string{"--disable-shared", "--enable-static", makeOpt("prefix", targetDir), makeOpt("build", arch)})
standardConfigureBuild(b, mpfrName, ".", []string{"--disable-shared", "--enable-static", makeWith("gmp", targetDir, ""), makeOpt("prefix", targetDir)})
standardConfigureBuild(b, mpcName, ".", []string{"--disable-shared", "--enable-static", makeOpt("with-gmp", targetDir), makeOpt("with-mpfr", targetDir), makeOpt("prefix", targetDir)})
standardConfigureBuild(b, islName, ".", []string{"--disable-shared", "--enable-static", makeOpt("with-gmp-prefix", targetDir), makeOpt("prefix", targetDir)})
standardConfigureBuild(b, gccName, "gcc/objdir", []string{"--enable-languages=c,c++,go", "--disable-shared", "--enable-static", "--disable-multilib", "--disable-shared", "--enable-static", makeWith("gmp", targetDir, ""), makeWith("mpfr", targetDir, ""), makeWith("mpc", targetDir, ""), makeWith("isl", targetDir, ""), makeOpt("prefix", targetDir)})
}
func unSevenZ(b Config, file string) {
fmt.Println(b.SzPath, file)
wg.Add(1)
startpipe := make(chan int)
if false {
func() {
args := []string{b.SzPath, "x", file, "-aoa"}
log.Printf("Args: %v\n", args)
os.StartProcess(b.SzPath, args, &os.ProcAttr{})
startpipe <- 1
//FIXME start another thread to monitor the unzip and call wg.Done when it finishes
}()
<-startpipe
}
if !noInstall {
func() {
defer wg.Done()
//startpipe <- 1 //Go functions can take a few seconds to be scheduled
doCommand(b.SzPath, []string{"x", file, "-aoa"})
}()
//<-startpipe
time.Sleep(1 * time.Second)
}
if false {
defer wg.Done()
doCommand(b.SzPath, []string{"x", file, "-aoa"})
}
}
/*
func unzipWithPathMake(zipName) {
cwd, _ := os.Getwd()
os.Chdir(srcDir)
unSevenZ(b, "../zips/zeromq-4.2.1.zip")
os.Chdir("zeromq-4.2.1/zeromq-4.2.1/builds/mingw32")
doCommand("make", []string{})
os.Chdir(zipName)
}
*/
func Make(b Config, p Package) {
cwd, _ := os.Getwd()
os.Chdir(b.InstallDir)
os.Chdir(p.Name)
here, _ := os.Getwd()
fmt.Printf("Making in %v\n", here)
doCommand("make", []string{"install"})
os.Chdir(cwd)
}
func goGetAndMake(targetDir, name, goPath, url, p1 string) {
if noGit {
return
}
//p1 is the branch name
cwd, _ := os.Getwd()
doCommand("go", []string{"get", "-u", url})
os.Chdir(goPath)
os.Chdir("src")
os.Chdir(url)
doCommand("git", []string{"checkout", p1})
thsDir, _ := os.Getwd()
fmt.Printf("Making in %v\n", thsDir)
doCommand("make", []string{"install"})
os.Chdir(cwd)
}
func zipFilePath(b Config, name string) string {
path := fmt.Sprintf("%v/%v", b.ZipDir, name)
return path
}
func zipWithDirectory(b Config, p Package) {
cwd, _ := os.Getwd()
targetDir := fmt.Sprintf("%v", b.InstallDir) //Make an appsdir and install there?
os.Mkdir(targetDir, os.ModeDir|0777)
os.Chdir(targetDir)
unTar(b, zipFilePath(b, p.Zip))
unSevenZ(b, zipFilePath(b, p.Zip))
os.Chdir(cwd)
}
func zipWithNoDirectory(b Config, p Package) {
cwd, _ := os.Getwd()
targetDir := fmt.Sprintf("%v/%v", b.InstallDir, p.Name)
os.Mkdir(targetDir, os.ModeDir|0777)
os.Chdir(targetDir)
unTar(b, zipFilePath(b, p.Zip))
unSevenZ(b, zipFilePath(b, p.Zip))
os.Chdir(cwd)
}
func CopyFile(src, dst string) (int64, error) {
src_file, err := os.Open(src)
if err != nil {
return 0, err
}
defer src_file.Close()
src_file_stat, err := src_file.Stat()
if err != nil {
return 0, err
}
if !src_file_stat.Mode().IsRegular() {
return 0, fmt.Errorf("%s is not a regular file", src)
}
dst_file, err := os.Create(dst)
if err != nil {
return 0, err
}
defer dst_file.Close()
return io.Copy(dst_file, src_file)
}
func rawData(b Config, p Package) {
cwd, _ := os.Getwd()
targetDir := fmt.Sprintf("%v/%v", b.InstallDir, p.Name)
os.Mkdir(targetDir, os.ModeDir|0777)
os.Chdir(targetDir)
CopyFile(zipFilePath(b, p.Zip), p.Name)
os.Chdir(cwd)
}
func doFetch(p Package, b Config) {
fetch := p.Fetch
if fetch == "web" {
downloadFile(b.TempDir+"/"+p.Zip, fmt.Sprintf("%v/%v", b.ZipDir, p.Zip), p.Url)
}
if fetch == "git" {
if noGit {
return
}
url := p.Url
branch := p.Branch
name := p.Name
targetDir := b.InstallDir
cwd, _ := os.Getwd()
os.Chdir(targetDir)
doCommand("git", []string{"clone", url, name, "--recursive"})
os.Chdir(name)
doCommand("git", []string{"checkout", branch})
doCommand("git", []string{"pull"})
doCommand("git", []string{"submodule", "foreach", "--recursive", "git", "checkout", "master"})
os.Chdir(cwd)
}
}
func doGit(p Package, b Config) {
url := p.Url
branch := p.Branch
name := p.Name
targetDir := b.InstallDir
cwd, _ := os.Getwd()
os.Chdir(targetDir)
doCommand("git", []string{"clone", url, name})
os.Chdir(name)
doCommand("git", []string{"checkout", branch})
os.Chdir(cwd)
}
func force_winpath(str string) string {
winpath := strings.Replace(str, "/", "\\", -1)
return winpath
}
func msi(b Config, p Package) {
targetDir := fmt.Sprintf("%v/%v", b.InstallDir, p.Name)
fmt.Println(b.SzPath, zipFilePath(b, p.Zip))
// we can use /i to do full installs including registry updates, but that requires the user to click things
// prefer /a because it just dumps the files in the directory, and most open source programs don't actually
// use the registry
args := []string{"/a", force_winpath(zipFilePath(b, p.Zip)), fmt.Sprintf("INSTALLLOCATION=%v", force_winpath(targetDir)),
fmt.Sprintf("INSTALLDIR=%v", force_winpath(targetDir)),
fmt.Sprintf("TARGETDIR=%v", force_winpath(targetDir)),
"/q", "/lv", "log.txt"}
doCommand("msiexec.exe", args)
}
func dmg(b Config, p Package) {
targetDir := fmt.Sprintf("%v/%v", b.InstallDir, p.Name)
fmt.Println("I> installing ", zipFilePath(b, p.Zip), " to ", targetDir)
mountpoint, device := attachDMG(zipFilePath(b, p.Zip))
if mountpoint != "" {
fmt.Println("I> Mounted DMG on ", mountpoint)
copyFile(mountpoint+"/"+p.Name+".app", b.InstallDir)
detachDMG(device)
}
}
func doAll(p Package, b Config) {
figSay(p.Name)
targetDir := b.InstallDir
doFetch(p, b)
initialDir, _ := os.Getwd()
os.Chdir(targetDir)
//unBzLib(b, p.Name)
//unTgzLib(b, p.Name)
plan := p.Plan
os.Chdir(initialDir)
if plan == "standardConfigure" {
standardConfigureBuild(b, p.Name, ".", []string{makeOpt("prefix", targetDir)}) //, makeOpt("with-sysroot", targetDir)
} else if plan == "goGetAndMake" {
goGetAndMake(targetDir, p.Name, b.InstallDir, p.Url, p.Branch) //use zip field as goPath
} else if plan == "gitAndMake" {
Make(b, p) //use zip field as srcDir (i.e. buildDir)
} else if plan == "zipWithNoDirectory" {
zipWithNoDirectory(b, p)
} else if plan == "zipWithDirectory" {
zipWithDirectory(b, p)
} else if plan == "rawData" {
rawData(b, p)
} else if plan == "msi" {
msi(b, p)
} else if plan == "dmg" {
dmg(b, p)
} else if plan == "customCommand" {
//customCommand(b, p)
} else {
log.Println("Unknown plan: ", plan)
}
if p.BinDir != "" {
subPaths = append(subPaths, b.SourceDir+"/"+p.Name+"/"+p.BinDir)
}
for _, v := range p.BinDirs {
subPaths = append(subPaths, b.InstallDir+"/"+p.Name+"/"+v)
}
//Cleanup build files, if required
for _, v := range p.Deletes {
os.Remove(b.InstallDir + "/" + p.Name + "/" + v)
}
os.Chdir(b.InstallDir+"/"+p.Name)
fmt.Println("Current directory: ", goof.Cwd())
distZipPath := "dist.zip"
//Package up the binaries from the dist/ directory into a zip file
doCommand("zip", []string{"-r", distZipPath, "dist/"})
os.Chdir(initialDir)
}
func figSay(s string) {
fmt.Println(figlet(s))
}
var working = 0
func processDir(b Config, d string) {
log.Printf("Processing control files in %v\n", d)
files, err := ioutil.ReadDir(d)
if err != nil {
log.Fatal(err)
}
for _, file := range files {
//working = working + 1
fname := fmt.Sprintf("%v/%v", d, file.Name())
if _, err := os.Stat(fname); os.IsNotExist(err) {
fname = fmt.Sprintf("%v\\%v", d, file.Name())
}
p := LoadJSON(fname)
doAll(p, b)
//working--
}
}
func isWindows() bool {
return runtime.GOOS == "windows"
}
func isOSX() bool {
return runtime.GOOS == "darwin"
}
func main() {
flag.BoolVar(&noGcc, "no-gcc", false, "Don't install gcc locally")
flag.BoolVar(&noGo, "no-golang", false, "Don't install the Go compiler")
flag.BoolVar(&noGit, "no-git", false, "Don't attempt to clone or update with git")
flag.BoolVar(&noInstall, "no-install", false, "Don't install anything")
flag.StringVar(&oneFile, "file", "", "Install using settings from file")
flag.BoolVar(&develMode, "devel", false, "Only process packages-develop directory")
flag.Parse()
printEnv()
figSay(runtime.GOOS)
os.Setenv("CFLAGS", "-D_XOPEN_SOURCE=1")
folderPath, err := osext.ExecutableFolder()
if err != nil {
os.Exit(1)
}
//Update the predefined paths from relative to absolute
for i, v := range subPaths {
subPaths[i] = fmt.Sprintf("%v/%v", folderPath, v)
}
langlibs := fmt.Sprintf("%v/langlibs", folderPath)
gopathDir := fmt.Sprintf("%v/gopath", langlibs)
cpanDir := fmt.Sprintf("%v/cpan", langlibs)
zipsDir := fmt.Sprintf("%v/zips", folderPath)
rootDir := fmt.Sprintf("%v/%v", folderPath, installDir)
srcDir := fmt.Sprintf("%v/src", folderPath)
SzDir := fmt.Sprintf("%v/7zip", folderPath)
SzPath := fmt.Sprintf("%v/7zip/7z.exe", folderPath)
goDir := fmt.Sprintf("%v/go", folderPath)
tmpDir := fmt.Sprintf("%v/%v", folderPath, tempDir)
fmt.Println("I> Creating directories")
os.Mkdir(tmpDir, os.ModeDir|0777)
os.Mkdir(langlibs, os.ModeDir|0777)
os.Mkdir(gopathDir, os.ModeDir|0777)
os.Mkdir(cpanDir, os.ModeDir|0777)
os.Mkdir(zipsDir, os.ModeDir|0777)
os.Mkdir(rootDir, os.ModeDir|0777)
os.Mkdir(SzDir, os.ModeDir|0777)
os.Mkdir(srcDir, os.ModeDir|0777)
os.Mkdir("packages-develop", os.ModeDir|0777)
fmt.Println("I> Creating ", goDir)
os.Mkdir(goDir, os.ModeDir|0777)
os.Setenv("GOPATH", gopathDir)
os.Setenv("GOROOT_BOOTSTRAP", runtime.GOROOT())
os.Chdir(folderPath)
var b Config
b.InstallDir = rootDir
b.GoPath = gopathDir
b.SourceDir = srcDir
b.SzPath = SzPath
b.ZipDir = zipsDir
b.TempDir = tmpDir
fmt.Printf("I> Selected configuration: %+v\n", b)
//b.SiloDir = fmt.Sprintf("%v/silo", folderPath)
//os.Mkdir(b.SiloDir, os.ModeDir|0777)
downloadFile(b.TempDir+"/7z1604.exe", "zips/7z1604.exe", "http://www.7-zip.org/a/7z1604.exe")
if isWindows() {
figSay("7zip")
doCommand("zips/7z1604.exe", []string{"/S", fmt.Sprintf("/D=%v", SzDir)})
}
if oneFile != "" {
p := LoadJSON(oneFile)
doAll(p, b)
} else {
downloadFile(b.TempDir+"/nuwen-15.3.7.7z", "zips/nuwen-15.3.7.7z", "https://nuwen.net/files/mingw/components-15.3.7z")
downloadFile(b.TempDir+"/Sources.gz", "zips/Sources.gz", "http://nl.archive.ubuntu.com/ubuntu/dists/devel/main/source/Sources.gz")
downloadFile(b.TempDir+"/gcc-5.1.0-tdm64-1-core.zip", "zips/gcc-5.1.0-tdm64-1-core.zip", "https://kent.dl.sourceforge.net/project/tdm-gcc/TDM-GCC%205%20series/5.1.0-tdm64-1/gcc-5.1.0-tdm64-1-core.zip")
downloadFile(b.TempDir+"/gmp-6.1.2.tar.bz2", "zips/gmp-6.1.2.tar.bz2", "https://gmplib.org/download/gmp/gmp-6.1.2.tar.bz2")
figSay("GCC COMPILER")
if !noGcc {
if !isWindows() {
buildGcc(b, folderPath)
} else {
os.Chdir(rootDir)
doCommand("../7zip/7z.exe", []string{"x", "../zips/nuwen-15.3.7.7z"})
os.Chdir("components-15.3")
files, err := ioutil.ReadDir(".")
if err != nil {
log.Fatal(err)
}
for _, file := range files {
if strings.HasSuffix(file.Name(), "7z") {
unSevenZ(b, file.Name())
}
}
os.Chdir(folderPath)
printEnv()
}
}
os.Setenv("PATH", fmt.Sprintf("%v/components-15.3/bin/;%v", rootDir, os.Getenv("PATH")))
processDir(b, "packages-data")
if develMode {
processDir(b, "packages-develop")
} else {
switch {
case isWindows():
processDir(b, "packages-windows")
case isOSX():
processDir(b, "packages-osx")
default:
processDir(b, "packages")
}
}
var repos []string
if !develMode {
figSay("CPAN")
working++
func() {
repos = loadRepos("packages-other/cpan")
for _, v := range repos {
v = strings.Replace(v, "\r", "", -1)
installCpan(v)
}
working--
}()
}
if !develMode {
if !noGit {
figSay("LIBRARIES")
repos = loadRepos("packages-other/go_libs")
for _, v := range repos {
v = strings.Replace(v, "\r", "", -1)
installGoGithub(v)
}
figSay("APPLICATIONS")
repos = loadRepos("packages-other/go_apps")
for _, v := range repos {
v = strings.Replace(v, "\r", "", -1)
installGoGithub(v)
}
figSay("GITHUB")
repos = loadRepos("packages-other/github")
os.Mkdir("git", 0777)
os.Chdir(fmt.Sprintf("%v/git", folderPath))
for _, v := range repos {
v = strings.Replace(v, "\r", "", -1)
installGithub(v)
}
os.Chdir(folderPath)
}
}
}
fmt.Println(figlet("ENVIRONMENT"))
fmt.Printf("\nNow set your path with one of the following commands\n\n")
fmt.Println("Windows:")
var text string = fmt.Sprintf("set GOPATH=%v/go\n", folderPath)
for _, v := range subPaths {
winpath := strings.Replace(v, "/", "\\", -1)
text = fmt.Sprintf("%sset PATH=%v;%%PATH%%\n", text, winpath)
}
text = text + "\nstart cmd /k cmder\nstart cmd /k cmd"
fmt.Println(text)
ioutil.WriteFile("environment.bat", []byte(text), 0644)
text = ""
fmt.Println("Fish Shell:")
for _, v := range subPaths {
text = fmt.Sprintf("%sset -x PATH %v $PATH\n", text, v)
}
fmt.Println(text)
ioutil.WriteFile("environment.fish", []byte(text), 0644)
text = ""
fmt.Println("Bash Shell")
for _, v := range subPaths {
text = fmt.Sprintf("%sexport PATH=%v:$PATH\n", text, v)
}
fmt.Println(text)
ioutil.WriteFile("environment.bash", []byte(text), 0644)
text = ""
for {
time.Sleep(1 * time.Second)
}
fmt.Printf("Job's a good'un, boss\n")
}
func setCommand(p string) string {
return fmt.Sprintf("set -x PATH %v $PATH\nexport PATH=%v/:$PATH\nset PATH=%v;\n\n\n", p, p, p)
}