7 Commits
v0.38 ... v0.39

5 changed files with 39 additions and 23 deletions

View File

@ -1,8 +1,9 @@
package cmd package cmd
import ( import (
"errors" "os"
"fmt" "fmt"
"errors"
"reflect" "reflect"
"strconv" "strconv"
"strings" "strings"
@ -20,7 +21,7 @@ func GetJailProperties(args []string) {
jail, err = getJailFromArray(a, []string{""}, gJails) jail, err = getJailFromArray(a, []string{""}, gJails)
if err != nil { if err != nil {
fmt.Printf("Error: %s\n", err.Error()) fmt.Printf("Error: %s\n", err.Error())
return os.Exit(1)
} }
} else { } else {
props = append(props, a) props = append(props, a)
@ -105,20 +106,20 @@ func SetJailProperties(args []string) {
return return
} }
// Get jail by index to modify it cj, err := getJailFromArray(jail.Name, []string{""}, gJails)
for i, _ := range gJails { if err != nil {
if gJails[i].Name == jail.Name { fmt.Printf("Error getting jail %s: %v\n", jail.Name, err)
for _, p := range props { return
err := setStructFieldValue(&gJails[i], p.name, p.value) }
if err != nil {
fmt.Printf("Error: %s\n", err.Error()) for _, p := range props {
return err := setStructFieldValue(cj, p.name, p.value)
} else { if err != nil {
fmt.Printf("%s: %s set to %s\n", gJails[i].Name, p.name, p.value) fmt.Printf("Error: %s\n", err.Error())
gJails[i].ConfigUpdated = true return
} } else {
} fmt.Printf("%s: %s set to %s\n", cj.Name, p.name, p.value)
writeConfigToDisk(&gJails[i], false)
} }
} }
cj.WriteConfigToDisk(false)
} }

View File

@ -14,7 +14,7 @@ import (
) )
const ( const (
gVersion = "0.38" gVersion = "0.39"
// TODO : Get from $jail_zpool/defaults.json // TODO : Get from $jail_zpool/defaults.json
MIN_DYN_DEVFS_RULESET = 1000 MIN_DYN_DEVFS_RULESET = 1000

View File

@ -840,7 +840,7 @@ func setupVnetInterfaceHostSide(jail *Jail) ([]string, error) {
bridge := v[1] bridge := v[1]
// Get host side MAC // Get host side MAC
pname := fmt.Sprintf("Config.%s_mac", nic) pname := fmt.Sprintf("Config.%s_mac", strings.Title(nic))
var val *reflect.Value var val *reflect.Value
val, pname, err = getStructFieldValue(jail, pname) val, pname, err = getStructFieldValue(jail, pname)
if err != nil { if err != nil {
@ -853,7 +853,10 @@ func setupVnetInterfaceHostSide(jail *Jail) ([]string, error) {
return []string{}, err return []string{}, err
} }
} else { } else {
hsmac = val.Bytes() hsmac, err = hex.DecodeString(strings.Split(val.String(), " ")[0])
if err != nil {
return []string{}, fmt.Errorf("Error converting %s to hex\n", strings.Split(val.String(), " ")[0])
}
} }
// Get bridge MTU // Get bridge MTU
@ -934,7 +937,7 @@ func setupVnetInterfaceJailSide(jail *Jail, hostepairs []string) error {
jsepair := fmt.Sprintf("%sb", strings.TrimSuffix(hostepairs[i], "a")) jsepair := fmt.Sprintf("%sb", strings.TrimSuffix(hostepairs[i], "a"))
// Get jail side MAC // Get jail side MAC
pname := fmt.Sprintf("Config.%s_mac", nic) pname := fmt.Sprintf("Config.%s_mac", strings.Title(nic))
var val *reflect.Value var val *reflect.Value
val, pname, err = getStructFieldValue(jail, pname) val, pname, err = getStructFieldValue(jail, pname)
if err != nil { if err != nil {
@ -947,7 +950,11 @@ func setupVnetInterfaceJailSide(jail *Jail, hostepairs []string) error {
return err return err
} }
} else { } else {
jsmac = val.Bytes() jsmac, err = hex.DecodeString(strings.Split(val.String(), " ")[1])
if err != nil {
return fmt.Errorf("Error converting %s to hex\n", strings.Split(val.String(), " ")[1])
}
} }
cmd := fmt.Sprintf("/sbin/ifconfig %s vnet %s", jsepair, jail.InternalName) cmd := fmt.Sprintf("/sbin/ifconfig %s vnet %s", jsepair, jail.InternalName)

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
//"log" //"log"
"time" "time"
"strings"
) )
@ -62,7 +63,13 @@ func UpdateJail(args []string) {
fmt.Printf("Error getting jail: %s\n", err) fmt.Printf("Error getting jail: %s\n", err)
continue continue
} }
// We cant update basejail as system is readonly
if strings.EqualFold(cj.Config.Jailtype, "basejail") {
fmt.Printf("%s is a basejail using %s system files. Please update %s!\n", cj.Name, cj.Config.Origin, cj.Config.Origin)
continue
}
fmt.Printf(" > Snapshot jail %s\n", cj.Name) fmt.Printf(" > Snapshot jail %s\n", cj.Name)
// Set snapshot name // Set snapshot name
dt := time.Now() dt := time.Now()

View File

@ -917,7 +917,8 @@ func getFstab(path string) ([]Mount, error) {
scan := bufio.NewScanner(f) scan := bufio.NewScanner(f)
for scan.Scan() { for scan.Scan() {
res := strings.Fields(scan.Text()) res := strings.Fields(scan.Text())
if len(res) != 6 { // iocage create lines like that : "/iocage/releases/13.2-RELEASE/root/bin /iocage/jails/smtp-router-02/root/bin nullfs ro 0 0 # Added by iocage on 2023-10-10 17:20:51"
if (len(res) > 6 && !strings.EqualFold(res[6], "#")) || len(res) < 6 {
return mounts, fmt.Errorf("Incorrect format for fstab line %s", scan.Text()) return mounts, fmt.Errorf("Incorrect format for fstab line %s", scan.Text())
} }
freq, err := strconv.Atoi(res[4]) freq, err := strconv.Atoi(res[4])