xcode 如何在 Mac OSX Snow Leopard 中升级 Bash [并将其设置为正确的路径]?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26080275/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:43:32  来源:igfitidea点击:

How do I upgrade Bash in Mac OSX Snow Leopard [and set it the correct path]?

xcodebashhomebrewosx-snow-leopardshellshock-bash-bug

提问by C-K

I want to update my Bash (and Sh) programs in my Mac OS X Snow Leopard (10.6.8), in light of the recent bugs to bash - Shellshock. I am purposely using 10.6.8, so I don't want to update to a newer version of OS X right now.

鉴于最近的 bash 错误 - Shellshock,我想在我的 Mac OS X Snow Leopard (10.6.8) 中更新我的 Bash(和 Sh)程序。我故意使用 10.6.8,所以我现在不想更新到更新版本的 OS X。

I have read this Q&A - How do I upgrade Bash in Mac OSX Mountain Lion and set it the correct path?but it doesn't work for me because I don't have [home?]brew (or Xcode, or any compiler, etc) installed. I'm just getting into doing programming on a Max OS X platform.

我已阅读此问答 -如何在 Mac OSX Mountain Lion 中升级 Bash 并将其设置为正确的路径?但它对我不起作用,因为我没有安装 [home?]brew(或 Xcode,或任何编译器等)。我刚刚开始在 Max OS X 平台上进行编程。

Btw, when I type brew update in terminal I get this output:

顺便说一句,当我在终端中输入 brew update 时,我得到了这个输出:

[489]$ brew update
-bash: brew: command not found

So, what steps (from scratch) do I need to do to be able to install a fixedversion of bashfor OS X 10.6.8?
Is it:

那么,我需要执行哪些步骤(从头开始)才能为 OS X 10.6.8安装固定版本的bash
是吗:

  1. Install XCode 3.2.6 (I'm currenlty downloading the 4.1 GB install file now)
  2. Install Homebrew (how though?)
  3. Follow steps in How do I upgrade Bash in Mac OSX Mountain Lion and set it the correct path??
  1. 安装 XCode 3.2.6(我现在正在下载 4.1 GB 的安装文件)
  2. 安装 Homebrew(如何安装?)
  3. 按照如何在 Mac OSX Mountain Lion 中升级 Bash 并将其设置为正确路径中的步骤操作??

Or, since I am using OS X 10.6.8, do I need to download Bash code from somewhere and compile it using XCode 3.2.6 (or 4.2 if I paid for it) and manually replace the /bin/bash and /bin/sh files?

或者,由于我使用的是 OS X 10.6.8,我是否需要从某处下载 Bash 代码并使用 XCode 3.2.6(或 4.2,如果我付费)并手动替换 /bin/bash 和 /bin/ .sh 文件?

Like I said, I am a new to all this on a Mac, but I do have [a bit out-of-date] programming experience.

就像我说的,我是 Mac 上的新手,但我确实有 [有点过时] 编程经验。

Thanks.

谢谢。

回答by paranoid

Homebrew is a package management system for Mac. A lot of people use it to manage mysql, python, and (as you could have guessed) bash. What Homebrew does is simply install these packages and makes them available to the user. While some people douse it for bash, updating bash with Homebrew doesn't protect their entire system from shellshock (which my team tested and identified today).

Homebrew 是 Mac 的包管理系统。很多人使用它来管理 mysql、python 和(您可能已经猜到)bash。Homebrew 所做的只是简单地安装这些软件包并使它们可供用户使用。虽然有些人确实将它用于 bash,使用 Homebrew 更新 bash 并不能保护他们的整个系统免受 shellshock(我的团队今天测试并确定)的影响。

What I would suggest you do is download XCode for your version of OS X, download the xcode command line utilities (by going to preferences -> downloads -> command line utilities) and then running this script I wrote. To be clear, this script is simply following the same steps outlined here, I just made it easier for the dev team to update.

我建议您做的是为您的 OS X 版本下载 XCode,下载 xcode 命令行实用程序(通过转到首选项 -> 下载 -> 命令行实用程序),然后运行我编写的这个脚本。需要明确的是,此脚本只是遵循此处概述的相同步骤,我只是让开发团队更容易更新。

You can copy this code into an executable bash script and run it using ./bash-fixer.sh

您可以将此代码复制到可执行的 bash 脚本中并使用 ./bash-fixer.sh 运行它

#!/bin/bash
# In all good conscience, I can not guarantee anything in this script. 
# I've tested it to the best of my ability, but please use at your own risk

    if [ "$EUID" -eq 0 ]; then
      echo "DO NOT RUN AS SUDO! Running as sudo will break the world and will make your computer very unhappy."
      echo "There are commands later that are appropriately sudo'd."
      exit 1
    fi

    xcode-select --version

    if [[ $? != 0 ]] ; then
      echo "You need to install the xcode stuff that makes magic. Let's try that together"
      xcode-select --install || echo "Something broke. Try running \"xcode-select --install\" manually" && exit 1
    fi

    cd ~/
    test=$( env x='() { :;}; echo vulnerable' bash -c 'echo hello' | wc -l )

    if [[ ${test} -lt 2 ]]; then
      echo "Your version of bash is up to date"
    else
      mkdir -p bash-fix
      cd bash-fix
      curl https://opensource.apple.com/tarballs/bash/bash-92.tar.gz | tar zxf -
      cd bash-92/bash-3.2
      for i in $(seq -f "%03g" 52 54); do
        curl https://ftp.gnu.org/pub/gnu/bash/bash-3.2-patches/bash32-$i | patch -p0
      done
      cd ..

      xcodebuild
      sudo cp /bin/bash /bin/bash.old
      sudo cp /bin/sh /bin/sh.old

      echo
      echo
      echo "Current version of bash is $(build/Release/bash --version | head -1 | awk -F "version " '{ print  }')"
      echo "Current version of sh is $(build/Release/sh --version | head -1 | awk -F "version " '{ print  }' )"

      if [[ $(build/Release/bash --version) =~ "3.2.54(1)-release" && $(build/Release/sh --version) =~ "3.2.54(1)-release" ]]; then
        echo "So far so good. Let's do some more checks, because we like dilligence"
      else
        echo "The bash and shell versions are not showing up as being the most recent. Something is afoot!"
        exit 1
      fi

      if [[ "${test}" < 2 ]]; then
        echo "Your version of bash is up to date"
        exit 0
      else
        echo "Something went horribly wrong!"
        exit 1
      fi

      echo "Awesome. All checks have passed. Cleaning up, and removing executable privaleges from the old bash and sh, just in case"
      sudo cp build/Release/bash /bin
      sudo cp build/Release/sh /bin
      sudo chmod a-x /bin/bash.old /bin/sh.old

    fi

Let me know how you make out, and good luck!

让我知道你是怎么做到的,祝你好运!

回答by v86

You can also do it in all-terminal-style (Lion update package given):

您也可以在所有终端样式(提供 Lion 更新包)中执行此操作:

# pkgutil --expand ~/BashUpdateLion.pkg ~/BashUpdate
# vi ~/BashUpdate/Distribution

edit the InstallationCheckand VolumeCheckfunctions to read like this:

InstallationCheckVolumeCheck函数编辑为如下所示:

function InstallationCheck(prefix) {
     return true;
}
function VolumeCheck(prefix) {
     return true;
}

and finally flatten it down to an installable package again

最后再次将其压平为可安装的包

# pkgutil --flatten ~/BashUpdate ~/Desktop/BashUpdateModified.pkg

回答by Jonathan Leffler

Note that Apple released a set of official patch versions of Bash on 2014-09-29. However, the support only goes as far back as Lion, not back to Snow Leopard. So, you are still stuck with building and installing your own patched version on Snow Leopard.

请注意,Apple 于 2014-09-29 发布了一组官方的 Bash 补丁版本。然而,支持只追溯到Lion,而不是Snow Leopard。因此,您仍然坚持在 Snow Leopard 上构建和安装您自己的补丁版本。

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

APPLE-SA-2014-09-29-1 OS X bash Update 1.0

OS X bash Update 1.0 is now available and addresses the following:

Bash
Available for: OS X Lion v10.7.5, OS X Lion Server v10.7.5, OS X Mountain Lion v10.8.5,
OS X Mavericks v10.9.5
Impact: In certain configurations, a remote attacker may be able to execute arbitrary
shell commands
Description: An issue existed in Bash's parsing of environment variables. This issue was
addressed through improved environment variable parsing by better detecting the end of
the function statement.
This update also incorporated the suggested CVE-2014-7169 change, which resets the
parser state.
In addition, this update added a new namespace for exported functions by creating a
function decorator to prevent unintended header passthrough to Bash. The names of all
environment variables that introduce function definitions are required to have a
prefix "__BASH_FUNC<" and suffix ">()" to prevent unintended function passing via
HTTP headers.
CVE-ID
CVE-2014-6271 : Stephane Chazelas
CVE-2014-7169 : Tavis Ormandy


OS X bash Update 1.0 may be obtained from the following webpages:
http://support.apple.com/kb/DL1767 – OS X Lion
http://support.apple.com/kb/DL1768 – OS X Mountain Lion
http://support.apple.com/kb/DL1769 – OS X Mavericks

To check that bash has been updated:

* Open Terminal
* Execute this command:
bash --version
* The version after applying this update will be:
OS X Mavericks:  GNU bash, version 3.2.53(1)-release (x86_64-apple-darwin13)
OS X Mountain Lion:  GNU bash, version 3.2.53(1)-release (x86_64-apple-darwin12)
OS X Lion:  GNU bash, version 3.2.53(1)-release (x86_64-apple-darwin11)

Information will also be posted to the Apple Security Updates
web site: http://support.apple.com/kb/HT1222

This message is signed with Apple's Product Security PGP key,
and details are available at:
https://www.apple.com/support/security/pgp/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.22 (Darwin)

iQIcBAEBAgAGBQJUKdToAAoJEBcWfLTuOo7t4QEP/jrigiLB9GYO5JIdVHSFPUtx
MBr4hAe90LnyAIuhxny1PgAC8BZCPv4otm6DQBQSlX1PxLv8TWm8yp5IKCKJP6ZN
Smm+OqJLLWwcTOVv345bi5W9dp2nyZVLjWxx9MUfn4YLxKrBJ3fKyHWIycD0WpbD
4kfXW1G1JGTtyUX6Ge2lnhbOiYBPxJN2TSX4qEmix3KLmEwCwsZVgbjzW2ijNO0O
3AaUkFIICAECMCE+VZj/fGFQaEmYaPzpt3Tjy+X2NdXL8E0hnui4ymfU0DyR39Oz
8DQpP499hISeXucdAEH6b2mMO2pOmuDs6FWTSS6talT8ftLUpTmWqv2Rghto5ZXN
b8RZpOp9RUwurZPMq66BjbHfidEaLjMPCVcfAnjO6HwBaKGQ5kM5+ThPA5/DLSL6
gGPa4t3qM/JdQAzm8da9m62vjWZ1BXzIlLSmxpIq/5bDMpBNiA783f+uuDUjpQ/N
3SkKNn2U47VsCLYaoSSmL6FUBLsInnNvwkVyNsnMiEjMVn/BtV5ogAYAc8SSvGM7
Mlx9OBKYork0bNuViPK09j/8te74tt6t38B+0lb4mG5m1r2CyI96f2uVBpKkqDlj
K6INwsDZKqtg1Y+6xtnJb9F3ZNZarzSxZa2C8qKaVCH11vLaXVPJJCrYspWnV8yI
DrlKtF9VhcfUGTKJiRNX
=ZVVk
-----END PGP SIGNATURE——

回答by George Of The Jungle

http://hacksagogo.wordpress.com/2014/10/02/shell-shock-os-x-bash-update-installer-for-snow-leopard/

http://hacksagogo.wordpress.com/2014/10/02/shell-shock-os-x-bash-update-installer-for-snow-leopard/

Here's for the crazy ones, the misfits, the trouble makers, the round pegs in the square holes. The ones who see things differently... and are still running Snow Leopard.

这是为疯狂的人、不合群的人、麻烦制造者、方孔中的圆钉准备的。那些以不同方式看待事物的人……并且仍在运行 Snow Leopard。

1.- Open bashUpdateLion.pkg in PackageMaker

1.- 在 PackageMaker 中打开 bashUpdateLion.pkg

2.- Goto project/raw editing mode and modify the functions “InstallationCheck” and “VolumeCheck” in the file “Distribution” to look like this:

2.- 进入项目/原始编辑模式并修改“Distribution”文件中的“InstallationCheck”和“VolumeCheck”功能,如下所示:

function InstallationCheck(prefix) {
    return true; }

function VolumeCheck(prefix) {
    return true; }

3.- Hit “build” and choose a name for the installer package.

3.- 点击“build”并为安装包选择一个名称。

That's all folks.

这就是所有的人。