Last active
October 1, 2021 20:54
-
-
Save neruthes/1559ff5ef6683ae3850eb246fdc64326 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# | |
# Copyright (c) 2021 Neruthes. | |
# Released under GNU GPLv2. | |
# | |
### Initialize config vars | |
DefaultPythonVer=3 | |
### Read config | |
source /etc/fakepython/conf | |
echo "Welcome to FakePython.">&2 | |
echo "You should put me at '/usr/bin/python',">&2 | |
echo "So I can decide the version expectation of the incoming script.">&2 | |
echo "This is a mitigation against stupid scripts who put this path in their shebang.">&2 | |
echo "Decisions are made by looking up '/etc/fakepython/list.force{2,3}*' for their paths.">&2 | |
echo "">&2 | |
SRCPATH=$(realpath $1) | |
echo "The script is: $SRCPATH">&2 | |
ALLARGS="$@" | |
OTHERARGS="" | |
COUNT=0 | |
for i in $ALLARGS; do | |
if [[ $COUNT == 0 ]]; then | |
COUNT=999 | |
else | |
OTHERARGS="$OTHERARGS $i" | |
fi | |
done | |
echo "The arguments are:">&2 | |
echo " $OTHERARGS">&2 | |
echo "">&2 | |
echo "Can we find this in 'list.force2'?" | |
if [[ "$(cat /etc/fakepython/list.force2* | grep "^$SRCPATH\$")" == "" ]]; then | |
echo "> Cannot find it.">&2 | |
else | |
echo "> YES!">&2 | |
echo "--------------------------------------------------------------------">&2 | |
exec /usr/bin/python2 "$@" | |
fi | |
echo "">&2 | |
echo "Can we find this in 'list.force3'?" | |
if [[ "$(cat /etc/fakepython/list.force3* | grep "^$SRCPATH\$")" == "" ]]; then | |
echo "> Cannot find it.">&2 | |
else | |
echo "> YES!">&2 | |
echo "--------------------------------------------------------------------">&2 | |
exec /usr/bin/python3 "$@" | |
fi | |
echo "">&2 | |
echo "">&2 | |
echo "If we reach here, there is no specific configuration for $SRCPATH">&2 | |
echo "Defaulting to /usr/bin/python$DefaultPythonVer">&2 | |
echo "exec /usr/bin/python$DefaultPythonVer \"$@\"">&2 | |
echo "--------------------------------------------------------------------">&2 | |
exec /usr/bin/python$DefaultPythonVer "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment