Amazon LinuxでGoogle Driveをマウントできると、CSVを保存したり、すでに保存してあるHTMLを参照して、Emailが送れたりできて便利です。
FUSE filesystem over Google Driveを使って、FUSEファイルシステムによりGoogle Driveをマウントしてみます。
インストール手順
InstallationのInstalling with OPAM on AWS Linuxを参考にしてインストールします。
パッケージのインストール
まず、リポジトリを足して、yumで各種必要なものをインストールします。
sudo wget http://download.opensuse.org/repositories/home:ocaml/CentOS_7/home:ocaml.repo -P /etc/yum.repos.d/
sudo yum install opam ocaml gcc gcc-c++ m4 make ocamldoc sqlite-devel libcurl-devel fuse fuse-devel zlib-devel ocaml-camlp4-devel ncurses-devel -y
google-drive-ocamlfuseのインストール
次に、OCaml Package Managerの初期設定をして、その後、google-drive-ocamlfuseをインストールします。
何か聞かれたら、はい、と適切に答えてください。
opam init
opam install google-drive-ocamlfuse
Google Cloud Console で OAuth2 の認証情報を取得
AuthorizationのAlternative authorization modeを参照しながら、Google Cloud ConsoleでOAuth2のClinet IDとClient Secretを取得します。
You can create OAuth2 credentials from the Google APIs Console. Here you can find how to create a new application and here how to set up OAuth 2.0 credentials. When activating APIs, you must select the Drive API. When creating a new client ID, you must select "Installed applications" as Application type and "Other" as Installed application type (Redirect URI should be urn:ietf:wg:oauth:2.0:oob). Check that Drive API is among the Enabled APIs of your Developers Console.
Client IDとClient Secretを使って、認証を通しておきます。
OAuth2の認証情報を使って、google-drive-ocamlfuseを設定する
Client IDをxxx.apps.googleusercontent.com、secretをyyyとして、以下を実行します。
(パスが通ってないかもしれないので、一度ログアウトしてからログインするとかするといいです)
google-drive-ocamlfuse -headless -id xxx.apps.googleusercontent.com -secret yyy
すると、あるURLにアクセスしろといわれるので、Google Cloud Consoleでログインした状態のブラウザで、アクセスします。
許可するとTokenが表示されるので、Please enter the verification code: のあとに貼り付けて、エンターをおします。
Access token retrieved correctly.と出たら完了です。
マウントするフォルダを作り、マウントする
mkdir ~/google-drive
google-drive-ocamlfuse /home/ec2-user/google-drive
lsやfindなどで中身をみてマウントできていれば完了です。