コンポジットマネージャーのXcompmgrでウィンドウ透過設定

久々にMATE環境を使ってみています.
awesomeだとショートカットキーでウィンドウの配置を設定できるので簡単にウィンドウを並べ変えて動画を見ながら別のことをするといったことが簡単に出来ました.しかしMATEで同じことをしようとすると面倒.以前はGnome端末で背景を透過させていましたがこの機能はなくなっていました.

Gnome端末から無くなった後もMATE端末には透過機能が残っていましたがこちらからもいつの間にかなくなっていました.もう復活することは無さそうなので他の端末アプリを幾つか試してみましたが擬似透過しか見当たりません.

ということで今回はXcompmgrを試してみました.

前提

xorgでComposite, RENDER が有効になっている必要がああります.以下OKの例.

$ xdpyinfo | grep -i "render\|composite"
    Composite
    RENDER

必要パッケージの導入

コンポジットマネージャーのxcompmgrと,透過の設定をするtranssetの含まれたx11-appsを導入します.

$ sudo apt install xcompmgr x11-apps

コンポジットマネージャの起動

$ xcompmgr -c &

とか

$ xcompmgr -cf &

とか

$ xcompmgr -c -C -t-5 -l-5 -r4.2 -o.55 &

とかお好みで.

transsetでの透過

xcompmgrが起動した状態でtranssetを使うとウィドウを透過させることが出来ます.
引数には0~1の値を設定します.0が完全に透明.1が不透明です.

$ transset 0.6

として実行するとマウスカーソルが+マークになり,クリックしたウィンドウが透過されます.
以下はブラウザフルスクリーンでニコ生を再生した上に透過設定したMATE端末を表示しています.

Screenshot at 2016-03-19 07:06:39

自動起動設定

毎回手動で起動&設定するのは面倒なのでこんな感じで自動起動設定をします.
コンポジットマネージャーは「システム」->「設定」>「ユーザ向け」->「自動起動するアプリ」から.

Screenshot at 2016-03-20 06:27:22

MATE端末の透過設定は~/.bashrcに以下のように書いてbash起動時にMATE端末だったらtranssetを起動するようにしてみました.sleepを付けないとうまく動きませんでした.sleepの値は環境によって変わると思います.

$ tail -4 ~/.bashrc
case "$COLORTERM" in
    mate-terminal) sleep 0.3 && transset -a 0.6 > /dev/null;;
esac
 

ショートカット設定

MATE端末だけを透過設定する場合はここまでの設定で大丈夫ですが,他のウィンドウや透過度を変更するのにショートカット設定をしておくと便利そうです.

「システム」->「設定」->「ハードウェア」->「キーボードショートカット」でtranssetを登録してショートカットを設定します.

ここで設定したtranssetのオプションは-aはアクティブウィンドウの指定,--inc/--decはインクリメント,デクリメントのオプションです.

Screenshot at 2016-03-20 07:48:08Screenshot at 2016-03-20 07:48:03

Screenshot at 2016-03-20 06:25:27

これで未設定のアプリで透過させたり,ちょっと透過度を調整したいと行った時にショートカットですぐ設定できるようになりました :)

Screenshot at 2016-03-20 06:30:06







Dragonboard 410c eMMC領域のOS入れ替え方法2種類

以下のガイドのとおりなんですが一応メモを.

microSD Card経由と,Fastboot経由の2種類があります.
microSD Card経由の場合はDIP switchの変更が必要でディスプレイとマウスが必要です.
Fastboot経由の場合はHostPCとmicroUSB Cableが必要です.USB-LANアダプタを使えばヘッドレスで全て設定できます.

#こういうのを使ったほうがいいけど.

microSD Card経由での書き込み

USBキーボード,マウス,HDMIモニタと4GB以上のmicroSDが必要です.

イメージの入手とmicroSD Cardへの書き込み

このファイル名は現在の最新です.以下のページを見て最新を入手してください.

$ wget http://builds.96boards.org/releases/dragonboard410c/linaro/debian/latest/dragonboard410c_sdcard_install_debian-66.zip http://builds.96boards.org/releases/dragonboard410c/linaro/debian/latest/MD5SUMS.txt
$ md5sum -c MD5SUMS.txt 2>&1 | egrep -v 'FAILED|ありません'
dragonboard410c_sdcard_install_debian-66.zip: 完了
md5sum: 警告: 一覧にある 15 個のファイルが読み込めませんでした
$ unzip -l dragonboard410c_sdcard_install_debian-66.zip
Archive:  dragonboard410c_sdcard_install_debian-66.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
    14022  2016-02-27 14:36   license.txt
2621440000  2016-02-27 14:36   db410c_sd_install_debian.img
---------                     -------
2621454022                     2 files
$ unzip dragonboard410c_sdcard_install_debian-66.zip
$ cat ./db410c_sd_install_debian.img | pv | sudo dd of=/dev/sdz bs=4M

microSDからの起動とセットアップ

microSD CardをDragonboard 410cに差し込んで,基盤の裏面のDIP switch(s6)を操作してSD boot(2)だけをOnにします.シルクがあるので解りやすいです.
Dragonboard 410cにUSBキーボード,マウス,HDMIモニタを接続して起動するとシンプルなインストーラが起動するのでポチポチと押していくと完了です.

IMGP2730IMGP2731IMGP2732IMGP2733

一旦電源を切ってDIP swatchを元に戻し,microSD Cardを取り外して起動するとLXDEが起動してきます.

ちなみにDIP switchにUSB bootもあるので試してみましたが未実装化手順が違うのかうまく行きませんでした.

Fastboot経由での書き込み

microSD経由より手順が多いですが必要なものが少ない&DIP swatchの操作が必要ないのでケースに入れている場合などもいいかもしれません.
microUSB Cableは必要なので用意してください.

fastbootの導入

HostPCにfastbootを導入します.Android開発環境が既にある人は入っていそうですね.

$ sudo apt install android-tools-fastboot

bootloaderイメージの入手

次のsiteからbootloaderイメージを入手します.最新版を入手してください.
96Boards Builds for: latest

ディレクトリを掘って展開しておきます.

$ unzip -l dragonboard410c_bootloader_emmc_linux-46.zip 
Archive:  dragonboard410c_bootloader_emmc_linux-46.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
57344  2016-02-10 10:00   hyp.mbn
   744042  2016-02-10 10:00   emmc_appsboot.mbn
14022  2016-02-10 10:00   license.txt
   154980  2016-02-10 10:00   rpm.mbn
   483468  2016-02-10 10:00   tz.mbn
 23102976  2016-02-10 10:00   NON-HLOS.bin
   80  2016-02-10 10:00   sec.dat
   252868  2016-02-10 10:00   sbl1.mbn
34304  2016-02-10 10:00   gpt_both0.bin
  324  2016-02-10 10:00   flashall
---------                     -------
 24844408                     10 files
$ mkdir dragonboard410c_bootloader_emmc_linux-46
$ unzip dragonboard410c_bootloader_emmc_linux-46.zip

fastboot modeに入るために基板上の(-)ボタン(s4)を押しながら電源を投入します.すぐにfastboot modeになるのでfastboot devicesコマンドで確認します.何も出てない場合は失敗しているので電源投入をやり直します.

$ sudo fastboot devices
b5d12d18        fastboot

デバイスが認識できているのが確認できたらflashall scriptで書き込みを開始します.書き込みを開始した後は(-)ボタン(s4)を離しても大丈夫そうです.

$ sudo ./flashall
target reported max download size of 268435456 bytes
sending 'partition' (33 KB)...
OKAY [  0.005s]
writing 'partition'...
OKAY [  1.451s]
finished. total time: 1.457s
target reported max download size of 268435456 bytes
sending 'hyp' (56 KB)...
OKAY [  0.005s]
writing 'hyp'...
OKAY [  0.011s]
finished. total time: 0.016s
target reported max download size of 268435456 bytes
sending 'modem' (22561 KB)...
OKAY [  0.732s]
writing 'modem'...
OKAY [  0.756s]
finished. total time: 1.488s
target reported max download size of 268435456 bytes
sending 'rpm' (151 KB)...
OKAY [  0.008s]
writing 'rpm'...
OKAY [  0.010s]
finished. total time: 0.018s
target reported max download size of 268435456 bytes
sending 'sbl1' (246 KB)...
OKAY [  0.011s]
writing 'sbl1'...
OKAY [  0.010s]
finished. total time: 0.021s
target reported max download size of 268435456 bytes
sending 'sec' (0 KB)...
OKAY [  0.004s]
writing 'sec'...
OKAY [  0.006s]
finished. total time: 0.010s
target reported max download size of 268435456 bytes
sending 'tz' (472 KB)...
OKAY [  0.017s]
writing 'tz'...
OKAY [  0.015s]
finished. total time: 0.033s
target reported max download size of 268435456 bytes
sending 'aboot' (726 KB)...
OKAY [  0.026s]
writing 'aboot'...
OKAY [  0.025s]
finished. total time: 0.052s
erasing 'boot'...
OKAY [  0.036s]
finished. total time: 0.037s
erasing 'rootfs'...
OKAY [  0.267s]
finished. total time: 0.267s
erasing 'devinfo'...
OKAY [  0.034s]
finished. total time: 0.034s

boot/root領域の書き込み

OSイメージのboot/root領域のデータを入手して書き込みます.
書き込みはfastboot modeにしてから行ってください.

$ wget http://builds.96boards.org/releases/dragonboard410c/linaro/debian/latest/linaro-jessie-alip-qcom-snapdragon-arm64-20160227-66.img.gz http://builds.96boards.org/releases/dragonboard410c/linaro/debian/latest/boot-linaro-jessie-qcom-snapdragon-arm64-20160227-66.img.gz http://builds.96boards.org/releases/dragonboard410c/linaro/debian/latest/MD5SUMS.txt
$ md5sum -c MD5SUMS.txt 2&>1 |grep 完了
boot-linaro-jessie-qcom-snapdragon-arm64-20160227-66.img.gz: 完了
linaro-jessie-alip-qcom-snapdragon-arm64-20160227-66.img.gz: 完了
$ sudo fastboot flash boot ./boot-linaro-jessie-qcom-snapdragon-arm64-20160227-66.img 
target reported max download size of 268435456 bytes
sending 'boot' (17480 KB)...
OKAY [  0.562s]
writing 'boot'...
OKAY [  0.329s]
finished. total time: 0.891s
$ sudo fastboot flash rootfs ./linaro-jessie-alip-qcom-snapdragon-arm64-20160227-66.img 
target reported max download size of 268435456 bytes
sending sparse 'rootfs' (262140 KB)...
OKAY [  9.309s]
writing 'rootfs'...
OKAY [ 18.304s]
sending sparse 'rootfs' (262140 KB)...
OKAY [  9.236s]
writing 'rootfs'...
OKAY [ 19.888s]
sending sparse 'rootfs' (262140 KB)...
OKAY [  9.255s]
writing 'rootfs'...
OKAY [ 19.759s]
sending sparse 'rootfs' (262140 KB)...
OKAY [  9.295s]
writing 'rootfs'...
OKAY [ 19.834s]
sending sparse 'rootfs' (262140 KB)...
OKAY [  9.317s]
writing 'rootfs'...
OKAY [ 19.828s]
sending sparse 'rootfs' (262140 KB)...
OKAY [  9.290s]
writing 'rootfs'...
OKAY [ 19.765s]
sending sparse 'rootfs' (59016 KB)...
OKAY [  2.118s]
writing 'rootfs'...
OKAY [  4.450s]
finished. total time: 179.649s

起動するとlxdeが起動してきます.sshdも起動してくるのでdhcpdの動いている環境でUSB-LANアダプタを接続すればヘッドレス環境で設定が可能です.avahiは動いてないのでipはポートスキャンなりarpなりで探してください.

$ sudo nmap -sP 192.168.2.200-255 --spoof-mac 00:90:cc:e8:0b:db

Starting Nmap 7.01 ( https://nmap.org ) at 2016-03-11 01:39 JST
Spoofing MAC address 00:90:CC:E8:0B:DB (Planex Communications)
Nmap scan report for 192.168.2.203
Host is up.
Nmap done: 56 IP addresses (1 host up) scanned in 19.15 seconds
$ sudo arp|grep 00:90:cc
192.168.2.214            ether   00:90:cc:e8:0b:db   C                     wlp3s0

ユーザ名はlinaroパスワードも同じです.

$ ssh linaro@192.168.2.202
$ uname -a
Linux linaro-alip 4.4.0-linaro-lt-qcom #1 SMP PREEMPT Sat Feb 27 04:55:16 UTC 2016 aarch64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 8.3 (jessie)
Release:        8.3
Codename:       jessie

ちなみに,セットアップ終了後のeMMCの容量はこのくらいです.

$ df /
Filesystem      1K-blocks    Used Available Use% Mounted on
/dev/mmcblk0p10   7260748 1814312   5120404  27% /

後は普通のDebianなのでsource listを日本に向けてUpdateしてほげりましょう.

/etc/apt/sources.list.d/の下はこんな感じ.後ろ2つは/etc/apt/sources.listと重複しているような?

$ find /etc/apt/sources.list.d/ -type f | xargs -n1 -I{} sh -c "echo \#-- {} ; cat {}"
#-- /etc/apt/sources.list.d/hwpack.qcom.list
deb http://repo.linaro.org/ubuntu/qcom-overlay jessie main
#-- /etc/apt/sources.list.d/linaro-overlay-repo.list
deb http://repo.linaro.org/ubuntu/linaro-overlay jessie main
deb-src http://repo.linaro.org/ubuntu/linaro-overlay jessie main
#-- /etc/apt/sources.list.d/hwpack.debian.list
deb http://ftp.debian.org/debian/ jessie main contrib non-free
#-- /etc/apt/sources.list.d/hwpack.backports.list
deb http://ftp.debian.org/debian/ jessie-backports main

Radikoを自動的に録音してPodcast化してくれるradicastを試す

Radikoを自動的に録音してPodcast化してくれるradicastというものを見つけました.

昔はこんな感じで録音したりしていましたが仕様が変わって録音できなくなって対応というのが面倒で最近は録音していませんでした.たまに聞くときはAndroidのRazikoを使っています.でもradicastならお手軽に動かせてPodcastとして扱えるので便利そうということで試してみました.

試した環境はUbuntu 14.04 amd64/Debian stretch testing amd64/Rasbian jessieですが,Ubuntu環境では録音開始時に以下のようにコアダンプしてしまうようでうまく行っていません :-(

2016/03/09 05:20:00 [radiko] start record
2016/03/09 05:20:00 [radiko] GET http://radiko.jp/player/swf/player_3.0.0.01.swf
2016/03/09 05:20:04 [radiko] POST https://radiko.jp/v2/api/auth1_fms
Segmentation fault (コアダンプ)

dockerでも動きますが,今回は実機で動かしています.

必要なpkgの導入

$ sudo apt install libav-tools swftools rtmpdump golang-go

※Debian stretchの場合はlibav-toolsの代わりにffmpegを導入.

go getで導入

$ GOPATH=~/usr/local/go go get github.com/soh335/radicast

オプションはこんな感じでした.

$ ~/usr/local/go/bin/radicast -h
Usage of /home/mk/usr/local/go/bin/radicast:
  -bitrate string
        bitrate (default "64k")
  -buffer int
        buffer for recording (default 60)
  -config string
        path of config.json (default "config.json")
  -converter string
        ffmpeg or avconv. If not set this option, radicast search its automatically.
  -host string
        host (default "0.0.0.0")
  -output string
        output (default "output")
  -port string
        port (default "3355")
  -setup
        initialize json configuration
  -title string
        title (default "radicast")

設定ファイル作成

--setupオプションでスケルトンを作成して,

$ ~/usr/local/go/bin/radicast --setup > ~/usr/local/go/etc/radicast.json
$ cat ~/usr/local/go/etc/radicast.json
{
  "HOUSOU-DAIGAKU": [],
  "MBC": [],
  "RN1": [],
  "RN2": []
}

次のページを参考にcron形式で設定します.crontabと違い秒単位まで指定できるようです.

例えば"0 0 7 * * MON-FRI" だと月曜から金曜の07:00:00の番組を録音となります.
録音停止は自動的にされるようです.

$ cat ~/usr/local/go/etc/radicast.json
{
  "HOUSOU-DAIGAKU": [],
  "MBC": [
    "0 0 5 * * MON-FRI",
    "0 10 5 * * MON-FRI",
    "0 0 7 * * MON-FRI"
  ],
  "RN1": [],
  "RN2": []
}

実行

設定ファイルを指定して実行します.

$ ~/usr/local/go/bin/radicast -config=$HOME/usr/local/go/etc/radicast.json
2016/03/09 05:00:12 [radicast] station:MBC spec:0 0 5 * * MON-FRI
2016/03/09 05:00:12 [radicast] station:MBC spec:0 10 5 * * MON-FRI
2016/03/09 05:00:12 [radicast] station:MBC spec:0 0 7 * * MON-FRI
2016/03/09 05:00:12 [radicast] start new cron
2016/03/09 05:00:12 [server] start 0.0.0.0:3355

指定時刻になると,番組情報を取得して録音が始まり,番組終了時に録音が終了して次のジョブまで待機します.

2016/03/09 06:30:00 [radiko] start record
2016/03/09 06:30:00 [radiko] GET http://radiko.jp/player/swf/player_3.0.0.01.swf
2016/03/09 06:30:04 [radiko] POST https://radiko.jp/v2/api/auth1_fms
2016/03/09 06:30:05 [radiko] POST https://radiko.jp/v2/api/auth2_fms
2016/03/09 06:30:06 [radiko] GET http://radiko.jp/v2/api/program/today?area_id=JP46
2016/03/09 06:30:07 [radiko] start recording モーニング・スマイル
2016/03/09 06:30:07 [radiko] rtmpdump command: /usr/bin/rtmpdump --live --quiet -r rtmpe://f-radiko.smartstream.ne.jp --playpath simul-stream.stream --app MBC/_definst_ -W http://radiko.jp/player/swf/player_3.0.0.01.swf -C S:"" -C S:"" -C S:"" -C S:J_Rb9kLWN2Cb5XlcGqQjfw --stop 1853 -o -
2016/03/09 06:30:07 [radiko] converter command: /usr/bin/ffmpeg -y -i - -vn -acodec libmp3lame -ar 44100 -ab 64k -ac 2 /tmp/radiko240330221/radiko_0.mp3

データは以下のようにoutput以下に保存されています.

$ find output -ls
  6724248      0 drwxr-xr-x   1 mk       mk             36  3月  9 05:55 output
  6724778      0 drwxr-xr-x   1 mk       mk             44  3月  9 05:55 output/20160309053000_MBC
  6724327  10168 -rw-r--r--   1 mk       mk       10409132  3月  9 05:55 output/20160309053000_MBC/podcast.mp3
  6724779      4 -rw-r--r--   1 mk       mk            650  3月  9 05:55 output/20160309053000_MBC/podcast.xml

録音中のテンポラリファイルは/tmp以下に作られます.

$ ls -lA /tmp/radiko077215706/
合計 5184
-rw-r--r-- 1 mk mk 5223512  3月  9 07:10 radiko_0.mp3

録音したデータはPodcastとして配信されます.このURLは規定値ではlocalhostからしかアクセスできません.このURLをPodcast Aggregatorに指定してあげると普通にPodcastとして扱えます :)

$ xmllint http://localhost:3355/rss
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
    <channel>
        <title>radicast</title>
        <itunes:owner/>
        <itunes:image/>
        <itunes:category/>
        <item>
            <title>生島ヒロシのおはよう一直線 (2016-03-09 05:30:00 +0900 JST)</title>
            <itunes:author>生島ヒロシ</itunes:author>
            <itunes:summary> &lt;br /&gt;&lt;A href="http://www.mbc.co.jp/radio/" target="_blank"&gt;&lt;img src="http://www.mbc.co.jp/radio/radiko/bn/mbcradio_pr1410.png" alt="MBCradio" /&gt;&lt;/A&gt;&lt;br /&gt;&lt;br /&gt;twitterハッシュタグは「&lt;a href="http://twitter.com/#!/search/%23mbc1107"&gt;#mbc1107&lt;/a&gt;」</itunes:summary>
            <itunes:image/>
            <enclosure url="http://localhost:3355/podcast/20160309053000_MBC.mp3" length="10409132" type="audio/mpeg"/>
            <pubDate>Wed, 9 Mar 2016 05:55:45 +0900</pubDate>
        </item>
    </channel>
</rss>

Podcast Aggregatorとこのサーバが別の場合以下のように-hostオプションを指定してインターフェイスに割り当てたipを指定するとそのネットワークからアクセスできるようになります.

$ ~/usr/local/go/bin/radicast -config=$HOME/usr/local/go/etc/radicast.json -host 192.168.2.203
  :
2016/03/09 07:42:34 [server] start 192.168.2.203:3355

proxy

は使えない感じかな?

$ w3m -dump http://radiko.jp/area
document.write('<span class="JP46">KAGOSHIMA JAPAN</span>');
$ tsocks w3m -dump http://radiko.jp/area
document.write('<span class="JP13">TOKYO JAPAN</span>');
$ ALL_PROXY=socks5h://localhost:8080 ~/usr/local/go/bin/radicast -setup
2016/03/09 07:56:00 [radiko] GET http://radiko.jp/player/swf/player_3.0.0.01.swf
2016/03/09 07:56:01 [radiko] POST https://radiko.jp/v2/api/auth1_fms
2016/03/09 07:56:02 [radiko] POST https://radiko.jp/v2/api/auth2_fms
2016/03/09 07:56:02 [radiko] GET http://radiko.jp/v2/api/program/today?area_id=JP46
{
  "HOUSOU-DAIGAKU": [],
  "MBC": [],
  "RN1": [],
  "RN2": []
}
$ tsocks ~/usr/local/go/bin/radicast -setup
   :
  "MBC": [],
   :
$ tsocks ~/usr/local/go/bin/radicast -setup
   :
  "MBC": [],
   :
$ ALL_PROXY=http://localhost:8080 ~/usr/local/go/bin/radicast -setup
   :
  "MBC": [],
   :

ちょっと変わったminiUSB-B Cableを買う

デモの時やスマホなどでこの折りたたみキーボード( Targus PA875 )が重宝しています.確か秋葉原で結構前に3千円くらいで買ったような気がします.最近はBluetoothが主流ですが有線も安定してていい感じです.

久しぶりに使おうとしたらケーブル皮膜が剥けてしまっています.断線はしていないようで今のところ利用できますが出先で使えないと致命的.しかしコネクタは一般的なUSB形状とは違い四角いもの.

IMG_20160308_074032IMG_20160308_074044IMG_20160308_073704IMG_20160308_073652IMG_20160308_073524

以下のページの「ヒロセ4P:四角(4P)」と同じようです.

こういうコネクタに強いCOMONのページをみるとありました.

秋葉原に行ければ千石(確か巻取りじゃないのも店頭に置いてあったはず)やコンピュエース辺りで買うのですが遠いので通販を.(千石はひと通り試せるようになっています)最近はこの手のはメール便を使えるフタバヤさんをよく利用しています.前回はAmazonのマーケットプレイス経由で買いましたが今回はポイントが残ってたので楽天店から購入.

そして届いたのがこれです.
普通に使えました.

IMG_20160308_043453

ロゴも張り替えたのでぱっと見同じです.これで安心して利用できます.
ということで,Targus PA875のUSBはヒロセ4PやHIROSE Typeと呼ばれているもので,COMON EC-HABHが適合するよという情報でした.

おまけ?

$ dmesg | tail
   :
[125061.384207] CPU1: Package temperature/speed normal
[125491.780430] usb 2-1.1: new low-speed USB device number 4 using ehci-pci
[125491.880961] usb 2-1.1: New USB device found, idVendor=0a81, idProduct=0101
[125491.880969] usb 2-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[125491.880975] usb 2-1.1: Product: USB Keyboard
[125491.880980] usb 2-1.1: Manufacturer: CHESEN
[125491.886178] input: CHESEN USB Keyboard as /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1:1.0/0003:0A81:0101.0003/input/input21
[125491.940690] hid-generic 0003:0A81:0101.0003: input,hidraw0: USB HID v1.10 Keyboard [CHESEN USB Keyboard] on usb-0000:00:1d.0-1.1/input0
[125491.947369] input: CHESEN USB Keyboard as /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1:1.1/0003:0A81:0101.0004/input/input22
[125492.000811] hid-generic 0003:0A81:0101.0004: input,hidraw1: USB HID v1.10 Device [CHESEN USB Keyboard] on usb-0000:00:1d.0-1.1/input1
$ lsusb -d 0a81:0101
Bus 002 Device 005: ID 0a81:0101 Chesen Electronics Corp. Keyboard

ストリーミング配信補助ソフトのCastawesomeを試す

3/5はOpenDataDayでした.
去年までは鹿児島市で募ってMapCafeと称してOSMする集まりをしていたのですが人が集まらないので今年は家で地図を書こうかと.そしてそのデスクトップをストリーミングしてみようかなと.

ということデスクトップストリーミングの話です.

いつものようにffmpegでRTMP配信なのですが,今回はCastawesomeというGUIの皮を見つけたので試してみました.これを使うとオプションなどがGUIで入力するだけで埋まっていくので便利です.

導入はcloneした後makeするだけ.システムに導入したいならmake installも.(Raspberry Piでも動きました.)
ffmpeg or avconvとPython 3, GTK-3ライブラリなどが必要です.(make時に足りないものがある場合DEPENDSが参考になります)

$ git clone -b 0.16.0 https://github.com/TheSamsai/Castawesome.git
$ cd Castawesome
$ make

の後

$ ./castawesome.py

or

$ sudo make install

してスタートメニューから実行.

こんな画面が出てきてフォームを埋めていくだけでOKです.
配信先はTwitch/YouTube/Hitbox/Pocarto/Local/Customに対応.多分Customを使えばUstream.tvも行けますね.

20160305_22:03:24-21661

ただ,細かい設定は苦手だったりエラーチェックも甘く配信されないことも多いのでそういう場合にはターミナルから起動して配信(「録画」ボタン)した時の以下のようなログを利用してffmpegで配信するようにするのが良さそうです.

ffmpeg -f x11grab -show_region 0 -s 1366x768 -framerate " 8" -i :0.0+0,0 -f pulse -ac 1 -i  -vcodec h264 -s 798x449 -preset medium -acodec mp3 -ar 44100 -threads 4
-qscale 3 -b:a 128k -b:v 300k -minrate 300k -g 16 -pix_fmt yuv420p -f flv "rtmp://a.rtmp.youtube.com/live2/<_stream_key_>"

設定ファイルは~/.config/castawesome以下に保存されます.keyはYouTubeのものを設定しても.twitch_keyというファイルに保存されていました.

$ ls -A ~/.config/castawesome/
.twitch_key  config.txt

よし,これで配信準備出来たと思ったのですが体調悪くスクリーンセーバーを垂れ流しながら寝落ちしてしまっていましたorz

起動済みのXをTigerVNCで共有

通常はVNCは新しいXを起動して使うことが多いと思いますが,ヘッドレス環境や入力デバイスの貧弱な環境デモの際など既に起動済みのXの画面を利用したいことがあります.(例えばKoboとかマウス忘れたとか><)


昔はvinoを使っていましたが,設定画面がGnomeに統合されてGnome環境以外で利用するのが面倒になってしまいました.


一応dconfを書き換えれば設定できます.

% gsettings list-recursively org.gnome.Vino
org.gnome.Vino notify-on-connect true
org.gnome.Vino alternative-port uint16 5900
org.gnome.Vino disable-background false
org.gnome.Vino use-alternative-port true
org.gnome.Vino icon-visibility 'client'
org.gnome.Vino use-upnp true
org.gnome.Vino view-only false
org.gnome.Vino prompt-enabled false
org.gnome.Vino disable-xdamage false
org.gnome.Vino authentication-methods ['vnc']
org.gnome.Vino network-interface ''
org.gnome.Vino require-encryption false
org.gnome.Vino mailto ''
org.gnome.Vino lock-screen-on-disconnect false
org.gnome.Vino vnc-password 'xxxxxxxxxxx'

GUIが良ければdconf-editorとかを.

20160304_00:03:38-25955

#MATE環境でvinoが起動してこない場合は次のページを -> Raspberry_Pi/Ubuntu_MATE – matoken’s wiki.

Gnome重いしdconf書き換えるんもめんどいなということで最近はx11vncを使っていました.

$ sudo apt install x11vnc
$ x11vnc -localhost -rfbauth $HOME/.vnc/passwd -display :0

今回以下の記事を読んでTigerVNCでも出来ることを知りました!

今回はVinoと同じく現在ログインしているデスクトップを転送するため,TigerVNCサーバーはユーザー権限で動作し,新しい仮想ディスプレイは作成しません。TigerVNCにはそのような便利なコマンドが用意されています。

続いて次のコマンドを実行し,TigerVNCを起動します。

$ x0vncserver -display :0 -passwordfile ~/.vnc/passwd

TigerVNCに含まれるx0vncserverを使うといけるようです.

しかしDebianにもパッケージがないようです.

$ w3m -dump 'https://packages.debian.org/search?suite=all&section=all&arch=any&searchon=names&keywords=tigervnc'|grep 'tigervnc を名前に含むパッケージを' -A4
tigervnc を名前に含むパッケージを、すべてのスイート、すべてのセクション、すべて
のアーキテクチャで検索しました。
 
残念ながら、検索結果はありませんでした
 

Ubuntu 14.04環境が別にあるのでそちらにいくやさんの用意されたリポジトリを用意して導入してみます.

しかし,add-apt-reposotoryが見当たりません.環境がおかしくなっている?

$ sudo add-apt-reposotory ppa:ikuya-fruitsbasket/tigervnc
sudo: add-apt-reposotory: command not found
$ add-apt-reposotory
コマンド 'add-apt-reposotory' は見つかりませんでした。もしかして:
 コマンド 'add-apt-repository' - パッケージ 'software-properties-common' (main)
add-apt-reposotory: コマンドが見つかりません
$ sudo apt install software-properties-common
$ add-apt-reposotory -h
コマンド 'add-apt-reposotory' は見つかりませんでした。もしかして:
 コマンド 'add-apt-repository' - パッケージ 'software-properties-common' (main)
add-apt-reposotory: コマンドが見つかりません
$ apt-file update
$ apt-file search add-apt-reposotory
$ dpkg -L software-properties-common|grep add-apt-reposotory

見つからない?

あ,スペルミスだ
~s/add-apt-reposotory/add-apt-repository/gですね.よく見ましょうorz

$ dpkg -L software-properties-common |grep bin
/usr/bin
/usr/bin/add-apt-repository
/usr/bin/apt-add-repository
$ add-apt-repository
エラー: root で実行する必要があります
$ add-apt-repository
エラー: root で実行する必要があります

ということでこんな感じでいけました.

$ sudo apt install software-properties-common
$ sudo add-apt-repository ppa:ikuya-fruitsbasket/tigervnc
$ sudo apt update && sudo apt upgrade
$ sudo apt install tigervncserver

よし早速!

$ x0vncserver -display :0 -passwordfile ~/.vnc/passwd
x0vncserver: unable to open display ":0"
~ImageCleanup called

そういえば起動してませんでした.この端末はX入れているけどX転送でたまにアプリを使うくらいなので起動していないのです.
slimを起動(確かデフォルトはlightdm)してloginして

$ sudo service slim start

再度

$ x0vncserver -display :0 -passwordfile ~/.vnc/passwd

そしてRemminaで接続……出来ない.fwのせいでした.とりあえずssh -L で5900を転送してlocalhostに接続しました.

20160304_04:03:41-24566

うまく行きました :)

しかし,クライアント側もTigerVNCで繋いでみたいところ.とりあえずi686とx86_64についてはバイナリ配布もされているようなのでこれを利用してみます.

とりあえず適当なディレクトリに展開して実行で動きました.

$ wget http://tigervnc.bphinz.com/nightly/xc/x86_64/tigervnc-Linux-x86_64-1.6.80-20160302gitf34a386c.tar.gz
$ md5sum tigervnc-Linux-x86_64-1.6.80-20160302gitf34a386c.tar.gz
ea9ea2396d42819d4ea588a6598f583b  tigervnc-Linux-x86_64-1.6.80-20160302gitf34a386c.tar.gz
$ tar xf tigervnc-Linux-x86_64-1.6.80-20160302gitf34a386c.tar.gz -C ~/tmp
$ ~/tmp/usr/bin/vncviewer &

ちなみに
vnc4serverにもx0vnc4serverというそれらしいものがあるようです.そのうち試してみよう.

Ustream.tvの放送状況を確認する

Ustream.tvの放送状況を確認して放送中なら再生するというものが作れないかと思って少し調べたメモです.

やりたいのはこんな感じ.

  • Ustream.tvの「登録済みチャンネル」から放送中のチャンネルを抽出
  • 放送中のものがあったら再生
  • 放送中のものがなかったらNASA.TV辺りを流す

APIをざっと見てみるとチャンネルの放送状況は取得できました.

この機能はデベロッパーIDなども必要ないようです.

$ w3m -dump_source https://api.ustream.tv/channels/17125175.xml|grep status
        <status><![CDATA[live]]></status>
$ w3m -dump_source https://api.ustream.tv/channels/27482.xml|grep status
        <status><![CDATA[offair]]></status>

ここで指定するのはチャンネルIDでチャンネルURLの後ろのチャンネルではありません.これは以下のAPIで取得できます.

$ w3m -dump_source http://api.ustream.tv/xml/channel/ospn-tv/getValueOf/id|grep results
<results>10635140</results>

ということで「登録済みチャンネル」の取得以外は出来そうです.後はこれをlivestreamerに流し込むとUstream.tvのサイネージが作れそうな感じ.

ちなみにAPIにはLive開始時などに教えてくれる機能などもあるようですがそちらはレシーバが必要になるので今回の用途には向か無さそうなのでちゃんと調べていません.


Google Chromeのproxy切り替え

昨日久々に外出してssh -NでChromeにsocks proxyを設定して使おうとしたのですが以下のようなメッセージが表示されて設定できませんでした.

20160302_20:03:07-5155

恐らく統合デスクトップ環境ではないawesomeを使っているのでこの機能に対応していないんだろうなと.

manの該当部分はこんな感じでpacファイルなども利用できるよう.

       --proxy-server=host:port
              Specify the HTTP/SOCKS4/SOCKS5 proxy server to use for requests.  This overrides any environment variables or settings picked via the options dialog.
              An individual proxy server is specified using the format:
 
                [<proxy-scheme>://]<proxy-host>[:<proxy-port>]
 
              Where <proxy-scheme> is the protocol of the proxy server, and is one of:
 
                "http", "socks", "socks4", "socks5".
 
              If the <proxy-scheme> is omitted, it defaults to "http". Also note that "socks" is equivalent to "socks5".
 
              Examples:
 
                --proxy-server="foopy:99"
                    Use the HTTP proxy "foopy:99" to load all URLs.
 
                --proxy-server="socks://foobar:1080"
                    Use the SOCKS v5 proxy "foobar:1080" to load all URLs.
 
                --proxy-server="socks4://foobar:1080"
                    Use the SOCKS v4 proxy "foobar:1080" to load all URLs.
 
                --proxy-server="socks5://foobar:66"
                    Use the SOCKS v5 proxy "foobar:66" to load all URLs.
 
              It is also possible to specify a separate proxy server for different URL types, by prefixing the proxy server specifier with a URL specifier:
 
              Example:
 
                --proxy-server="https=proxy1:80;http=socks4://baz:1080"
                    Load https://* URLs using the HTTP proxy "proxy1:80". And load http://*
                    URLs using the SOCKS v4 proxy "baz:1080".
 
       --no-proxy-server
              Disables the proxy server.  Overrides any environment variables or settings picked via the options dialog.
 
       --proxy-auto-detect
              Autodetect proxy configuration.  Overrides any environment variables or settings picked via the options dialog.
 
       --proxy-pac-url=URL
              Specify proxy autoconfiguration URL.  Overrides any environment variables or settings picked via the options dialog.

とりあえずは以下のようなオプションで起動することで回避できました.

$ google-chrome --proxy-server="socks://localhost:8080"

この状態で設定を見るとグレーアウトになって設定変更できません.

20160303_07:03:40-2248

ということでこの方法だと切り替えのたびにChromeの起動し直しが必要でタブを大量に開いている時など辛いです.proxy.pacを作りこんだらとも思ったのですがこの感じだと起動時にしか評価し無さそう.

ということでこのようなものを入れてみました.

設定を作っておいてワンタッチで切り替えできるようになりました.
そもそもシステムのプロキシの設定が見えない問題は未解決ですが…….

ちなみにproxyの確認には以下のsiteが便利です.欲しい情報だけ貰うことやxml/json形式でも情報を貰うことが出来ます.

昔は自分のsiteにこんな感じのscript仕込んでましたが最近は色々なサービスが合って便利ですね :)

echo -e 'Content-Type: text/plain\n\n'
echo `printenv`


OpenSSH 7.2で入ったssh-keygenの新機能を試す

OpenSSH 7.2リリースネタ続きです.

ここではssh-keygenの新機能を試してみます.

鍵のコメント変更

先ずは鍵のコメント変更.

* ssh-keygen(1): allow ssh-keygen to change the key comment for all
supported formats.

ssh-keygen(1): すべてのサポートする形式について ssh-keygen が
鍵のコメントを変更できるようにする

manやhelpを見ると-cオプションのようです.

    -c      Requests changing the comment in the private and public key files.  This operation is only supported for RSA1 keys.  The program will prompt for the
            file containing the private keys, for the passphrase if the key has one, and for the new comment.
$ ~/usr/local/openssh-portable/bin/ssh-keygen --help |& grep '\-c'
       ssh-keygen -c [-P passphrase] [-C comment] [-f keyfile]

適当な鍵を作って書き換えてみました.test commentchange commentに書き換わりました.手で書き換えるとミスすることもあるのでいいかもしれません.

$ ssh-keygen -t ed25519 -N '' -C "test comment" -f ./testkey
$ cat ./testkey.pub
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHBYXP3okrQO7hejY7f0d6PvjD++puLFuvozI5Trxv8D test comment
$ ~/usr/local/openssh-portable/bin/ssh-keygen -c -C "change comment" -f ./testkey
Key now has comment 'test comment'
The comment in your key file has been changed.
$ cat testkey.pub
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHBYXP3okrQO7hejY7f0d6PvjD++puLFuvozI5Trxv8D change comment

標準入力からの鍵の読み込みと鍵指紋の表示

-fオプションのファイルの代わりに-を指定すると標準入力から鍵を読み込みます.ファイル指定の場合は秘密鍵も公開鍵もいけますが,標準入力からだと公開鍵のみのようです.

$ cat ./testkey.pub | ~/usr/local/openssh-portable/bin/ssh-keygen -lf -
256 SHA256:v7zpU4SoiUIIEqWhaftbuUy2t2Tuny9Ld5WVrDD2Sjs change comment (ED25519)
$ cat ./testkey | ~/usr/local/openssh-portable/bin/ssh-keygen -lf -
(stdin) is not a public key file.
$ ~/usr/local/openssh-portable/bin/ssh-keygen -lf ./testkey.pub
256 SHA256:v7zpU4SoiUIIEqWhaftbuUy2t2Tuny9Ld5WVrDD2Sjs change comment (ED25519)
$ ~/usr/local/openssh-portable/bin/ssh-keygen -lf ./testkey
256 SHA256:v7zpU4SoiUIIEqWhaftbuUy2t2Tuny9Ld5WVrDD2Sjs change comment (ED25519)

host鍵全部とかはこんな感じで行けますね.

$$ cat /etc/ssh/ssh_host_*_key.pub | ~/usr/local/openssh-portable/bin/ssh-keygen -lf -
521 SHA256:WdWtCQFxH+Xno527Cl+PomQ5ZKj81/NUzIzYOckXsWA root@x220 (ECDSA)
256 SHA256:rONiKpthZZORiwOKpfNVcrMp+FgBhfE20GuCuuNrgA8 root@x220 (ED25519)
4096 SHA256:o2xTrmNmkd2RwNybmaO+TWIFw6xeoZmXmbLdhC1gIpU root@x220 (RSA)

ファイルに含まれる複数の公開鍵の指紋表示

* ssh-keygen(1): allow fingerprinting multiple public keys in a
file, e.g. “ssh-keygen -lf ~/.ssh/authorized_keys” bz#1319

ssh-keygen(1): ファイルに含まれる複数の公開鍵の指紋表示を
できるようにする. つまり
“ssh-keygen -lf ~/.ssh/authorized_keys” bz#1319

こちらの場合も秘密鍵の鍵指紋は取得できないです.ちなみにエラーなどは出ずスキップされます.

$ ssh-keygen -t ed25519 -f /tmp/hoge_key
$ ssh-keygen -t ed25519 -f /tmp/hoge2_key
$ cat /tmp/hoge_key.pub /tmp/hoge2_key.pub > /tmp/keys.pub
$ ~/usr/local/openssh-portable/bin/ssh-keygen -l -f /tmp/keys.pub
256 SHA256:/fZluTkiB9Ogv3mT9mniaZ2YPbL2XkMwge+bQ0r74dg mk@x220(ED25519)
256 SHA256:iHSZ0ucbwTR0VLScSF5l29iBFQIT13I+fELvue/N+xM mk@x220(ED25519)
$ cat /tmp/hoge_key.pub /tmp/hoge2_key > /tmp/keys.mix
$ ~/usr/local/openssh-portable/bin/ssh-keygen -l -f /tmp/keys.mix
256 SHA256:/fZluTkiB9Ogv3mT9mniaZ2YPbL2XkMwge+bQ0r74dg mk@x220(ED25519)
$ cat /tmp/hoge_key.pub /tmp/hoge2_key /tmp/hoge2_key.pub> /tmp/keys.mix
$ ~/usr/local/openssh-portable/bin/ssh-keygen -l -f /tmp/keys.mix256 SHA256:/fZluTkiB9Ogv3mT9mniaZ2YPbL2XkMwge+bQ0r74dg mk@x220(ED25519)
256 SHA256:iHSZ0ucbwTR0VLScSF5l29iBFQIT13I+fELvue/N+xM mk@x220(ED25519)

#見づらいですね><

-vを付けると秘密鍵のところでnot a public keyと言われるようになります.

$ ./ssh-keygen -l -v -f /tmp/keys.mix
256 SHA256:/fZluTkiB9Ogv3mT9mniaZ2YPbL2XkMwge+bQ0r74dg mk@x220(ED25519)
+--[ED25519 256]--+
|            ..   |
|           .  .  |
|            .o   |
|         . . .o  |
|        S o +  . |
|         . = +. .|
|          o O.Oo=|
|           *=^oX*|
|           +@E&Bo|
+--[SHA256]---+
debug1: /tmp/keys.mix:2: not a public key
debug1: /tmp/keys.mix:8: not a public key
256 SHA256:iHSZ0ucbwTR0VLScSF5l29iBFQIT13I+fELvue/N+xM mk@x220(ED25519)
+--[ED25519 256]--+
|       .+.+**+*+.|
|     . = = +o*oB.|
|    o = + o +.B.o|
|   . + + .    .+o|
|    . . S      o+|
|         o     E.|
|        .       o|
|               +.|
|               o@|
+--[SHA256]---+



OpenSSH 7.2のsshdに入ったauthorized_keysの新オプションを試す

OpenSSH 7.2がリリースされました :)

ということで気になった以下の新機能を試してみます.

* sshd(8): add a new authorized_keys option “restrict” that includes
all current and future key restrictions (no-*-forwarding, etc.).
Also add permissive versions of the existing restrictions, e.g.
“no-pty” -> “pty”. This simplifies the task of setting up
restricted keys and ensures they are maximally-restricted,
regardless of any permissions we might implement in the future.

sshd(8): authorized_keys のオプションに “restrict” を追加する.
これは, (no-*-forwarding などの) 現在と将来のすべての制限を含む.
さらに, 現在の制限の許可バージョンも追加する. つまり,
“no-pty” -> “pty”. これにより, 制限付きの鍵の設定のタスクが
単純化し, 将来実装するすべての許可に関係なく
鍵が最大に制限されていることを圃場できる.

prefix以外は規定値のままでbuid

$ sudo apt install build-essentialbuild-essential
$ sudo apt build-dep openssh
$ git pull
$ ./configure --prefix=$HOME/usr/local/openssh-portable
$ make
$ make install

適当に7.2のデーモンを起動

$ `pwd`/sbin/sshd -D -p 22222
$ ps -ef|grep openssh-portable
mk       21788 14885  0 00:46 pts/7    00:00:00 /home/mk/usr/local/openssh-portable/sbin/sshd -D -p 22222

適当な鍵を作って~/.ssh/authorized_keysに登録してログインテスト.

$ ssh-keygen -t ed25519 -N '' -f ./testkey
$ cat testkey.pub >> ~/.ssh/authorized_keys
$ ssh localhost -p 22222 -i ./testkey

authorized_keysの該当鍵行の頭に

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFm5sR98q060FFlT1cpBVbwm0caShCYGl39D5k9PCenB mk@x220

restrictを追記して

restrict ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFm5sR98q060FFlT1cpBVbwm0caShCYGl39D5k9PCenB mk@x220

ssh 7.2で接続を試します.

$ /home/mk/usr/local/openssh-portable/bin/ssh localhost -p 22222 -i ./testkey
PTY allocation request failed
printenv|grep -i ssh
SSH_CLIENT=::1 56910 22222
SSH_CONNECTION=::1 56910 ::1 22222
exit
Shared connection to localhost closed.

sshd側の機能なのでssh 7.1で繋いでも制限されます.

$ ssh localhost -p 22222 -i ./testkey
PTY allocation request failed
printenv|grep -i ssh
SSH_CLIENT=::1 56910 22222
SSH_CONNECTION=::1 56910 ::1 22222
Shared connection to localhost closed.

restrict,pty のようにptyを追記して-X/-Yを試すとptyが使えてXは制限されているのが確認できました.

$ grep restrict authorized_keys
restrict,pty ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFm5sR98q060FFlT1cpBVbwm0caShCYGl39D5k9PCenB mk@x220
$ ssh localhost -p 22222 -i ./testkey -X
X11 forwarding request failed
mk@x220:~$ xeyes
Error: Can't open display:

これまではずらずらと制限を書く必要がったのがシンプルに書けるようになりそうです :)

以下の件は別エントリにて