[d17dffe] | 1 | #!/bin/sh |
---|
| 2 | # |
---|
| 3 | # Script to install OpenWorkouts for development |
---|
| 4 | # |
---|
| 5 | |
---|
| 6 | # Full path to where we run the script from |
---|
| 7 | current=`pwd` |
---|
| 8 | # Full path to the main python binary (will be set by check_python3()) |
---|
| 9 | python_bin='' |
---|
| 10 | # Full path to the env |
---|
| 11 | env_path=${current}/env |
---|
| 12 | |
---|
[7783f97] | 13 | |
---|
| 14 | set_scripts_permissions() { |
---|
| 15 | # ensure the shell scripts we will need have proper permissions |
---|
| 16 | chmod u+x ${current}/bin/js_deps |
---|
| 17 | chmod u+x ${current}/bin/start |
---|
| 18 | chmod u+x ${current}/bin/screenshot_map |
---|
| 19 | } |
---|
| 20 | |
---|
[d17dffe] | 21 | check_python3() { |
---|
| 22 | # if python3 is not installed, exit with an error |
---|
| 23 | if command -v python3 > /dev/null; then |
---|
| 24 | # ok |
---|
| 25 | python_bin=`command -v python3` |
---|
| 26 | return |
---|
| 27 | else |
---|
| 28 | # no python3 binary, look for python |
---|
| 29 | if command -v python > /dev/null; then |
---|
| 30 | # python found, check if it is 3.x |
---|
| 31 | if `command -v python` -c "import sys; exit(0) if sys.version.startswith('3.') else exit(1)"; then |
---|
| 32 | python_bin=`command -v python` |
---|
| 33 | return |
---|
| 34 | else |
---|
| 35 | # no python binary, error |
---|
| 36 | echo "Error: could not find a suitable python version installed, please install python 3.x" |
---|
| 37 | exit 1 |
---|
| 38 | fi |
---|
| 39 | else |
---|
| 40 | # no python binary, error |
---|
| 41 | echo "Error: could not find a suitable python version installed, please install python 3.x" |
---|
| 42 | exit 1 |
---|
| 43 | fi |
---|
| 44 | fi |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | create_venv() { |
---|
| 48 | # create a new virtual environment |
---|
| 49 | ${python_bin} -m venv ${env_path} |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | upgrade_pip_setuptools() { |
---|
| 53 | . ${env_path}/bin/activate |
---|
| 54 | yes | pip install --upgrade setuptools pip |
---|
| 55 | deactivate |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | install_openworkouts() { |
---|
| 59 | . ${env_path}/bin/activate |
---|
| 60 | yes | pip install --upgrade --process-dependency-links -e ${current}[testing] |
---|
| 61 | deactivate |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | install_js_deps() { |
---|
| 65 | ${current}/bin/js_deps |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | setup_start_stop() { |
---|
| 69 | echo "OpenWorkouts successfully installed in ${env_path}" |
---|
| 70 | echo "" |
---|
| 71 | echo "You can now start the OpenWorkouts service calling:" |
---|
| 72 | echo "" |
---|
| 73 | echo " cd ${current} && ./bin/start" |
---|
| 74 | echo "" |
---|
| 75 | # echo "You can stop any running OpenWorkouts instances calling:" |
---|
| 76 | # echo "" |
---|
| 77 | # echo " ${current}/bin/stop" |
---|
| 78 | # echo "" |
---|
| 79 | } |
---|
| 80 | |
---|
[7783f97] | 81 | set_script_permissions |
---|
[d17dffe] | 82 | check_python3 |
---|
| 83 | create_venv |
---|
| 84 | upgrade_pip_setuptools |
---|
| 85 | install_openworkouts |
---|
| 86 | install_js_deps |
---|
| 87 | setup_start_stop |
---|
| 88 | |
---|
| 89 | echo ${python_bin} |
---|