Compare commits
	
		
			14 Commits
		
	
	
		
			v0.40
			...
			2507f10b59
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 2507f10b59 | |||
| 900e1939f3 | |||
| 43a958cdec | |||
| 5b9862d641 | |||
| 7ca633d946 | |||
| 199b3b1f7f | |||
| 372e92fc41 | |||
| 2afccc5a0e | |||
| 3d77209b53 | |||
| 5ce62bc7de | |||
| 0e0ab8c653 | |||
| 3b548e4c85 | |||
| 9d7db268cc | |||
| 4cc1c476aa | 
							
								
								
									
										96
									
								
								cmd/api.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										96
									
								
								cmd/api.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,96 @@
 | 
				
			|||||||
 | 
					package cmd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						//"io"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
 | 
						"github.com/gin-contrib/cors"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func printJails(jails []string, fields []string) ([]byte, error) {
 | 
				
			||||||
 | 
						var res []byte
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						res = append(res, []byte("[")...)
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// Build a filtered jail list
 | 
				
			||||||
 | 
						var filteredJails []Jail
 | 
				
			||||||
 | 
						if (len(jails) >= 1 && len(jails[0]) > 0) {
 | 
				
			||||||
 | 
							for _, j := range gJails {
 | 
				
			||||||
 | 
								if isStringInArray(jails, j.Name) {
 | 
				
			||||||
 | 
									filteredJails = append(filteredJails, j)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							filteredJails = gJails
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						for i, j := range filteredJails {
 | 
				
			||||||
 | 
							out, err := j.PrintJSON(fields)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return res, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							res = append(res, out...)
 | 
				
			||||||
 | 
							if i < len(filteredJails) - 1 {
 | 
				
			||||||
 | 
								res = append(res, []byte(",")...)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						res = append(res, []byte("]")...)
 | 
				
			||||||
 | 
						return res, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func startApi(address string, port int) {
 | 
				
			||||||
 | 
						// Initialize gJails. 
 | 
				
			||||||
 | 
						// FIXME: How to update this at running time without doubling the same jails?
 | 
				
			||||||
 | 
						// core will do this for us in add and delete functions
 | 
				
			||||||
 | 
						ListJails([]string{""}, false)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						r := gin.Default()
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// Cross Origin Request Support
 | 
				
			||||||
 | 
						config := cors.DefaultConfig()
 | 
				
			||||||
 | 
						// DANGER !
 | 
				
			||||||
 | 
						config.AllowOrigins = []string{"*"}
 | 
				
			||||||
 | 
						r.Use(cors.New(config))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						r.GET("/jail/list", func(c *gin.Context) {
 | 
				
			||||||
 | 
							jailstr := c.Query("jail")
 | 
				
			||||||
 | 
							fields := c.Query("fields")
 | 
				
			||||||
 | 
							if len(fields) == 0 {
 | 
				
			||||||
 | 
								// TODO : Put this default value in (user?) configuration
 | 
				
			||||||
 | 
								fields = "Name,Running,Config.Release,Config.Ip4_addr"
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							jsout, err := printJails(strings.Split(jailstr, ","), strings.Split(fields, ","))
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								c.JSON(http.StatusInternalServerError, gin.H{"status": 1, "error": err.Error()})
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								c.Data(http.StatusOK, "application/json", jsout)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						r.POST("/jail/start/:jail", func(c *gin.Context) {
 | 
				
			||||||
 | 
							jailstr := c.Params.ByName("jail")
 | 
				
			||||||
 | 
							// TODO : Capture or redirect output so we can know if jail was started or not
 | 
				
			||||||
 | 
							StartJail(strings.Split(jailstr, ","))
 | 
				
			||||||
 | 
							c.JSON(http.StatusOK, gin.H{"status": 0, "error": ""})
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						r.POST("/jail/stop/:jail", func(c *gin.Context) {
 | 
				
			||||||
 | 
							jailstr := c.Params.ByName("jail")
 | 
				
			||||||
 | 
							// TODO : Capture or redirect output so we can know if jail was started or not
 | 
				
			||||||
 | 
							StopJail(strings.Split(jailstr, ","))
 | 
				
			||||||
 | 
							c.JSON(http.StatusOK, gin.H{"status": 0, "error": ""})
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						r.GET("/jail/properties", func(c *gin.Context) {
 | 
				
			||||||
 | 
							props, err := ListJailsProps("json")
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								c.JSON(http.StatusInternalServerError, gin.H{"status": 1, "error": err.Error()})
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								c.Data(http.StatusOK, "application/json", []byte(props))
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						r.Run(fmt.Sprintf("%s:%d", address, port))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -1,85 +0,0 @@
 | 
				
			|||||||
package cmd
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const (
 | 
					 | 
				
			||||||
	fbsdUpdateConfig = `
 | 
					 | 
				
			||||||
	# $FreeBSD$
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	# Trusted keyprint.  Changing this is a Bad Idea unless you've received
 | 
					 | 
				
			||||||
	# a PGP-signed email from <security-officer@FreeBSD.org> telling you to
 | 
					 | 
				
			||||||
	# change it and explaining why.
 | 
					 | 
				
			||||||
	KeyPrint 800651ef4b4c71c27e60786d7b487188970f4b4169cc055784e21eb71d410cc5
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	# Server or server pool from which to fetch updates.  You can change
 | 
					 | 
				
			||||||
	# this to point at a specific server if you want, but in most cases
 | 
					 | 
				
			||||||
	# using a "nearby" server won't provide a measurable improvement in
 | 
					 | 
				
			||||||
	# performance.
 | 
					 | 
				
			||||||
	ServerName update.FreeBSD.org
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	# Components of the base system which should be kept updated.
 | 
					 | 
				
			||||||
	Components world
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	# Example for updating the userland and the kernel source code only:
 | 
					 | 
				
			||||||
	# Components src/base src/sys world
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	# Paths which start with anything matching an entry in an IgnorePaths
 | 
					 | 
				
			||||||
	# statement will be ignored.
 | 
					 | 
				
			||||||
	IgnorePaths
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	# Paths which start with anything matching an entry in an IDSIgnorePaths
 | 
					 | 
				
			||||||
	# statement will be ignored by "freebsd-update IDS".
 | 
					 | 
				
			||||||
	IDSIgnorePaths /usr/share/man/cat
 | 
					 | 
				
			||||||
	IDSIgnorePaths /usr/share/man/whatis
 | 
					 | 
				
			||||||
	IDSIgnorePaths /var/db/locate.database
 | 
					 | 
				
			||||||
	IDSIgnorePaths /var/log
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	# Paths which start with anything matching an entry in an UpdateIfUnmodified
 | 
					 | 
				
			||||||
	# statement will only be updated if the contents of the file have not been
 | 
					 | 
				
			||||||
	# modified by the user (unless changes are merged; see below).
 | 
					 | 
				
			||||||
	UpdateIfUnmodified /etc/ /var/ /root/ /.cshrc /.profile
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	# When upgrading to a new FreeBSD release, files which match MergeChanges
 | 
					 | 
				
			||||||
	# will have any local changes merged into the version from the new release.
 | 
					 | 
				
			||||||
	MergeChanges /etc/
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	### Default configuration options:
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	# Directory in which to store downloaded updates and temporary
 | 
					 | 
				
			||||||
	# files used by FreeBSD Update.
 | 
					 | 
				
			||||||
	WorkDir /iocage/freebsd-update
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	# Destination to send output of "freebsd-update cron" if an error
 | 
					 | 
				
			||||||
	# occurs or updates have been downloaded.
 | 
					 | 
				
			||||||
	# MailTo root
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	# Is FreeBSD Update allowed to create new files?
 | 
					 | 
				
			||||||
	# AllowAdd yes
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	# Is FreeBSD Update allowed to delete files?
 | 
					 | 
				
			||||||
	# AllowDelete yes
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	# If the user has modified file ownership, permissions, or flags, should
 | 
					 | 
				
			||||||
	# FreeBSD Update retain this modified metadata when installing a new version
 | 
					 | 
				
			||||||
	# of that file?
 | 
					 | 
				
			||||||
	# KeepModifiedMetadata yes
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	# When upgrading between releases, should the list of Components be
 | 
					 | 
				
			||||||
	# read strictly (StrictComponents yes) or merely as a list of components
 | 
					 | 
				
			||||||
	# which *might* be installed of which FreeBSD Update should figure out
 | 
					 | 
				
			||||||
	# which actually are installed and upgrade those (StrictComponents no)?
 | 
					 | 
				
			||||||
	StrictComponents yes
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	# When installing a new kernel perform a backup of the old one first
 | 
					 | 
				
			||||||
	# so it is possible to boot the old kernel in case of problems.
 | 
					 | 
				
			||||||
	BackupKernel no
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	# If BackupKernel is enabled, the backup kernel is saved to this
 | 
					 | 
				
			||||||
	# directory.
 | 
					 | 
				
			||||||
	# BackupKernelDir /boot/kernel.old
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	# When backing up a kernel also back up debug symbol files?
 | 
					 | 
				
			||||||
	BackupKernelSymbolFiles no
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	# Create a new boot environment when installing patches
 | 
					 | 
				
			||||||
	CreateBootEnv no
 | 
					 | 
				
			||||||
	`
 | 
					 | 
				
			||||||
) 
 | 
					 | 
				
			||||||
							
								
								
									
										26
									
								
								cmd/list.go
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								cmd/list.go
									
									
									
									
									
								
							@ -15,23 +15,37 @@ import (
 | 
				
			|||||||
 * List all properties a jail have, with their internal name
 | 
					 * List all properties a jail have, with their internal name
 | 
				
			||||||
 * Only print properties name. To get name & values, use GetJailProperties()
 | 
					 * Only print properties name. To get name & values, use GetJailProperties()
 | 
				
			||||||
 *******************************************************************************/
 | 
					 *******************************************************************************/
 | 
				
			||||||
func ListJailsProps(args []string) {
 | 
					func ListJailsProps(format string) (string, error) {
 | 
				
			||||||
	var conf Jail
 | 
						var conf Jail
 | 
				
			||||||
	var result []string
 | 
						var props []string
 | 
				
			||||||
 | 
						var out string
 | 
				
			||||||
	// Mandatory constructor to init default values
 | 
						// Mandatory constructor to init default values
 | 
				
			||||||
	jailconf, err := NewJailConfig()
 | 
						jailconf, err := NewJailConfig()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		fmt.Printf("Error allocating JailConfig: %s\n", err.Error())
 | 
							fmt.Printf("Error allocating JailConfig: %s\n", err.Error())
 | 
				
			||||||
		return
 | 
							return out, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	conf.Config = jailconf
 | 
						conf.Config = jailconf
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	result = getStructFieldNames(conf, result, "")
 | 
						props = getStructFieldNames(conf, props, "")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, f := range result {
 | 
						if format == "json" {
 | 
				
			||||||
		fmt.Printf("%s\n", f)
 | 
							out = "{\"properties\":["
 | 
				
			||||||
 | 
							for i, p := range props {
 | 
				
			||||||
 | 
								out += fmt.Sprintf("\"%s\"", p)
 | 
				
			||||||
 | 
								if i < len(props) - 1 {
 | 
				
			||||||
 | 
									out += ","
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							out += "]}"
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							for _, p := range props {
 | 
				
			||||||
 | 
								out += fmt.Sprintf("%s\n", p)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return out, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/********************************************************************************
 | 
					/********************************************************************************
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										70
									
								
								cmd/root.go
									
									
									
									
									
								
							
							
						
						
									
										70
									
								
								cmd/root.go
									
									
									
									
									
								
							@ -14,7 +14,7 @@ import (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	gVersion = "0.40"
 | 
						gVersion = "0.42b"
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	// TODO : Get from $jail_zpool/defaults.json
 | 
						// TODO : Get from $jail_zpool/defaults.json
 | 
				
			||||||
	MIN_DYN_DEVFS_RULESET = 1000
 | 
						MIN_DYN_DEVFS_RULESET = 1000
 | 
				
			||||||
@ -28,6 +28,9 @@ type createArgs struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var (
 | 
					var (
 | 
				
			||||||
 | 
						gApiAddress string
 | 
				
			||||||
 | 
						gApiPort    int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	gJailHost   JailHost
 | 
						gJailHost   JailHost
 | 
				
			||||||
	gJails      []Jail
 | 
						gJails      []Jail
 | 
				
			||||||
	gDatastores []Datastore
 | 
						gDatastores []Datastore
 | 
				
			||||||
@ -56,6 +59,9 @@ var (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	gTimeZone     string
 | 
						gTimeZone     string
 | 
				
			||||||
	gSnapshotName string
 | 
						gSnapshotName string
 | 
				
			||||||
 | 
						gZPool        string
 | 
				
			||||||
 | 
						gBridge       string
 | 
				
			||||||
 | 
						gInterface    string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	gMigrateDestDatastore string
 | 
						gMigrateDestDatastore string
 | 
				
			||||||
	gYesToAll             bool
 | 
						gYesToAll             bool
 | 
				
			||||||
@ -97,19 +103,13 @@ It support iocage jails and can coexist with iocage.`,
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* TODO
 | 
					 | 
				
			||||||
	Initialize datastore(s) /iocage, /iocage/jails
 | 
					 | 
				
			||||||
	Put defaults.json, update it with hostid,interfaces, and maybe other necessary fields
 | 
					 | 
				
			||||||
	Initialize bridge
 | 
					 | 
				
			||||||
	initCmd = &cobra.Command{
 | 
						initCmd = &cobra.Command{
 | 
				
			||||||
		Use:   "init",
 | 
							Use:   "init",
 | 
				
			||||||
		Short: "Initialize GoCage",
 | 
							Short: "Initialize GoCage",
 | 
				
			||||||
		//Long:  `Let this show you how much fail I had to get this *cough* perfect`,
 | 
					 | 
				
			||||||
		Run: func(cmd *cobra.Command, args []string) {
 | 
							Run: func(cmd *cobra.Command, args []string) {
 | 
				
			||||||
			fv, _ := getFreeBSDVersion()
 | 
								InitGoCage(args)
 | 
				
			||||||
			fmt.Printf("GoCage v.%s on FreeBSD %d.%d-%s\n", gVersion, fv.major, fv.minor, fv.flavor)
 | 
					 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}*/
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	listCmd = &cobra.Command{
 | 
						listCmd = &cobra.Command{
 | 
				
			||||||
		Use:   "list",
 | 
							Use:   "list",
 | 
				
			||||||
@ -127,7 +127,12 @@ ex: gocage list srv-db srv-web`,
 | 
				
			|||||||
		Short: "Print jails properties",
 | 
							Short: "Print jails properties",
 | 
				
			||||||
		Long:  "Display jails properties. You can use properties to filter, get or set them.",
 | 
							Long:  "Display jails properties. You can use properties to filter, get or set them.",
 | 
				
			||||||
		Run: func(cmd *cobra.Command, args []string) {
 | 
							Run: func(cmd *cobra.Command, args []string) {
 | 
				
			||||||
			ListJailsProps(args)
 | 
								out, err := ListJailsProps("text")
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									fmt.Printf("Error listing properties : %v\n", err)
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									fmt.Printf("%s\n", out)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -357,6 +362,14 @@ You can specify multiple datastores.`,
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						apiCmd = &cobra.Command{
 | 
				
			||||||
 | 
							Use:   "startapi",
 | 
				
			||||||
 | 
							Short: "Run docage as a daemon, exposing API",
 | 
				
			||||||
 | 
							Run: func(cmd *cobra.Command, args []string) {
 | 
				
			||||||
 | 
								startApi(gApiAddress, gApiPort)
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	testCmd = &cobra.Command{
 | 
						testCmd = &cobra.Command{
 | 
				
			||||||
		Use:   "test",
 | 
							Use:   "test",
 | 
				
			||||||
		Short: "temporary command to test some code snippet",
 | 
							Short: "temporary command to test some code snippet",
 | 
				
			||||||
@ -379,6 +392,10 @@ func init() {
 | 
				
			|||||||
	rootCmd.PersistentFlags().BoolVar(&gDebug, "debug", false, "Debug mode")
 | 
						rootCmd.PersistentFlags().BoolVar(&gDebug, "debug", false, "Debug mode")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Command dependant switches
 | 
						// Command dependant switches
 | 
				
			||||||
 | 
						initCmd.Flags().StringVarP(&gZPool, "pool", "p", "", "ZFS pool to create datastore on")
 | 
				
			||||||
 | 
						initCmd.Flags().StringVarP(&gBridge, "bridge", "b", "", "bridge to create for jails networking")
 | 
				
			||||||
 | 
						initCmd.Flags().StringVarP(&gInterface, "interface", "i", "", "interface to add as bridge member. This should be your main interface")
 | 
				
			||||||
 | 
						initCmd.MarkFlagsRequiredTogether("bridge", "interface")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// We reuse these flags in "gocage snapshot list myjail" and 'gocage datastore list" commands
 | 
						// We reuse these flags in "gocage snapshot list myjail" and 'gocage datastore list" commands
 | 
				
			||||||
	listCmd.Flags().StringVarP(&gDisplayJColumns, "outcol", "o", "JID,Name,Config.Release,Config.Ip4_addr,Running", "Show these columns in output")
 | 
						listCmd.Flags().StringVarP(&gDisplayJColumns, "outcol", "o", "JID,Name,Config.Release,Config.Ip4_addr,Running", "Show these columns in output")
 | 
				
			||||||
@ -423,7 +440,11 @@ func init() {
 | 
				
			|||||||
	createCmd.Flags().BoolVarP(&gCreateArgs.BaseJail, "basejail", "b", false, "Basejail. This will create a jail mounted read only from a release, so every up(date|grade) made to this release will immediately propagate to new jail.\n")
 | 
						createCmd.Flags().BoolVarP(&gCreateArgs.BaseJail, "basejail", "b", false, "Basejail. This will create a jail mounted read only from a release, so every up(date|grade) made to this release will immediately propagate to new jail.\n")
 | 
				
			||||||
	createCmd.Flags().StringVarP(&gCreateArgs.Datastore, "datastore", "d", "", "Datastore to create the jail on. Defaults to first declared in config.")
 | 
						createCmd.Flags().StringVarP(&gCreateArgs.Datastore, "datastore", "d", "", "Datastore to create the jail on. Defaults to first declared in config.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						apiCmd.Flags().StringVarP(&gApiAddress, "listen-addr", "l", "127.0.0.1", "API listening address")
 | 
				
			||||||
 | 
						apiCmd.Flags().IntVarP(&gApiPort, "listen-port", "p", 1234, "API listening port")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Now declare commands
 | 
						// Now declare commands
 | 
				
			||||||
 | 
						rootCmd.AddCommand(initCmd)
 | 
				
			||||||
	rootCmd.AddCommand(versionCmd)
 | 
						rootCmd.AddCommand(versionCmd)
 | 
				
			||||||
	rootCmd.AddCommand(listCmd)
 | 
						rootCmd.AddCommand(listCmd)
 | 
				
			||||||
	listCmd.AddCommand(listPropsCmd)
 | 
						listCmd.AddCommand(listPropsCmd)
 | 
				
			||||||
@ -441,7 +462,7 @@ func init() {
 | 
				
			|||||||
	rootCmd.AddCommand(updateCmd)
 | 
						rootCmd.AddCommand(updateCmd)
 | 
				
			||||||
	rootCmd.AddCommand(upgradeCmd)
 | 
						rootCmd.AddCommand(upgradeCmd)
 | 
				
			||||||
	rootCmd.AddCommand(createCmd)
 | 
						rootCmd.AddCommand(createCmd)
 | 
				
			||||||
	
 | 
						rootCmd.AddCommand(apiCmd)
 | 
				
			||||||
	rootCmd.AddCommand(testCmd)
 | 
						rootCmd.AddCommand(testCmd)
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	snapshotCmd.AddCommand(snapshotListCmd)
 | 
						snapshotCmd.AddCommand(snapshotListCmd)
 | 
				
			||||||
@ -472,17 +493,6 @@ func initConfig() {
 | 
				
			|||||||
		os.Exit(1)
 | 
							os.Exit(1)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Load default configs from datastores
 | 
					 | 
				
			||||||
	err := ListDatastores(viper.GetStringSlice("datastore"), false)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		fmt.Printf("ERROR: error checking datastores: %v\n", err)
 | 
					 | 
				
			||||||
		os.Exit(1)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	//	fmt.Println("Using config file:", viper.ConfigFileUsed())
 | 
					 | 
				
			||||||
	//	fmt.Printf("datastore in config : %s\n", viper.GetStringSlice("datastore"))
 | 
					 | 
				
			||||||
	//	fmt.Printf("datastore.0 in config : %s\n", viper.GetStringSlice("datastore.0"))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Command line flags have priority on config file
 | 
						// Command line flags have priority on config file
 | 
				
			||||||
	if rootCmd.Flags().Lookup("sudo") != nil && false == rootCmd.Flags().Lookup("sudo").Changed {
 | 
						if rootCmd.Flags().Lookup("sudo") != nil && false == rootCmd.Flags().Lookup("sudo").Changed {
 | 
				
			||||||
		gUseSudo = viper.GetBool("sudo")
 | 
							gUseSudo = viper.GetBool("sudo")
 | 
				
			||||||
@ -516,11 +526,25 @@ func initConfig() {
 | 
				
			|||||||
		os.Exit(1)
 | 
							os.Exit(1)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	if gDebug {
 | 
						if gDebug {
 | 
				
			||||||
		log.SetLevel(log.DebugLevel)
 | 
							log.SetLevel(log.DebugLevel)
 | 
				
			||||||
		log.Debugf("Debug mode enabled\n")
 | 
							log.Debugf("Debug mode enabled\n")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// no need to check prerequesites if we are initializing gocage
 | 
				
			||||||
 | 
						for _, rc := range rootCmd.Commands() {
 | 
				
			||||||
 | 
							//fmt.Printf("DEBUG: rootCmd subcommand: %v. Was it called? %s\n", rc.Use, rootCmd.Commands()[i].CalledAs())
 | 
				
			||||||
 | 
							if len(rc.CalledAs()) > 0 && strings.EqualFold("init", rc.CalledAs()) {
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Load default configs from datastores
 | 
				
			||||||
 | 
						err := ListDatastores(viper.GetStringSlice("datastore"), false)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Printf("ERROR: error checking datastores: %v\n", err)
 | 
				
			||||||
 | 
							os.Exit(1)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										23
									
								
								cmd/start.go
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								cmd/start.go
									
									
									
									
									
								
							@ -870,7 +870,7 @@ func setupVnetInterfaceHostSide(jail *Jail) ([]string, error) {
 | 
				
			|||||||
		// Get bridge MTU
 | 
							// Get bridge MTU
 | 
				
			||||||
		mtu, err := gJailHost.GetBridgeMTU(bridge)
 | 
							mtu, err := gJailHost.GetBridgeMTU(bridge)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return []string{}, fmt.Errorf("Error getting bridge mtu: %v\n", err)
 | 
								return []string{}, fmt.Errorf("Error getting bridge \"%s\" mtu: %v\n", bridge, err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		// Create epair interface
 | 
							// Create epair interface
 | 
				
			||||||
@ -976,7 +976,7 @@ func setupVnetInterfaceJailSide(jail *Jail, hostepairs []string) error {
 | 
				
			|||||||
		// Get bridge MTU
 | 
							// Get bridge MTU
 | 
				
			||||||
		mtu, err := gJailHost.GetBridgeMTU(bridge)
 | 
							mtu, err := gJailHost.GetBridgeMTU(bridge)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return fmt.Errorf("Error getting bridge %s mtu: %v\n", bridge, err)
 | 
								return fmt.Errorf("Error getting bridge \"%s\" mtu: %v\n", bridge, err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		cmd = fmt.Sprintf("/usr/sbin/jexec %d ifconfig %s mtu %d", jail.JID, jsepair, mtu)
 | 
							cmd = fmt.Sprintf("/usr/sbin/jexec %d ifconfig %s mtu %d", jail.JID, jsepair, mtu)
 | 
				
			||||||
@ -1421,6 +1421,25 @@ func StartJail(args []string) {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Get a reference to current jail, to update its properties in RAM so API will get fresh data
 | 
				
			||||||
 | 
							for i, j := range gJails {
 | 
				
			||||||
 | 
								if strings.EqualFold(j.Name, cj.Name) && strings.EqualFold(j.Datastore, cj.Datastore) {
 | 
				
			||||||
 | 
									if err = setStructFieldValue(&gJails[i], "Running", "true"); err != nil {
 | 
				
			||||||
 | 
										fmt.Printf("ERROR: setting Running property to true: %s\n", err.Error())
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									if err = setStructFieldValue(&gJails[i], "JID", fmt.Sprintf("%d", cj.JID)); err != nil {
 | 
				
			||||||
 | 
										fmt.Printf("ERROR: setting JID property to %d: %s\n", cj.JID, err.Error())
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									if err = setStructFieldValue(&gJails[i], "InternalName", cj.InternalName); err != nil {
 | 
				
			||||||
 | 
										fmt.Printf("ERROR: Setting InternalName property: %s\n", err.Error())
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									// FIXME: this value of devfs_ruleset should not go in Config, it should reside in Jail root properties as it is volatile (only valid while jail is running)
 | 
				
			||||||
 | 
									/*if err = setStructFieldValue(&gJails[i], "Devfs_ruleset", "0"); err != nil {
 | 
				
			||||||
 | 
										fmt.Printf("ERROR: setting Devfs_ruleset property to 0: %s\n", err.Error())
 | 
				
			||||||
 | 
									}*/
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		hostInt, err := gJailHost.GetInterfaces()
 | 
							hostInt, err := gJailHost.GetInterfaces()
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			fmt.Printf("Error listing jail host interfaces: %v\n", err)
 | 
								fmt.Printf("Error listing jail host interfaces: %v\n", err)
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										39
									
								
								cmd/stop.go
									
									
									
									
									
								
							
							
						
						
									
										39
									
								
								cmd/stop.go
									
									
									
									
									
								
							@ -7,8 +7,8 @@ import (
 | 
				
			|||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"regexp"
 | 
						"regexp"
 | 
				
			||||||
 | 
						"slices"
 | 
				
			||||||
	"os/exec"
 | 
						"os/exec"
 | 
				
			||||||
	//"reflect"
 | 
					 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
@ -83,26 +83,39 @@ func umountAndUnjailZFS(jail *Jail) error {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func destroyVNetInterfaces(jail *Jail) error {
 | 
					func destroyVNetInterfaces(jail *Jail) error {
 | 
				
			||||||
	if !strings.EqualFold(jail.Config.Ip4_addr, "none") {
 | 
						// Wherever ipv6/ipv4 is enabled, if interface exist we destroy it
 | 
				
			||||||
 | 
						var vnetnames []string
 | 
				
			||||||
	for _, i := range strings.Split(jail.Config.Ip4_addr, ",") {
 | 
						for _, i := range strings.Split(jail.Config.Ip4_addr, ",") {
 | 
				
			||||||
 | 
							if len(strings.Split(i, "|")) == 2 {
 | 
				
			||||||
			iname := fmt.Sprintf("%s.%d", strings.Split(i, "|")[0], jail.JID)
 | 
								iname := fmt.Sprintf("%s.%d", strings.Split(i, "|")[0], jail.JID)
 | 
				
			||||||
			fmt.Printf("%s: ", iname)
 | 
								if !slices.Contains(vnetnames, iname) {
 | 
				
			||||||
			_, err := executeCommand(fmt.Sprintf("ifconfig %s destroy", iname))
 | 
									vnetnames = append(vnetnames, iname)
 | 
				
			||||||
			//_, err := executeScript(fmt.Sprintf("ifconfig %s destroy >/dev/null 2>&1", iname))
 | 
					 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				return err
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				fmt.Printf("OK\n")
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if !strings.EqualFold(jail.Config.Ip6_addr, "none") {
 | 
					 | 
				
			||||||
	for _, i := range strings.Split(jail.Config.Ip6_addr, ",") {
 | 
						for _, i := range strings.Split(jail.Config.Ip6_addr, ",") {
 | 
				
			||||||
 | 
							if len(strings.Split(i, "|")) == 2 {
 | 
				
			||||||
			iname := fmt.Sprintf("%s.%d", strings.Split(i, "|")[0], jail.JID)
 | 
								iname := fmt.Sprintf("%s.%d", strings.Split(i, "|")[0], jail.JID)
 | 
				
			||||||
			fmt.Printf("%s: ", iname)
 | 
								if !slices.Contains(vnetnames, iname) {
 | 
				
			||||||
			_, err := executeCommand(fmt.Sprintf("ifconfig %s destroy", iname))
 | 
									vnetnames = append(vnetnames, iname)
 | 
				
			||||||
			//_, err := executeScript(fmt.Sprintf("ifconfig %s destroy >/dev/null 2>&1", iname))
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, iname := range vnetnames {
 | 
				
			||||||
 | 
							fmt.Printf("    >%s: ", iname)
 | 
				
			||||||
 | 
							_, err := executeCommand(fmt.Sprintf("ifconfig %s", iname))
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
 | 
								if strings.Contains(err.Error(), "does not exist") {
 | 
				
			||||||
 | 
									fmt.Printf("OK\n")
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									fmt.Printf("ERR: %v\n", err)
 | 
				
			||||||
 | 
									return err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								_, err := executeCommand(fmt.Sprintf("ifconfig %s destroy", iname))
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									fmt.Printf("ERR: %v\n", err)
 | 
				
			||||||
				return err
 | 
									return err
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				fmt.Printf("OK\n")
 | 
									fmt.Printf("OK\n")
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,10 @@
 | 
				
			|||||||
package cmd
 | 
					package cmd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"sort"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
@ -561,3 +564,90 @@ type DatastoreSort struct {
 | 
				
			|||||||
	AvailableDec  datastoreLessFunc
 | 
						AvailableDec  datastoreLessFunc
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Field struct {
 | 
				
			||||||
 | 
						Name   string
 | 
				
			||||||
 | 
						MaxLen int
 | 
				
			||||||
 | 
						Value  string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (j *Jail) PrintJSON(fields []string) ([]byte, error) {
 | 
				
			||||||
 | 
						return j.PrintJSONWithUpper("", fields)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (j *Jail) PrintJSONWithUpper(upper string, fields []string) ([]byte, error) {
 | 
				
			||||||
 | 
						var res []byte
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(fields) < 1 {
 | 
				
			||||||
 | 
							return res, nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(upper) > 0 {
 | 
				
			||||||
 | 
							res = append(res, []byte(fmt.Sprintf("\"%s\": {", upper))...)
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							res = append(res, []byte("{")...)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Reorder fields so we got fields of a sub-structure adjacents
 | 
				
			||||||
 | 
						sort.Strings(fields)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var ffname string
 | 
				
			||||||
 | 
						offset := 0
 | 
				
			||||||
 | 
						for i, _ := range fields {
 | 
				
			||||||
 | 
							if i + offset >= len(fields) {
 | 
				
			||||||
 | 
								break
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							// Is this struct in struct?
 | 
				
			||||||
 | 
							if strings.Contains(fields[i+offset], ".") {
 | 
				
			||||||
 | 
								// Count items in this struct
 | 
				
			||||||
 | 
								var subfields []string
 | 
				
			||||||
 | 
								var newUpper string
 | 
				
			||||||
 | 
								for _, sf := range fields[i+offset:] {
 | 
				
			||||||
 | 
									if strings.Split(sf, ".")[0] == strings.Split(fields[i+offset], ".")[0] {
 | 
				
			||||||
 | 
										newUpper = strings.Split(sf, ".")[0]
 | 
				
			||||||
 | 
										sub := strings.Join(strings.Split(string(sf), ".")[1:], ".")
 | 
				
			||||||
 | 
										subfields = append(subfields, sub)
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								out, err := j.PrintJSONWithUpper(newUpper, subfields)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return []byte{}, err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								res = append(res, out...)
 | 
				
			||||||
 | 
								offset += len(subfields)-1
 | 
				
			||||||
 | 
								if i + offset < len(fields) - 1 {
 | 
				
			||||||
 | 
									res = append(res, []byte(",")...)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if len(upper) > 0 {
 | 
				
			||||||
 | 
								ffname = fmt.Sprintf("%s.%s", upper, fields[i+offset])
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								ffname = fields[i+offset]
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							val, _, err := getStructFieldValue(j, ffname)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return []byte{}, fmt.Errorf("Error accessing field \"%s\" : %v\n", fields[i+offset], err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							res = append(res, []byte(fmt.Sprintf("\"%s\": ", fields[i+offset]))...)
 | 
				
			||||||
 | 
							switch val.Interface().(type) {
 | 
				
			||||||
 | 
								case string:
 | 
				
			||||||
 | 
									res = append(res, []byte(fmt.Sprintf("\"%s\"", val.Interface().(string)))...)
 | 
				
			||||||
 | 
								case int:
 | 
				
			||||||
 | 
									res = append(res, []byte(fmt.Sprintf("%d", val.Interface().(int)))...)
 | 
				
			||||||
 | 
								case bool:
 | 
				
			||||||
 | 
									res = append(res, []byte(fmt.Sprintf("%t", val.Interface().(bool)))...)
 | 
				
			||||||
 | 
								default:
 | 
				
			||||||
 | 
									fmt.Printf("ERREUR dans Jail.PrintJSONWithUpper() : Type inconnu : %T\n", val.Interface())
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if i + offset < len(fields) - 1 {
 | 
				
			||||||
 | 
								res = append(res, []byte(",")...)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						res = append(res, []byte("}")...)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return res, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										147
									
								
								cmd/utils.go
									
									
									
									
									
								
							
							
						
						
									
										147
									
								
								cmd/utils.go
									
									
									
									
									
								
							@ -25,7 +25,88 @@ const (
 | 
				
			|||||||
	// Maximum thread qty for start/stop
 | 
						// Maximum thread qty for start/stop
 | 
				
			||||||
	gMaxThreads    = 4
 | 
						gMaxThreads    = 4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	gDefaultsJson = ` {
 | 
						fbsdUpdateConfig = `# $FreeBSD$
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Trusted keyprint.  Changing this is a Bad Idea unless you've received
 | 
				
			||||||
 | 
					# a PGP-signed email from <security-officer@FreeBSD.org> telling you to
 | 
				
			||||||
 | 
					# change it and explaining why.
 | 
				
			||||||
 | 
					KeyPrint 800651ef4b4c71c27e60786d7b487188970f4b4169cc055784e21eb71d410cc5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Server or server pool from which to fetch updates.  You can change
 | 
				
			||||||
 | 
					# this to point at a specific server if you want, but in most cases
 | 
				
			||||||
 | 
					# using a "nearby" server won't provide a measurable improvement in
 | 
				
			||||||
 | 
					# performance.
 | 
				
			||||||
 | 
					ServerName update.FreeBSD.org
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Components of the base system which should be kept updated.
 | 
				
			||||||
 | 
					Components world
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Example for updating the userland and the kernel source code only:
 | 
				
			||||||
 | 
					# Components src/base src/sys world
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Paths which start with anything matching an entry in an IgnorePaths
 | 
				
			||||||
 | 
					# statement will be ignored.
 | 
				
			||||||
 | 
					IgnorePaths
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Paths which start with anything matching an entry in an IDSIgnorePaths
 | 
				
			||||||
 | 
					# statement will be ignored by "freebsd-update IDS".
 | 
				
			||||||
 | 
					IDSIgnorePaths /usr/share/man/cat
 | 
				
			||||||
 | 
					IDSIgnorePaths /usr/share/man/whatis
 | 
				
			||||||
 | 
					IDSIgnorePaths /var/db/locate.database
 | 
				
			||||||
 | 
					IDSIgnorePaths /var/log
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Paths which start with anything matching an entry in an UpdateIfUnmodified
 | 
				
			||||||
 | 
					# statement will only be updated if the contents of the file have not been
 | 
				
			||||||
 | 
					# modified by the user (unless changes are merged; see below).
 | 
				
			||||||
 | 
					UpdateIfUnmodified /etc/ /var/ /root/ /.cshrc /.profile
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# When upgrading to a new FreeBSD release, files which match MergeChanges
 | 
				
			||||||
 | 
					# will have any local changes merged into the version from the new release.
 | 
				
			||||||
 | 
					MergeChanges /etc/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Default configuration options:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Directory in which to store downloaded updates and temporary
 | 
				
			||||||
 | 
					# files used by FreeBSD Update.
 | 
				
			||||||
 | 
					WorkDir /iocage/freebsd-update
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Destination to send output of "freebsd-update cron" if an error
 | 
				
			||||||
 | 
					# occurs or updates have been downloaded.
 | 
				
			||||||
 | 
					# MailTo root
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Is FreeBSD Update allowed to create new files?
 | 
				
			||||||
 | 
					# AllowAdd yes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Is FreeBSD Update allowed to delete files?
 | 
				
			||||||
 | 
					# AllowDelete yes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# If the user has modified file ownership, permissions, or flags, should
 | 
				
			||||||
 | 
					# FreeBSD Update retain this modified metadata when installing a new version
 | 
				
			||||||
 | 
					# of that file?
 | 
				
			||||||
 | 
					# KeepModifiedMetadata yes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# When upgrading between releases, should the list of Components be
 | 
				
			||||||
 | 
					# read strictly (StrictComponents yes) or merely as a list of components
 | 
				
			||||||
 | 
					# which *might* be installed of which FreeBSD Update should figure out
 | 
				
			||||||
 | 
					# which actually are installed and upgrade those (StrictComponents no)?
 | 
				
			||||||
 | 
					StrictComponents yes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# When installing a new kernel perform a backup of the old one first
 | 
				
			||||||
 | 
					# so it is possible to boot the old kernel in case of problems.
 | 
				
			||||||
 | 
					BackupKernel no
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# If BackupKernel is enabled, the backup kernel is saved to this
 | 
				
			||||||
 | 
					# directory.
 | 
				
			||||||
 | 
					# BackupKernelDir /boot/kernel.old
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# When backing up a kernel also back up debug symbol files?
 | 
				
			||||||
 | 
					BackupKernelSymbolFiles no
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Create a new boot environment when installing patches
 | 
				
			||||||
 | 
					CreateBootEnv no
 | 
				
			||||||
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						gDefaultsJson = `{
 | 
				
			||||||
    "CONFIG_VERSION": "27",
 | 
					    "CONFIG_VERSION": "27",
 | 
				
			||||||
    "allow_chflags": 0,
 | 
					    "allow_chflags": 0,
 | 
				
			||||||
    "allow_mlock": 0,
 | 
					    "allow_mlock": 0,
 | 
				
			||||||
@ -79,9 +160,9 @@ const (
 | 
				
			|||||||
    "exec_timeout": "60",
 | 
					    "exec_timeout": "60",
 | 
				
			||||||
    "host_domainname": "none",
 | 
					    "host_domainname": "none",
 | 
				
			||||||
    "host_time": 1,
 | 
					    "host_time": 1,
 | 
				
			||||||
       "hostid": "36353536-3135-5a43-4a34-313130315a56",
 | 
					    "hostid": "TO-BE-REPLACED-WITH-HOSTID",
 | 
				
			||||||
    "hostid_strict_check": 0,
 | 
					    "hostid_strict_check": 0,
 | 
				
			||||||
       "interfaces": "vnet0:bridge0",
 | 
					    "interfaces": "vnet0:TO-BE-REPLACED-WITH-BRIDGE",
 | 
				
			||||||
    "ip4": "new",
 | 
					    "ip4": "new",
 | 
				
			||||||
    "ip4_addr": "none",
 | 
					    "ip4_addr": "none",
 | 
				
			||||||
    "ip4_saddrsel": 1,
 | 
					    "ip4_saddrsel": 1,
 | 
				
			||||||
@ -157,7 +238,7 @@ const (
 | 
				
			|||||||
    "wallclock": "off",
 | 
					    "wallclock": "off",
 | 
				
			||||||
    "writebps": "off",
 | 
					    "writebps": "off",
 | 
				
			||||||
    "writeiops": "off"
 | 
					    "writeiops": "off"
 | 
				
			||||||
       }
 | 
					}
 | 
				
			||||||
`
 | 
					`
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -362,7 +443,7 @@ func executeCommand(cmdline string) (string, error) {
 | 
				
			|||||||
		out, err = exec.Command(cmd[0]).CombinedOutput()
 | 
							out, err = exec.Command(cmd[0]).CombinedOutput()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return string(out), err
 | 
						return strings.TrimSuffix(string(out), "\n"), err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* From iocage: 
 | 
					/* From iocage: 
 | 
				
			||||||
@ -629,9 +710,7 @@ func executeCommandInJail(jail *Jail, cmdline string) (string, error) {
 | 
				
			|||||||
		word = word + string(c)
 | 
							word = word + string(c)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if gDebug {
 | 
						log.Debugf("executeCommandInJail: will execute \"%s\"\n", strings.Join(cmd, " "))
 | 
				
			||||||
		fmt.Printf("DEBUG: executeCommandInJail: prepare to execute \"%s\"\n", cmd)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	out, err := exec.Command(cmd[0], cmd[1:]...).CombinedOutput()
 | 
						out, err := exec.Command(cmd[0], cmd[1:]...).CombinedOutput()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -814,7 +893,9 @@ func zfsCreateDataset(dataset, mountpoint, compression string) error {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
// Return dataset name for a given mountpoint
 | 
					// Return dataset name for a given mountpoint
 | 
				
			||||||
func zfsGetDatasetByMountpoint(mountpoint string) (string, error) {
 | 
					func zfsGetDatasetByMountpoint(mountpoint string) (string, error) {
 | 
				
			||||||
	cmd := fmt.Sprintf("zfs list -p -r -H -o name %s", mountpoint)
 | 
						// We dont want no recursivity
 | 
				
			||||||
 | 
						//cmd := fmt.Sprintf("zfs list -p -r -H -o name %s", mountpoint)
 | 
				
			||||||
 | 
						cmd := fmt.Sprintf("zfs list -p -H -o name %s", mountpoint)
 | 
				
			||||||
	out, err := executeCommand(cmd)
 | 
						out, err := executeCommand(cmd)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return "", errors.New(fmt.Sprintf("%v; command returned \"%s\"", err, out))
 | 
							return "", errors.New(fmt.Sprintf("%v; command returned \"%s\"", err, out))
 | 
				
			||||||
@ -868,6 +949,17 @@ func getPermissions(path string) (os.FileInfo, error) {
 | 
				
			|||||||
	return os.Stat(path)
 | 
						return os.Stat(path)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func doFileExist(filePath string) (bool, error) {
 | 
				
			||||||
 | 
						if _, err := os.Stat(filePath); err != nil {
 | 
				
			||||||
 | 
							if errors.Is(err, os.ErrNotExist) {
 | 
				
			||||||
 | 
								return false, nil
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								return false, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return true, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*****************************************************************************
 | 
					/*****************************************************************************
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * rc.conf management
 | 
					 * rc.conf management
 | 
				
			||||||
@ -902,6 +994,43 @@ func disableRcKey(rcconfpath string, key string) error {
 | 
				
			|||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// returns no error if rc key does not exist
 | 
				
			||||||
 | 
					func getCurrentRcKeyValue(rcconfpath string, key string) (string, error) {
 | 
				
			||||||
 | 
						cmd := "/usr/sbin/sysrc -a"
 | 
				
			||||||
 | 
						kvs, err := executeCommand(cmd)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return "", err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for _, kv := range strings.Split(string(kvs), "\n") {
 | 
				
			||||||
 | 
							fmt.Printf("%s\n", kv)
 | 
				
			||||||
 | 
							if strings.HasPrefix(kv, fmt.Sprintf("%s:", key)) {
 | 
				
			||||||
 | 
								return strings.TrimPrefix(strings.Join(strings.Split(kv, ":")[1:], ":"), " "), nil
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return "", nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Add a value to current existing key value
 | 
				
			||||||
 | 
					func addRcKeyValue(rcconfpath string, key string, value string) error {
 | 
				
			||||||
 | 
						var nv string
 | 
				
			||||||
 | 
						cv, err := getCurrentRcKeyValue(rcconfpath, key)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(cv) > 0 {
 | 
				
			||||||
 | 
							log.Debugf("Current value of %s: %s\n", key, cv)
 | 
				
			||||||
 | 
							nv = fmt.Sprintf("\"%s %s\"", cv, value)
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							nv = fmt.Sprintf("\"%s\"", value)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						cmd := fmt.Sprintf("/usr/sbin/sysrc -f %s %s=%s", rcconfpath, key, nv)
 | 
				
			||||||
 | 
						_, err = executeCommand(cmd)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
/*****************************************************************************
 | 
					/*****************************************************************************
 | 
				
			||||||
* Parse an fstab file, returning an array of Mount
 | 
					* Parse an fstab file, returning an array of Mount
 | 
				
			||||||
*****************************************************************************/
 | 
					*****************************************************************************/
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										62
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										62
									
								
								go.mod
									
									
									
									
									
								
							@ -1,32 +1,60 @@
 | 
				
			|||||||
module gocage
 | 
					module gocage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
go 1.17
 | 
					go 1.21
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
	github.com/c-robinson/iplib v1.0.3
 | 
						github.com/c-robinson/iplib v1.0.3
 | 
				
			||||||
	github.com/c2h5oh/datasize v0.0.0-20220606134207-859f65c6625b
 | 
						github.com/c2h5oh/datasize v0.0.0-20220606134207-859f65c6625b
 | 
				
			||||||
 | 
						github.com/gin-contrib/cors v1.7.2
 | 
				
			||||||
 | 
						github.com/gin-gonic/gin v1.10.0
 | 
				
			||||||
	github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
 | 
						github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
 | 
				
			||||||
	github.com/otiai10/copy v1.12.0
 | 
						github.com/otiai10/copy v1.12.0
 | 
				
			||||||
	github.com/sirupsen/logrus v1.8.1
 | 
						github.com/sirupsen/logrus v1.8.1
 | 
				
			||||||
	github.com/spf13/cobra v1.2.1
 | 
						github.com/spf13/cobra v1.8.1
 | 
				
			||||||
	github.com/spf13/viper v1.9.0
 | 
						github.com/spf13/viper v1.19.0
 | 
				
			||||||
	golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420
 | 
						golang.org/x/net v0.25.0
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
	github.com/fsnotify/fsnotify v1.5.1 // indirect
 | 
						github.com/bytedance/sonic v1.11.6 // indirect
 | 
				
			||||||
 | 
						github.com/bytedance/sonic/loader v0.1.1 // indirect
 | 
				
			||||||
 | 
						github.com/cloudwego/base64x v0.1.4 // indirect
 | 
				
			||||||
 | 
						github.com/cloudwego/iasm v0.2.0 // indirect
 | 
				
			||||||
 | 
						github.com/fsnotify/fsnotify v1.7.0 // indirect
 | 
				
			||||||
 | 
						github.com/gabriel-vasile/mimetype v1.4.3 // indirect
 | 
				
			||||||
 | 
						github.com/gin-contrib/sse v0.1.0 // indirect
 | 
				
			||||||
 | 
						github.com/go-playground/locales v0.14.1 // indirect
 | 
				
			||||||
 | 
						github.com/go-playground/universal-translator v0.18.1 // indirect
 | 
				
			||||||
 | 
						github.com/go-playground/validator/v10 v10.20.0 // indirect
 | 
				
			||||||
 | 
						github.com/goccy/go-json v0.10.2 // indirect
 | 
				
			||||||
	github.com/hashicorp/hcl v1.0.0 // indirect
 | 
						github.com/hashicorp/hcl v1.0.0 // indirect
 | 
				
			||||||
	github.com/inconshreveable/mousetrap v1.0.0 // indirect
 | 
						github.com/inconshreveable/mousetrap v1.1.0 // indirect
 | 
				
			||||||
	github.com/magiconair/properties v1.8.5 // indirect
 | 
						github.com/json-iterator/go v1.1.12 // indirect
 | 
				
			||||||
	github.com/mitchellh/mapstructure v1.4.2 // indirect
 | 
						github.com/klauspost/cpuid/v2 v2.2.7 // indirect
 | 
				
			||||||
	github.com/pelletier/go-toml v1.9.4 // indirect
 | 
						github.com/leodido/go-urn v1.4.0 // indirect
 | 
				
			||||||
	github.com/spf13/afero v1.6.0 // indirect
 | 
						github.com/magiconair/properties v1.8.7 // indirect
 | 
				
			||||||
	github.com/spf13/cast v1.4.1 // indirect
 | 
						github.com/mattn/go-isatty v0.0.20 // indirect
 | 
				
			||||||
	github.com/spf13/jwalterweatherman v1.1.0 // indirect
 | 
						github.com/mitchellh/mapstructure v1.5.0 // indirect
 | 
				
			||||||
 | 
						github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
 | 
				
			||||||
 | 
						github.com/modern-go/reflect2 v1.0.2 // indirect
 | 
				
			||||||
 | 
						github.com/pelletier/go-toml/v2 v2.2.2 // indirect
 | 
				
			||||||
 | 
						github.com/sagikazarmark/locafero v0.4.0 // indirect
 | 
				
			||||||
 | 
						github.com/sagikazarmark/slog-shim v0.1.0 // indirect
 | 
				
			||||||
 | 
						github.com/sourcegraph/conc v0.3.0 // indirect
 | 
				
			||||||
 | 
						github.com/spf13/afero v1.11.0 // indirect
 | 
				
			||||||
 | 
						github.com/spf13/cast v1.6.0 // indirect
 | 
				
			||||||
	github.com/spf13/pflag v1.0.5 // indirect
 | 
						github.com/spf13/pflag v1.0.5 // indirect
 | 
				
			||||||
	github.com/subosito/gotenv v1.2.0 // indirect
 | 
						github.com/subosito/gotenv v1.6.0 // indirect
 | 
				
			||||||
	golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
 | 
						github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
 | 
				
			||||||
	golang.org/x/text v0.3.6 // indirect
 | 
						github.com/ugorji/go/codec v1.2.12 // indirect
 | 
				
			||||||
	gopkg.in/ini.v1 v1.63.2 // indirect
 | 
						go.uber.org/atomic v1.9.0 // indirect
 | 
				
			||||||
	gopkg.in/yaml.v2 v2.4.0 // indirect
 | 
						go.uber.org/multierr v1.9.0 // indirect
 | 
				
			||||||
 | 
						golang.org/x/arch v0.8.0 // indirect
 | 
				
			||||||
 | 
						golang.org/x/crypto v0.23.0 // indirect
 | 
				
			||||||
 | 
						golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
 | 
				
			||||||
 | 
						golang.org/x/sys v0.20.0 // indirect
 | 
				
			||||||
 | 
						golang.org/x/text v0.15.0 // indirect
 | 
				
			||||||
 | 
						google.golang.org/protobuf v1.34.1 // indirect
 | 
				
			||||||
 | 
						gopkg.in/ini.v1 v1.67.0 // indirect
 | 
				
			||||||
 | 
						gopkg.in/yaml.v3 v3.0.1 // indirect
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user