QNAP にパッケージマネージャを入れる

## (注意) この記事は古い情報です
ipkg はもうなくなったようなのでこちらの記事を参照してください。

* [QNAPのパッケージマネージャ - Qiita](http://qiita.com/nak1114/items/b534cd3bd79db3e3f256)

## やりたいこと

QNAP に ssh ログインすると、デフォルトのシェルが `sh` だったり、
`less` や `file` コマンドもインストールされてなかったりするので、
じゃあ何か追加したいけど、 `yum` や `apt` みたいなパッケージマネージャも入ってない。

QNAP 用パッケージマネージャとして **Optware IPKG** というやつが提供されてるので、これを利用する。

この IPKG で提供されてるパッケージ数はそんなに多くないけど、とりあえず利用したいものはあるていどそろってるぽい。



## Optware IPKG インストール

Web管理画面 App Center から **Optware IPKG** を選択してインストールするだけ。

![optware-ipkg.png](https://qiita-image-store.s3.amazonaws.com/0/3189/90f1a594-b70a-4b98-d8af-c8b2bfd3ef1c.png)

* Optware IPKG をインストールすると `/opt` が `/share/VOLUME/.qpkg/Optware/` へのシンボリックリンクになる
* Optware IPKG をインストールすると 通常の conf 等は `/opt/etc/` の下に入る

```console
# ipkg
ipkg: ipkg must have one sub-command argument
ipkg version 0.99.163
usage: ipkg [options...] sub-command [arguments...]
where sub-command is one of:

Package Manipulation:
  update      Update list of available packages
  upgrade     Upgrade all installed packages to latest version
  install <pkg>   Download and install <pkg> (and dependencies)
  install <file.ipk>  Install package <file.ipk>
  configure [<pkg>] Configure unpacked packages
  remove <pkg|regexp> Remove package <pkg|packages following regexp>
  flag <flag> <pkg> ... Flag package(s) <pkg>
   <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation)

Informational Commands:
  list        List available packages and descriptions
  list_installed    List all and only the installed packages and description
  files <pkg>   List all files belonging to <pkg>
  search <file|regexp>    Search for a package providing <file>
  info [pkg|regexp]   Display all info for <pkg>
  status [pkg|regexp]   Display all status for <pkg>
  download <pkg>    Download <pkg> to current directory.
  compare_versions <v1> <op> <v2>
                            compare versions using <= < > >= = << >>
  print_architecture      prints the architecture.
  print_installation_architecture
  whatdepends [-A] [pkgname|pat]+
  whatdependsrec [-A] [pkgname|pat]+
  whatprovides [-A] [pkgname|pat]+
  whatconflicts [-A] [pkgname|pat]+
  whatreplaces [-A] [pkgname|pat]+
                          prints the installation architecture.

Options:
  -A                      Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts
  -V <level>               Set verbosity level to <level>. If no value is
  --verbosity <level>      provided increase verbosity by one. Verbosity levels:
                           0 errors only
                           1 normal messages (default)
                           2 informative messages
                           3 debug output
  -f <conf_file>    Use <conf_file> as the ipkg configuration file
  -conf <conf_file> Default configuration file location
        is /opt/etc/ipkg.conf
  -d <dest_name>    Use <dest_name> as the the root directory for
  -dest <dest_name> package installation, removal, upgrading.
        <dest_name> should be a defined dest name from
        the configuration file, (but can also be a
        directory name in a pinch).
  -o <offline_root> Use <offline_root> as the root directory for
  -offline <offline_root> offline installation of packages.
  -verbose_wget   more wget messages
  Force Options (use when ipkg is too smart for its own good):
  -force-depends    Make dependency checks warnings instead of errors
          Install/remove package in spite of failed dependences
  -force-defaults   Use default options for questions asked by ipkg.
        (no prompts). Note that this will not prevent
        package installation scripts from prompting.
  -force-reinstall  Allow ipkg to reinstall a package.
  -force-overwrite  Allow ipkg to overwrite files from another package during an install.
  -force-downgrade  Allow ipkg to downgrade packages.
  -force_space            Install even if there does not seem to be enough space.
  -noaction               No action -- test only
  -nodeps                 Do not follow dependences
  -force-removal-of-dependent-packages
  -recursive    Allow ipkg to remove package and all that depend on it.
  -test                   No action -- test only
  -t            Specify tmp-dir.
  --tmp-dir           Specify tmp-dir.

  regexp could be something like 'pkgname*' '*file*' or similar
  eg: ipkg info 'libstd*'  or ipkg search '*libop*' or ipkg remove 'libncur*'
```


## パッケージのインストール

* zsh
* less
* file

これらをそれぞれ `# ipkg install (パッケージ名)` としていったあと
インストール済みパッケージリストを表示したらこうなってた。

```console
# ipkg list_installed
bash - 3.2.54-1 - A bourne style shell
file - 5.12-1 - Ubiquitous file identification utility.
gdbm - 1.8.3-4 - GNU dbm is a set of database routines that use extensible hashing. It works similar to the standard UNIX dbm routines.
ipkg-web - 7-7 - A web frontend for ipkg
less - 444-1 - Less file browser
ncurses - 5.7-3 - NCurses libraries
ncursesw - 5.7-2 - NCurses libraries with wide char support
readline - 6.1-2 - The GNU Readline library provides a set of functions for use by applications that allow users to edit command lines as they are
sudo - 1.8.4.5-1 - System utility to execute commands as the superuser
termcap - 1.3.1-2 - Terminal emulation library
zlib - 1.2.5-1 - zlib is a library implementing the 'deflate' compression system.
zsh - 4.3.17-1 - Zsh is a shell designed for interactive use.
Successfully terminated.
```



## 参考

* [QNAP を使い倒すなら Optware IPKG をインストールしようという話 - uittie::blog](http://blog.uittie.com/entry/2014/01/25/QNAP_%E3%82%92%E4%BD%BF%E3%81%84%E5%80%92%E3%81%99%E3%81%AA%E3%82%89_Optware_IPKG_%E3%82%92%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB%E3%81%97%E3%82%88%E3%81%86%E3%81%A8%E3%81%84%E3%81%86)