Skip to content

Commit a340c97

Browse files
send command fully working
1 parent d419444 commit a340c97

File tree

7 files changed

+39
-28
lines changed

7 files changed

+39
-28
lines changed

config/remote .go renamed to config/remote.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type Remote struct {
1010
KnownHostsPath string `mapstructure:"known-hosts" description:"Path to the known hosts file"`
1111
BinaryPath string `mapstructure:"binary-path" description:"Path to the resticprofile binary to use on the remote client"`
1212
ConfigurationFile string `mapstructure:"configuration-file" description:"Path to the configuration file to transfer to the remote client"`
13+
ProfileName string `mapstructure:"profile-name" description:"Name of the profile to use on the remote client"`
1314
SendFiles []string `mapstructure:"send-files" description:"Other configuration files to transfer to the remote client"`
1415
}
1516

examples/linux.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ src:
101101
run-after: echo All Done!
102102
run-before:
103103
- echo Starting!
104-
- ls -al ~/go
104+
- ls -al ~/go/src/github.com/creativeprojects/resticprofile
105105
source:
106-
- ~/go
106+
- ~/go/src/github.com/creativeprojects/resticprofile
107107
tag:
108108
- test
109109
- dev

main.go

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func main() {
143143
banner()
144144

145145
if flags.remote != "" {
146-
closeFS, err := setupRemoteConfiguration(flags.remote)
146+
closeFS, remoteParameters, err := setupRemoteConfiguration(flags.remote)
147147
if err != nil {
148148
// need to setup console logging to display the error message
149149
closeLogger := setupLogging(nil)
@@ -152,6 +152,13 @@ func main() {
152152
exitCode = constants.ExitCannotSetupRemoteConfiguration
153153
return
154154
}
155+
if flags.config == constants.DefaultConfigurationFile && remoteParameters.ConfigurationFile != "" {
156+
flags.config = remoteParameters.ConfigurationFile
157+
}
158+
if flags.name == constants.DefaultProfileName && remoteParameters.ProfileName != "" {
159+
flags.name = remoteParameters.ProfileName
160+
}
161+
flags.resticArgs = remoteParameters.CommandLineArguments
155162
shutdown.AddHook(closeFS)
156163
}
157164

@@ -287,29 +294,18 @@ func main() {
287294
}
288295

289296
func banner() {
290-
clog.Debugf("resticprofile %s compiled with %s", version, runtime.Version())
297+
clog.Debugf(
298+
"resticprofile %s compiled with %s %s/%s",
299+
version,
300+
runtime.Version(),
301+
runtime.GOOS,
302+
runtime.GOARCH,
303+
)
291304
}
292305

293306
func loadConfig(flags commandLineFlags, silent bool) (cfg *config.Config, global *config.Global, err error) {
294307
fs := afero.NewOsFs()
295308

296-
// if flags.remote != "" {
297-
// // fs = afero.NewMemMapFs()
298-
// // parameters, err := loadRemoteConfiguration(fs, flags.remote)
299-
// os.Chdir()
300-
// _, parameters, err := loadRemoteFiles(flags.remote)
301-
// if err != nil {
302-
// return nil, nil, fmt.Errorf("cannot load remote configuration: %w", err)
303-
// }
304-
// // we should probably move this to the context (and keep flags intact)
305-
// if flags.config == constants.DefaultConfigurationFile {
306-
// flags.config = parameters.ConfigurationFile
307-
// }
308-
// if flags.name == constants.DefaultProfileName {
309-
// flags.name = parameters.ProfileName
310-
// }
311-
// }
312-
313309
var configFile string
314310
if configFile, err = filesearch.FindConfigurationFile(fs, flags.config); err == nil {
315311
if configFile != flags.config && !silent {

own_commands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (o *OwnCommands) Run(ctx *Context) error {
6565
return fmt.Errorf("command not found: %v", ctx.request.command)
6666
}
6767
if command.experimental {
68-
clog.Warning("this command is experimental and its behaviour may change in the future")
68+
clog.Warningf("%s: this command is experimental and its behaviour may change in the future", ctx.request.command)
6969
}
7070
return command.action(os.Stdout, commandContext{
7171
ownCommands: o,

remote.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ func getManifestParameters(reader io.Reader) (*remote.Manifest, error) {
9191
}
9292

9393
// setupRemoteConfiguration downloads the configuration files from the remote endpoint and mounts the virtual FS
94-
func setupRemoteConfiguration(remoteEndpoint string) (func(), error) {
94+
func setupRemoteConfiguration(remoteEndpoint string) (func(), *remote.Manifest, error) {
9595
files, parameters, err := loadRemoteFiles(remoteEndpoint)
9696
if err != nil {
97-
return nil, err
97+
return nil, nil, err
9898
}
9999

100100
closeMountpoint := func() {}
@@ -111,15 +111,26 @@ func setupRemoteConfiguration(remoteEndpoint string) (func(), error) {
111111
}
112112
err = os.MkdirAll(mountpoint, 0o755)
113113
if err != nil {
114-
return nil, fmt.Errorf("failed to create mount directory: %w", err)
114+
return nil, parameters, fmt.Errorf("failed to create mount directory: %w", err)
115115
}
116116

117117
closeFs, err := fuse.MountFS(mountpoint, files)
118118
if err != nil {
119-
return closeMountpoint, err
119+
return closeMountpoint, parameters, err
120120
}
121+
122+
wd, _ := os.Getwd()
123+
err = os.Chdir(mountpoint)
124+
if err != nil {
125+
return func() {
126+
closeFs()
127+
closeMountpoint()
128+
}, parameters, fmt.Errorf("failed to change directory: %w", err)
129+
}
130+
121131
return func() {
132+
_ = os.Chdir(wd)
122133
closeFs()
123134
closeMountpoint()
124-
}, nil
135+
}, parameters, nil
125136
}

send.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ func sendProfileCommand(w io.Writer, cmdCtx commandContext) error {
2929
handler := http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
3030
// prepare manifest file
3131
manifest := remote.Manifest{
32-
ConfigurationFile: path.Base(remoteConfig.ConfigurationFile), // need to take file path into consideration
32+
ConfigurationFile: path.Base(remoteConfig.ConfigurationFile), // need to take file path into consideration
33+
ProfileName: remoteConfig.ProfileName,
34+
CommandLineArguments: cmdCtx.flags.resticArgs[2:],
3335
}
3436
manifestData, err := json.Marshal(manifest)
3537
if err != nil {

serve.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func serveCommand(w io.Writer, cmdCtx commandContext) error {
4141
// prepare manifest file
4242
manifest := remote.Manifest{
4343
ConfigurationFile: path.Base(remoteConfig.ConfigurationFile), // need to take file path into consideration
44+
ProfileName: remoteConfig.ProfileName,
4445
}
4546
manifestData, err := json.Marshal(manifest)
4647
if err != nil {

0 commit comments

Comments
 (0)