Repository navigation
Expand file tree
/
Copy pathsetup_python.sh
More file actions
56 lines (47 loc) · 1.68 KB
/
Copy pathsetup_python.sh
File metadata and controls
56 lines (47 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
set -euo pipefail
PYTHON_KEY="python"
# Get the version
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
PYTHON_VERSION=$(jq -r --arg keyvar "$PYTHON_KEY" '.[$keyvar]' "$SCRIPT_DIR/versions.json")
if ! command -v pyenv &> /dev/null; then
echo "Installing PyEnv for management of Python versions"
curl --proto '=https' --tlsv1.2 https://pyenv.run -sSf | sh -s -- --help
echo ""
echo "Adding pyenv to your local environment"
function append_pyenv_init_to_file () {
FILE="$1"
if [[ -f "$FILE" ]]; then
ALREADY_INSTALLED=$(grep -c "pyenv" "$FILE") || true
if [ "$ALREADY_INSTALLED" -eq 0 ]; then
echo "Appending pyenv preamble to $FILE"
{
# shellcheck disable=SC2016
echo 'export PYENV_ROOT="$HOME/.pyenv"'
# shellcheck disable=SC2016
echo 'if [ ! $(command -v pyenv >/dev/null) ]; then if [[ -d "$PYENV_ROOT"/bin ]]; then export PATH="$PYENV_ROOT/bin:$PATH" fi; fi; fi'
# shellcheck disable=SC2016
echo 'eval "$(pyenv init -)"'
# shellcheck disable=SC2016
echo 'eval "$(pyenv init --path)"'
} >> "$FILE"
else
echo "$FILE already contains the pyenv preamble."
fi
else
echo "Skipping appending to $FILE. It does not exist."
fi
}
export PYENV_ROOT="/home/gensyn/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
append_pyenv_init_to_file "/home/gensyn/.zshrc"
append_pyenv_init_to_file "/home/gensyn/.bashrc"
append_pyenv_init_to_file "/home/gensyn/.profile"
fi
echo ""
echo "Installing Python $PYTHON_VERSION"
pyenv install "$PYTHON_VERSION"
echo ""
echo "Setting Python $PYTHON_VERSION as the default."
pyenv global "$PYTHON_VERSION"
echo "Complete. Please reload your shell."