diff options
| author | Shulhan <ms@kilabit.info> | 2023-10-21 19:52:17 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-10-21 19:59:10 +0700 |
| commit | f1cdc424327be91cfdbeb35449275cd8582bba8d (patch) | |
| tree | 5d350edefd9a17400179252a1018be7004988fe7 /ssh_client.go | |
| parent | 143e4c8c6825884ae864563b93689200a55c2d49 (diff) | |
| download | awwan-f1cdc424327be91cfdbeb35449275cd8582bba8d.tar.xz | |
all: implement remote "#get!" and "#put!" with owner and mode
When script with magic command "#get!" or "#put!" executed using "play"
command, one can changes the owner and/or permission mode by setting
the user/group and permission bits after the magic command, for example,
#get!user:group+0600 src dst
Will changes the owner of dst in local into "user:group" with permission
"0600", while
#put!user:group+0600 src dst
Will changes the owner of dst in remote into "user:group" with permission
"0600".
Diffstat (limited to 'ssh_client.go')
| -rw-r--r-- | ssh_client.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/ssh_client.go b/ssh_client.go index 692f050..786417c 100644 --- a/ssh_client.go +++ b/ssh_client.go @@ -155,6 +155,29 @@ func (sshc *sshClient) rmdirAll(dir string) { } } +// sudoChmod change the permission of remoteFile using sudo. +func (sshc *sshClient) sudoChmod(remoteFile string, mode fs.FileMode) (err error) { + var cmd = fmt.Sprintf(`sudo chmod %o %q`, mode, remoteFile) + + err = sshc.conn.Execute(cmd) + if err != nil { + return err + } + return nil + +} + +// sudoChown change the owner of remoteFile using sudo. +func (sshc *sshClient) sudoChown(remoteFile, owner string) (err error) { + var cmd = fmt.Sprintf(`sudo chown %s %q`, owner, remoteFile) + + err = sshc.conn.Execute(cmd) + if err != nil { + return err + } + return nil +} + // sudoGet copy the remote file using sudo to local. // The remote file is copied to temporary directory first, chmod-ed to // current SSH user so it can be read. |
