firespace

package module
v0.0.0-...-5f090ee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2023 License: MIT Imports: 16 Imported by: 0

README

Firespace

(Work)Spaces / User-Profiles for firejail

Why?

Was tired of allways typing the mostly same, but slightly diffrent firejail commands with options not covert by local profiles.

Features

  • Define usage context like "normal", "private", "school", "work"
  • Specify firejail arguments and program arguments to be apply depending on the selected context and/or program you run
  • Config validation
  • Dry run

Usage

Example config

config.yaml (use firespace --help to see the default location)

spaces:
  working:
    home: "/some/path/working"

  private:
    home: ""
    allow_empty_home: true
    env:
      PROXY: "socks5://..."

  nospace:
    home: ""
    allow_empty_home: true
    no_private: true

programms:
  firefox:
    flags:
      - "--no-remote"
      - "https://duckduckgo.com/?q=firejail"
    spaces:
      private:
        overwrites:
          flags: true
        flags:
          - "--no-remote"
          - "--private-window"
          - "https://duckduckgo.com/?q=firejail"
Cli usage

firespace working firefox
will be executed as
=> /usr/bin/firejail --private=/some/path/working firefox --no-remote https://duckduckgo.com/?q=firejail

firespace private firefox
will be executed as
=> /usr/bin/firejail --private firefox --no-remote --private-window https://duckduckgo.com/?q=firejail

firespace nospace firefox
will be executed as => /usr/bin/firejail firefox --no-remote https://duckduckgo.com/?q=firejail

Installation

go install github.com/scaxyz/firespace/cli/firespace@latest

Templating

TODO: improve readme

  • using golang's text/template
  • see TemplateContext
  • e. g.
    global:
      env:
        _proxy_host: "some-server.mullvad.net"
        _proxy_port: "1080"
        PROXY: "socks5://{{.Space.Env._proxy_host}}:{{.Space.Env._proxy_port}}"
        HTTP_PROXY: "socks5://{{.Space.Env._proxy_host}}:{{.Space.Env._proxy_port}}"
        HTTP_PROXY: "socks5://{{.Space.Env._proxy_host}}:{{.Space.Env._proxy_port}}"
    
    

Development

git clone https://github.com/scaxyz/firespace
cd firespace
make install_hook # installed hook will run go tests before commiting #TODO maybe replace with github workflow

Config

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CueFiles embed.FS

Functions

func GetLogger

func GetLogger() *zap.SugaredLogger

func SetLogger

func SetLogger(newSugar *zap.SugaredLogger)

Types

type AdditionalSpaceSettings

type AdditionalSpaceSettings struct {
	// CommonSpaceSettings   `json:",inline"`
	// CommonSettings `json:",inline"`
	// HasEnv        `json:",inline"`
	Env Env `json:"env"`

	Before        []ExtendedShellCommand `json:"before,omitempty"`
	After         ShellCommands          `json:"after,omitempty"`
	FirejailFlags []string               `json:"firejail_flags"`

	// HasOverwrites `json:",inline"`
	Overwrites Overwrites `json:"overwrites"`

	PreFlags []string `json:"pre_flags"`
	Flags    []string `json:"flags"`
}

type CanControllHome

type CanControllHome struct {
	AllowEmptyHome bool `json:"allow_empty_home"`
	NoPrivate      bool `json:"no_private"`
}

type CanSetHome

type CanSetHome struct {
	Home string `json:"home"`
}

type CommonProgramSettings

type CommonProgramSettings struct {
	// CommonSettings `json:",inline"`
	// HasEnv        `json:",inline"`
	Env Env `json:"env"`

	Before        []ExtendedShellCommand `json:"before,omitempty"`
	After         ShellCommands          `json:"after,omitempty"`
	FirejailFlags []string               `json:"firejail_flags"`

	// HasOverwrites  `json:",inline"`
	Overwrites Overwrites `json:"overwrites"`

	PreFlags []string `json:"pre_flags"`
	Flags    []string `json:"flags"`
}

type CommonSettings

type CommonSettings struct {
	// HasEnv        `json:",inline"`
	Env Env `json:"env"`

	Before        []ExtendedShellCommand `json:"before,omitempty"`
	After         ShellCommands          `json:"after,omitempty"`
	FirejailFlags []string               `json:"firejail_flags"`
}

type CommonSpaceSettings

type CommonSpaceSettings struct {
	// CommonSettings `json:",inline"`
	// HasEnv        `json:",inline"`
	Env Env `json:"env"`

	Before        []ExtendedShellCommand `json:"before,omitempty"`
	After         ShellCommands          `json:"after,omitempty"`
	FirejailFlags []string               `json:"firejail_flags"`

	// HasOverwrites  `json:",inline"`
	Overwrites Overwrites `json:"overwrites"`
}

type ConfigFile

type ConfigFile struct {
	Global    GlobalSettings             `json:"global"`
	Spaces    map[string]SpaceSettings   `json:"spaces"`
	Programms map[string]ProgramSettings `json:"programms"`
}

func LoadYamlConfig

func LoadYamlConfig(yamlPath string) (*ConfigFile, error)

type Env

type Env map[string]string

type ExtendedShellCommand

type ExtendedShellCommand struct {
	Command    string `json:"command"`
	AllowError bool   `json:"allow_error"`
}

type FirespaceContext

type FirespaceContext struct {
	// CommonSettings
	// HasEnv        `json:",inline"`
	Env Env `json:"env"`

	Before        []ExtendedShellCommand `json:"before,omitempty"`
	After         ShellCommands          `json:"after,omitempty"`
	FirejailFlags []string               `json:"firejail_flags"`

	// CanControllHome
	AllowEmptyHome bool `json:"allow_empty_home"`
	NoPrivate      bool `json:"no_private"`

	// CanSetHome
	Home string `json:"home"`

	// HasOverwrites `yaml:",inline"`
	Overwrites Overwrites `json:"overwrites"`

	Executeable string
	PreFlags    []string `yaml:"pre_flags"`
	Flags       []string
}

func Merge

func Merge(base *FirespaceContext, updates *FirespaceContext) *FirespaceContext

func NewFirespaceFromConfig

func NewFirespaceFromConfig(config *ConfigFile, space string, program string) *FirespaceContext

func (FirespaceContext) BuildFirejailArgs

func (space FirespaceContext) BuildFirejailArgs(cliArgs []string) []string

func (FirespaceContext) BuildFirejailCommand

func (space FirespaceContext) BuildFirejailCommand(cliArgs []string) *exec.Cmd

func (FirespaceContext) ExecuteTemplates

func (space FirespaceContext) ExecuteTemplates() *FirespaceContext

func (FirespaceContext) Start

func (space FirespaceContext) Start(cliArgs []string, dry bool) (err error)

type GlobalSettings

type GlobalSettings struct {
	/*
		#CommonSettings
	*/
	Before        []ExtendedShellCommand `json:"before,omitempty"`
	After         ShellCommands          `json:"after,omitempty"`
	FirejailFlags []string               `json:"firejail_flags"`

	Env Env `json:"env"`
}

type HasEnv

type HasEnv struct {
	Env Env `json:"env"`
}

type HasOverwrites

type HasOverwrites struct {
	Overwrites Overwrites `json:"overwrites"`
}

type Overwrites

type Overwrites struct {
	Env           bool
	Before        bool
	After         bool
	FirejailFlags bool
	PreFlags      bool
	Flags         bool
}

type ProgramSettings

type ProgramSettings struct {
	// CommonProgramSettings `json:",inline"`
	// CommonSettings `json:",inline"`
	// HasEnv        `json:",inline"`
	Env Env `json:"env"`

	Before        []ExtendedShellCommand `json:"before,omitempty"`
	After         ShellCommands          `json:"after,omitempty"`
	FirejailFlags []string               `json:"firejail_flags"`

	// HasOverwrites  `json:",inline"`
	Overwrites Overwrites `json:"overwrites"`

	PreFlags []string `json:"pre_flags"`
	Flags    []string `json:"flags"`

	Spaces      map[string]AdditionalSpaceSettings `json:"spaces"`
	Executeable string                             `json:"executeable,omitempty"`
}

type ShellCommand

type ShellCommand string

type ShellCommands

type ShellCommands []string

type SpaceSettings

type SpaceSettings struct {
	// CommonSettings `json:",inline"
	// HasEnv        `json:",inline"`
	Env Env `json:"env"`

	Before        []ExtendedShellCommand `json:"before,omitempty"`
	After         ShellCommands          `json:"after,omitempty"`
	FirejailFlags []string               `json:"firejail_flags"`

	// HasOverwrites   `json:",inline"`
	Overwrites Overwrites `json:"overwrites"`

	// CanControllHome `json:",inline"`
	AllowEmptyHome bool `json:"allow_empty_home"`
	NoPrivate      bool `json:"no_private"`

	// CanSetHome      `json:",inline"`
	Home string `json:"home"`
}

type TemplateContext

type TemplateContext struct {
	OS struct {
		Env map[string]string
	}
	Space struct {
		Env    map[string]string
		Config FirespaceContext
	}
}

Directories

Path Synopsis
cli

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL