bashで/sbinも確実にコマンド検索したい。

■Squeezeだけでなく、Lenny、CentOS5.6でも通る、
 インストーラと再パッケージ化スクリプトを書いてたら
 古いファイルで上書きしてしまったので、
 もうやる気を失った。

 異なるディストロをサポートするメインの部分だけ。

■たとえばこんな単純なコマンド

$ whereis -b ifconfig
ifconfig: /sbin/ifconfig

■「test.sh」を以下のようにすると。。。

$ cat test.sh
#!/bin/bash
ifconfig

$ chmod +x test.sh
$ ./test.sh
./test.sh: line 4: ifconfig: command not found

■意図した環境変数を引き継ぐ方法

 ユーザ権限で実行する場合や、CentOSなど、「/sbin」のパスが通っていない場合や、
 ユーザ環境をデフォルトでは引き継がないcronなどのスクリプトが対象。

 「/etc/init.d/」配下のコードは「set -e」で環境変数を引き継ぐのが定番なので。

$ test.sh
#!/bin/bash
set -e
echo ${PATH} |sed s/":"/"\n"/g | grep "^/sbin\$" || export PATH=/sbin:${PATH}
ifconfig

$ ./test.sh > /dev/null && echo "ok"
ok

■中のバージョンでの振り分けは別として、
 ディストロの振り分け。

test -f /etc/redhat_release && echo "Redhat or CentOS"
test -f /etc/debian_version && echo "debian"

他にも色々修正したけど、消えたので、また後日。。。