system_setup_tool/dotfiles.go

43 lines
972 B
Go

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
}