macOS, Linux で Dropbox を fuse mount する dbxfs を少し試す

Dropbox を FUSE mount 出来る dbxfs というものを見つけたので試してみました．

rianhunter/dbxfs: A Dropbox-backed file system

Doropbox の Linux client はファイルシステムがext4のみと制限されます．dbxfs であればおそらくこの制限も問題ないのではないかと思います．(未確認)

What are the system requirements to run Dropbox? – Dropbox Help

The Dropbox folder will need to be on an ext4-formatted hard drive or partition
Note: ecryptfs is not supported, but Dropbox will continue to sync with supported file systems that are encrypted via full disk encryption (e.g. LUKS)

導入

$ sudo apt install libfuse2 python3-pip

help

$ ~/.local/bin/dbxfs -h
usage: dbxfs [-h] [-f] [-v] [-s] [-n] [-l SMB_LISTEN_ADDRESS] [-c CONFIG_FILE]
[-e ENCRYPTED_FOLDERS] [--print-default-config-file]
[mount_point]

positional arguments:
mount_point

optional arguments:
-h, --help show this help message and exit
-f, --foreground keep filesystem server in foreground
-v, --verbose show log messages, use twice for maximum verbosity
-s, --smb force mounting via SMB
-n, --smb-no-mount export filesystem via SMB but don't mount it
-l SMB_LISTEN_ADDRESS, --smb-listen-address SMB_LISTEN_ADDRESS
address that SMB service should listen on, append
colon to specify port
-c CONFIG_FILE, --config-file CONFIG_FILE
config file path
-e ENCRYPTED_FOLDERS, --encrypted-folder ENCRYPTED_FOLDERS
relative paths of encrypted folders, can be used
multiple times. requires safefs
--print-default-config-file
print default config file path to standard out and
quit

初回mount

$ ~/.local/bin/dbxfs ~/fuse/dbxfs
We need an access token. Perform the following steps:
1. Go to https://www.dropbox.com/oauth2/authorize?response_type=code&client_id=vinkudorurc8kno
2. Click "Allow" (you may have to log in first)
3. Copy the authorization code.
Enter authoritization code (Ctrl-C to quit): NodigIOndefkiwitshOrackazEuweavirtyedCibEdI
We're all connected. Do you want to save your credentials for future runs? [Y/n] Y
Would you like to help us improve dbxfs by providing anonymous error reports? [Y/n] Y
Mount point "/home/matoken/fuse/dbxfs" doesn't exist, do you want to create it? [Y/n] Y

のurl をブラウザで開いて認証を行う
認証後の画面で cli-dbxfs のアクセスを許可する．

許可後に表示されるトークンを 3. の後ろにコピー&ペーストする．

We’re all connected. Do you want to save your credentials for future runs?
次回以降のために資格情報を保存するか?

Would you like to help us improve dbxfs by providing anonymous error reports?
匿名のエラー報告を行いdbxfsに改善の支援を行うか?

Mount point “/home/matoken/fuse/dbxfs” doesn’t exist, do you want to create it?
マウントポイントが存在しないので作成するか?

マウント確認

$ ls ~/fuse/dbxfs/

アンマウントする

$ fusermount -u ~/fuse/dbxfs

資格情報を保存していた場合2回目以降のマウントは何も聞かれない

$ ~/.local/bin/dbxfs ~/fuse/dbxfs

.

アクセストークンをpgpファイルに格納することも出来るようだが手元の環境では未だうまく行っていない(多分何か勘違いをしている)

EDIT: やはり使い方が間違っていた．次の記事に書いた -> Dropbox を FUSE mount する dbxfs のアクセストークンを gpg で暗号化する – matoken’s meme

設定ファイルの場所確認

$ ~/.local/bin/dbxfs --print-default-config-file
/home/matoken/.config/dbxfs/config.json

アクセストークンをpgpファイルにする

$ jq . /home/matoken/.config/dbxfs/config.json
{
"keyring_user": "yigwulbaf6shnutugaivkilj",
"send_error_reports": true,
"asked_send_error_reports": true
}
$ gpg -r EAA13B982D937827 -e /home/matoken/.config/dbxfs/config.json
$ ls -l /home/matoken/.config/dbxfs/config.json*
-rw-r--r-- 1 matoken matoken 115 10月 4 07:19 /home/matoken/.config/dbxfs/config.json
-rw-r--r-- 1 matoken matoken 685 10月 4 07:22 /home/matoken/.config/dbxfs/config.json.gpg
$ shred /home/matoken/.config/dbxfs/config.json
$ echo '"access_token_command": ["gpg", "--decrypt", "/home/matoken/.config/dbxfs/config.json.gpg"]' > /home/matoken/.config/dbxfs/config.json

マウント

$ ~/.local/bin/dbxfs ~/fuse/dbxfs
Running 'gpg --decrypt /home/matoken/.config/dbxfs/config.json.gpg' for access token
gpg: 4096-ビットRSA鍵, ID EAA13B982D937827, 日付2015-06-11に暗号化されました
"K.I.Matohara <matoken@gmail.com>"
Traceback (most recent call last):
File "/home/matoken/.local/bin/dbxfs", line 11, in <module>
sys.exit(main())
File "/home/matoken/.local/lib/python3.6/site-packages/dbxfs/main.py", line 212, in main
dropbox.Dropbox(access_token).users_get_current_account()
File "/home/matoken/.local/lib/python3.6/site-packages/dropbox/base.py", line 4245, in users_get_current_account
None,
File "/home/matoken/.local/lib/python3.6/site-packages/dropbox/dropbox.py", line 274, in request
timeout=timeout)
File "/home/matoken/.local/lib/python3.6/site-packages/dropbox/dropbox.py", line 365, in request_json_string_with_retry
timeout=timeout)
File "/home/matoken/.local/lib/python3.6/site-packages/dropbox/dropbox.py", line 449, in request_json_string
timeout=timeout,
File "/home/matoken/.local/lib/python3.6/site-packages/requests/sessions.py", line 559, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/home/matoken/.local/lib/python3.6/site-packages/requests/sessions.py", line 498, in request
prep = self.prepare_request(req)
File "/home/matoken/.local/lib/python3.6/site-packages/requests/sessions.py", line 441, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "/home/matoken/.local/lib/python3.6/site-packages/requests/models.py", line 310, in prepare
self.prepare_headers(headers)
File "/home/matoken/.local/lib/python3.6/site-packages/requests/models.py", line 444, in prepare_headers
check_header_validity(header)
File "/home/matoken/.local/lib/python3.6/site-packages/requests/utils.py", line 941, in check_header_validity
raise InvalidHeader("Invalid return character or leading space in header: %s" % name)
requests.exceptions.InvalidHeader: Invalid return character or leading space in header: Authorization

持ち運びモバイルPCだと辛いでしょうが，据え置きデスクトップ環境などのオンラインのマシンでは便利そうです．

環境

$ grep ^Version: ~/.local/lib/python3.6/site-packages/dbxfs-1.0.4.dist-info/METADATA
Version: 1.0.4
$ dpkg-query -W libfuse2 python3-pip
libfuse2:amd64 2.9.8-2
python3-pip 9.0.1-2.3
$ lsb_release -d
Description: Debian GNU/Linux unstable (sid)
$ uname -m
x86_64