Compare commits
	
		
			14 Commits
		
	
	
		
			v0.39
			...
			5b2f3a2f0a
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 5b2f3a2f0a | |||
| 2df22b10b1 | |||
| c19e40b139 | |||
| 259c3ee1e0 | |||
| 8cabae7134 | |||
| 9fcc7a6572 | |||
| 5586b164c6 | |||
| 4cc1c476aa | |||
| ce79783540 | |||
| 18d35b9224 | |||
| f41c93368d | |||
| 452b0e4b4e | |||
| dbe9622a01 | |||
| 6ead474a78 | 
							
								
								
									
										14
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								README.md
									
									
									
									
									
								
							@ -18,23 +18,17 @@ Create jails
 | 
				
			|||||||
------------
 | 
					------------
 | 
				
			||||||
For now, we can't pass config at creation time. We have to define config after creation:  
 | 
					For now, we can't pass config at creation time. We have to define config after creation:  
 | 
				
			||||||
<pre><code>
 | 
					<pre><code>
 | 
				
			||||||
gocage create jail1 -r 13.2-RELEASE
 | 
					gocage create jail1 -r 13.2-RELEASE -p "Config.Ip4_addr='vnet0|192.168.1.91/24',Config.Ip6=none,Config.Boot=1"
 | 
				
			||||||
gocage set Config.Ip4_addr="vnet0|192.168.1.91/24" Config.Vnet=1 jail1
 | 
					 | 
				
			||||||
</code></pre>
 | 
					</code></pre>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Create basejail (jail based on a template, system will be nullfs read-only mounted from the template):
 | 
					Create basejail (jail based on a release, system will be nullfs read-only mounted from the release directory):
 | 
				
			||||||
<pre><code>
 | 
					<pre><code>
 | 
				
			||||||
# First create basetpl from 13.2-RELEASE, set it as a template
 | 
					gocage create -b -r 14.0-RELEASE basejail1
 | 
				
			||||||
gocage create -r 13.2-RELEASE basetpl
 | 
					 | 
				
			||||||
gocage set Config.Jailtype="template" basetpl
 | 
					 | 
				
			||||||
# Then create basejail1 based on basetpl
 | 
					 | 
				
			||||||
gocage create -b basetpl basejail1
 | 
					 | 
				
			||||||
</code></pre>
 | 
					</code></pre>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
List jails
 | 
					List jails
 | 
				
			||||||
----------
 | 
					----------
 | 
				
			||||||
Nothing fancy, just use  
 | 
					 | 
				
			||||||
`gocage list`
 | 
					`gocage list`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Specify fields to display
 | 
					### Specify fields to display
 | 
				
			||||||
@ -237,7 +231,7 @@ Fetch
 | 
				
			|||||||
Files can be fetched from custom repository, or from local directory with "from" option.  
 | 
					Files can be fetched from custom repository, or from local directory with "from" option.  
 | 
				
			||||||
For example if you destroyed releases/12.3-RELEASE and still have the downloaded files in /iocage/download/12.3-RELEASE:  
 | 
					For example if you destroyed releases/12.3-RELEASE and still have the downloaded files in /iocage/download/12.3-RELEASE:  
 | 
				
			||||||
<pre><code>
 | 
					<pre><code>
 | 
				
			||||||
gocage fetch -r 12.3 -o iocage --from file:/iocage/download
 | 
					gocage fetch -r 12.3 -d iocage -f file:/iocage/download
 | 
				
			||||||
</pre></code>
 | 
					</pre></code>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										11
									
								
								TODO.md
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								TODO.md
									
									
									
									
									
								
							@ -1,8 +1,19 @@
 | 
				
			|||||||
Replicating jails between two servers (use zrepl)
 | 
					Replicating jails between two servers (use zrepl)
 | 
				
			||||||
 | 
					Manage remote jails :
 | 
				
			||||||
 | 
					  - Make gocage a service
 | 
				
			||||||
 | 
					  - All commands should become API endpoint
 | 
				
			||||||
 | 
					  - How to handle authentication ?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DEBUG: 
 | 
					DEBUG: 
 | 
				
			||||||
- cmd/list.go:275:
 | 
					- cmd/list.go:275:
 | 
				
			||||||
    // FIXME ??? Shouldn't be ioc-$Name ?
 | 
					    // FIXME ??? Shouldn't be ioc-$Name ?
 | 
				
			||||||
    j.InternalName = rj.Name
 | 
					    j.InternalName = rj.Name
 | 
				
			||||||
- WriteConfigToDisk don't write neither "release" in cmd stop neither "last_started" in cmd start
 | 
					- WriteConfigToDisk don't write neither "release" in cmd stop neither "last_started" in cmd start
 | 
				
			||||||
 | 
					  26/08/2023 : Last_started is updated
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					BUGS:
 | 
				
			||||||
 | 
					- unable to set values containing equal sign :
 | 
				
			||||||
 | 
					  # gocage set Config.Exec_poststart="jail -m allow.mount.linprocfs=1 name=ioc-poudriere-noo" poudriere-noo
 | 
				
			||||||
 | 
					  Error parsing args: Config.Exec_poststart=jail -m allow.mount.linprocfs=1 name=ioc-poudriere-noo
 | 
				
			||||||
 | 
					- Fix fstab when migrating jail  
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -16,6 +16,11 @@ func CreateJail(args []string) {
 | 
				
			|||||||
	var err error
 | 
						var err error
 | 
				
			||||||
	var jtype []string
 | 
						var jtype []string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if gCreateArgs.BaseJail && gCreateArgs.Release == "" {
 | 
				
			||||||
 | 
							fmt.Println("Release should be set when creating basejail")
 | 
				
			||||||
 | 
							os.Exit(1)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if len(gCreateArgs.JailType) > 0 {
 | 
						if len(gCreateArgs.JailType) > 0 {
 | 
				
			||||||
		jtype = []string{gCreateArgs.JailType}
 | 
							jtype = []string{gCreateArgs.JailType}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -39,7 +44,7 @@ func CreateJail(args []string) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		var ds *Datastore
 | 
							var ds *Datastore
 | 
				
			||||||
		if len(gCreateArgs.Datastore) > 0 {
 | 
							if len(gCreateArgs.Datastore) > 0 {
 | 
				
			||||||
			fmt.Printf("DEBUG: Use %s datastore\n", gCreateArgs.Datastore)
 | 
								log.Debugf("Use %s datastore\n", gCreateArgs.Datastore)
 | 
				
			||||||
			ds, err = getDatastoreFromArray(gCreateArgs.Datastore, gDatastores)
 | 
								ds, err = getDatastoreFromArray(gCreateArgs.Datastore, gDatastores)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				fmt.Printf("ERROR Getting datastore: %s\n", gCreateArgs.Datastore, err.Error())
 | 
									fmt.Printf("ERROR Getting datastore: %s\n", gCreateArgs.Datastore, err.Error())
 | 
				
			||||||
@ -50,21 +55,20 @@ func CreateJail(args []string) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Get base template if specified
 | 
							// Get base template if specified
 | 
				
			||||||
		if len(gCreateArgs.BaseTemplate) > 0 {
 | 
							if gCreateArgs.BaseJail {
 | 
				
			||||||
			/**************************************************************************
 | 
								/**************************************************************************
 | 
				
			||||||
			*  Create based jail from a template
 | 
								*  Create based jail from a template
 | 
				
			||||||
			*/
 | 
								*/
 | 
				
			||||||
			log.Debugf("Jail will be created from a base template\n")
 | 
								log.Debugf("Jail will be created read-only from release %s\n", gCreateArgs.Release)
 | 
				
			||||||
			bj, err := getJailFromArray(gCreateArgs.BaseTemplate, []string{"template"}, gJails)
 | 
					
 | 
				
			||||||
			if err != nil {
 | 
								// First check if we got release on the same datastore
 | 
				
			||||||
				if strings.EqualFold(err.Error(), "Jail not found") {
 | 
								releasePath := fmt.Sprintf("%s/releases/%s/root", ds.Mountpoint, gCreateArgs.Release)
 | 
				
			||||||
					fmt.Printf("Template not found\n")
 | 
								_, err := os.Stat(releasePath)
 | 
				
			||||||
					return
 | 
								if os.IsNotExist(err) {
 | 
				
			||||||
				} else {
 | 
									fmt.Printf("ERROR: Release locally not available. Run \"gocage fetch\"\n")
 | 
				
			||||||
					fmt.Printf("ERROR: %s\n", err.Error())
 | 
					 | 
				
			||||||
				return
 | 
									return
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			}
 | 
					
 | 
				
			||||||
			// Create jail datasets
 | 
								// Create jail datasets
 | 
				
			||||||
			dstDset := fmt.Sprintf("%s/jails/%s", ds.ZFSDataset, jname)
 | 
								dstDset := fmt.Sprintf("%s/jails/%s", ds.ZFSDataset, jname)
 | 
				
			||||||
			fmt.Printf("    > Initialize dataset %s\n", dstDset)
 | 
								fmt.Printf("    > Initialize dataset %s\n", dstDset)
 | 
				
			||||||
@ -87,7 +91,7 @@ func CreateJail(args []string) {
 | 
				
			|||||||
			dstRootDir := fmt.Sprintf("%s/jails/%s/root", ds.Mountpoint, jname)
 | 
								dstRootDir := fmt.Sprintf("%s/jails/%s/root", ds.Mountpoint, jname)
 | 
				
			||||||
			for _, d := range append(gBaseDirs, gEmptyDirs...) {
 | 
								for _, d := range append(gBaseDirs, gEmptyDirs...) {
 | 
				
			||||||
				dstPath := dstRootDir
 | 
									dstPath := dstRootDir
 | 
				
			||||||
				srcPath := bj.RootPath
 | 
									srcPath := releasePath
 | 
				
			||||||
				for _, cd := range strings.Split(d, "/") {
 | 
									for _, cd := range strings.Split(d, "/") {
 | 
				
			||||||
					srcPath = fmt.Sprintf("%s/%s", srcPath, cd)
 | 
										srcPath = fmt.Sprintf("%s/%s", srcPath, cd)
 | 
				
			||||||
					dstPath = fmt.Sprintf("%s/%s", dstPath, cd)
 | 
										dstPath = fmt.Sprintf("%s/%s", dstPath, cd)
 | 
				
			||||||
@ -110,9 +114,9 @@ func CreateJail(args []string) {
 | 
				
			|||||||
			// Copy these from basejail
 | 
								// Copy these from basejail
 | 
				
			||||||
			fmt.Printf("    > Create base writable directories\n")
 | 
								fmt.Printf("    > Create base writable directories\n")
 | 
				
			||||||
			for _, d := range gCopyDirs {
 | 
								for _, d := range gCopyDirs {
 | 
				
			||||||
				err := cp.Copy(fmt.Sprintf("%s/%s", bj.RootPath, d), fmt.Sprintf("%s/%s", dstRootDir, d))
 | 
									err := cp.Copy(fmt.Sprintf("%s/%s", releasePath, d), fmt.Sprintf("%s/%s", dstRootDir, d))
 | 
				
			||||||
				if err != nil {
 | 
									if err != nil {
 | 
				
			||||||
					fmt.Printf("ERROR copying %s to %s: %s\n", fmt.Sprintf("%s/%s", bj.RootPath, d),
 | 
										fmt.Printf("ERROR copying %s to %s: %s\n", fmt.Sprintf("%s/%s", releasePath, d),
 | 
				
			||||||
						   fmt.Sprintf("%s/%s", dstRootDir, d), err.Error())
 | 
											   fmt.Sprintf("%s/%s", dstRootDir, d), err.Error())
 | 
				
			||||||
					return
 | 
										return
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
@ -150,7 +154,7 @@ func CreateJail(args []string) {
 | 
				
			|||||||
			// 2. Add a json item to config ("basejail_template" p.e.), but iocage would delete it once jail is started from iocage
 | 
								// 2. Add a json item to config ("basejail_template" p.e.), but iocage would delete it once jail is started from iocage
 | 
				
			||||||
			// 3. Add a gocage specific config ("config.gocage.json" p.e.)
 | 
								// 3. Add a gocage specific config ("config.gocage.json" p.e.)
 | 
				
			||||||
			j.Config.Jailtype = "basejail"
 | 
								j.Config.Jailtype = "basejail"
 | 
				
			||||||
			j.Config.Origin = bj.Name
 | 
								j.Config.Origin = gCreateArgs.Release
 | 
				
			||||||
			j.Config.Host_hostname = jname
 | 
								j.Config.Host_hostname = jname
 | 
				
			||||||
			j.Config.Host_hostuuid = jname
 | 
								j.Config.Host_hostuuid = jname
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -166,7 +170,7 @@ func CreateJail(args []string) {
 | 
				
			|||||||
			defer fstabHandle.Close()
 | 
								defer fstabHandle.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			for _, d := range gBaseDirs {
 | 
								for _, d := range gBaseDirs {
 | 
				
			||||||
				fmt.Fprintf(fstabHandle, "%s\t%s\tnullfs\tro\t0\t0\n", fmt.Sprintf("%s/%s", bj.RootPath, d), fmt.Sprintf("%s/%s", dstRootDir, d))
 | 
									fmt.Fprintf(fstabHandle, "%s\t%s\tnullfs\tro\t0\t0\n", fmt.Sprintf("%s/%s", releasePath, d), fmt.Sprintf("%s/%s", dstRootDir, d))
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			fmt.Printf("  > Jail created!\n")
 | 
								fmt.Printf("  > Jail created!\n")
 | 
				
			||||||
@ -268,7 +272,6 @@ func CreateJail(args []string) {
 | 
				
			|||||||
			j.Config.Host_hostname = jname
 | 
								j.Config.Host_hostname = jname
 | 
				
			||||||
			j.Config.Host_hostuuid = jname
 | 
								j.Config.Host_hostuuid = jname
 | 
				
			||||||
			j.Config.Jailtype = "jail"
 | 
								j.Config.Jailtype = "jail"
 | 
				
			||||||
						
 | 
					 | 
				
			||||||
			j.WriteConfigToDisk(false)
 | 
								j.WriteConfigToDisk(false)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			///////////////////////////////////////////////////////////////////////
 | 
								///////////////////////////////////////////////////////////////////////
 | 
				
			||||||
@ -281,5 +284,17 @@ func CreateJail(args []string) {
 | 
				
			|||||||
			defer fstabHandle.Close()
 | 
								defer fstabHandle.Close()
 | 
				
			||||||
			fmt.Printf("  > Jail created!\n")
 | 
								fmt.Printf("  > Jail created!\n")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var cmdline []string
 | 
				
			||||||
 | 
							for _, props := range strings.Split(gCreateArgs.Properties, ",") {
 | 
				
			||||||
 | 
								cmdline = append(cmdline, props)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Reload jail list so SetJailProperties will see it
 | 
				
			||||||
 | 
							ListJails(nil, false)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							cmdline = append(cmdline, jname)
 | 
				
			||||||
 | 
							log.Debugf("cmdline: \"%v\"", cmdline)
 | 
				
			||||||
 | 
							SetJailProperties(cmdline)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -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
 | 
					 | 
				
			||||||
	`
 | 
					 | 
				
			||||||
) 
 | 
					 | 
				
			||||||
							
								
								
									
										59
									
								
								cmd/root.go
									
									
									
									
									
								
							
							
						
						
									
										59
									
								
								cmd/root.go
									
									
									
									
									
								
							@ -14,7 +14,7 @@ import (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	gVersion = "0.39"
 | 
						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
 | 
				
			||||||
@ -22,9 +22,10 @@ const (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type createArgs struct {
 | 
					type createArgs struct {
 | 
				
			||||||
	Release      string
 | 
						Release      string
 | 
				
			||||||
	BaseTemplate string
 | 
						BaseJail     bool
 | 
				
			||||||
	Datastore    string
 | 
						Datastore    string
 | 
				
			||||||
	JailType     string
 | 
						JailType     string
 | 
				
			||||||
 | 
						Properties   string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var (
 | 
					var (
 | 
				
			||||||
@ -56,6 +57,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 +101,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",
 | 
				
			||||||
@ -379,6 +377,11 @@ 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.MarkFlagRequired("bridge")
 | 
				
			||||||
 | 
						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")
 | 
				
			||||||
@ -411,8 +414,8 @@ func init() {
 | 
				
			|||||||
	migrateCmd.MarkFlagRequired("datastore")
 | 
						migrateCmd.MarkFlagRequired("datastore")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fetchCmd.Flags().StringVarP(&gFetchRelease, "release", "r", "", "Release to fetch (e.g.: \"13.1-RELEASE\"")
 | 
						fetchCmd.Flags().StringVarP(&gFetchRelease, "release", "r", "", "Release to fetch (e.g.: \"13.1-RELEASE\"")
 | 
				
			||||||
	fetchCmd.Flags().StringVarP(&gFetchIntoDS, "datastore", "o", "", "Datastore release will be saved to")
 | 
						fetchCmd.Flags().StringVarP(&gFetchIntoDS, "datastore", "d", "", "Datastore release will be saved to")
 | 
				
			||||||
	fetchCmd.Flags().StringVarP(&gFetchFrom, "from", "d", "", "Repository to download from. Should contain XY.Z-RELEASE. File protocol supported")
 | 
						fetchCmd.Flags().StringVarP(&gFetchFrom, "from", "f", "", "Repository to download from. Should contain XY.Z-RELEASE. File protocol supported")
 | 
				
			||||||
	fetchCmd.MarkFlagRequired("release")
 | 
						fetchCmd.MarkFlagRequired("release")
 | 
				
			||||||
	fetchCmd.MarkFlagRequired("datastore")
 | 
						fetchCmd.MarkFlagRequired("datastore")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -420,10 +423,12 @@ func init() {
 | 
				
			|||||||
	upgradeCmd.MarkFlagRequired("release")
 | 
						upgradeCmd.MarkFlagRequired("release")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	createCmd.Flags().StringVarP(&gCreateArgs.Release, "release", "r", "", "Release for the jail (e.g.: \"13.1-RELEASE\"")
 | 
						createCmd.Flags().StringVarP(&gCreateArgs.Release, "release", "r", "", "Release for the jail (e.g.: \"13.1-RELEASE\"")
 | 
				
			||||||
	createCmd.Flags().StringVarP(&gCreateArgs.BaseTemplate, "basetpl", "b", "", "Base template. This will create a jail based on basetpl, so every up(date|grade) made to basetpl 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.")
 | 
				
			||||||
 | 
						createCmd.Flags().StringVarP(&gCreateArgs.Properties, "configuration", "p", "", "Configuration properties with format k1=v1,k2=v2 (Ex: \"Config.Ip4_addr='vnet0|192.168.1.2',Config.Ip6=none\")")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 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 +446,6 @@ func init() {
 | 
				
			|||||||
	rootCmd.AddCommand(updateCmd)
 | 
						rootCmd.AddCommand(updateCmd)
 | 
				
			||||||
	rootCmd.AddCommand(upgradeCmd)
 | 
						rootCmd.AddCommand(upgradeCmd)
 | 
				
			||||||
	rootCmd.AddCommand(createCmd)
 | 
						rootCmd.AddCommand(createCmd)
 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	rootCmd.AddCommand(testCmd)
 | 
						rootCmd.AddCommand(testCmd)
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	snapshotCmd.AddCommand(snapshotListCmd)
 | 
						snapshotCmd.AddCommand(snapshotListCmd)
 | 
				
			||||||
@ -472,17 +476,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 +509,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)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										22
									
								
								cmd/start.go
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								cmd/start.go
									
									
									
									
									
								
							@ -340,7 +340,7 @@ func configureDhcpOrAcceptRtadv(jail *Jail, ipproto int, enable bool) error {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		if ipproto == IPv6 {
 | 
							if ipproto == IPv6 {
 | 
				
			||||||
			key = fmt.Sprintf("%s_ipv6", key)
 | 
								key = fmt.Sprintf("%s_ipv6", key)
 | 
				
			||||||
			value = "inet6 auto_linklocal accept_rtadv autoconf"
 | 
								value = "\"inet6 auto_linklocal accept_rtadv autoconf\""
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if enable == true {
 | 
							if enable == true {
 | 
				
			||||||
@ -363,7 +363,7 @@ func checkRtsold(jail *Jail) error {
 | 
				
			|||||||
	if strings.Contains(jail.Config.Ip6_addr, "accept_rtadv") == false {
 | 
						if strings.Contains(jail.Config.Ip6_addr, "accept_rtadv") == false {
 | 
				
			||||||
		return fmt.Errorf("Must set at least one ip6_addr to accept_rtadv!\n")
 | 
							return fmt.Errorf("Must set at least one ip6_addr to accept_rtadv!\n")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	err := enableRcKeyValue(jail.ConfigPath, "rtsold_enable", "yes")
 | 
						err := enableRcKeyValue(fmt.Sprintf("%s/etc/rc.conf", jail.RootPath), "rtsold_enable", "yes")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return fmt.Errorf("ERROR setting rtsold_enable=YES with sysrc for jail %s: %s\n", jail.Name, err)
 | 
							return fmt.Errorf("ERROR setting rtsold_enable=YES with sysrc for jail %s: %s\n", jail.Name, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -810,7 +810,9 @@ func generateMAC(jail *Jail, nic string) ([]byte, []byte, error) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	hsmac := append(prefix, suffix...)
 | 
						hsmac := append(prefix, suffix...)
 | 
				
			||||||
	jsmac := append(hsmac[:5], hsmac[5]+1)
 | 
						jsmac := make([]byte, 6)
 | 
				
			||||||
 | 
						copy(jsmac, hsmac)
 | 
				
			||||||
 | 
						jsmac[5] = jsmac[5] + 1
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	// Save MACs to config
 | 
						// Save MACs to config
 | 
				
			||||||
	pname := fmt.Sprintf("Config.%s_mac", strings.Title(nic))
 | 
						pname := fmt.Sprintf("Config.%s_mac", strings.Title(nic))
 | 
				
			||||||
@ -853,6 +855,12 @@ func setupVnetInterfaceHostSide(jail *Jail) ([]string, error) {
 | 
				
			|||||||
				return []string{}, err
 | 
									return []string{}, err
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
 | 
								if strings.EqualFold(val.String(), "none") {
 | 
				
			||||||
 | 
									hsmac, _, err = generateMAC(jail, nic)
 | 
				
			||||||
 | 
									if err != nil {
 | 
				
			||||||
 | 
										return []string{}, err
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			hsmac, err = hex.DecodeString(strings.Split(val.String(), " ")[0])
 | 
								hsmac, err = hex.DecodeString(strings.Split(val.String(), " ")[0])
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				return []string{}, fmt.Errorf("Error converting %s to hex\n", strings.Split(val.String(), " ")[0])
 | 
									return []string{}, fmt.Errorf("Error converting %s to hex\n", strings.Split(val.String(), " ")[0])
 | 
				
			||||||
@ -862,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
 | 
				
			||||||
@ -912,8 +920,10 @@ func setupVnetInterfaceJailSide(jail *Jail, hostepairs []string) error {
 | 
				
			|||||||
	
 | 
						
 | 
				
			||||||
	for _, i := range strings.Split(jail.Config.Ip4_addr, ",") {
 | 
						for _, i := range strings.Split(jail.Config.Ip4_addr, ",") {
 | 
				
			||||||
		v := strings.Split(i, "|")
 | 
							v := strings.Split(i, "|")
 | 
				
			||||||
 | 
							if len(v) > 1 {
 | 
				
			||||||
			ip4s[v[0]] = v[1]
 | 
								ip4s[v[0]] = v[1]
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	for _, i := range strings.Split(jail.Config.Ip6_addr, ",") {
 | 
						for _, i := range strings.Split(jail.Config.Ip6_addr, ",") {
 | 
				
			||||||
		v := strings.Split(i, "|")
 | 
							v := strings.Split(i, "|")
 | 
				
			||||||
		if len(v) > 1 {
 | 
							if len(v) > 1 {
 | 
				
			||||||
@ -966,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)
 | 
				
			||||||
@ -1438,7 +1448,7 @@ func StartJail(args []string) {
 | 
				
			|||||||
		fmt.Printf("  > Setup VNet network: OK\n")
 | 
							fmt.Printf("  > Setup VNet network: OK\n")
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		// Set default route, unless main network is dhcp
 | 
							// Set default route, unless main network is dhcp
 | 
				
			||||||
		if ! cj.isFirstNetDhcp() {
 | 
							if ! cj.isFirstNetDhcp() && !strings.EqualFold(cj.Config.Ip4_addr, "none") {
 | 
				
			||||||
			fmt.Printf("  > Setup default ipv4 gateway:\n")
 | 
								fmt.Printf("  > Setup default ipv4 gateway:\n")
 | 
				
			||||||
			cmd := fmt.Sprintf("/usr/sbin/setfib %s /usr/sbin/jexec %d route add default %s", cj.Config.Exec_fib, cj.JID, cj.Config.Defaultrouter)
 | 
								cmd := fmt.Sprintf("/usr/sbin/setfib %s /usr/sbin/jexec %d route add default %s", cj.Config.Exec_fib, cj.JID, cj.Config.Defaultrouter)
 | 
				
			||||||
			out, err := executeCommand(cmd)
 | 
								out, err := executeCommand(cmd)
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										15
									
								
								cmd/stop.go
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								cmd/stop.go
									
									
									
									
									
								
							@ -83,6 +83,7 @@ func umountAndUnjailZFS(jail *Jail) error {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func destroyVNetInterfaces(jail *Jail) error {
 | 
					func destroyVNetInterfaces(jail *Jail) error {
 | 
				
			||||||
 | 
						if !strings.EqualFold(jail.Config.Ip4_addr, "none") {
 | 
				
			||||||
		for _, i := range strings.Split(jail.Config.Ip4_addr, ",") {
 | 
							for _, i := range strings.Split(jail.Config.Ip4_addr, ",") {
 | 
				
			||||||
			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)
 | 
								fmt.Printf("%s: ", iname)
 | 
				
			||||||
@ -94,6 +95,20 @@ func destroyVNetInterfaces(jail *Jail) error {
 | 
				
			|||||||
				fmt.Printf("OK\n")
 | 
									fmt.Printf("OK\n")
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if !strings.EqualFold(jail.Config.Ip6_addr, "none") {
 | 
				
			||||||
 | 
							for _, i := range strings.Split(jail.Config.Ip6_addr, ",") {
 | 
				
			||||||
 | 
								iname := fmt.Sprintf("%s.%d", strings.Split(i, "|")[0], jail.JID)
 | 
				
			||||||
 | 
								fmt.Printf("%s: ", iname)
 | 
				
			||||||
 | 
								_, err := executeCommand(fmt.Sprintf("ifconfig %s destroy", iname))
 | 
				
			||||||
 | 
								//_, err := executeScript(fmt.Sprintf("ifconfig %s destroy >/dev/null 2>&1", iname))
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return err
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									fmt.Printf("OK\n")
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										166
									
								
								cmd/utils.go
									
									
									
									
									
								
							
							
						
						
									
										166
									
								
								cmd/utils.go
									
									
									
									
									
								
							@ -25,6 +25,87 @@ const (
 | 
				
			|||||||
	// Maximum thread qty for start/stop
 | 
						// Maximum thread qty for start/stop
 | 
				
			||||||
	gMaxThreads    = 4
 | 
						gMaxThreads    = 4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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 = `{
 | 
						gDefaultsJson = `{
 | 
				
			||||||
    "CONFIG_VERSION": "27",
 | 
					    "CONFIG_VERSION": "27",
 | 
				
			||||||
    "allow_chflags": 0,
 | 
					    "allow_chflags": 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,
 | 
				
			||||||
@ -147,7 +228,7 @@ const (
 | 
				
			|||||||
    "type": "jail",
 | 
					    "type": "jail",
 | 
				
			||||||
    "used": "readonly",
 | 
					    "used": "readonly",
 | 
				
			||||||
    "vmemoryuse": "off",
 | 
					    "vmemoryuse": "off",
 | 
				
			||||||
       "vnet": 0,
 | 
					    "vnet": 1,
 | 
				
			||||||
    "vnet0_mac": "none",
 | 
					    "vnet0_mac": "none",
 | 
				
			||||||
    "vnet1_mac": "none",
 | 
					    "vnet1_mac": "none",
 | 
				
			||||||
    "vnet2_mac": "none",
 | 
					    "vnet2_mac": "none",
 | 
				
			||||||
@ -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: 
 | 
				
			||||||
@ -670,6 +751,30 @@ func executeScript(script string) (string, error) {
 | 
				
			|||||||
	return string(out), err
 | 
						return string(out), err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*****************************************************************************
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Network related operations
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *****************************************************************************/
 | 
				
			||||||
 | 
					func getBridgeMembers(bridge string) ([]string, error) {
 | 
				
			||||||
 | 
						var members []string
 | 
				
			||||||
 | 
						cmd := fmt.Sprintf("/sbin/ifconfig %s", bridge)
 | 
				
			||||||
 | 
						out, err := executeCommand(cmd)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return members, errors.New(fmt.Sprintf("%v; command returned \"%s\"", err, out))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, line := range strings.Split(out, "\n") {
 | 
				
			||||||
 | 
							if strings.HasPrefix(strings.TrimLeft(line, " \t"), "member:") {
 | 
				
			||||||
 | 
								m := strings.Split(strings.TrimLeft(strings.Split(line, ":")[1], " "), " ")[0]
 | 
				
			||||||
 | 
								log.Debugf("%s is member of %s\n", m, bridge)
 | 
				
			||||||
 | 
								members = append(members, m)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return members, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*****************************************************************************
 | 
					/*****************************************************************************
 | 
				
			||||||
*
 | 
					*
 | 
				
			||||||
* ZFS datasets/pools operations
 | 
					* ZFS datasets/pools operations
 | 
				
			||||||
@ -814,7 +919,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 +975,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 +1020,44 @@ 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
 | 
				
			||||||
*****************************************************************************/
 | 
					*****************************************************************************/
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										58
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										58
									
								
								go.mod
									
									
									
									
									
								
							@ -8,25 +8,51 @@ require (
 | 
				
			|||||||
	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