templatefile/pkg/templater/repo-deb.go

44 lines
766 B
Go
Raw Normal View History

2022-06-27 15:58:37 +02:00
package templater
import (
"fmt"
"os"
"forge.cadoles.com/pcaseiro/templatefile/pkg/utils"
)
type DebRepository struct {
2022-06-29 16:18:28 +02:00
Repository
2022-06-27 15:58:37 +02:00
}
func (hr *DebRepository) Add() error {
//deb http://fr.archive.ubuntu.com/ubuntu/ focal main restricted
data := fmt.Sprintf("deb %s", hr.URL)
2022-06-29 12:13:32 +02:00
if err := os.WriteFile("/etc/apt/source.list.d", []byte(data), 0600); err != nil {
2022-06-27 15:58:37 +02:00
return err
}
return nil
}
func (hr *DebRepository) Update() error {
if _, stdErr, err := utils.RunSystemCommand("apt", "update", "-y"); err != nil {
return fmt.Errorf("%s [%s]", stdErr, err)
}
return nil
}
func (hr *DebRepository) Delete() error {
//TODO
return nil
}
func (hr *DebRepository) Manage() error {
if hr.Enabled {
return hr.Add()
} else {
return hr.Delete()
}
}