Raspberry Pi に google-home-notifier を入れた時に躓いたメモ

Raspberry Pi に google-home-notifier を入れた時にいろいろと躓いたメモ
>> 素のラズパイへ入れようとしました(一部、ディレクトリ名は伏せ字です)

【先に結論】
node.js と npm と google-home-notifier を入れる前にやっておくべき事
  • sudo ではなく su や sudo -s で root になっておくとトラブル少ないかも
  • 下記が入っていない場合は、入れておく
    # apt-get install git
    # apt-get install libavahi-compat-libdnssd-dev
これらをインストールしていないと、下記のような目にあいます
(別の素のラズパイで、上記をインストールしてからは問題なしでした)

gitが入っていなければ
# apt-get install git

こちらを参考に node.js と npm をインストール
# apt-get update
# apt-get install nodejs npm
# npm cache clean
# npm install npm n -g
ここで ssh へ入り直したほうがよい??
# n stable

途中で README がねー とか WARN が2つほど出ますが無視(して問題無さそう)

こちら や こちら を参考に google-home-notifier をインストール
としたわけですが # npm install でエラーがドバーッっと

  1. >>>>> /google-home-notifier# npm install  
  2. npm WARN package.json google-home-notifier@1.2.0 No repository field.  
  3. /  
  4. > mdns@2.3.3 install /hogehoge/google-home-notifier/node_modules/mdns  
  5. > node-gyp rebuild  
  6.   
  7. make: Entering directory '/hogehoge/google-home-notifier/node_modules/mdns/build'  
  8.   CXX(target) Release/obj.target/dns_sd_bindings/src/dns_sd.o  
  9. In file included from ../src/dns_sd.cpp:1:0:  
  10. ../src/mdns.hpp:32:20: fatal error: dns_sd.h: そのようなファイルやディレクトリはありません  
  11.  #include <dns_sd .h="">  
  12.                     ^  
  13. compilation terminated.  
  14. dns_sd_bindings.target.mk:132: recipe for target 'Release/obj.target/dns_sd_bindings/src/dns_sd.o' failed  
  15. make: *** [Release/obj.target/dns_sd_bindings/src/dns_sd.o] Error 1  
  16. make: Leaving directory '/hogehoge/google-home-notifier/node_modules/mdns/build'  
  17. gyp ERR! build error  
  18. gyp ERR! stack Error: `make` failed with exit code: 2  
  19. gyp ERR! stack     at ChildProcess.onExit (/usr/share/node-gyp/lib/build.js:267:23)  
  20. gyp ERR! stack     at ChildProcess.emit (events.js:98:17)  
  21. gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:809:12)  
  22. gyp ERR! System Linux 4.9.35+  
  23. gyp ERR! command "nodejs" "/usr/bin/node-gyp" "rebuild"  
  24. gyp ERR! cwd /hogehoge/google-home-notifier/node_modules/mdns  
  25. gyp ERR! node -v v0.10.29  
  26. gyp ERR! node-gyp -v v0.12.2  
  27. gyp ERR! not ok  
  28. npm WARN This failure might be due to the use of legacy binary "node"  
  29. npm WARN For further explanations, please read  
  30. /usr/share/doc/nodejs/README.Debian  
  31.   
  32. npm ERR! mdns@2.3.3 install: `node-gyp rebuild`  
  33. npm ERR! Exit status 1  
  34. npm ERR!  
  35. npm ERR! Failed at the mdns@2.3.3 install script.  
  36. npm ERR! This is most likely a problem with the mdns package,  
  37. npm ERR! not with npm itself.  
  38. npm ERR! Tell the author that this fails on your system:  
  39. npm ERR!     node-gyp rebuild  
  40. npm ERR! You can get their info via:  
  41. npm ERR!     npm owner ls mdns  
  42. npm ERR! There is likely additional logging output above.  
  43.   
  44. npm ERR! System Linux 4.9.35+  
  45. npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install"  
  46. npm ERR! cwd /hogehoge/google-home-notifier  
  47. npm ERR! node -v v0.10.29  
  48. npm ERR! npm -v 1.4.21  
  49. npm ERR! code ELIFECYCLE  
  50. npm ERR!  
  51. npm ERR! Additional logging details can be found in:  
  52. npm ERR!     /hogehoge/google-home-notifier/npm-debug.log  
  53. npm ERR! not ok code 0  
  54. </dns_sd>  

これ node が無ぇ、、、のが原因なので

# ln -s /usr/bin/nodejs /usr/bin/node

で、先ほど入れた nodejs へ node からシンボリックリンクを張ってやります
これで # npm install をやってみる・・・・ なんだか快調にスクロールしてるじゃん
あれ、なんか同じ内容を繰り返してね?→コピペーしてみる→ウギャーーループしてるだけ
(ctrl+c とかで殺します)

↓ループしてる一部
  1. gyp WARN EACCES user "root" does not have permission to access the dev dir "/hogehoge/google-home-notifier/node_modules/mdns/.node-gyp/8.8.1"  
  2. gyp WARN EACCES attempting to reinstall using temporary dev dir "/hogehoge/google-home-notifier/node_modules/mdns/.node-gyp"  
  3. gyp verb tmpdir == cwd automatically will remove dev files after to save disk space  
  4. gyp verb command install [ '8.8.1' ]  
  5. gyp verb install input version string "8.8.1"  
  6. gyp verb install installing version: 8.8.1  
  7. gyp verb install --ensure was passed, so won't reinstall if already installed  
  8. gyp verb install version not already installed, continuing with install 8.8.1  
  9. gyp verb ensuring nodedir is created /hogehoge/google-home-notifier/node_modules/mdns/.node-gyp/8.8.1  
  10. gyp WARN EACCES user "root" does not have permission to access the dev dir "/hogehoge/google-home-notifier/node_modules/mdns/.node-gyp/8.8.1"  
  11. gyp WARN EACCES attempting to reinstall using temporary dev dir "/hogehoge/google-home-notifier/node_modules/mdns/.node-gyp"  
  12. gyp verb tmpdir == cwd automatically will remove dev files after to save disk space  
  13. gyp verb command install [ '8.8.1' ]  
  14. gyp verb install input version string "8.8.1"  
  15. gyp verb install installing version: 8.8.1  
  16. gyp verb install --ensure was passed, so won't reinstall if already installed  
  17. gyp verb install version not already installed, continuing with install 8.8.1  
  18. gyp verb ensuring nodedir is created /hogehoge/google-home-notifier/node_modules/mdns/.node-gyp/8.8.1  

展開したディレクトリに権限がないのに無限にリトライしているようなので
google-home-notifier を置いたフォルダに戻って

# cd ../
# chown -R root google-home-notifier

と、持ち主を変更、再度
後で思ったのだが $ sudo -s で作業するとこうなるみたい # su で root になってから作業するべき

# cd google-home-notifier
# npm install

でなんとか入ったもよう
よしよし、テスト起動

# node example.js
  1. module.js:515  
  2.     throw err;  
  3.     ^  
  4.   
  5. Error: Cannot find module '../build/Release/dns_sd_bindings'  
  6.     at Function.Module._resolveFilename (module.js:513:15)  
  7.     at Function.Module._load (module.js:463:25)  
  8.     at Module.require (module.js:556:17)  
  9.     at require (internal/module.js:11:18)  
  10.     at Object.<anonymous> (/hogehoge/google-home-notifier/node_modules/mdns/lib/dns_sd.js:32:22)  
  11.     at Module._compile (module.js:612:30)  
  12.     at Object.Module._extensions..js (module.js:623:10)  
  13.     at Module.load (module.js:531:32)  
  14.     at tryModuleLoad (module.js:494:12)  
  15.     at Function.Module._load (module.js:486:3)  
  16. </anonymous>  

またまたエラー → モジュールが足りないぜ
※ su で root になってから(sudo だと またループするぜー)

# npm install --unsafe-perm mdns

エラ~ fatal error: dns_sd.h: そのようなファイルやディレクトリはありません

apt-get install libavahi-compat-libdnssd-dev
再度
# npm install --unsafe-perm mdns → 時間のかかる build へ進んでいればOK
問題なければ続けて
# npm rebuild --unsafe-perm

やっと
node example.js

起動しているっぽいので、別の ssh を開いて
$ curl -X POST -d "text=OK Google" http://127.0.0.1:8080/google-home-notifier
アドレス部は、ラズパイのアドレス

ところで、 node example.js を起動すると、サンプルが出て ngrok 経由でどこからでも使えるっぽい
※ngrok のサブドメインは起動毎に変動する

が、どこからでも使える必要がない = ngrok を使わないなら
example.js の下記の箇所をコメントアウト

  1. var express = require('express');  
  2. var googlehome = require('./google-home-notifier');  
  3. // var ngrok = require('ngrok'); ←ココ  
  4. var bodyParser = require('body-parser');  
  5. var app = express();  
  6. // (略)  
  7. app.listen(serverPort, function () {  
  8.   /*  ココから 
  9.   ngrok.connect(serverPort, function (err, url) { 
  10.     console.log('POST "text=Hello Google Home" to:'); 
  11.     console.log('    http://localhost:' + serverPort + '/google-home-notifier'); 
  12.     console.log('    ' +url + '/google-home-notifier'); 
  13.     console.log('example:'); 
  14.     console.log('curl -X POST -d "text=Hello Google Home" ' + url + '/google-home-notifier'); 
  15.   }); 
  16.   ココまで 
  17.   */  
  18. })  


コメント