github.com/keybase/client/go@v0.0.0-20240520164431-4f512a4c85a3/client/cmd_ctl_autostart.go (about)

     1  // Copyright 2019 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  //go:build !darwin
     5  // +build !darwin
     6  
     7  package client
     8  
     9  import (
    10  	"fmt"
    11  
    12  	"github.com/keybase/cli"
    13  	"github.com/keybase/client/go/install"
    14  	"github.com/keybase/client/go/libcmdline"
    15  	"github.com/keybase/client/go/libkb"
    16  )
    17  
    18  type CmdCtlAutostart struct {
    19  	libkb.Contextified
    20  	ToggleOn bool
    21  }
    22  
    23  func NewCmdCtlAutostart(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
    24  	const backtick = "`"
    25  
    26  	cmd := &CmdCtlAutostart{
    27  		Contextified: libkb.NewContextified(g),
    28  	}
    29  	return cli.Command{
    30  		Name: "autostart",
    31  		Usage: `Configure autostart settings via the XDG autostart standard.
    32  
    33      On Linux this creates a file at ~/.config/autostart/keybase.desktop.
    34  
    35  	If you change this file after initial install, it will not be changed unless
    36  	you run ` + backtick + `keybase ctl autostart` + backtick + ` or delete
    37  	the sentinel file at ~/.config/keybase/autostart_created.
    38  
    39  	If you are using a headless machine or a minimal window manager that doesn't
    40  	respect this standard, you will need to configure autostart in another way.
    41  
    42  	If you are running Keybase on a headless machine using systemd, you may be
    43  	interested in enabling the systemd user manager units keybase.service and
    44  	kbfs.service: ` + backtick + `systemctl --user enable keybase kbfs
    45  	keybase-redirector` + backtick + `.
    46  
    47  
    48      On Windows, registry and shortcuts are used for this.
    49  `,
    50  		Flags: []cli.Flag{
    51  			cli.BoolFlag{
    52  				Name:  "enable",
    53  				Usage: "Toggle on Keybase, KBFS, and GUI autostart on startup.",
    54  			},
    55  			cli.BoolFlag{
    56  				Name:  "disable",
    57  				Usage: "Toggle off Keybase, KBFS, and GUI autostart on startup.",
    58  			},
    59  		},
    60  		ArgumentHelp: "",
    61  		Action: func(c *cli.Context) {
    62  			cl.ChooseCommand(cmd, "autostart", c)
    63  			cl.SetForkCmd(libcmdline.NoFork)
    64  			cl.SetLogForward(libcmdline.LogForwardNone)
    65  		},
    66  	}
    67  }
    68  
    69  func (c *CmdCtlAutostart) ParseArgv(ctx *cli.Context) error {
    70  	toggleOn := ctx.Bool("enable")
    71  	toggleOff := ctx.Bool("disable")
    72  	if toggleOn && toggleOff {
    73  		return fmt.Errorf("Cannot specify both --enable and --disable.")
    74  	}
    75  	if !toggleOn && !toggleOff {
    76  		return fmt.Errorf("Must specify either --enable or --disable.")
    77  	}
    78  	c.ToggleOn = toggleOn
    79  	return nil
    80  }
    81  
    82  func (c *CmdCtlAutostart) Run() error {
    83  	err := install.ToggleAutostart(c.G(), c.ToggleOn, false)
    84  	if err != nil {
    85  		return err
    86  	}
    87  	return nil
    88  }
    89  
    90  func (c *CmdCtlAutostart) GetUsage() libkb.Usage {
    91  	return libkb.Usage{
    92  		Config: true,
    93  		API:    true,
    94  	}
    95  }