Logical Rabbit.

さくらのVPS

bash

CentOS 3.9環境のbashを最新版に更新する

色々あってOSが古いままの環境で、せめてbashだけをshellshockから回避したい。

CentOS 3.9のbashはバージョン2.5が最終。

ログインシェルなので単純にyum erase bash とかやると依存関係がバギバギ出てくる。なので上書きインストールで行く(ていうか最終目標はOSの入れ替えなので、ここであまり丁寧に作業して時間をとりたくない)。

ということで以下作業記録。

現在bash関連物品が入っている場所の確認。個々のファイルは見ていられないのでdirnameで端折る。

rpm -q --list bash|xargs -l -i dirname {} |uniq
/bin
/etc/skel
/usr/lib
/usr/share/doc
/usr/share/doc/bash-2.05b
/usr/share/doc/bash-2.05b/bashdb
/usr/share/doc/bash-2.05b
/usr/share/doc/bash-2.05b/complete
/usr/share/doc/bash-2.05b
/usr/share/doc/bash-2.05b/functions
/usr/share/doc/bash-2.05b
/usr/share/doc/bash-2.05b/loadables
/usr/share/doc/bash-2.05b/loadables/perl
/usr/share/doc/bash-2.05b/loadables
/usr/share/doc/bash-2.05b
/usr/share/doc/bash-2.05b/misc
/usr/share/doc/bash-2.05b
/usr/share/doc/bash-2.05b/scripts.noah
/usr/share/doc/bash-2.05b
/usr/share/doc/bash-2.05b/scripts.v2
/usr/share/doc/bash-2.05b/scripts
/usr/share/doc/bash-2.05b
/usr/share/doc/bash-2.05b/startup-files
/usr/share/doc/bash-2.05b/startup-files/apple
/usr/share/doc/bash-2.05b/startup-files
/usr/share/info
/usr/share/man/man1

現状のタイムスタンプを確認。

$ ls -l /bin/bash*
-rwxr-xr-x 1 root root 585908 May 30 2006 /bin/bash
lrwxrwxrwx 1 root root 4 Mar 2 2007 /bin/bash2 -> bash

$ ls -l /usr/share/info/bash*
-rw-r--r-- 1 root root 94034 May 30 2006 /usr/share/info/bash.info.gz

$ ls -l /usr/share/man/man1/bash*
-rw-r--r-- 1 root root 64921 May 30 2006 /usr/share/man/man1/bash.1.gz

最新版をビルド。bash 4.3にパッチまで当ててやっとshellshockが解消するので、パッチも全部当てる(正確には28まで当てればよかったはず)。

このとき上書きされるようにprefix、bindir、sysconfdirをいじる。基本的に/usr以下に入っているのに実行コマンドだけが /bin にあるのがいやらしい。

$ tar xfz bash-4.3.tar.gz
$ cd bash-4.3
$ for patchfile in `ls -1 ../bash43-*`; do echo $patchfile; patch -p0 < $patchfile; done
$ grep "#define PATCHLEVEL" patchlevel.h
#define PATCHLEVEL 30

$ ./configure --prefix=/usr --bindir=/bin --sysconfdir=/etc
$ make ; make check ; echo $?

0
$ ./bash --version
GNU bash, version 4.3.30(1)-release (i686-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

上書きインストールする。

$ sudo make install

インストール結果確認。

$ which bash
/bin/bash

$ bash --version
GNU bash, version 4.3.30(1)-release (i686-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ ls -l /bin/bash*
-rwxr-xr-x 1 root root 1832115 Oct 15 06:51 /bin/bash
lrwxrwxrwx 1 root root 4 Mar 2 2007 /bin/bash2 -> bash
-r-xr-xr-x 1 root root 6800 Oct 15 06:51 /bin/bashbug

$ ls -l /bin/bash*
-rwxr-xr-x 1 root root 1832115 Oct 15 06:51 /bin/bash
lrwxrwxrwx 1 root root 4 Mar 2 2007 /bin/bash2 -> bash
-r-xr-xr-x 1 root root 6800 Oct 15 06:51 /bin/bashbug
$ ls -l /usr/share/info/bash*
-rw-r--r-- 1 root root 486450 Oct 15 06:51 /usr/share/info/bash.info
-rw-r--r-- 1 root root 94034 May 30 2006 /usr/share/info/bash.info.gz

$ ls -l /usr/share/man/man1/bash*
-rw-r--r-- 1 root root 299110 Oct 15 06:51 /usr/share/man/man1/bash.1
-rw-r--r-- 1 root root 64921 May 30 2006 /usr/share/man/man1/bash.1.gz
-rw-r--r-- 1 root root 1817 Oct 15 06:51 /usr/share/man/man1/bashbug.1

man bash とか info bash の結果はちゃんと4.3が出てくるけど、旧バージョンのgzファイルが後々混乱の元になりそうなので、新バージョンの非圧縮ファイルをgzip圧縮したもので上書きしておく。

/bin/bash へのシンボリックリンクになっている/bin/shも、ちゃんとバージョンアップされた。

$ sh --version
GNU bash, version 4.3.30(1)-release (i686-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

/usr/share/doc/bash-2.05b は実害無いし面倒くさいので後で削除しよう(そして忘れる)。

どっとはらい。