LoginSignup
15
11

More than 3 years have passed since last update.

MacOSでbash 4.4.xを最終版にする【重要】

Last updated at Posted at 2019-01-13

MacOS
bash 4.4.18
bash 4.4.23

MacOSを更新(アップグレード)したら最初にBashの最新版を入れるべき。

1.注意点

[bash shellshock]で検索すると問題が分かる。
GNU bash の脆弱性 ~ shellshock 問題~ について
OSを10.9->10.11にした場合など、MacOSを更新(アップグレード)したら最初にBashの最新版を入れるべき。

Bash - GNU Project - Free Software Foundation( https://www.gnu.org/software/bash )

bashは手動でダウンロード、.configure、make、sudo make installするのがベスト。
/bin/bashは消さないこと。

手動、あるいはbrewでlibiconvをインストールしないこと。
libiconv以外にも他にもあるかもしれない。

2.筆者はlibiconvインストールを推奨しない。

筆者はbashインストール前に、手動かbrew install libiconvでインストールを推奨しない。

もし万一、homebrew、libiconv又はlibiconv周りの調子が悪くなるとbash環境が壊れて、ターミナルが全く使えない場合がある。
cygwin版やmac版libiconvだけの問題で必ず起こるわけではないかもしれない。
(brew全削除が困難になる)
筆者はLinux版libiconvを入れことがなくlinuxは問題ないのかもしれない。

また安易にbrew install bashを推奨しているサイトが多い。
brewのソフトでbashしか使わないのであればいいが、通常は他のソフトもインストールすると思われる。
homebrewトラブル時に対処できない人が多いのでは?

Macでログインシェルを確認/変更するいくつかの方法

3.bash ビルドを行う。

brewのソフトやlibiconvを入れる前に行う。

curl -#LO http://ftp.jaist.ac.jp/pub/GNU/bash/bash-4.4.18.tar.gz
(オプションは-#ROなどでも可)
tar xvfz bash-4.4.18.tar.gz
cd bash-4.4.18
./configure
make
sudo make install

sudo bash -c 'echo /usr/local/bin/bash >> /etc/shells'

chsh -s /usr/local/bin/bash
(再起動)

Upgrade to bash 4 in Mac OS X – clubmate.fi

4−0.bash4.4.18にbash44-019以降のパッチを当てる。

上記では既にbash4.4.18をインストールしてログインシェルとしているので注意。

4−1.パッチダウンロード

連番の場合はダブルクォーテーションが必要
Oのオプションを使えば保存。
oの場合はファイル名を指定。Oはそのファイル名のまま保存。

bash-4.4.18 $ curl -L -O "http://ftp.gnu.org/gnu/bash/bash-4.4-patches/bash44-[019-023]"

[1/5]: http://ftp.gnu.org/gnu/bash/bash-4.4-patches/bash44-019 --> bash44-019
--_curl_--http://ftp.gnu.org/gnu/bash/bash-4.4-patches/bash44-019
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1671  100  1671    0     0   5180      0 --:--:-- --:--:-- --:--:--  5189

[2/5]: http://ftp.gnu.org/gnu/bash/bash-4.4-patches/bash44-020 --> bash44-020
--_curl_--http://ftp.gnu.org/gnu/bash/bash-4.4-patches/bash44-020
100  5156  100  5156    0     0  32056      0 --:--:-- --:--:-- --:--:-- 32056

[3/5]: http://ftp.gnu.org/gnu/bash/bash-4.4-patches/bash44-021 --> bash44-021
--_curl_--http://ftp.gnu.org/gnu/bash/bash-4.4-patches/bash44-021
100  1810  100  1810    0     0  11288      0 --:--:-- --:--:-- --:--:-- 11288

[4/5]: http://ftp.gnu.org/gnu/bash/bash-4.4-patches/bash44-022 --> bash44-022
--_curl_--http://ftp.gnu.org/gnu/bash/bash-4.4-patches/bash44-022
100  1818  100  1818    0     0  11365      0 --:--:-- --:--:-- --:--:--     0

[5/5]: http://ftp.gnu.org/gnu/bash/bash-4.4-patches/bash44-023 --> bash44-023
--_curl_--http://ftp.gnu.org/gnu/bash/bash-4.4-patches/bash44-023
100  1557  100  1557    0     0   9656      0 --:--:-- --:--:-- --:--:--  9656
bash-4.4.18 $

4−2.パッチを当てる

bash-4.4.18 $ find ./bash44-???
./bash44-019
./bash44-020
./bash44-021
./bash44-022
./bash44-023

$ find ./bash44-??? -exec /bin/sh -c 'patch -p0 < {}' \;
patching file lib/readline/display.c
patching file patchlevel.h
patching file jobs.c
patching file patchlevel.h
patching file jobs.c
patching file patchlevel.h
patching file lib/readline/readline.c
patching file patchlevel.h
patching file builtins/trap.def
patching file patchlevel.h
bash-4.4.18 $

4−3.bashビルド

一旦、homebrewを動作させないようにする

$ export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

ビルド

$ ./configure
$ make
$ ./bash --version
GNU bash, バージョン 4.4.23(1)-release (x86_64-apple-darwin13.4.0)
(中略)
選択肢1
$ chsh -s /usr/local/bin/bash
選択肢2
$ chsh -s /bin/bash(インストール後に/bin/bashへコピーを行う)

/etc/shellsに「/usr/local/bin/bash」必要な場合は以下を実行
(sudo bash -c 'echo /usr/local/bin/bash >> /etc/shells')

4−4.bashインストール

$ sudo make install

選択肢1
/usr/local/bin/bashをメインに使う。(古い/bin/bashを残す)
選択肢2
$ sudo cp /usr/local/bin/bash /bin/bash(筆者はこちらが好み)

Macを再起動してchshした先のbashで動作を確認すること

以上

動作未確認
wget http://ftp.gnu.org/gnu/bash/bash-4.4-patches/bash44-{001..033}


以上

--

15
11
4

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
15
11