[oracle] wsl2/ubuntu20.4にsqlplus(OracleInstantClient21.7)をインストール

MOSにログインした状態で、
https://www.oracle.com/jp/database/technologies/instant-client/linux-x86-64-downloads.html
にアクセスし、以下をDL

Basic Light Package (OL7 RPM)	
oracle-instantclient-basiclite-21.7.0.0.0-1.x86_64.rpm

SQL*Plus Package (OL7 RPM)	
oracle-instantclient-sqlplus-21.7.0.0.0-1.x86_64.rpm

alienでrpmをdebに変換

```
~/oracle-instantclient$ sudo alien --to-deb oracle-instantclient-basiclite-21.7.0.0.0-1.x86_64.rpm

~/oracle-instantclient$ sudo alien -c oracle-instantclient-basiclite-21.7.0.0.0-1.x86_64.rpm
oracle-instantclient-basiclite_21.7.0.0.0-2_amd64.deb generated

~/oracle-instantclient$ sudo alien -c oracle-instantclient-sqlplus-21.7.0.0.0-1.x86_64.rpm
oracle-instantclient-sqlplus_21.7.0.0.0-2_amd64.deb generated
```

/mnt/cのサブディレクトリで実行したらパーミッションエラーがでた(wsl特有の問題)
のでホームディレクトリ(~)のサブディレクトリで実施

エラーメッセージは長いので最後に記載

ちなみに-c(スクリプトも変換)をつけないとエラーが出力される

```
Warning: Skipping conversion of scripts in package oracle-instantclient-sqlplus: postinst postrm
Warning: Use the --scripts parameter to include the scripts.
oracle-instantclient-sqlplus_21.7.0.0.0-2_amd64.deb generated
```

生成されたdebをインストール

```
~/oracle-instantclient$ sudo dpkg -i oracle-instantclient-basiclite_21.7.0.0.0-2_amd64.deb
Selecting previously unselected package oracle-instantclient-basiclite.
(Reading database ... 56504 files and directories currently installed.)
Preparing to unpack oracle-instantclient-basiclite_21.7.0.0.0-2_amd64.deb ...
Unpacking oracle-instantclient-basiclite (21.7.0.0.0-2) ...
Setting up oracle-instantclient-basiclite (21.7.0.0.0-2) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...

~/oracle-instantclient$ sudo dpkg -i oracle-instantclient-sqlplus_21.7.0.0.0-2_amd64.deb
Selecting previously unselected package oracle-instantclient-sqlplus.
(Reading database ... 56550 files and directories currently installed.)
Preparing to unpack oracle-instantclient-sqlplus_21.7.0.0.0-2_amd64.deb ...
Unpacking oracle-instantclient-sqlplus (21.7.0.0.0-2) ...
Setting up oracle-instantclient-sqlplus (21.7.0.0.0-2) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...
```

libaio-1を入れるといいみたいだが、とりあえず入れずに使ってみる
入れる場合は以下やる

```
sudo apt install libaio1
```

環境変数をセットする
.bashrcに以下を追記し、再読み込みする

```
export ORACLE_HOME=/usr/lib/oracle/21/client64
export PATH=~/.local/bin:~/bin:$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
```

接続テスト

```
~/oracle-instantclient$ sqlplus user/pass@hostname:1521/servicename

SQL*Plus: Release 21.0.0.0.0 - Production on Fri Jul 22 13:27:23 2022
Version 21.7.0.0.0

Copyright (c) 1982, 2022, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Release 11.2.0.4.0 - 64bit Production

SQL>
```

OK

# /mnt/cのサブディレクトリでalian実行時のエラー

```
$ sudo alien --to-deb oracle-instantclient-basiclite-21.7.0.0.0-1.x86_64.rpm
Warning: Skipping conversion of scripts in package oracle-instantclient-basiclite: postinst postrm
Warning: Use the --scripts parameter to include the scripts.
Package build failed. Here's the log:
dh_testdir
dh_testdir
dh_testroot
dh_prep
dh_installdirs
dh_installdirs: warning: Compatibility levels before 9 are deprecated (level 7 in use)
dh_installdocs
dh_installdocs: warning: Compatibility levels before 9 are deprecated (level 7 in use)
dh_installchangelogs
find . -maxdepth 1 -mindepth 1 -not -name debian -print0 | \
        xargs -0 -r -i cp -a {} debian/oracle-instantclient-basiclite
dh_compress
dh_compress: warning: Compatibility levels before 9 are deprecated (level 7 in use)
dh_makeshlibs
dh_makeshlibs: warning: Compatibility levels before 9 are deprecated (level 7 in use)
dh_installdeb
dh_installdeb: warning: Compatibility levels before 9 are deprecated (level 7 in use)
dh_shlibdeps
dh_shlibdeps: warning: Compatibility levels before 9 are deprecated (level 7 in use)
dpkg-shlibdeps: error: cannot find library libclntsh.so.21.1 needed by debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/lib/libociicus.so (ELF format: 'elf64-x86-64' abi: '0201003e00000000'; RPATH: '')
dpkg-shlibdeps: error: cannot find library libclntshcore.so.21.1 needed by debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/lib/libociicus.so (ELF format: 'elf64-x86-64' abi: '0201003e00000000'; RPATH: '')
dpkg-shlibdeps: warning: debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/lib/libocci.so.21.1 contains an unresolvable reference to symbol OCIObjectGetObjectRef: it's probably a plugin
dpkg-shlibdeps: warning: 264 other similar warnings have been skipped (use -v to see them all)
dpkg-shlibdeps: error: cannot find library libclntsh.so.21.1 needed by debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/lib/liboramysql.so (ELF format: 'elf64-x86-64' abi: '0201003e00000000'; RPATH: '')
dpkg-shlibdeps: error: cannot find library libclntshcore.so.21.1 needed by debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/lib/liboramysql.so (ELF format: 'elf64-x86-64' abi: '0201003e00000000'; RPATH: '')
dpkg-shlibdeps: error: cannot find library libclntsh.so.21.1 needed by debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/lib/libocijdbc21.so (ELF format: 'elf64-x86-64' abi: '0201003e00000000'; RPATH: '')
dpkg-shlibdeps: error: cannot find library libclntshcore.so.21.1 needed by debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/lib/libocijdbc21.so (ELF format: 'elf64-x86-64' abi: '0201003e00000000'; RPATH: '')
dpkg-shlibdeps: warning: cannot find library libnnz21.so needed by debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/lib/libocijdbc21.so (ELF format: 'elf64-x86-64' abi: '0201003e00000000'; RPATH: '')
dpkg-shlibdeps: error: cannot find library libclntshcore.so.21.1 needed by debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/lib/libnnz21.so (ELF format: 'elf64-x86-64' abi: '0201003e00000000'; RPATH: '')
dpkg-shlibdeps: error: cannot find library libclntsh.so.21.1 needed by debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/bin/adrci (ELF format: 'elf64-x86-64' abi: '0201003e00000000'; RPATH: '')
dpkg-shlibdeps: error: cannot find library libclntshcore.so.21.1 needed by debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/bin/adrci (ELF format: 'elf64-x86-64' abi: '0201003e00000000'; RPATH: '')
dpkg-shlibdeps: warning: cannot find library libnnz21.so needed by debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/bin/adrci (ELF format: 'elf64-x86-64' abi: '0201003e00000000'; RPATH: '')
dpkg-shlibdeps: warning: debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/lib/libocci_gcc53.so.21.1 contains an unresolvable reference to symbol LdiParseForOutput: it's probably a plugin
dpkg-shlibdeps: warning: 273 other similar warnings have been skipped (use -v to see them all)
dpkg-shlibdeps: warning: cannot find library libnnz21.so needed by debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/lib/libclntsh.so.21.1 (ELF format: 'elf64-x86-64' abi: '0201003e00000000'; RPATH: '')
dpkg-shlibdeps: error: cannot find library libclntshcore.so.21.1 needed by debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/lib/libclntsh.so.21.1 (ELF format: 'elf64-x86-64' abi: '0201003e00000000'; RPATH: '')
dpkg-shlibdeps: error: cannot find library libclntsh.so.21.1 needed by debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/bin/genezi (ELF format: 'elf64-x86-64' abi: '0201003e00000000'; RPATH: '')
dpkg-shlibdeps: error: cannot find library libclntshcore.so.21.1 needed by debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/bin/genezi (ELF format: 'elf64-x86-64' abi: '0201003e00000000'; RPATH: '')
dpkg-shlibdeps: error: cannot continue due to the errors listed above
Note: libraries are not searched in other binary packages that do not have any shlibs or symbols file.
To help dpkg-shlibdeps find private libraries, you might need to use -l.
dh_shlibdeps: error: dpkg-shlibdeps -Tdebian/oracle-instantclient-basiclite.substvars debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/bin/adrci debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/bin/genezi debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/lib/libclntsh.so.21.1 debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/lib/libclntshcore.so.21.1 debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/lib/libnnz21.so debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/lib/libocci.so.21.1 debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/lib/libocci_gcc53.so.21.1 debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/lib/libociicus.so debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/lib/libocijdbc21.so debian/oracle-instantclient-basiclite/usr/lib/oracle/21/client64/lib/liboramysql.so returned exit code 2
dh_shlibdeps: error: Aborting due to earlier error
make: [debian/rules:27: binary-arch] Error 25 (ignored)
dh_gencontrol
dpkg-gencontrol: warning: Depends field of package oracle-instantclient-basiclite: substitution variable ${shlibs:Depends} used, but is not defined
dh_md5sums
dh_builddeb
dpkg-deb: error: control directory has bad permissions 777 (must be >=0755 and <=0775)
dh_builddeb: error: dpkg-deb --build debian/oracle-instantclient-basiclite .. returned exit code 2
dh_builddeb: error: Aborting due to earlier error
make: *** [debian/rules:30: binary-arch] Error 25
```

# 参考文献

https://goodbyegangster.hatenablog.com/entry/2019/08/22/193413
https://ponsuke-tarou.hatenablog.com/entry/2020/03/09/232129