-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.go
79 lines (66 loc) · 1.92 KB
/
setup.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
// Writing a setup script in Go is a terrible idea, but practice is practice.
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"strings"
)
func main() {
var homedir string = os.Getenv("HOME") + "/"
fmt.Println(homedir) // /home/rafael
var repodir string = homedir + "x/"
fmt.Println(repodir) // /home/rafael/x/
files, err := ioutil.ReadDir("/home/rafael/x")
if err != nil {
log.Fatal(err)
}
fmt.Println(files)
printMessage("INFO", "Running a command")
printMessage("ADD", "Running a command")
printMessage("WARN", "Running a command")
printMessage("ERR", "Running a command")
cmd := exec.Command("ls", "-alh", "/etc/skel")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
fmt.Println("cmd.Run() failed: ", err)
}
}
// Check if a given file or directory exists
func exists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
// Prints a message to the console with a coloured status (Info, Warn, Err)
func printMessage(messageLevel string, message string) {
var level = strings.ToLower(messageLevel)
if level == "info" {
fmt.Println("\033[1;34m[i]\033[0;37m " + message)
} else if level == "add" {
fmt.Println("\033[1;32m[+]\033[0;37m " + message)
} else if level == "warn" {
fmt.Println("\033[1;33m[*]\033[0;37m " + message)
} else {
fmt.Println("\033[1;31m[!]\033[0;37m " + message)
}
}
/* TO DO:
* https://gobyexample.com/directories
* https://blog.kowalczyk.info/article/wOYk/advanced-command-execution-in-go-with-osexec.html
* https://golang.org/pkg/os/
* Remove the default files in /etc/skel and replace with ones from dotfiles/config
* Sync the vim plugins directory
* Create symlinks for useful directories if they exist - gdrive, documents, etc
* Sync git repositories
* Define and build go modules (then create a separate go module to rebuild them)
*/