2022-08-28 11:21:57 +00:00
|
|
|
// Package rcd provides the rcd command.
|
2018-10-27 15:02:45 +00:00
|
|
|
package rcd
|
|
|
|
|
|
|
|
import (
|
2020-11-05 15:18:51 +00:00
|
|
|
"context"
|
2018-10-27 15:02:45 +00:00
|
|
|
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/cmd"
|
2024-08-18 14:58:35 +00:00
|
|
|
"github.com/rclone/rclone/fs"
|
2024-07-04 09:47:05 +00:00
|
|
|
"github.com/rclone/rclone/fs/rc"
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/fs/rc/rcflags"
|
|
|
|
"github.com/rclone/rclone/fs/rc/rcserver"
|
2022-12-11 14:47:47 +00:00
|
|
|
libhttp "github.com/rclone/rclone/lib/http"
|
2023-09-04 15:32:04 +00:00
|
|
|
"github.com/rclone/rclone/lib/systemd"
|
2018-10-27 15:02:45 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-08-04 11:32:37 +00:00
|
|
|
cmd.Root.AddCommand(commandDefinition)
|
2018-10-27 15:02:45 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 11:32:37 +00:00
|
|
|
var commandDefinition = &cobra.Command{
|
2018-10-27 15:02:45 +00:00
|
|
|
Use: "rcd <path to files to serve>*",
|
|
|
|
Short: `Run rclone listening to remote control commands only.`,
|
2024-04-05 11:27:33 +00:00
|
|
|
Long: `This runs rclone so that it only listens to remote control commands.
|
2018-10-27 15:02:45 +00:00
|
|
|
|
|
|
|
This is useful if you are controlling rclone via the rc API.
|
|
|
|
|
|
|
|
If you pass in a path to a directory, rclone will serve that directory
|
|
|
|
for GET requests on the URL passed in. It will also open the URL in
|
|
|
|
the browser when rclone is run.
|
2018-10-28 14:31:24 +00:00
|
|
|
|
|
|
|
See the [rc documentation](/rc/) for more info on the rc flags.
|
2024-04-05 11:27:33 +00:00
|
|
|
|
2023-03-23 12:04:17 +00:00
|
|
|
` + libhttp.Help(rcflags.FlagPrefix) + libhttp.TemplateHelp(rcflags.FlagPrefix) + libhttp.AuthHelp(rcflags.FlagPrefix),
|
2022-11-26 22:40:49 +00:00
|
|
|
Annotations: map[string]string{
|
|
|
|
"versionIntroduced": "v1.45",
|
2023-07-10 17:34:10 +00:00
|
|
|
"groups": "RC",
|
2022-11-26 22:40:49 +00:00
|
|
|
},
|
2018-10-27 15:02:45 +00:00
|
|
|
Run: func(command *cobra.Command, args []string) {
|
|
|
|
cmd.CheckArgs(0, 1, command, args)
|
2024-07-04 09:47:05 +00:00
|
|
|
if rc.Opt.Enabled {
|
2024-08-18 14:58:35 +00:00
|
|
|
fs.Fatalf(nil, "Don't supply --rc flag when using rcd")
|
2018-10-27 15:02:45 +00:00
|
|
|
}
|
2019-08-04 11:32:37 +00:00
|
|
|
|
2018-10-27 15:02:45 +00:00
|
|
|
// Start the rc
|
2024-07-04 09:47:05 +00:00
|
|
|
rc.Opt.Enabled = true
|
2018-10-27 15:02:45 +00:00
|
|
|
if len(args) > 0 {
|
2024-07-04 09:47:05 +00:00
|
|
|
rc.Opt.Files = args[0]
|
2018-10-27 15:02:45 +00:00
|
|
|
}
|
2019-08-04 11:32:37 +00:00
|
|
|
|
2024-07-04 09:47:05 +00:00
|
|
|
s, err := rcserver.Start(context.Background(), &rc.Opt)
|
2018-11-01 17:20:04 +00:00
|
|
|
if err != nil {
|
2024-08-18 14:58:35 +00:00
|
|
|
fs.Fatalf(nil, "Failed to start remote control: %v", err)
|
2018-11-01 17:20:04 +00:00
|
|
|
}
|
|
|
|
if s == nil {
|
2024-08-18 14:58:35 +00:00
|
|
|
fs.Fatal(nil, "rc server not configured")
|
2018-11-01 17:20:04 +00:00
|
|
|
}
|
2019-08-04 11:32:37 +00:00
|
|
|
|
2021-03-02 10:09:33 +00:00
|
|
|
// Notify stopping on exit
|
2023-09-04 15:32:04 +00:00
|
|
|
defer systemd.Notify()()
|
2021-03-02 10:09:33 +00:00
|
|
|
|
2018-11-01 17:20:04 +00:00
|
|
|
s.Wait()
|
2018-10-27 15:02:45 +00:00
|
|
|
},
|
|
|
|
}
|