[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 |
---|
[7f335a4] | 12 | # full path to the install logs |
---|
| 13 | install_log=${current}/var/log/install.log |
---|
[7783f97] | 14 | |
---|
| 15 | set_scripts_permissions() { |
---|
[7f335a4] | 16 | echo "Setting up script permissions" |
---|
[7783f97] | 17 | # ensure the shell scripts we will need have proper permissions |
---|
| 18 | chmod u+x ${current}/bin/js_deps |
---|
| 19 | chmod u+x ${current}/bin/start |
---|
| 20 | } |
---|
| 21 | |
---|
[d17dffe] | 22 | check_python3() { |
---|
| 23 | # if python3 is not installed, exit with an error |
---|
| 24 | if command -v python3 > /dev/null; then |
---|
| 25 | # ok |
---|
| 26 | python_bin=`command -v python3` |
---|
[7f335a4] | 27 | echo "Found valid python installation: ${python_bin}" |
---|
[d17dffe] | 28 | return |
---|
| 29 | else |
---|
| 30 | # no python3 binary, look for python |
---|
| 31 | if command -v python > /dev/null; then |
---|
| 32 | # python found, check if it is 3.x |
---|
| 33 | if `command -v python` -c "import sys; exit(0) if sys.version.startswith('3.') else exit(1)"; then |
---|
| 34 | python_bin=`command -v python` |
---|
[7f335a4] | 35 | echo "Found valid python installation: ${python_bin}" |
---|
[d17dffe] | 36 | return |
---|
| 37 | else |
---|
| 38 | # no python binary, error |
---|
| 39 | echo "Error: could not find a suitable python version installed, please install python 3.x" |
---|
| 40 | exit 1 |
---|
| 41 | fi |
---|
| 42 | else |
---|
| 43 | # no python binary, error |
---|
| 44 | echo "Error: could not find a suitable python version installed, please install python 3.x" |
---|
| 45 | exit 1 |
---|
| 46 | fi |
---|
| 47 | fi |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | create_venv() { |
---|
| 51 | # create a new virtual environment |
---|
[7f335a4] | 52 | echo "Creating new python virtual environment [${env_path}]" |
---|
[d17dffe] | 53 | ${python_bin} -m venv ${env_path} |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | upgrade_pip_setuptools() { |
---|
| 57 | . ${env_path}/bin/activate |
---|
[7f335a4] | 58 | echo "Upgrading python packaging tools" |
---|
| 59 | yes | pip install --upgrade setuptools pip >> ${install_log}.stdout 2>> ${install_log}.stderr |
---|
[d17dffe] | 60 | deactivate |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | install_openworkouts() { |
---|
| 64 | . ${env_path}/bin/activate |
---|
[7f335a4] | 65 | echo "Installing OpenWorkouts dependencies" |
---|
| 66 | yes | pip install --upgrade -e ${current}[testing] >> ${install_log}.stdout 2>> ${install_log}.stderr |
---|
[d17dffe] | 67 | deactivate |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | install_js_deps() { |
---|
[7f335a4] | 71 | echo "Installing javascript components" |
---|
| 72 | ${current}/bin/js_deps >> ${install_log}.stdout 2>> ${install_log}.stderr |
---|
[d17dffe] | 73 | } |
---|
| 74 | |
---|
| 75 | setup_start_stop() { |
---|
| 76 | echo "OpenWorkouts successfully installed in ${env_path}" |
---|
| 77 | echo "" |
---|
| 78 | echo "You can now start the OpenWorkouts service calling:" |
---|
| 79 | echo "" |
---|
| 80 | echo " cd ${current} && ./bin/start" |
---|
| 81 | echo "" |
---|
[7f335a4] | 82 | echo "(the installation script left a log under ${install_log})" |
---|
| 83 | echo "" |
---|
[d17dffe] | 84 | # echo "You can stop any running OpenWorkouts instances calling:" |
---|
| 85 | # echo "" |
---|
| 86 | # echo " ${current}/bin/stop" |
---|
| 87 | # echo "" |
---|
| 88 | } |
---|
| 89 | |
---|
[4af38e8] | 90 | set_scripts_permissions |
---|
[d17dffe] | 91 | check_python3 |
---|
| 92 | create_venv |
---|
| 93 | upgrade_pip_setuptools |
---|
| 94 | install_openworkouts |
---|
| 95 | install_js_deps |
---|
| 96 | setup_start_stop |
---|