本記事は2019/12/27に作成したものです。
最新の環境ではうまく動作しない可能性がありますのでご注意ください。
その1の記事 で作成したデジタルサイネージを運用しはじめたところ、以下の悩みが発生しました。。。
サイネージのコンテンツ更新のたびに、pdfのスライドを毎度アップロードするのがしんどい!
なので、Google ドライブとrcloneを使って、今まで手動でアップロードしていた作業を自動化しました。
Google ドライブの指定ディレクトリをrcloneで同期させるスクリプトを定期実行させる仕組みです。
Raspberry Pi 3 Model B+
Raspbian 9.4 stretch (日本語環境)
rclone v1.50.2
$ curl https://rclone.org/install.sh | sudo bash
$ rclone config
以下対話形式で進めます
2019/12/27 10:50:07 NOTICE: Config file "/home/pi/.config/rclone/rclone.conf" not found - using defaults
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
name> drive
Type of storage to configure.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
多いので省略
13 / Google Drive
\ "drive"
多いので省略
Storage> 13
Google Application Client Id
Setting your own is recommended.
See https://rclone.org/drive/#making-your-own-client-id for how to create your own.
If you leave this blank, it will use an internal key which is low performance.
Enter a string value. Press Enter for the default ("").
client_id>
Google Application Client Secret
Setting your own is recommended.
Enter a string value. Press Enter for the default ("").
client_secret>
Scope that rclone should use when requesting access from drive.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
1 / Full access all files, excluding Application Data Folder.
\ "drive"
2 / Read-only access to file metadata and file contents.
\ "drive.readonly"
/ Access to files created by rclone only.
3 | These are visible in the drive website.
| File authorization is revoked when the user deauthorizes the app.
\ "drive.file"
/ Allows read and write access to the Application Data folder.
4 | This is not visible in the drive website.
\ "drive.appfolder"
/ Allows read-only access to file metadata but
5 | does not allow any access to read or download file content.
\ "drive.metadata.readonly"
scope> 2
ID of the root folder
Leave blank normally.
Fill in to access "Computers" folders (see docs), or for rclone to use
a non root folder as its starting point.
Note that if this is blank, the first time rclone runs it will fill it
in with the ID of the root folder.
Enter a string value. Press Enter for the default ("").
root_folder_id>
Service Account Credentials JSON file path
Leave blank normally.
Needed only if you want use SA instead of interactive login.
Enter a string value. Press Enter for the default ("").
service_account_file>
Edit advanced config? (y/n)
y) Yes
n) No
y/n> n
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
If your browser doesn't open automatically go to the following link: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=(省略)
Log in and authorize rclone for access
Enter verification code>
go to the following link: の後のURLをコピーし、WebブラウザでコピーしたURLへ接続します。
画面の指示にしたがってGoogleアカウントの認証とrcloneのアクセス許可を与えてください。
最後に、表示されたコードをコピーして、Enter verification codeに貼り付けます。
Configure this as a team drive?
y) Yes
n) No
y/n> n
--------------------
[drive]
type = drive
scope = drive.readonly
token = {"access_token":"(省略)"}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y
Current remotes:
Name Type
==== ====
drive drive
e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q
ラズパイから、Google ドライブに作成しておいたディレクトリの参照ができることを確認します
(以下例はGoogle ドライブのsinageディレクトリを参照しています)
$ rclone ls drive:sinage
1565471 slide.pdf
$ mkdir /home/pi/cron
$ vi /home/pi/cron/syncsinage.sh
syncsinage.shの中身
(Google ドライブのsinageディレクトリを/home/pi/sinage/へ同期させています)
#!/bin/bash
rclone sync drive:sinage /home/pi/sinage/
$ chmod 744 /home/pi/cron/syncsinage.sh
使うエディタの選択はお好みで...
$ crontab -e
cronの中身
(5分おきにsyncsinage.shを実行させています)
SHELL=/bin/bash
### sync gdrive to sinage
*/5 * * * * /home/pi/cron/syncsinage.sh
以上で作業は完了です!
これで面倒なアップロード作業とはお別れできました!
あとは、ラズパイ起動時に自動でスライドショーを始める方法を探したいと思います。
これができたら、もっと運用が楽になりそうです。
Crieitは誰でも投稿できるサービスです。 是非記事の投稿をお願いします。どんな軽い内容でも投稿できます。
また、「こんな記事が読みたいけど見つからない!」という方は是非記事投稿リクエストボードへ!
こじんまりと作業ログやメモ、進捗を書き残しておきたい方はボード機能をご利用ください。
ボードとは?
コメント