mirror of
https://github.com/rclone/rclone.git
synced 2025-01-10 16:28:30 +01:00
Tweaks to rclone authorize
* Document the headless / remote setup procedure * Move Config constants into fs * Parse arguments in main for Authorize
This commit is contained in:
parent
bcbd30bb8a
commit
5189231a34
@ -155,6 +155,7 @@ Add your fs to the docs
|
|||||||
* `README.md` - main Github page
|
* `README.md` - main Github page
|
||||||
* `docs/content/remote.md` - main docs page
|
* `docs/content/remote.md` - main docs page
|
||||||
* `docs/content/overview.md` - overview docs
|
* `docs/content/overview.md` - overview docs
|
||||||
|
* `docs/content/docs.md` - list of remotes in config section
|
||||||
* `docs/content/about.md` - front page of rclone.org
|
* `docs/content/about.md` - front page of rclone.org
|
||||||
* `docs/layouts/chrome/navbar.html` - add it to the website navigation
|
* `docs/layouts/chrome/navbar.html` - add it to the website navigation
|
||||||
* `make_manual.py` - add the page to the `docs` constant
|
* `make_manual.py` - add the page to the `docs` constant
|
||||||
|
@ -69,10 +69,10 @@ func init() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Options: []fs.Option{{
|
Options: []fs.Option{{
|
||||||
Name: oauthutil.ConfigClientID,
|
Name: fs.ConfigClientID,
|
||||||
Help: "Amazon Application Client Id - leave blank normally.",
|
Help: "Amazon Application Client Id - leave blank normally.",
|
||||||
}, {
|
}, {
|
||||||
Name: oauthutil.ConfigClientSecret,
|
Name: fs.ConfigClientSecret,
|
||||||
Help: "Amazon Application Client Secret - leave blank normally.",
|
Help: "Amazon Application Client Secret - leave blank normally.",
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
|
@ -58,6 +58,9 @@ d) Delete this remote
|
|||||||
y/e/d> y
|
y/e/d> y
|
||||||
```
|
```
|
||||||
|
|
||||||
|
See the [remote setup docs](/remote_setup/) for how to set it up on a
|
||||||
|
machine with no Internet browser available.
|
||||||
|
|
||||||
Note that rclone runs a webserver on your local machine to collect the
|
Note that rclone runs a webserver on your local machine to collect the
|
||||||
token as returned from Amazon. This only runs from the moment it
|
token as returned from Amazon. This only runs from the moment it
|
||||||
opens your browser to the moment you get back the verification
|
opens your browser to the moment you get back the verification
|
||||||
|
@ -25,6 +25,11 @@ See the following for detailed instructions for
|
|||||||
* [Dropbox](/dropbox/)
|
* [Dropbox](/dropbox/)
|
||||||
* [Google Cloud Storage](/googlecloudstorage/)
|
* [Google Cloud Storage](/googlecloudstorage/)
|
||||||
* [Local filesystem](/local/)
|
* [Local filesystem](/local/)
|
||||||
|
* [Amazon Cloud Drive](/amazonclouddrive/)
|
||||||
|
* [Backblaze B2](/b2/)
|
||||||
|
* [Hubic](/hubic/)
|
||||||
|
* [Microsoft One Drive](/onedrive/)
|
||||||
|
* [Yandex Disk](/yandex/)
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
-----
|
-----
|
||||||
|
@ -12,31 +12,17 @@ Frequently Asked Questions
|
|||||||
Yes they do. All the rclone commands (eg `sync`, `copy` etc) will
|
Yes they do. All the rclone commands (eg `sync`, `copy` etc) will
|
||||||
work on all the remote storage systems.
|
work on all the remote storage systems.
|
||||||
|
|
||||||
|
|
||||||
### Can I copy the config from one machine to another ###
|
### Can I copy the config from one machine to another ###
|
||||||
|
|
||||||
Sure! Rclone stores all of its config in a single file. If you want
|
Sure! Rclone stores all of its config in a single file. If you want
|
||||||
to find this file, the simplest way is to run `rclone -h` and look at
|
to find this file, the simplest way is to run `rclone -h` and look at
|
||||||
the help for the `--config` flag which will tell you where it is. Eg,
|
the help for the `--config` flag which will tell you where it is.
|
||||||
|
|
||||||
```
|
See the [remote setup docs](/remote_setup/) for more info.
|
||||||
$ rclone -h
|
|
||||||
Sync files and directories to and from local and remote object stores - v1.18.
|
|
||||||
[snip]
|
|
||||||
Options:
|
|
||||||
--bwlimit=0: Bandwidth limit in kBytes/s, or use suffix k|M|G
|
|
||||||
--checkers=8: Number of checkers to run in parallel.
|
|
||||||
-c, --checksum=false: Skip based on checksum & size, not mod-time & size
|
|
||||||
--config="/home/user/.rclone.conf": Config file.
|
|
||||||
[snip]
|
|
||||||
```
|
|
||||||
|
|
||||||
So in this config the config file can be found in
|
### How do I configure rclone on a remote / headless box with no browser? ###
|
||||||
`/home/user/.rclone.conf`.
|
|
||||||
|
|
||||||
Just copy that to the equivalent place in the destination (run `rclone
|
|
||||||
-h` above again on the destination machine if not sure).
|
|
||||||
|
|
||||||
|
This has now been documented in its own [remote setup page](/remote_setup/).
|
||||||
|
|
||||||
### Can rclone sync directly from drive to s3 ###
|
### Can rclone sync directly from drive to s3 ###
|
||||||
|
|
||||||
|
@ -60,6 +60,9 @@ d) Delete this remote
|
|||||||
y/e/d> y
|
y/e/d> y
|
||||||
```
|
```
|
||||||
|
|
||||||
|
See the [remote setup docs](/remote_setup/) for how to set it up on a
|
||||||
|
machine with no Internet browser available.
|
||||||
|
|
||||||
Note that rclone runs a webserver on your local machine to collect the
|
Note that rclone runs a webserver on your local machine to collect the
|
||||||
token as returned from Hubic. This only runs from the moment it opens
|
token as returned from Hubic. This only runs from the moment it opens
|
||||||
your browser to the moment you get back the verification code. This
|
your browser to the moment you get back the verification code. This
|
||||||
|
@ -59,6 +59,9 @@ d) Delete this remote
|
|||||||
y/e/d> y
|
y/e/d> y
|
||||||
```
|
```
|
||||||
|
|
||||||
|
See the [remote setup docs](/remote_setup/) for how to set it up on a
|
||||||
|
machine with no Internet browser available.
|
||||||
|
|
||||||
Note that rclone runs a webserver on your local machine to collect the
|
Note that rclone runs a webserver on your local machine to collect the
|
||||||
token as returned from Microsoft. This only runs from the moment it
|
token as returned from Microsoft. This only runs from the moment it
|
||||||
opens your browser to the moment you get back the verification
|
opens your browser to the moment you get back the verification
|
||||||
|
88
docs/content/remote_setup.md
Normal file
88
docs/content/remote_setup.md
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
---
|
||||||
|
title: "Remote Setup"
|
||||||
|
description: "Configuring rclone up on a remote / headless machine"
|
||||||
|
date: "2016-01-07"
|
||||||
|
---
|
||||||
|
|
||||||
|
# Configuring rclone on a remote / headless machine #
|
||||||
|
|
||||||
|
Some of the configurations (those involving oauth2) require an
|
||||||
|
Internet connected web browser.
|
||||||
|
|
||||||
|
If you are trying to set rclone up on a remote or headless box with no
|
||||||
|
browser available on it (eg a NAS or a server in a datacenter) then
|
||||||
|
you will need to use an alternative means of configuration. There are
|
||||||
|
two ways of doing it, described below.
|
||||||
|
|
||||||
|
## Configuring using rclone authorize ##
|
||||||
|
|
||||||
|
On the headless box
|
||||||
|
|
||||||
|
```
|
||||||
|
...
|
||||||
|
Remote config
|
||||||
|
Use auto config?
|
||||||
|
* Say Y if not sure
|
||||||
|
* Say N if you are working on a remote or headless machine
|
||||||
|
y) Yes
|
||||||
|
n) No
|
||||||
|
y/n> n
|
||||||
|
For this to work, you will need rclone available on a machine that has a web browser available.
|
||||||
|
Execute the following on your machine:
|
||||||
|
rclone authorize "amazon cloud drive"
|
||||||
|
Then paste the result below:
|
||||||
|
result>
|
||||||
|
```
|
||||||
|
|
||||||
|
Then on your main desktop machine
|
||||||
|
|
||||||
|
```
|
||||||
|
rclone authorize "amazon cloud drive"
|
||||||
|
If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth
|
||||||
|
Log in and authorize rclone for access
|
||||||
|
Waiting for code...
|
||||||
|
Got code
|
||||||
|
Paste the following into your remote machine --->
|
||||||
|
SECRET_TOKEN
|
||||||
|
<---End paste
|
||||||
|
```
|
||||||
|
|
||||||
|
Then back to the headless box, paste in the code
|
||||||
|
|
||||||
|
```
|
||||||
|
result> SECRET_TOKEN
|
||||||
|
--------------------
|
||||||
|
[acd12]
|
||||||
|
client_id =
|
||||||
|
client_secret =
|
||||||
|
token = SECRET_TOKEN
|
||||||
|
--------------------
|
||||||
|
y) Yes this is OK
|
||||||
|
e) Edit this remote
|
||||||
|
d) Delete this remote
|
||||||
|
y/e/d>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuring by copying the config file ##
|
||||||
|
|
||||||
|
Rclone stores all of its config in a single configuration file. This
|
||||||
|
can easily be copied to configure a remote rclone.
|
||||||
|
|
||||||
|
So first configure rclone on your desktop machine
|
||||||
|
|
||||||
|
rclone config
|
||||||
|
|
||||||
|
to set up the config file.
|
||||||
|
|
||||||
|
Find the config file by running `rclone -h` and looking for the help for the `--config` option
|
||||||
|
|
||||||
|
```
|
||||||
|
$ rclone -h
|
||||||
|
[snip]
|
||||||
|
--config="/home/user/.rclone.conf": Config file.
|
||||||
|
[snip]
|
||||||
|
```
|
||||||
|
|
||||||
|
Now transfer it to the remote box (scp, cut paste, ftp, sftp etc) and
|
||||||
|
place it in the correct place (use `rclone -h` on the remote box to
|
||||||
|
find out where).
|
@ -58,7 +58,16 @@ d) Delete this remote
|
|||||||
y/e/d> y
|
y/e/d> y
|
||||||
```
|
```
|
||||||
|
|
||||||
This remote is called `remote` and can now be used like this
|
See the [remote setup docs](/remote_setup/) for how to set it up on a
|
||||||
|
machine with no Internet browser available.
|
||||||
|
|
||||||
|
Note that rclone runs a webserver on your local machine to collect the
|
||||||
|
token as returned from Yandex Disk. This only runs from the moment it
|
||||||
|
opens your browser to the moment you get back the verification code.
|
||||||
|
This is on `http://127.0.0.1:53682/` and this it may require you to
|
||||||
|
unblock it temporarily if you are running a host firewall.
|
||||||
|
|
||||||
|
Once configured you can then use `rclone` like this,
|
||||||
|
|
||||||
See top level directories
|
See top level directories
|
||||||
|
|
||||||
|
@ -72,10 +72,10 @@ func init() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Options: []fs.Option{{
|
Options: []fs.Option{{
|
||||||
Name: oauthutil.ConfigClientID,
|
Name: fs.ConfigClientID,
|
||||||
Help: "Google Application Client Id - leave blank normally.",
|
Help: "Google Application Client Id - leave blank normally.",
|
||||||
}, {
|
}, {
|
||||||
Name: oauthutil.ConfigClientSecret,
|
Name: fs.ConfigClientSecret,
|
||||||
Help: "Google Application Client Secret - leave blank normally.",
|
Help: "Google Application Client Secret - leave blank normally.",
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
|
34
fs/config.go
34
fs/config.go
@ -26,6 +26,18 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
configFileName = ".rclone.conf"
|
configFileName = ".rclone.conf"
|
||||||
|
|
||||||
|
// ConfigToken is the key used to store the token under
|
||||||
|
ConfigToken = "token"
|
||||||
|
|
||||||
|
// ConfigClientID is the config key used to store the client id
|
||||||
|
ConfigClientID = "client_id"
|
||||||
|
|
||||||
|
// ConfigClientSecret is the config key used to store the client secret
|
||||||
|
ConfigClientSecret = "client_secret"
|
||||||
|
|
||||||
|
// ConfigAutomatic indicates that we want non-interactive configuration
|
||||||
|
ConfigAutomatic = "config_automatic"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SizeSuffix is parsed by flag with k/M/G suffixes
|
// SizeSuffix is parsed by flag with k/M/G suffixes
|
||||||
@ -533,21 +545,13 @@ func EditConfig() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Duplicated from oauthutil to avoid circular reference.
|
|
||||||
const (
|
|
||||||
// ConfigClientID is the config key used to store the client id
|
|
||||||
ConfigClientID = "client_id"
|
|
||||||
|
|
||||||
// ConfigClientSecret is the config key used to store the client secret
|
|
||||||
ConfigClientSecret = "client_secret"
|
|
||||||
|
|
||||||
// ConfigAutomatic indicates that we want non-interactive configuration
|
|
||||||
ConfigAutomatic = "config_automatic"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Authorize is for remote authorization of headless machines.
|
// Authorize is for remote authorization of headless machines.
|
||||||
func Authorize() {
|
//
|
||||||
args := pflag.Args()[1:]
|
// It expects 1 or 3 arguments
|
||||||
|
//
|
||||||
|
// rclone authorize "fs name"
|
||||||
|
// rclone authorize "fs name" "client id" "client secret"
|
||||||
|
func Authorize(args []string) {
|
||||||
switch len(args) {
|
switch len(args) {
|
||||||
case 1, 3:
|
case 1, 3:
|
||||||
default:
|
default:
|
||||||
@ -560,7 +564,7 @@ func Authorize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if fs.Config == nil {
|
if fs.Config == nil {
|
||||||
log.Fatalf("No configuration on fs %v", newType)
|
log.Fatalf("Can't authorize fs %q", newType)
|
||||||
}
|
}
|
||||||
// Name used for temporary fs
|
// Name used for temporary fs
|
||||||
name := "**temp-fs**"
|
name := "**temp-fs**"
|
||||||
|
@ -65,10 +65,10 @@ func init() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Options: []fs.Option{{
|
Options: []fs.Option{{
|
||||||
Name: oauthutil.ConfigClientID,
|
Name: fs.ConfigClientID,
|
||||||
Help: "Google Application Client Id - leave blank normally.",
|
Help: "Google Application Client Id - leave blank normally.",
|
||||||
}, {
|
}, {
|
||||||
Name: oauthutil.ConfigClientSecret,
|
Name: fs.ConfigClientSecret,
|
||||||
Help: "Google Application Client Secret - leave blank normally.",
|
Help: "Google Application Client Secret - leave blank normally.",
|
||||||
}, {
|
}, {
|
||||||
Name: "project_number",
|
Name: "project_number",
|
||||||
|
@ -54,10 +54,10 @@ func init() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Options: []fs.Option{{
|
Options: []fs.Option{{
|
||||||
Name: oauthutil.ConfigClientID,
|
Name: fs.ConfigClientID,
|
||||||
Help: "Hubic Client Id - leave blank normally.",
|
Help: "Hubic Client Id - leave blank normally.",
|
||||||
}, {
|
}, {
|
||||||
Name: oauthutil.ConfigClientSecret,
|
Name: fs.ConfigClientSecret,
|
||||||
Help: "Hubic Client Secret - leave blank normally.",
|
Help: "Hubic Client Secret - leave blank normally.",
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
|
@ -16,6 +16,7 @@ docs = [
|
|||||||
"about.md",
|
"about.md",
|
||||||
"install.md",
|
"install.md",
|
||||||
"docs.md",
|
"docs.md",
|
||||||
|
"remote_setup.md",
|
||||||
"filtering.md",
|
"filtering.md",
|
||||||
"overview.md",
|
"overview.md",
|
||||||
"drive.md",
|
"drive.md",
|
||||||
|
@ -17,18 +17,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// ConfigToken is the key used to store the token under
|
|
||||||
ConfigToken = "token"
|
|
||||||
|
|
||||||
// ConfigClientID is the config key used to store the client id
|
|
||||||
ConfigClientID = "client_id"
|
|
||||||
|
|
||||||
// ConfigClientSecret is the config key used to store the client secret
|
|
||||||
ConfigClientSecret = "client_secret"
|
|
||||||
|
|
||||||
// ConfigAutomatic indicates that we want non-interactive configuration
|
|
||||||
ConfigAutomatic = "config_automatic"
|
|
||||||
|
|
||||||
// TitleBarRedirectURL is the OAuth2 redirect URL to use when the authorization
|
// TitleBarRedirectURL is the OAuth2 redirect URL to use when the authorization
|
||||||
// code should be returned in the title bar of the browser, with the page text
|
// code should be returned in the title bar of the browser, with the page text
|
||||||
// prompting the user to copy the code and paste it in the application.
|
// prompting the user to copy the code and paste it in the application.
|
||||||
@ -64,7 +52,7 @@ type oldToken struct {
|
|||||||
// getToken returns the token saved in the config file under
|
// getToken returns the token saved in the config file under
|
||||||
// section name.
|
// section name.
|
||||||
func getToken(name string) (*oauth2.Token, error) {
|
func getToken(name string) (*oauth2.Token, error) {
|
||||||
tokenString, err := fs.ConfigFile.GetValue(string(name), ConfigToken)
|
tokenString, err := fs.ConfigFile.GetValue(string(name), fs.ConfigToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -107,9 +95,9 @@ func putToken(name string, token *oauth2.Token) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
tokenString := string(tokenBytes)
|
tokenString := string(tokenBytes)
|
||||||
old := fs.ConfigFile.MustValue(name, ConfigToken)
|
old := fs.ConfigFile.MustValue(name, fs.ConfigToken)
|
||||||
if tokenString != old {
|
if tokenString != old {
|
||||||
fs.ConfigFile.SetValue(name, ConfigToken, tokenString)
|
fs.ConfigFile.SetValue(name, fs.ConfigToken, tokenString)
|
||||||
fs.SaveConfig()
|
fs.SaveConfig()
|
||||||
fs.Debug(name, "Saving new token in config file")
|
fs.Debug(name, "Saving new token in config file")
|
||||||
}
|
}
|
||||||
@ -155,12 +143,12 @@ func Context() context.Context {
|
|||||||
// If any value is overridden, true is returned.
|
// If any value is overridden, true is returned.
|
||||||
func overrideCredentials(name string, config *oauth2.Config) bool {
|
func overrideCredentials(name string, config *oauth2.Config) bool {
|
||||||
changed := false
|
changed := false
|
||||||
ClientID := fs.ConfigFile.MustValue(name, ConfigClientID)
|
ClientID := fs.ConfigFile.MustValue(name, fs.ConfigClientID)
|
||||||
if ClientID != "" {
|
if ClientID != "" {
|
||||||
config.ClientID = ClientID
|
config.ClientID = ClientID
|
||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
ClientSecret := fs.ConfigFile.MustValue(name, ConfigClientSecret)
|
ClientSecret := fs.ConfigFile.MustValue(name, fs.ConfigClientSecret)
|
||||||
if ClientSecret != "" {
|
if ClientSecret != "" {
|
||||||
config.ClientSecret = ClientSecret
|
config.ClientSecret = ClientSecret
|
||||||
changed = true
|
changed = true
|
||||||
@ -196,7 +184,7 @@ func NewClient(name string, config *oauth2.Config) (*http.Client, error) {
|
|||||||
// It may run an internal webserver to receive the results
|
// It may run an internal webserver to receive the results
|
||||||
func Config(id, name string, config *oauth2.Config) error {
|
func Config(id, name string, config *oauth2.Config) error {
|
||||||
changed := overrideCredentials(name, config)
|
changed := overrideCredentials(name, config)
|
||||||
automatic := fs.ConfigFile.MustValue(name, ConfigAutomatic) != ""
|
automatic := fs.ConfigFile.MustValue(name, fs.ConfigAutomatic) != ""
|
||||||
|
|
||||||
// See if already have a token
|
// See if already have a token
|
||||||
tokenString := fs.ConfigFile.MustValue(name, "token")
|
tokenString := fs.ConfigFile.MustValue(name, "token")
|
||||||
|
@ -65,10 +65,10 @@ func init() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Options: []fs.Option{{
|
Options: []fs.Option{{
|
||||||
Name: oauthutil.ConfigClientID,
|
Name: fs.ConfigClientID,
|
||||||
Help: "Microsoft App Client Id - leave blank normally.",
|
Help: "Microsoft App Client Id - leave blank normally.",
|
||||||
}, {
|
}, {
|
||||||
Name: oauthutil.ConfigClientSecret,
|
Name: fs.ConfigClientSecret,
|
||||||
Help: "Microsoft App Client Secret - leave blank normally.",
|
Help: "Microsoft App Client Secret - leave blank normally.",
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
|
@ -227,9 +227,11 @@ var Commands = []Command{
|
|||||||
{
|
{
|
||||||
Name: "authorize",
|
Name: "authorize",
|
||||||
Help: `
|
Help: `
|
||||||
Remote authorization.`,
|
Remote authorization. Used to authorize a remote or headless
|
||||||
|
rclone from a machine with a browser - use as instructed by
|
||||||
|
rclone config.`,
|
||||||
Run: func(fdst, fsrc fs.Fs) error {
|
Run: func(fdst, fsrc fs.Fs) error {
|
||||||
fs.Authorize()
|
fs.Authorize(pflag.Args()[1:])
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
NoStats: true,
|
NoStats: true,
|
||||||
|
@ -51,10 +51,10 @@ func init() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Options: []fs.Option{{
|
Options: []fs.Option{{
|
||||||
Name: oauthutil.ConfigClientID,
|
Name: fs.ConfigClientID,
|
||||||
Help: "Yandex Client Id - leave blank normally.",
|
Help: "Yandex Client Id - leave blank normally.",
|
||||||
}, {
|
}, {
|
||||||
Name: oauthutil.ConfigClientSecret,
|
Name: fs.ConfigClientSecret,
|
||||||
Help: "Yandex Client Secret - leave blank normally.",
|
Help: "Yandex Client Secret - leave blank normally.",
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user