2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

termux on GeminiPDAでsoracom cliを動かす

Posted at

これは

Android上にLinux + terminal環境を実現するtermux上で、soracom cliを動かしたときのメモです。
あれこれ試行錯誤した上でクリーン環境での再検証をしていないので、もしかしたら手順が抜けてるかもしれませんがその際はご指摘いただけたら修正いたします。

termuxとは

termuxは、Android上にLinux + terminal環境を実現するアプリです。rootを取る必要は無く、普通にPlayストアからダウンロードできます。

詳しくは公式ページをご覧ください。

termuxにsoracm cliをダウンロードしてみる

termuxをインストールしたら、普通にsoracom cliをダウンロードしてみましょう。私はGeminiPDAで試しているからアーキテクチャはArmになるので(ほとんどのAndroid端末はそうだと思います)、soracom cliのgitページから、「soracom_(バージョン番号)_linux_arm」をダウンロードしてきます。

早速実行してみると、こんな感じです。ダウンロードしたファイルには実行権限ついてないのでchmodを忘れずに。

%cp (ダウンロードしたフォルダ)/soracom_(バージョン番号)_linux_arg soracom
%chmod +x soracom
%./soracom 
A command line tool to invoke SORACOM API

Usage:
  soracom [command]

Available Commands:
  auth               Performs authentication to access to the SORACOM API.
  bills              Show or export billing info.
  completion         Generate script for bash or zsh completion.
  configure          Show, create or update configurations (profiles).
  configure-sandbox  Create configurations (profiles) for API Sandbox.
  coupons            List or register coupons.
  credentials        List, create, update or delete credentials sets.
(省略)

はい、動きましたね?さすがgo、どこでも動きます。
あとはアカウントのセットアップをいつも通りすれば完了・・だったらいいんですけどね(´・ω・`)

あれ、動かない・・

soracomコマンド自体は動くのですが、ネットワークに接続する必要のある動作を実行すると全く動きません。
あれこれ検索したところ、どうもこの辺が該当しそうです。

dns lookup issue when running my Go app in termux

要約すると

  • Linuxのリゾルバは/etc/resolv.confの有無を調べ、なければlocalhost:53にアクセスしてホスト名解決しようとする
  • termuxはroot取らないため(?)ちょっと特殊な形で/usr/etc/resolv.confになっている
  • termuxのlibc(?)はこちらを見るようにパッチが当たってる
  • しかし、クロスコンパイルしたgoのバイナリはこのパッチが当たってないリゾルバを使っているので/etc/resolv.confを見に行き、それがないのでlocalhost:53にアクセスしてだんまりになる

ということのようです。はて困った。

バイナリを自前でビルドしましょう

方法は色々ありえますが、手っ取り早いのはtermuxでビルドしてしまえばいいわけです。
ただ、READMEに載っている

bash scripts/build.sh (バージョン番号)

を実施すると全てのアーキテクチャのバイナリをクロスコンパイルしようとして途中でこけるので、自分が使う分だけビルドしましょう。

まずはgo環境とgitのインストール。ソースコードをZIPで落としてくるならgit不要ですが、せっかくなのでいれておきましょう。

%apt-get install golang git

ソースコードをcloneします。

%git clone https://github.com/soracom/soracom-cli.git

ビルドしましょう。

%cd soracom-cli/soracom
%go build

ビルドに成功したら、カレントディレクトリにバイナリが出来てるので試してみましょう。

%./soracm subscribers list
[
        {
                "apn": "soracom.io",
(出力略)

無事動きました。あとはこのバイナリをパスの通ったところにでも置いておきましょう。

まとめ

termuxを使えばAndroid端末にお手軽にLinux + terminal環境が作れ、そこでsoracom cliも動かせます。
キーボードついたSIMフリー端末であるGeminiPDAにSoracom Air挿してcli動かすと色々捗りますね!

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?