42 lines
988 B
Go
42 lines
988 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
type DotfilesConfig struct {
|
|
Enable bool `mapstructure:"enable"`
|
|
GitRepo string `mapstructure:"git_repo"`
|
|
}
|
|
|
|
func setupDotfiles(config DotfilesConfig) error {
|
|
if _, err := execLookPath("git"); err != nil {
|
|
return fmt.Errorf("git ist nicht installiert")
|
|
}
|
|
|
|
if _, err := execLookPath("stow"); err != nil {
|
|
return fmt.Errorf("gnu stow ist nicht installiert")
|
|
}
|
|
|
|
dotfilesDir := filepath.Join(os.Getenv("HOME"), "dotfiles")
|
|
|
|
cmd := execCommand("git", "clone", config.GitRepo, dotfilesDir)
|
|
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 = execCommand("stow", ".", "--override='*'")
|
|
if err := cmd.Run(); err != nil {
|
|
log.Printf("Fehler beim Linken: %v", err)
|
|
}
|
|
fmt.Printf("Alles erfolgreich verlinkt\n")
|
|
|
|
return nil
|
|
}
|