Last active
August 29, 2015 14:27
-
-
Save yarko/e653ecb1180c2fc434da to your computer and use it in GitHub Desktop.
mac homebrew python3 devel install prioritization & link checks
This file contains hidden or 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
#!/usr/bin/env bash | |
# When "brew upgrade python3 --devel", make the devel version | |
# the default python3 version, along w/ other py3-tools | |
# brew python 3.5 --devel installs seem to consistently mislink. | |
# this tries to correct. | |
# first, make any python3 apps in bin point to the python3-devel version | |
# next, make any current release python apps link to version-specific | |
# names, e.g. python3 => python3.5, but python3.4 => python3.4 | |
BN='/usr/local/bin' | |
PY='/usr/local/Cellar/python3' | |
DEBUG() { | |
# pick one of the following lines | |
: | |
# echo "$*" | |
} | |
## pass these into the script to modify defaults | |
# the release py3 version | |
REL="${REL:-3.4.3}" | |
#default to last created directory | |
DEV="${DEV:-$(ls -rt ${PY} | tail -1)}" | |
# 1) check for scripts which don't link to the DEV version | |
scr=() # collect DEV scripts | |
for i in $PY/$DEV/bin/*; do | |
scr+=(${i/*\//}); | |
done | |
# cd, so we can pass the array to ls; 9th field (i) is target filename | |
(cd $BN; ls -l ${scr[@]}) | | |
grep -v $DEV | while read a a a a a a a a i a; do # a is discarded; | |
# assuming everything in bin space is a symlink | |
if [ -L $BN/$i ]; then | |
ln -s -f $PY/$DEV/bin/$i $BN/$i | |
else # for now, just report it... | |
echo ">>> NOT PROCESSESED: $BN/$i" | |
fi | |
done | |
# 2) for BN located scripts, check the shell executor (if DEV) | |
# none for now, but check anyway: | |
### >>> done in the if...else..., above | |
# | |
# 3) for DEV scripts, check the target shell executor (redirect w/ brew) | |
# sort thru the scripts, and find the uniq references - | |
# most likely they will point to a single 'opt' instance, which may | |
# need updating; | |
shell_runner() { | |
if file -b $1 | fgrep 'script text'>/dev/null; then | |
# filter those paths which don't match our DEV version | |
head -1 $1 | grep -v $DEV | |
fi | |
} | |
# list of target scripts; | |
# these point somewhere other than DEV in Cellar | |
trg=() | |
for i in $PY/$DEV/bin/*; do | |
# these will most likely link into Cellar/.../Frameworks scripts: | |
# if it's not a script, don't process | |
n=$(shell_runner $i) | |
DEBUG " >> n: [$n] ${#n}" | |
[ -z "$n" ] || trg+=(/${n#*/}) | |
done # | sort -u | cut -c 3-)) | |
DEBUG "...trg: [${trg[@]}]" | |
# next, make sure these are run by the correct DEV version | |
for i in $(echo ${trg[@]} | tr ' ' '\n'| sort -u); do | |
# collected the linked-to shell executor, e.g. #!/bin/foo | |
# now find the links | |
unset n | |
# 9th item of (ls -l) is our link to replace | |
DEBUG "i: $i" | |
read a a a a a a a a n a < <( | |
ls -l /${i} | grep -v $DEV | |
) | |
DEBUG "... n: [${n}] (${#n})" | |
if [ -n "$n" ]; then | |
# pick same target as Cellar space has for this cmd: | |
# e.g. ${n##*/} == python3.5 | |
dest=$(ls -l $PY/$DEV/bin/${n##*/}) | |
# link, e.g., python3.5 to same destination as DEV's link | |
DEBUG " ..." ln -s -f "${dest/* /}" $n | |
ln -s -f "${dest/* /}" $n | |
fi | |
done | |
### finally, verify all REL scripts are properly linked | |
scr=() | |
# release version is just the major.minor part of REL: | |
for i in $PY/$REL/bin/*${REL%.*}; do | |
scr+=(${i##*/}) | |
done | |
echo "Verifying $REL is appropriately linked:" | |
(cd $BN; ls -l ${scr[@]}) | grep -v $REL | |
echo "...if any links were shown above, these need fixing." | |
echo "DONE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment