Linting fixes + FileManager share start refactor
This commit is contained in:
parent
f7ae303062
commit
b15e2df3d3
11 changed files with 66 additions and 120 deletions
|
|
@ -97,7 +97,7 @@ func (fm *FileManager) luksOpen(sc *ssh.Client, fullDevPath string) error {
|
|||
return errors.Wrap(err, "write prompt to stderr")
|
||||
}
|
||||
|
||||
pwd, err := term.ReadPassword(int(syscall.Stdin))
|
||||
pwd, err := term.ReadPassword(syscall.Stdin)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "read luks password")
|
||||
}
|
||||
|
|
@ -199,17 +199,6 @@ func (fm *FileManager) Mount(devName string, mo MountOptions) error {
|
|||
}
|
||||
|
||||
func (fm *FileManager) StartFTP(pwd string, passivePortStart uint16, passivePortCount uint16, extIP net.IP) error {
|
||||
// This timeout is for the SCP client exclusively.
|
||||
scpCtx, scpCtxCancel := context.WithTimeout(fm.vm.ctx, time.Second*5)
|
||||
defer scpCtxCancel()
|
||||
|
||||
scpClient, err := fm.vm.DialSCP()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "dial scp")
|
||||
}
|
||||
|
||||
defer scpClient.Close()
|
||||
|
||||
ftpdCfg := `anonymous_enable=NO
|
||||
local_enable=YES
|
||||
write_enable=YES
|
||||
|
|
@ -223,45 +212,10 @@ pasv_max_port=` + fmt.Sprint(passivePortStart+passivePortCount) + `
|
|||
pasv_address=` + extIP.String() + `
|
||||
`
|
||||
|
||||
err = scpClient.CopyFile(scpCtx, strings.NewReader(ftpdCfg), "/etc/vsftpd/vsftpd.conf", "0400")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "copy ftpd .conf file")
|
||||
}
|
||||
|
||||
scpClient.Close()
|
||||
|
||||
sc, err := fm.vm.DialSSH()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "dial ssh")
|
||||
}
|
||||
|
||||
defer func() { _ = sc.Close() }()
|
||||
|
||||
_, err = sshutil.RunSSHCmd(fm.vm.ctx, sc, "rc-update add vsftpd && rc-service vsftpd start")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "add and start ftpd service")
|
||||
}
|
||||
|
||||
err = sshutil.ChangeUnixPass(fm.vm.ctx, sc, "linsk", pwd)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "change unix pass")
|
||||
}
|
||||
|
||||
return nil
|
||||
return fm.startGenericShare(pwd, ftpdCfg, "/etc/vsftpd/vsftpd.conf", "vsftpd", sshutil.ChangeUnixPass)
|
||||
}
|
||||
|
||||
func (fm *FileManager) StartSMB(pwd string) error {
|
||||
// This timeout is for the SCP client exclusively.
|
||||
scpCtx, scpCtxCancel := context.WithTimeout(fm.vm.ctx, time.Second*5)
|
||||
defer scpCtxCancel()
|
||||
|
||||
scpClient, err := fm.vm.DialSCP()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "dial scp")
|
||||
}
|
||||
|
||||
defer scpClient.Close()
|
||||
|
||||
sambaCfg := `[global]
|
||||
workgroup = WORKGROUP
|
||||
dos charset = cp866
|
||||
|
|
@ -286,46 +240,10 @@ force user = linsk
|
|||
force group = linsk
|
||||
create mask = 0664
|
||||
`
|
||||
|
||||
err = scpClient.CopyFile(scpCtx, strings.NewReader(sambaCfg), "/etc/samba/smb.conf", "0400")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "copy samba config file")
|
||||
}
|
||||
|
||||
scpClient.Close()
|
||||
|
||||
sc, err := fm.vm.DialSSH()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "dial ssh")
|
||||
}
|
||||
|
||||
defer func() { _ = sc.Close() }()
|
||||
|
||||
_, err = sshutil.RunSSHCmd(fm.vm.ctx, sc, "rc-update add samba && rc-service samba start")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "add and start samba service")
|
||||
}
|
||||
|
||||
err = sshutil.ChangeSambaPass(fm.vm.ctx, sc, "linsk", pwd)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "change samba pass")
|
||||
}
|
||||
|
||||
return nil
|
||||
return fm.startGenericShare(pwd, sambaCfg, "/etc/samba/smb.conf", "samba", sshutil.ChangeSambaPass)
|
||||
}
|
||||
|
||||
func (fm *FileManager) StartAFP(pwd string) error {
|
||||
// This timeout is for the SCP client exclusively.
|
||||
scpCtx, scpCtxCancel := context.WithTimeout(fm.vm.ctx, time.Second*5)
|
||||
defer scpCtxCancel()
|
||||
|
||||
scpClient, err := fm.vm.DialSCP()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "dial scp")
|
||||
}
|
||||
|
||||
defer scpClient.Close()
|
||||
|
||||
afpCfg := `[Global]
|
||||
|
||||
[linsk]
|
||||
|
|
@ -337,9 +255,24 @@ force user = linsk
|
|||
force group = linsk
|
||||
`
|
||||
|
||||
err = scpClient.CopyFile(scpCtx, strings.NewReader(afpCfg), "/etc/afp.conf", "0400")
|
||||
return fm.startGenericShare(pwd, afpCfg, "/etc/afp.conf", "netatalk", sshutil.ChangeUnixPass)
|
||||
}
|
||||
|
||||
func (fm *FileManager) startGenericShare(pwd string, cfg string, cfgPath string, rcServiceName string, changePassFunc sshutil.ChangePassFunc) error {
|
||||
// This timeout is for the SCP client exclusively.
|
||||
scpCtx, scpCtxCancel := context.WithTimeout(fm.vm.ctx, time.Second*5)
|
||||
defer scpCtxCancel()
|
||||
|
||||
scpClient, err := fm.vm.DialSCP()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "copy netatalk config file")
|
||||
return errors.Wrap(err, "dial scp")
|
||||
}
|
||||
|
||||
defer scpClient.Close()
|
||||
|
||||
err = scpClient.CopyFile(scpCtx, strings.NewReader(cfg), cfgPath, "0400")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "copy config file")
|
||||
}
|
||||
|
||||
scpClient.Close()
|
||||
|
|
@ -351,14 +284,14 @@ force group = linsk
|
|||
|
||||
defer func() { _ = sc.Close() }()
|
||||
|
||||
_, err = sshutil.RunSSHCmd(fm.vm.ctx, sc, "rc-update add netatalk && rc-service netatalk start")
|
||||
_, err = sshutil.RunSSHCmd(fm.vm.ctx, sc, "rc-update add "+shellescape.Quote(rcServiceName)+" && rc-service "+shellescape.Quote(rcServiceName)+" start")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "add and start netatalk service")
|
||||
return errors.Wrap(err, "add and start rc service")
|
||||
}
|
||||
|
||||
err = sshutil.ChangeUnixPass(fm.vm.ctx, sc, "linsk", pwd)
|
||||
err = changePassFunc(fm.vm.ctx, sc, "linsk", pwd)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "change unix pass")
|
||||
return errors.Wrap(err, "change pass")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue