002_网上脚本执行请注意,慎重

一、进坑过程如下

执行ansible遇到这种错误:
(1)
dyld: Library not loaded: @executable_path/../.Python
  Referenced from: /your/home/.virtualenvs/virtualenv_name/bin/python
  Reason: image not found
[1]    95221 trace trap  python

(2)于是从Google查解决方案。看到是之前同事写的,就没细看就执行了,执行关键内容如下
#https://gist.github.com/tevino/1a557a0c200d61d4e4fb

read -p "‼️  Press Enter if you are not sure (y/N) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
    echo "♻️  Removing old symbolic links......"
    find "$ENV_PATH" -type l -delete -print      #######important########
    echo "💫  Creating new symbolic links......"
    $SYSTEM_VIRTUALENV "$ENV_PATH"
    echo "🎉  Done!"
fi

(3)执行完就哭了,很多命令都找不到了,原因是删除了/usr/local及/usr/local/bin下的所有软连接

(4)粗糙的执行恢复:
cd /usr/local/bin
for i in `ls ../Cellar/*/*/bin`;do
    softlinksrc=`sudo find /usr/local/Cellar  -name $i|sed  's#/usr/local#..#g'`
    ln -s $softlinksrc .
done
(5)或执行以下恢复
Updating Homebrew...
Warning: nginx 1.13.12 is already installed, it's just not linked
You can use `brew link nginx` to link this version.
即:
brew link custom_software_name
➜  nginx brew link --overwrite --dry-run wget
Would remove:
/usr/local/bin/wget -> /usr/local/Cellar/wget
../Cellar/wget/1.19.1_1/bin/wget
(6)
for cs in `ls /usr/local/Cellar`;do
    brew link --overwrite --dry-run $cs
    brew link $cs
done

拿wget举例:

这种warning单独处理下吧.已经提示很明显了

二、总结

坑的连接如下:
#https://gist.github.com/tevino/1a557a0c200d61d4e4fb

其中有个叫laymonk的哥们明确说了这有坑了,所以以后Google和github出的内容一定要看完,谨记!!!

laymonk commented on Oct 7, 2016 • 
I stumbled upon this, and just had to comment.

I imagine you reckon you are being helpful, but this a most dangerous thing to ask people to run. Running it could easily delete all links in /usr/local, which is the standard place homebrew installs pip (so, your $ENV_PATH will be /usr/local)

The simple fix involves just cd'ing into the virtualenv, and deleting all the stale links to the upgraded python by running:
find . -type l -delete

.. and then re-installing your virtualenv:
mkvirtualenv venv-name or virtualenv venv-name

An unsuspecting user may not understand the implication of answering yes, and have all symlinks blown away from /usr/local .. I think you should take this down, or amend it. No offence intended.

三、遗留问题处理

(1)diagnosis

➜  ~ brew doctor    #根据brew doctor的建议进行响应的操作,notice warning section.
Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  python
  ruby
  vim

Warning: Homebrew's sbin was not found in your PATH but you have installed
formulae that put executables in /usr/local/sbin.
Consider setting the PATH for example like so
  echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.zshrc

Warning: Broken symlinks were found. Remove them with `brew prune`:
  /usr/local/bin/bin
  /usr/local/bin/erb
  /usr/local/bin/gem
  /usr/local/bin/irb
  /usr/local/bin/rake
  /usr/local/bin/rdoc
  /usr/local/bin/ri
  /usr/local/bin/ruby
  /usr/local/bin/sqlite3

(2)multi-version question

➜  ~ brew ls --versions | grep vim
vim 8.0.1250 8.0.1600
➜  ~ brew uninstall --force vim
➜  ~ brew install vim    #解决

 

posted @ 2018-05-03 13:12  arun_yh  阅读(712)  评论(0编辑  收藏  举报