mikutterからGooglePhotosにアップロードするやつを試す

Google Photosってことは容量気にせず画像投げられる & Google+との連携もできそう?ってことで試してみました.

#mikutterについてはこちらを.

関連パッケージ導入

$ sudo apt install ruby-oauth2

mikutter-google-photos-uploader plugin導入

$ cd ~/.mikutter/plugin
$ git clone https://github.com/slimymars/mikutter-google-photos-uploader
$ cd mikutter-google-photos-uploader
$ bundle install

mikutter起動

……認識されない.mikutterが古い所為のようです.

$ grep mikutter: ~/.mikutter/plugin/mikutter-google-photos-uploader/.mikutter.yml 
  mikutter: 3.5.2
$ dpkg-query -W mikutter
mikutter        3.5.0+dfsg-1

Debianではjessie-backportsからsidまで3.5.0+dfsg-1experimentalだけ3.5.2+dfsg-1でした.

てことで,experimentalから借りてきます.

sources.listexperimentalがある状態で

$ grep experimental /etc/apt/sources.list
deb http://dennou-q.gfd-dennou.org/debian/ experimental main non-free contrib
deb-src http://dennou-q.gfd-dennou.org/debian/ experimental main non-free contrib

/etc/apt/preferences.d/mikutterを以下のような感じで用意して,

$ cat /etc/apt/preferences.d/mikutter
Package: mikutter
Pin: release a=experimental
Pin-Priority: 800

パッケージを更新して導入.

$ sudo apt upgrade

mikutterでの設定

mikutterが3.5.2になったので認識しました.設定画面を見ると,GooglePhotosというタブが増えているのでそのタブのAuthrise code 取得URLをブラウザで開いて認証し,出てきたコードをAuthrization_codeに貼り付けます.
更にmikutterからアップロードする保存先のアルバムを追加しておきます.GooglePhotosに存在しないアルバムは前もって

から登録しておきましょう.アルバムは複数登録できるので例えば

  • ミク
  • フレンズ

のようにアルバムを登録しておくと画像整理がはかどります?

20170228_19:02:23-16584

実際の画像保存方法は,mikutterの保存したい画像の上で右クリックしてGoogle Photosに画像をアップロードを選び,

shutter_17-03-01_08:33:12_001

その後表示されるアルバムを選択するだけです.

menu_018

Google Photosに見に行くとアップロードされているのが確認できます.

Google+へのクロスポストにも使えるかなと思ったのですが,Google+の投稿画面はタイムラグがあるようで少し待たないと表示されませんでした.これはGoogle側の問題ですね.Google Photosから投稿するようにすれば良さそうです.

関連?Tweet

環境

$ screenfetch
         _,met$$$$$gg.           mk@x220
      ,g$$$$$$$$$$$$$$$P.        OS: Debian 9.0 stretch
    ,g$$P""       """Y$$.".      Kernel: x86_64 Linux 4.9.0-2-amd64
   ,$$P'              `$$$.      Uptime: 4d 18h 51m
  ',$$P       ,ggs.     `$$b:    Packages: 5147
  `d$$'     ,$P"'   .    $$$     Shell: bash 4.4.11
   $$P      d$'     ,    $$P     Resolution: 1366x768
   $$:      $$.   -    ,d$$'     WM: Awesome
   $$\;      Y$b._   _,d$P'      WM Theme: default
   Y$$.    `.`"Y$$$$P"'          CPU: Intel Core i5-2540M CPU @ 3.3GHz
   `$$b      "-.__               GPU: Mesa DRI Intel(R) Sandybridge Mobile 
    `Y$$                         RAM: 13040MiB / 15934MiB
     `Y$$.                      
       `$$b.                    
         `Y$$b.                 
            `"Y$b._             
                `""""           

Ubuntu 17.04のSynergyと互換性が無くなったのでDebianでexperimentalのSynergyを使う

20170224_01-02-43-4533

リリース前のUbuntu 17.04をサブマシンで使用しているのですが,これをメインPCの横に置いてSynergyを使ってメインPCから操作しています.しかしUbuntu 17.04のSynergyが新しくなって繋がらなくなりました.
設定を確認するとこれまで暗号化通信にパスワードを指定する形でした.これがSSLになったようです.
GUIでもman synergys/synergycを見ても旧形式は使えなさそうで互換性が失われているようです.

20170224_01-02-53-4521
※Ubuntu 17.04のsynergy 1.8.7-stable+dfsg.1-2

20170224_01:02:47-1037
※Debian stretchのsynergy 1.4.16-2

DebianのSynergyのバージョンを確認すると,今のところsidでも1.4.16-2でexperimentalでは1.8.7-stable+dfsg.1-2でした.

とりあえずexperimentalから借りてくることにしました.

sources.listexperimentalがある状態で

$ grep experimental /etc/apt/sources.list
deb http://dennou-q.gfd-dennou.org/debian/ experimental main non-free contrib
deb-src http://dennou-q.gfd-dennou.org/debian/ experimental main non-free contrib

/etc/apt/preferences.d/synergyを以下のような感じで用意して,

$ cat /etc/apt/preferences.d/synergy
Package: synergy
Pin: release a=experimental
Pin-Priority: 800

パッケージ情報を更新して導入.

$ sudo apt update
$ sudo apt install synergy
 :
以下のパッケージはアップグレードされます:
  synergy
アップグレード: 1 個、新規インストール: 0 個、削除: 0 個、保留: 22 個。
853 kB のアーカイブを取得する必要があります。
この操作後に追加で 607 kB のディスク容量が消費されます。
取得:1 <http://dennou-q.gfd-dennou.org/debian> experimental/main amd64 synergy amd64 1.8.7-stable+dfsg.1-2 [853 kB]
853 kB を 3秒 で取得しました (235 kB/s)
 :
.../synergy_1.8.7-stable+dfsg.1-2_amd64.deb を展開する準備をしています ...
synergy (1.8.7-stable+dfsg.1-2)(1.4.16-2 に) 上書き展開しています ...
synergy (1.8.7-stable+dfsg.1-2) を設定しています ...
 :

という感じで導入できました.
元に戻す場合は/etc/apt/preferences.d/synergyを消してパッケージを更新すればいいはず.

バージョンが新しくなってからSynergyを起動するとウィザードが走ってSSL証明書が~/.synergy/SSL/Synergy.pemに作られます.フィンガープリントも~/.synergy/SSL/Fingerprints/Local.txtに作成されるので初回接続時にClient側に表示されるメッセージをSynergy Server側のこのフィンガープリントと見比べてから接続します.

$ cat ~/.synergy/SSL/Fingerprints/Local.txt 
2E:51:06:DC:05:42:09:81:7E:FB:3A:4F:C6:A4:A4:EE:98:ED:75:A0

20170225_00:02:32-4657

このフィンガープリントはClientの~/.synergy/SSL/Fingerprints/TrustedServers.txtに保存されます.

$ cat ~/.synergy/SSL/Fingerprints/TrustedServers.txt
2E:51:06:DC:05:42:09:81:7E:FB:3A:4F:C6:A4:A4:EE:98:ED:75:A0

てことでとりあえず使えるようになりました.

環境

  • server
$ lsb_release -d
Description:    Debian GNU/Linux 9.0 (stretch)
$ uname -a
Linux x220 4.9.0-2-amd64 #1 SMP Debian 4.9.10-1 (2017-02-17) x86_64 GNU/Linux
$ dpkg-query -W synergy
synergy 1.8.7-stable+dfsg.1-2
  • client
$ lsb_release -d
Description:    Ubuntu Zesty Zapus (development branch)
$ uname -a
Linux x200 4.9.0-15-generic #16-Ubuntu SMP Fri Jan 20 15:31:12 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
$ dpkg-query -W synergy
synergy 1.8.7-stable+dfsg.1-2

Raspberry Pi Zero Tips

ダウンロード
Raspberry-Pi-Zero-web
24日にKSYとスイッチサイエンスからRaspberry Pi Zero発売ってことでTipsを書いてみます.

Raspberry-Pi-Zero-web (コピー)

  • 本体の他に最低限microSD(OS領域)やmicroUSBケーブル(電源)が必要です.(microUSBへのOS導入に別途PCも必要).
  • HDMIディスプレイを利用したい場合は大抵の場合別途mini HDMIからフルサイズへの変換アダプタやケーブルが必要です.※PIZEROはmini HDMIです.よく見かけるのはmicro HDMIなので注意しましょう.
  • コンポジットのディスプレイを利用したい場合はジャックなどをはんだ付けする必要があります.(TVのシルク)
  • microUSBx2のうち片方(PWR IN)は電源専用です.
  • もう片方(USB)はUSB OTGでHOSTにもGadget(SerialやEthernetはdebugに便利!)にもなれます.電源供給も可能なので電源容量が足りるならこの1本だけで運用することも可能です.microUSBケーブルやOTGケーブルはそれなりのものを使ったほうが良いです.安いものを使ったらPIZERO側のコネクタが傷んで使えなくなってしまいました.
  • USBを利用する場合は給電が可能なmicroUSBのHUBがデバッグに便利です.
  • GPIO Pinは+以降と共通だけどピンは未実装なので利用したい場合は自分で別途ピンヘッダ等購入してはんだ付けする必要があります.カラフルなピンヘッダをASUS TINKER BOARDのようにピンの用途毎に変えると便利そうです.
    XxbHbzYFnf4AVH1a_setting_fff_1_90_end_1000C-06641

  • 純正カメラモジュールを利用する場合はRaspberry Pi Zero V1.3以降が必要(KSYもスイッチサイエンスもV1.3と書かれているので問題ない)で更にカメラモジュール付属のものとは別のPIZERO専用のケーブルが必要です.

  • KSYでは5000円以上送料無料,それ以下は一律756円の送料が掛かる.KSYを初めて使う人は形式チェックが厳しくて結構面倒なので前もってアカウントを登録しておいたほうが良いです.(単品で買うのであれば海外で買うのと変わらないか高いくらいなので早く欲しい人向け?)
  • スイッチサイエンスでは送料150円.3000円以上送料無料.単品で買う場合おすすめ.但し2017年3月20日週から順次発送予定なので届くまで暫くかかります.
  • 余録.チョコベビーの容器はケースにちょうどいいです :)
    • IMG_20170216_075638

Raspberry Piでコンポジットで起動した後に解像度やディスプレイを変更する

コンポジット出力の解像度変更

Raspberry Piを起動するときにHDMIを接続した状態で起動すると高解像度で起動しますが,繋いでいないとコンポジット出力で起動してXの解像度が720×480になってちょっと手狭です.
xrandrで解像度を追加するとXの再起動もせずに高解像度に出来ます.

※xrandrコマンドは対象のX端末上か,DISPLAY変数を対象のものを指定して実行すること

  • 720x480しか選べない
$ xrandr 
Screen 0: minimum 320 x 200, current 720 x 480, maximum 2048 x 2048
HDMI-0 disconnected (normal left inverted right x axis y axis)
Composite-0 unknown connection 720x480+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   720x480       62.69* 
DSI-0 disconnected (normal left inverted right x axis y axis)
  • cvtコマンドで設定したい解像度を指定してModelineを調べる
$ cvt 1360 768
# 1360x768 59.80 Hz (CVT) hsync: 47.72 kHz; pclk: 84.75 MHz
Modeline "1360x768_60.00"   84.75  1360 1432 1568 1776  768 771 781 798 -hsync +vsync
  • xrandrのmodeを作成する
$ xrandr --newmode "1360x768_60.00"   84.75  1360 1432 1568 1776  768 771 781 798 -hsync +vsync
  • modeが増えている
$ xrandr 
Screen 0: minimum 320 x 200, current 720 x 480, maximum 2048 x 2048
HDMI-0 disconnected (normal left inverted right x axis y axis)
Composite-0 unknown connection 720x480+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   720x480       62.69* 
DSI-0 disconnected (normal left inverted right x axis y axis)
  1360x768_60.00 (0x248) 84.750MHz
        h: width  1360 start 1432 end 1568 total 1776 skew    0 clock  47.72KHz
        v: height  768 start  771 end  781 total  798           clock  59.80Hz
  • modeをComposite-0に追加する
$ xrandr --addmode Composite-0 1368x768_60.00
$ xrandr 
Screen 0: minimum 320 x 200, current 720 x 480, maximum 2048 x 2048
HDMI-0 disconnected (normal left inverted right x axis y axis)
Composite-0 unknown connection 720x480+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   720x480       62.69* 
   1360x768_60.00  59.80  
DSI-0 disconnected (normal left inverted right x axis y axis)
  • 設定したmodeに切り替える
$ xrandr --output Composite-0 --mode 1360x768_60.00

起動後にHDMIに切り替える

解像度の変更ではなく起動後にHDMI接続に切り替えるのもxrandrで出来ます.こちらもXの再起動は必要ありません.

  • HDMIケーブルを接続するとHDMI-0 connectedとなってmodeが選べるようになる
$ xrandr 
Screen 0: minimum 320 x 200, current 1366 x 768, maximum 2048 x 2048
HDMI-0 connected 1366x768+0+0 (normal left inverted right x axis y axis) 580mm x 360mm
   1366x768      59.79*+
   1920x1080     60.00    59.94  
   1920x1080i    60.00    50.00    59.94  
   1280x1024     60.02  
   1152x864      75.00  
   1280x720      60.00    58.68    50.00    59.94  
   1024x768      75.03    70.07    60.00  
   832x624       74.55  
   800x600       72.19    75.00    60.32    56.25  
   720x576       50.00  
   720x576i      50.00  
   720x480       60.00    59.94  
   720x480i      60.00    59.94  
   640x480       75.00    72.81    66.67    60.00    59.94  
   720x400       70.08  
Composite-0 unknown connection (normal left inverted right x axis y axis)
   720x480       62.69  
   1360x768_60.00  59.80  
DSI-0 disconnected (normal left inverted right x axis y axis)
  • 一度にコンポジットを無効にしてHDMIを有効にしようとするとエラーとなる
$ xrandr --output Composite-0 --off --output HDMI-0 --auto
xrandr: cannot find crtc for output HDMI-0
  • 一度に行うのではなく先にコンポジットを無効にしてからHDMIを有効にするとうまく行った
$ DISPLAY=:0 xrandr --output Composite-0 --off
$ DISPLAY=:0 xrandr --output HDMI-0 --auto
  • 逆にHDMIからコンポジットに切り替えることも出来る
$ xrandr --output HDMI-0 --off
$ xrandr --output Composite-0 --mode 1360x768_60.00

環境

  • HW : Raspberry Pi B 2
$ screenfetch 
    .',;:cc;,'.    .,;::c:,,.    pi@raspberrypi
   ,ooolcloooo:  'oooooccloo:    OS: Unknown 8.0 jessie
   .looooc;;:ol  :oc;;:ooooo'    Kernel: armv7l Linux 4.9.11-v7+
     ;oooooo:      ,ooooooc.     Uptime: 4h 28m
       .,:;'.       .;:;'.       Packages: 1541
       .... ..'''''. ....        Shell: 3362
     .''.   ..'''''.  ..''.      Resolution: 1368x768
     ..  .....    .....  ..      DE: LXDE lxpanel 0.7.2
    .  .'''''''  .''''''.  .     WM: OpenBox
  .'' .''''''''  .'''''''. ''.   GTK Theme: Clearlooks [GTK2], Not Found [GTK3]
  '''  '''''''    .''''''  '''   Icon Theme: nuoveXT2
  .'    ........... ...    .'.   Font: Sans 10
    ....    ''''''''.   .''.     CPU: ARMv7 rev 5 (v7l) @ 900MHz
    '''''.  ''''''''. .'''''     RAM: 258MB / 922MB
     '''''.  .'''''. .'''''.    
      ..''.     .    .''..      
            .'''''''            
             ......       

mpv audio delay

動画プレイヤーのmpvを最近良く使うけどBluetoothで音が遅れるのでディレイ掛けたい.
vlcだとj,kというショートカットで50msずつずらせたので同じようなことがしたい.
man見ると載っててmpvだとCtrl + / Ctrl -みたい,だけど100ms単位.
コマンドラインオプションや設定ファイルだと細かく指定できた.

  • ショートカット
       Ctrl + and Ctrl -
              Adjust audio delay by +/- 0.1 seconds.

※100ms単位(VLCは50ms単位)

  • オプション
       --audio-delay=<sec>
              Audio delay in seconds (positive or negative float value). Positive values delay the audio, and negative values delay the video.

こちらは細かい時間を指定可能.以下は-250msを指定.
$ mpv --audio-delay=-0.25 FILE
この状態でショートカットを利用すると-250ms -> -150msのような感じに100ms単位で移動する.

  • 設定ファイル
$ cat ~/.config/mpv/mpv.conf
audio-delay=-0.25
  • 環境
$ lsb_release -d
Description:    Ubuntu Zesty Zapus (development branch)
$ uname -a
Linux x200 4.9.0-15-generic #16-Ubuntu SMP Fri Jan 20 15:31:12 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
$ dpkg-query -W mpv
mpv     0.23.0-2

引用はmpv(1)より

Mumble server設定メモ

鹿児島Linux勉強会 2017.01の遠隔で利用した設定メモです.

  • サーバのOSはDebian jessie amd64
  • 自動起動せず利用時に手動で起動する
  • fwも都度手動
  • サブチャンネルはなし
  • ssl証明書は既存のstartsslを利用

pkgの導入

$ sudo apt install mumble-server

自動起動を無効にする

$ sudo dpkg-reconfigure mumble-server

で設定画面に入り,

Mumble-server (murmurd) can start automatically when the server is booted.

Autostart mumble-server on server boot?

を選択する.
(/etc/default/mumble-serverMURMUR_DAEMON_START=0でも)

設定ファイルを編集

diff --git a/mumble-server.ini b/mumble-server.ini
index b445d4e..46f1dfd 100644
--- a/mumble-server.ini
+++ b/mumble-server.ini
@@ -12,7 +12,7 @@
 #        NOT regex = \w* BUT regex = \\w*

 # Path to database. If blank, will search for
-# murmur.sqlite in default locations or create it if not found.
+A
 database=/var/lib/mumble-server/mumble-server.sqlite

 # If you wish to use something other than SQLite, you'll need to set the name
@@ -86,7 +86,7 @@ pidfile=/var/run/mumble-server/mumble-server.pid
 # configure it here ehan ehrough D-Bus or Ice.
 #
 # Welcome message sent to clients when they connect.
-welcometext="<br />Welcome to this server running <b>Murmur</b>.<br />Enjoy your stay!<br />"
+welcometext="<br />Welcome to KagoLUG server running <b>Murmur</b>.<br />Enjoy your stay!<br />"

 # Port to bind TCP and UDP sockets to.
 port=64738
@@ -144,26 +144,28 @@ users=100
 # addresses.
 # Only uncomment the 'registerName' parameter if you wish to give your "Root" channel a custom name.
 #
-#registerName=Mumble Server
+registerName=KagoLUG Mumble Server
 #registerPassword=secret
 #registerUrl=http://mumble.sourceforge.net/
-#registerHostname=
+registerHostname=kagolug.org

 # If this option is enabled, the server will announce its presence via the 
 # bonjour service discovery protocol. To change the name announced by bonjour
 # adjust the registerName variable.
 # See http://developer.apple.com/networking/bonjour/index.html for more information
 # about bonjour.
-#bonjour=True
+bonjour=False

 # If you have a proper SSL certificate, you can provide the filenames here.
 # Otherwise, Murmur will create it's own certificate automatically.
-#sslCert=
-#sslKey=
+#sslCert=/etc/letsencrypt/live/kagolug.org/cert.pem
+sslCert=/etc/letsencrypt/live/kagolug.org/fullchain.pem
+sslKey=/etc/letsencrypt/live/kagolug.org/privkey.pem
+#sslCA=/etc/letsencrypt/live/kagolug.org/fullchain.pem

 # If Murmur is started as root, which user should it switch to?
 # This option is ignored if Murmur isn't started with root privileges.
-uname=mumble-server
+uname=root

 # If this options is enabled, only clients which have a certificate are allowed
 # to connect.

ssl証明書をクリア

$ sudo murmurd -wipessl
$ sudo killall murmurd

利用時

デーモンの起動とポート開放を行う

$ sudo service mumble-server start
$ sudo iptables -A INPUT -p udp -m udp --dport 64738 -j ACCEPT
$ sudo iptables -A INPUT -p tcp -m tcp --dport 64738 -j ACCEPT

利用者にはサーバとポートを伝える
– server : kagolug.org
– port : 64738

mumble://kagolug.org?title=KagoLUG%20Mumble%20Server&version=1.2.0

利用環境

  • PC : ThinkPad X200(Ubuntu 16.10 amd64)
  • マイク : elecom製の数百円のもの
  • スピーカー : Elecom LBT-SPTR01ECBK

はじめLBT-SPTR01ECBKでマイクとスピーカー両方の役割をと思っていたが,うまく音を拾えない&HSP/HFPでは音が悪く聞き取りづらかったので役割を分けた.
マイクはPC直付だったので音を拾いづらい&キー入力の音などを拾っていたはず.

利用完了時

デーモンの終了

$ sudo service mumble-server start

iptablesのmumbleルールを閉じる

$ sudo iptables -L --line-numbers | grep 64738
23   ACCEPT     udp  --  anywhere             anywhere             udp dpt:64738
24   ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:64738
$ sudo iptables -D INPUT 23
$ sudo iptables -D INPUT 24
$ sudo iptables -L --line-numbers | grep 64738

課題

ssl証明書ファイルを読み込むためにdaemonをrootで動かしているのをmumble-serverユーザに戻したい.

-uname=mumble-server
+uname=root
$ sudo ls -l /etc/letsencrypt/live/kagolug.org/fullchain.pem /etc/letsencrypt/live/kagolug.org/privkey.pem
lrwxrwxrwx 1 root ssl-cert 40 Dec 26 10:30 /etc/letsencrypt/live/kagolug.org/fullchain.pem -> ../../archive/kagolug.org/fullchain9.pem
lrwxrwxrwx 1 root ssl-cert 38 Dec 26 10:30 /etc/letsencrypt/live/kagolug.org/privkey.pem -> ../../archive/kagolug.org/privkey9.pem

ssl-certグループにmumble-serverを登録で行けそう?

マイク

会議向けの全方位のマイクが欲しい

鹿児島Linux勉強会 2017.01に参加

今回は遠隔参加を試してみました.BigBluebuttonなどの会議システムは映像も双方向に送れていい感じなのですが,野良勉強会では回線が無かったり今使っているPCではリアルタイムエンコードが難しいという問題があります.そこで音声のみのMumbleを利用しました.

サーバはさくらのVPSに設定,会場ではBluetoothマイク兼スピーカーで……と思ったのですが,このマイクではうまく音を拾わない&ヘッドホンのプロファイルでは音質も悪いのでA2DPにしてスピーカーのみの利用として,マイクはPC直付にしました.
このマイクは一応前指向性ですが数百円の安物なので音質は悪かったと思います.
でも双方向でのやり取りが出来るのは良かったです.会議室利用の際は良さそうです.

今回は資料が事前に共有できていたので良かったですが,資料が事前に共有できない場合はやはりどうにか映像を共有する方法を考えないといけないでしょうね.
そうするとやはりBBBやYoutubeLive等が必要に…….(帯域をなるべく絞って映像のみRaspberry PiでYoutubeLive配信というのが現実的かな?)

私の発表した内容は以下の3本でした.

Raspberry PiのUSB OTGを試す // Speaker Deck

USBを保護するUSBGuard // Speaker Deck

ゲーミングプラットホームのLutris紹介 // Speaker Deck

データはこちら.
matoken / 鹿児島Linux勉強会2017.01 / ソース / — Bitbucket

Raspberry PiのUSB OTGはさわりだけでちょっとあれでした.次回までにもうちょっと…….

次回は2月上旬の土日にと思っています.今年は月一ペース開催を目標にと思っています.
最近は開催場所どうしよう……となって日が過ぎていくパターンなのでとりあえず日程アナウンスはして会場見つからなかったらマクドナルドとかで開催という感じで考えています.

コマンドスニペットを手軽に調べられるコマンドのborg

borgはOK borgというsiteのスニペットをコマンドライン上から検索したり編集できるコマンドのようです.borgはgo製でApache License Version 2.0のソフトウェアです.

導入

導入方法は如何から対応バイナリを入手して適当な場所に置き,実行権をつけるだけです.arm linuxとか*BSDとか結構いろいろそろっています.

今回はこんな感じで導入しました.

$ wget https://github.com/ok-borg/borg/releases/download/v0.0.1/borg_linux_amd64 -O ~/usr/local/bin/borg && chmod +x ~/usr/local/bin/borg

利用方法

基本的にコマンドの後ろに調べたいキーワードをつけるだけです.規定値では5つの例が表示されます. bashでloopどう書くんだっけ?

$ borg "bash loop"
(1) Bash Shell Do While Loop Infinite loop?
         [11] while [ `prog -some flags` = "Another instance of this program is running, please exit it first" ]
              -
              bay=$(prog -some flags)
              while [ $bay = "Another instance of this program is running, please exit it first" ]
              do
              echo "Awaiting Access to program"
              bay=$(prog -some flags)
              done
              .....
         [12] while true
              do
         ...  

(2) Bash foreach loop
         [21] xargs cat <filenames.txt
              -
              for fn in `cat filenames.txt`; do
                  echo "the next file is $fn"
                  cat $fn
              done
         [22] for fn in `cat filenames.txt`; do cat "$fn"; done
         [23] while read filename
              do
                  echo "Printing: $filename"
                  cat "$filename"
         ...

(3) Bash loop ping successful
         [31] ((count = 100))                            # Maximum number to try.
              while [[ $count -ne 0 ]] ; do
                  ping -c 1 8.8.8.8                      # Try once.
                  rc=$?
                  if [[ $rc -eq 0 ]] ; then
                      ((count = 1))                      # If okay, flag to exit loop.
                  fi
                  ((count = count - 1))                  # So we don't go forever.
              done
              if [[ $rc -eq 0 ]] ; then                  # Make final determination.
         ...

(4) Limit for bash loop
        [41] for(( i=1; i <= 1000; i++ )); do
                 name=$(date --date="$i day ago" +%Y%m%d%H%M%S)
                 mkdir -p "$name" &&
                 touch "$name/${name}_file" ||
                 break
             done

(5) Bash 'for' loop syntax?
         [51] for (($i=0...
              -
              for ((i=0;i<10;i++))
         [52] for i in `seq 0 9`
              do
                  echo "the i is $i"
              done
         [53] for i in {0..9}
                do
                  echo $i
                done
         ...

画像をタイルに結合って?

$ borg "image tile"
(1) ImageMagick crop huge image
         [11] $ time convert -crop 512x512 +repage huge.tif x/image_out_%d.tif
              real    0m5.623s
              user    0m2.060s
              sys     0m2.148s
              $ time vips dzsave huge.tif x --depth 1 --tile-size 512 --overlap 0 --suffix .tif
              real    0m1.643s
              user    0m1.668s
              sys     0m1.000s
         [12]  convert -monitor -limit area 2mb myLargeImg.tif myLargeImg.mpc
              -
               #!/bin/bash
         ...

(2) Set clipboard to image - pbcopy
        [21] cat image.png | impbcopy -
        [22] # Copy image to clipboard
             uuencode SomeFile.jpg - | pbcopy
             -
             # Paste from clipboard to image file
             pbpaste | uudecode -o AnotherFile.jpg


(3) Using Amazon MapReduce/Hadoop for Image Processing
         [31] and should be able to be done using Bash
         [32] #!/usr/bin/env bash
              # NLineInputFormat gives a single line: key is offset, value is Isotropic Url
              read offset isofile
              # Retrieve file from Isotropic server to local disk
              echo "reporter:status:Retrieving $isofile" >&2
              target=`echo $isofile | awk '{split($0,a,"/");print a[5] a[6]}'`
              filename=$target.tar.bz2
              #$HADOOP_INSTALL/bin/hadoop fs -get $isofile ./$filename
              curl  $isofile -o $filename
         ...

(4) Convert multipage PDF to a single image
        [41] convert in.pdf -append out%d.png
             -
             convert *.png output.pdf
             -
             convert foo?.png output.pdf
        [42] convert in.pdf +append out%d.png

(5) bash cgi won't return image
        [51] echo -ne "Content-type: image/png\n\n"
             -
             echo -e "Content-type: image/png\n"
             -
               -n     do not output the trailing newline

とかとか.

オプションはこんな感じとりあえず省略されないように-fをつけてページャに渡すと良さそう.

$ borg --help
Usage of borg:
-f  (= false)
    Print full results, ie. no more '...'
-h (= "borg.crufter.com")
    Server to connect to
-l  (= 5)
    Result list limit. Defaults to 5
-p  (= false)
    Private search. Your search won't leave a trace. Pinky promise. Don't use this all the time if you want to see the search result relevancy improved

検索だけでなくスニペットの追加や編集もできるようです.

サーバも選べるので自分用のメモを蓄積することもできますね. ちょっと惜しいのはサーバと通信して結果を表示するのでオフラインでは使えないというところ. オフラインで使いたい場合はローカルにサーバを立てるか別の方法を使うしかなさそうです.

端末をWeb共有できるttyd

端末をWebブラウザで共有できるソフトウェエアです. 以前似たものでGoTTYを試してみましたが,ttydはGoTTYインスパイアらしいです. ttydはc製でMITライセンスです.

導入

今回はDebian stretch amd64(testing)に導入しました. README.mdではUbuntu 16.04での手順が書かれていますがそのまま使えました.

$ sudo apt install cmake g++ pkg-config git vim-common libwebsockets-dev libjson-c-dev libssl-dev
$ git clone https://github.com/tsl0922/ttyd.git
$ cd ttyd
$ mkdir build
$ cd build
$ cmake ..
$ make

動かしてみる

$ ./ttyd -p 8080 bash

としてウェブブラウザで http://localhost:8080/ に繋ぐと利用できます. tmuxのセッションを共有して複数のブラウザで1つの端末の操作とかdocker利用とかGoTTYと同じように利用できます.

$ ./ttyd -p 8080 tmux new -A -s ttyd
[2016/12/09 18:54:25:5954] NOTICE: Initial logging level 7
[2016/12/09 18:54:25:5954] NOTICE: Libwebsockets version: 2.0.3 unknown-build-hash
[2016/12/09 18:54:25:5954] NOTICE: IPV6 not compiled in
[2016/12/09 18:54:25:5954] NOTICE: libev support compiled in but disabled
[2016/12/09 18:54:25:5954] NOTICE: libuv support compiled in but disabled
[2016/12/09 18:54:25:5955] NOTICE:  Threads: 1 each 1024 fds
[2016/12/09 18:54:25:5955] NOTICE:  mem: platform fd map:  8192 bytes
[2016/12/09 18:54:25:5955] NOTICE:  Compiled with OpenSSL support
[2016/12/09 18:54:25:5955] NOTICE:  SSL disabled: no LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT
[2016/12/09 18:54:25:5955] NOTICE: Creating Vhost 'default' port 8080, 2 protocols
[2016/12/09 18:54:25:5955] NOTICE:  Listening on port 8080
[2016/12/09 18:54:25:5955] NOTICE:  mem: per-conn:          920 bytes + protocol rx buf
[2016/12/09 18:54:25:5956] NOTICE:  canonical_hostname = x220
[2016/12/09 18:54:25:5956] NOTICE: TTY configuration:
[2016/12/09 18:54:25:5956] NOTICE:   start command: tmux new -A -s ttyd
[2016/12/09 18:54:25:5956] NOTICE:   reconnect timeout: 10s
[2016/12/09 18:54:25:5956] NOTICE:   close signal: SIGHUP (1)
[2016/12/09 18:54:25:6057] NOTICE: lws_protocol_init
[2016/12/09 18:54:25:9806] NOTICE: HTTP connect from localhost (127.0.0.1), path: /
[2016/12/09 18:54:25:0015] NOTICE: HTTP connect from localhost (127.0.0.1), path: /auth_token.js
[2016/12/09 18:54:26:3474] NOTICE: client connected from localhost (127.0.0.1), total: 1
[2016/12/09 18:54:26:3548] NOTICE: started process, pid: 30365
[2016/12/09 18:54:34:2928] NOTICE: HTTP connect from localhost (127.0.0.1), path: /
[2016/12/09 18:54:34:3132] NOTICE: error on reading from skt : 104
[2016/12/09 18:54:34:3132] NOTICE: sending SIGHUP to process 30365
[2016/12/09 18:54:34:3138] NOTICE: process exited with code 256, pid: 30365
[2016/12/09 18:54:34:3138] NOTICE: client disconnected from localhost (127.0.0.1), total: 0
[2016/12/09 18:54:34:5554] NOTICE: HTTP connect from localhost (127.0.0.1), path: /auth_token.js
[2016/12/09 18:54:34:5732] NOTICE: client connected from localhost (127.0.0.1), total: 1
[2016/12/09 18:54:34:5811] NOTICE: started process, pid: 30505
[2016/12/09 18:54:40:0073] NOTICE: wsi 0x556bcbc34500: TIMEDOUT WAITING on 3 (did hdr 0, ah 0x556bcbbc0c50, wl 0, pfd events 0)
[2016/12/09 18:54:40:0074] NOTICE: lws_header_table_detach: wsi 0x556bcbc34500: ah held 6s, ah.rxpos 0, ah.rxlen 0, mode/state 0 4,wsi->more_rx_waiting 0

20161209_18:12:56-1180

GoTTYについてはこちらを.


勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る from Kenichiro MATOHARA

wgetライクにbittorrentを取得するtget

wgetコマンドのような使い勝手のBittorrentクライアントのtgetを試してみました. node製MITライセンスのアプリケーションです.

導入はnpmで.tgetではなくt-getなので注意.

$ npm install -g t-get

torrentファイル,マグネットリンクの他torrent URLでもダウンロードできるようです. 実行すると以下のようなプログレスが表示されてダウンロードが始まります.行幅はハードコードされているようです.

$ tget https://downloads.raspberrypi.org/raspbian_latest.torrent
 downloading 1 files (1.4GB) [============================= ] 97% 64.0s 588.8KB/s 99 peers

ダウンロード完了時は以下のような感じ.ダウンロード完了後直ちに終了します.

$ tget https://downloads.raspberrypi.org/raspbian_latest.torrent
------------------
2016-11-25-raspbian-jessie.zip 1.4GB
------------------
 downloaded 1 files (1.4GB)

ファイルの保存先はカレントディレクトリで,カレントディレクトリに書き込めない場合はエラーにならずファイルが消えてしまうようです.

便利だけどアップロード関係なく終了してしまうのでBittorrentへの貢献度は低そうです. ちなみに最近はリモートのTransmissionをfile serverで動作させて,Transmission-remote-gtkで操作しています.