Last active
December 19, 2018 09:56
-
-
Save dtaskoff/a71379bb89239622bdf72dfa9d1e8844 to your computer and use it in GitHub Desktop.
A script used for modifying the ghc's scripts installed by stack, so that they use a local sh executable
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
stackargs=$@ | |
shbin="$(which sh)" | |
if [ -z "$shbin" ] || [[ "$shbin" =~ "not found" ]]; then | |
echo "Couldn't find sh, exiting." | |
exit 1 | |
else | |
echo "Found sh: $shbin" | |
fi | |
compilerbin=$(stack path $stackargs | grep compiler-bin | cut -d' ' -f2) | |
echo "Current project's compiler-bin: $compilerbin" | |
cd $compilerbin | |
echo "Modifying the scripts in $compilerbin.." | |
sedexpr="s@#!$shbin@#!$compilerbin/sh@" | |
for file in $(ls) | |
do | |
# Modify every $file that is neither a symlink nor a binary file, | |
# nor is it a .bak file generated by a previous execution of this same script | |
if [[ ! -L "$file" ]] && [[ ! "$(file -b --mime $file)" =~ "binary" ]] && [[ ! "$file" =~ \.bak$ ]]; then | |
echo "Modifying $file.." | |
sed -i .bak "$sedexpr" $file | |
fi | |
done | |
echo "Copying $shbin to $compilerbin.." | |
cp $shbin $compilerbin | |
# Modify the write permissions of the copied 'sh', | |
# so that running this script again doesn't fail | |
chmod u+w $compilerbin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment