mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-19 17:25:01 +00:00
* ✨ Add state api This is related to https://github.com/kairos-io/kairos/issues/34. Starts to unify the API to retrieve the state in the sdk to have a common place to query system status information. * 🤖 Add test * Update go.mod * ⚙️ Fine-tune detection of partitions * 🤖 Add more fine-grained tests * 🎨 Add /dev/ to partition name * 🤖 Fixup tests * ⚙️ Remount accessors * ✨ Add state partition to cloud-init paths * 📝 Upper case Kairos in motd * 🎨 Add mounts sdk * 🎨 Set grub options via SDK * 🎨 Make it more idiomatic
49 lines
1010 B
Go
49 lines
1010 B
Go
package machine
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/kairos-io/kairos/pkg/utils"
|
|
)
|
|
|
|
func Umount(path string) error {
|
|
out, err := utils.SH(fmt.Sprintf("umount %s", path))
|
|
if err != nil {
|
|
return fmt.Errorf("failed umounting: %s: %w", out, err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func Remount(opt, path string) error {
|
|
out, err := utils.SH(fmt.Sprintf("mount -o %s,remount %s", opt, path))
|
|
if err != nil {
|
|
return fmt.Errorf("failed umounting: %s: %w", out, err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func Mount(label, mountpoint string) error {
|
|
part, _ := utils.SH(fmt.Sprintf("blkid -L %s", label))
|
|
if part == "" {
|
|
fmt.Printf("%s partition not found\n", label)
|
|
return fmt.Errorf("partition not found")
|
|
}
|
|
|
|
part = strings.TrimSuffix(part, "\n")
|
|
|
|
if !Exists(mountpoint) {
|
|
err := os.MkdirAll(mountpoint, 0755)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
mount, err := utils.SH(fmt.Sprintf("mount %s %s", part, mountpoint))
|
|
if err != nil {
|
|
fmt.Printf("could not mount: %s\n", mount+err.Error())
|
|
return err
|
|
}
|
|
return nil
|
|
}
|