refactor: seperate functionality into files
This commit is contained in:
parent
715e086fcd
commit
3081e34e2b
11 changed files with 871 additions and 792 deletions
43
dotfiles.go
Normal file
43
dotfiles.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type DotfilesConfig struct {
|
||||
Enable bool `mapstructure:"enable"`
|
||||
GitRepo string `mapstructure:"git_repo"`
|
||||
}
|
||||
|
||||
func setupDotfiles(config DotfilesConfig) error {
|
||||
if _, err := exec.LookPath("git"); err != nil {
|
||||
return fmt.Errorf("git ist nicht installiert")
|
||||
}
|
||||
|
||||
if _, err := exec.LookPath("stow"); err != nil {
|
||||
return fmt.Errorf("gnu stow ist nicht installiert")
|
||||
}
|
||||
|
||||
dotfilesDir := filepath.Join(os.Getenv("HOME"), "dotfiles")
|
||||
|
||||
cmd := exec.Command("git", "clone", config.GitRepo)
|
||||
if err := cmd.Run(); err != nil {
|
||||
return fmt.Errorf("Fehler beim Klonen der Dotfiles: %v", err)
|
||||
}
|
||||
|
||||
if err := os.Chdir(dotfilesDir); err != nil {
|
||||
return fmt.Errorf("Fehler beim Wechseln in das Dotfiles-Verzeichnis: %v", err)
|
||||
}
|
||||
|
||||
cmd = exec.Command("stow", ".")
|
||||
if err := cmd.Run(); err != nil {
|
||||
log.Printf("Fehler beim Linken: %v", err)
|
||||
}
|
||||
fmt.Printf("Alles erfolgreich verlinkt\n")
|
||||
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue