[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 |
---|
[1d8d5cd] | 14 | # mail queue directory (where automatically generated emails are stored) |
---|
| 15 | mail_queue_path=${current}/var/spool/mqueue |
---|
[7783f97] | 16 | |
---|
| 17 | set_scripts_permissions() { |
---|
[7f335a4] | 18 | echo "Setting up script permissions" |
---|
[7783f97] | 19 | # ensure the shell scripts we will need have proper permissions |
---|
| 20 | chmod u+x ${current}/bin/js_deps |
---|
| 21 | chmod u+x ${current}/bin/start |
---|
| 22 | } |
---|
| 23 | |
---|
[d17dffe] | 24 | check_python3() { |
---|
| 25 | # if python3 is not installed, exit with an error |
---|
| 26 | if command -v python3 > /dev/null; then |
---|
| 27 | # ok |
---|
| 28 | python_bin=`command -v python3` |
---|
[7f335a4] | 29 | echo "Found valid python installation: ${python_bin}" |
---|
[d17dffe] | 30 | return |
---|
| 31 | else |
---|
| 32 | # no python3 binary, look for python |
---|
| 33 | if command -v python > /dev/null; then |
---|
| 34 | # python found, check if it is 3.x |
---|
| 35 | if `command -v python` -c "import sys; exit(0) if sys.version.startswith('3.') else exit(1)"; then |
---|
| 36 | python_bin=`command -v python` |
---|
[7f335a4] | 37 | echo "Found valid python installation: ${python_bin}" |
---|
[d17dffe] | 38 | return |
---|
| 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 | else |
---|
| 45 | # no python binary, error |
---|
| 46 | echo "Error: could not find a suitable python version installed, please install python 3.x" |
---|
| 47 | exit 1 |
---|
| 48 | fi |
---|
| 49 | fi |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | create_venv() { |
---|
| 53 | # create a new virtual environment |
---|
[1d8d5cd] | 54 | if [ ! -d ${env_path} ]; then |
---|
| 55 | echo "Creating new python virtual environment [${env_path}]" |
---|
| 56 | ${python_bin} -m venv ${env_path} |
---|
| 57 | else |
---|
| 58 | if [ ! -f ${env_path}/bin/activate ]; then |
---|
| 59 | # env dir found, but not a virtual env |
---|
| 60 | echo "Error: ${env_path} exists and is not a valid virtual environment" |
---|
| 61 | exit 1 |
---|
| 62 | else |
---|
| 63 | echo "Reusing python virtual environment [${env_path}]" |
---|
| 64 | fi |
---|
| 65 | fi |
---|
[d17dffe] | 66 | } |
---|
| 67 | |
---|
| 68 | upgrade_pip_setuptools() { |
---|
| 69 | . ${env_path}/bin/activate |
---|
[7f335a4] | 70 | echo "Upgrading python packaging tools" |
---|
| 71 | yes | pip install --upgrade setuptools pip >> ${install_log}.stdout 2>> ${install_log}.stderr |
---|
[d17dffe] | 72 | deactivate |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | install_openworkouts() { |
---|
| 76 | . ${env_path}/bin/activate |
---|
[7f335a4] | 77 | echo "Installing OpenWorkouts dependencies" |
---|
| 78 | yes | pip install --upgrade -e ${current}[testing] >> ${install_log}.stdout 2>> ${install_log}.stderr |
---|
[d17dffe] | 79 | deactivate |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | install_js_deps() { |
---|
[7f335a4] | 83 | echo "Installing javascript components" |
---|
| 84 | ${current}/bin/js_deps >> ${install_log}.stdout 2>> ${install_log}.stderr |
---|
[d17dffe] | 85 | } |
---|
| 86 | |
---|
[1d8d5cd] | 87 | create_mail_queue() { |
---|
| 88 | # Creates a Maildir-format directory that pyramid_mailer can use to |
---|
| 89 | # queue mails. |
---|
| 90 | echo "Creating mail spool directory ${mail_queue_path}" |
---|
[ec51ffa] | 91 | mkdir -p ${mail_queue_path}/new >> ${install_log}.stdout 2>> ${install_log}.stderr |
---|
| 92 | mkdir -p ${mail_queue_path}/tmp >> ${install_log}.stdout 2>> ${install_log}.stderr |
---|
| 93 | mkdir -p ${mail_queue_path}/cur >> ${install_log}.stdout 2>> ${install_log}.stderr |
---|
[1d8d5cd] | 94 | } |
---|
| 95 | |
---|
[91517b1] | 96 | setup_mail_server() { |
---|
| 97 | echo "" |
---|
| 98 | echo "IMPORTANT, READ BEFORE STARTING OpenWorkouts" |
---|
| 99 | echo "--------------------------------------------" |
---|
| 100 | echo "" |
---|
| 101 | echo "For emails to be sent by OpenWorkouts you have to set up your mail" |
---|
| 102 | echo "server account. Edit the file development.ini and update the" |
---|
| 103 | echo "parameters:" |
---|
| 104 | echo "" |
---|
| 105 | echo " mail.host = SERVER" |
---|
| 106 | echo " mail.tls = True" |
---|
| 107 | echo " mail.username = USERNAME" |
---|
| 108 | echo " mail.password = PASSWORD" |
---|
| 109 | echo "" |
---|
| 110 | echo "--------------------------------------------" |
---|
| 111 | |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | create_cron_job() { |
---|
| 115 | echo "" |
---|
| 116 | echo "IMPORTANT, READ BEFORE STARTING OpenWorkouts" |
---|
| 117 | echo "--------------------------------------------" |
---|
| 118 | echo "" |
---|
| 119 | echo "Remember to add a periodic task in your operating system to process" |
---|
| 120 | echo "the mail queue, so emails are sent" |
---|
| 121 | echo "" |
---|
| 122 | echo "In a unix-like system, add this to your crontab:" |
---|
| 123 | echo "" |
---|
| 124 | echo "*/5 * * * * cd ${current} && ./bin/send_emails > /dev/null 2> /dev/null" |
---|
| 125 | echo "" |
---|
| 126 | echo "--------------------------------------------" |
---|
| 127 | echo "" |
---|
| 128 | } |
---|
| 129 | |
---|
[d17dffe] | 130 | setup_start_stop() { |
---|
| 131 | echo "OpenWorkouts successfully installed in ${env_path}" |
---|
| 132 | echo "" |
---|
| 133 | echo "You can now start the OpenWorkouts service calling:" |
---|
| 134 | echo "" |
---|
| 135 | echo " cd ${current} && ./bin/start" |
---|
| 136 | echo "" |
---|
[7f335a4] | 137 | echo "(the installation script left a log under ${install_log})" |
---|
| 138 | echo "" |
---|
[d17dffe] | 139 | # echo "You can stop any running OpenWorkouts instances calling:" |
---|
| 140 | # echo "" |
---|
| 141 | # echo " ${current}/bin/stop" |
---|
| 142 | # echo "" |
---|
| 143 | } |
---|
| 144 | |
---|
[4af38e8] | 145 | set_scripts_permissions |
---|
[d17dffe] | 146 | check_python3 |
---|
| 147 | create_venv |
---|
| 148 | upgrade_pip_setuptools |
---|
| 149 | install_openworkouts |
---|
| 150 | install_js_deps |
---|
[1d8d5cd] | 151 | create_mail_queue |
---|
[91517b1] | 152 | setup_mail_server |
---|
| 153 | create_cron_job |
---|
[d17dffe] | 154 | setup_start_stop |
---|