Created
June 25, 2019 07:10
-
-
Save caramelchocolate/de4b98d0dfb7f2c2a47df5ae386d49ff to your computer and use it in GitHub Desktop.
pkg bootstrap and install latest version of python
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/sh | |
pkg_base_path="/usr/local/bin/" | |
get_python_path () { | |
ls -1 "${pkg_base_path}" | grep -E '^python[0-9]{1}\.[0-9]{1}$' | |
} | |
pkg -N > /dev/null | |
st_code=$? | |
if [ "${st_code}" -eq 1 ]; then | |
env ASSUME_ALWAYS_YES=YES pkg bootstrap -f > /dev/null | |
fi | |
# python install check | |
pkg info | grep python | |
st_code=$? | |
if [ "${st_code}" -eq 0 ]; then | |
path=$(get_python_path) | |
echo '{ | |
"changed": false, | |
"path": "'"${pkg_base_path}${path}"'" | |
}' | |
else | |
# get latest version of python | |
pkg_name=$(pkg search 'python' | awk '{print $1}' | grep -E "^python[0-9]{1,}" | sort -r | head -n 1) | |
env ASSUME_ALWAYS_YES=YES pkg install "${pkg_name}" > /dev/null | |
path=$(get_python_path) | |
echo '{ | |
"changed": true, | |
"path": "'"${pkg_base_path}${path}"'" | |
}' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment