Created
March 26, 2013 06:14
-
-
Save eckrel/5243492 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# PYTHON_PATH="~/.pyenv/versions/anaconda" | |
FIND_PYTHON_PATH=~/.pyenv/versions/anaconda | |
echo "where is anaconda path [${FIND_PYTHON_PATH}]: " | |
read INPUT | |
if [ "$INPUT" != "" ] ; then | |
FIND_PYTHON_PATH="$INPUT" | |
fi | |
echo "find files in $FIND_PYTHON_PATH ..." | |
texts=(`grep -rI anaconda1 $FIND_PYTHON_PATH | awk -F ":" '{ print $1 }' | grep -v ".orig$" | sort | uniq`) | |
libs1_tmp=(`find $FIND_PYTHON_PATH -name "*.dylib"`) | |
libs2_tmp=(`find $FIND_PYTHON_PATH -name "*.so"`) | |
libs_all=(${libs1_tmp[@]} ${libs2_tmp[@]}) | |
libs=() | |
for item in "${libs_all[@]}"; do | |
ret=`otool -L ${item} | grep anaconda1` | |
if [ "$ret" != "" ]; then | |
libs=(${libs[@]} $item) | |
fi | |
done | |
echo "== fixed files are ==" | |
for item in "${texts[@]}"; do echo "$item"; done | |
for item in "${libs[@]}"; do echo "$item"; done | |
echo | |
echo | |
echo "exec OK? [y/N]: " | |
read INPUT | |
if [ "$INPUT" != "y" ]; then | |
exit | |
fi | |
echo "== execution ==" | |
# set full path | |
SED_REGEX="s/\/opt\/anaconda1anaconda2anaconda3/"`echo "${FIND_PYTHON_PATH}" | sed "s/\\//\\\\\\\\\\//g"`"/g" | |
for item in "${texts[@]}"; do | |
sed -i ".orig" $SED_REGEX $item | |
echo "$item: FIXED" | |
done | |
for item in "${libs[@]}"; do | |
# fix id? | |
current_path=`otool -D $item | grep anaconda1 | head -1 | awk '{print \$1}'` | |
# next_path=`echo $current_path | sed "s/\/opt\/anaconda1anaconda2anaconda3/@executable_path\/../g"` # relative | |
next_path=$(echo $current_path | sed "s/\/opt\/anaconda1anaconda2anaconda3/"`echo "${FIND_PYTHON_PATH}" | sed "s/\\//\\\\\\\\\\//g"`"/g") # full | |
if [ "$current_path" != "" ]; then | |
# fix id | |
install_name_tool -id $next_path $item | |
else | |
current_path=`otool -L $item | grep anaconda1 | head -1 | awk '{print \$1}'` | |
# next_path=`echo $current_path | sed "s/\/opt\/anaconda1anaconda2anaconda3/@executable_path\/../g"` | |
next_path=$(echo $current_path | sed "s/\/opt\/anaconda1anaconda2anaconda3/"`echo "${FIND_PYTHON_PATH}" | sed "s/\\//\\\\\\\\\\//g"`"/g") # full | |
while [ "$current_path" != "" ]; do | |
# dep lib | |
install_name_tool -change $current_path $next_path $item | |
current_path=`otool -L $item | grep anaconda1 | head -1 | awk '{print \$1}'` | |
# next_path=`echo $current_path | sed "s/\/opt\/anaconda1anaconda2anaconda3/@executable_path\/../g"` | |
next_path=$(echo $current_path | sed "s/\/opt\/anaconda1anaconda2anaconda3/"`echo "${FIND_PYTHON_PATH}" | sed "s/\\//\\\\\\\\\\//g"`"/g") # full | |
done | |
fi | |
echo "$item: FIXED" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment