Skip to content
This repository has been archived by the owner on Aug 15, 2020. It is now read-only.

Commit

Permalink
Put install.py into install.sh:
Browse files Browse the repository at this point in the history
Remove configuration setting, remove user input
  • Loading branch information
btseytlin committed Jun 26, 2020
1 parent 8206e26 commit e7b135f
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 139 deletions.
86 changes: 0 additions & 86 deletions distributions/linux/install.py

This file was deleted.

120 changes: 74 additions & 46 deletions distributions/linux/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,60 +33,28 @@ $cmdcol
"""

printf "Installing MindsDb requires Python 3.6+ and pip. We will now attempt to detect their paths."
# Attempt to detect python
python_path="$(which python3)"
pip_path="$(which pip3)"
printf "Detected python3: $python_path\ndetected pip3: $pip_path\nDo you want to use these [Y] or manually provide paths [N]? [Y/N]"
read use_detected_python
if [ "$use_detected_python" = "N" ] || [ "$use_detected_python" = "n" ]; then
echo "Please enter the path to your python (3.6+) interpreter:"
read python_path

echo "Please enter the path to your associate pip installation:"
read pip_path
if [ -z "${python_path}" ]
then
python_path="$(which python)"
fi

if [ -z "${pip_path}" ]
then
pip_path="$(which pip)"
fi
export MDB_INSTALL_PYTHONPATH="$python_path"
export MDB_INSTALL_PIPPATH="$pip_path"

printf "Detected python: $python_path\ndetected pip: $pip_path"

# Check that it's indeed python 3.6 and that pip works
${python_path} -c "import sys; print('Sorry, MindsDB requires Python 3.6+') and exit(1) if sys.version_info < (3,6) else exit(0)"
${pip_path} --version > /dev/null 2>&1

echo "Do you want us to install using the default parameters [Y] or should we go ahead and give you control to tweak stuff during installation ? [Y/N]"
read default_install
export MDB_DEFAULT_INSTALL="$default_install"

export MDB_MAKE_EXEC="Y"
if [ "$EUID" -ne 0 ]; then
install_as="user"
else
install_as="global"
fi

if [ "$default_install" = "N" ] || [ "$default_install" = "n" ]; then
if [ "$EUID" -ne 0 ]; then
install_as="user"
echo "You are currently installing Mindsdb for your user only, rather than globally. Is this intended ? [Y/N]"
read approve
if [ "$approve" = "N" ] || [ "$approve" = "n" ]; then
echo "Please run the installer using sudo in front of the command"
exit
fi
else
install_as="global"
echo "You are currently installing Mindsdb globally (as root), is this intended ? [Y/N]"
read approve
if [ "$approve" = "N" ] || [ "$approve" = "n" ]; then
echo "Please run the installer as your desired user instead (without using sudo in front of it)"
exit
fi
fi

echo "Should we make an executable for mindsdb (in /usr/bin/ if installing as root or in your home directory if install as user)? [Y/N]"
read make_exec
export MDB_MAKE_EXEC="$make_exec"
fi

export MDB_INSTALL_PYTHONPATH="$python_path"
export MDB_INSTALL_PIPPATH="$pip_path"

cmdcol="$(tput sgr0)$(tput bold)"
normalcol="$(tput sgr0)"
Expand Down Expand Up @@ -122,6 +90,66 @@ $cmdcol
"""

temp_file=$(mktemp)
trap "rm -f $temp_file" 0 2 3 15 #Making sure the file is deleted after script finishes

# Python code below
cat << EOF > $temp_file
#!$python_path
import traceback
import sys
import os
from pathlib import Path
import time
from os.path import expanduser
python_path = sys.argv[1]
pip_path = sys.argv[2]
home = expanduser("~")
mdb_home = os.path.join(home, 'mindsdb')
print(f'\nInstalling some large dependencies via pip ({pip_path}), this might take a while\n')
time.sleep(1)
retcode = os.system(f'{pip_path} install git+https://github.com/mindsdb/mindsdb_server.git@split --upgrade')
if retcode != 0:
raise(Exception("Command exited with error"))
dataskillet_source = None
lightwood_source = f'git+https://github.com/mindsdb/lightwood.git@stable'
mindsdb_native_source = f'git+https://github.com/mindsdb/mindsdb_native.git@stable'
for source in [dataskillet_source,lightwood_source,mindsdb_native_source]:
if isinstance(source,str):
retcode = os.system(f'{pip_path} install {source} --upgrade')
if retcode != 0:
raise(Exception("Command exited with error"))
time.sleep(1)
print('Done installing dependencies')
print('\nLast step: Configure Mindsdb\n')
from mindsdb_server.utilities.wizards import daemon_creator, make_executable
daemon_path = daemon_creator(python_path)
print(f"Created daemon service config {daemon_path}")
exec_path = str(os.path.join(mdb_home,'run'))
make_executable(python_path, exec_path)
print(f"Created executable at {exec_path}")
print('Installation complete!')
print(f'You can use Mindsdb by running {exec_path}. Or by importing it as the mindsdb_native library from within python.')
EOF
#/Python code

chmod 755 $temp_file

INSTALLER_SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"

"${MDB_INSTALL_PYTHONPATH}" "$INSTALLER_SCRIPT_DIR"/install.py "$install_as" "$MDB_INSTALL_PYTHONPATH" "$MDB_INSTALL_PIPPATH" "$MDB_DEFAULT_INSTALL" "$MDB_MAKE_EXEC"
"${MDB_INSTALL_PYTHONPATH}" "$temp_file" "$MDB_INSTALL_PYTHONPATH" "$MDB_INSTALL_PIPPATH"
17 changes: 10 additions & 7 deletions mindsdb_server/utilities/wizards.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,20 @@ def cli_config(python_path,pip_path,predictor_dir,datasource_dir,config_dir,use_
return config_path


def daemon_creator(python_path,config_path):
def daemon_creator(python_path, config_path=None):
daemon_path = '/etc/systemd/system/mindsdb.service'
service_txt = f"""[Unit]
Description=Mindsdb
[Service]
ExecStart={python_path} -m mindsdb_server --config={config_path}
ExecStart={python_path} -m mindsdb_server { "--config="+config_path if config_path else ""}
[Install]
WantedBy=multi-user.target
""".strip(' ')

try:
with open('/etc/systemd/system/mindsdb.service', 'w') as fp:
with open(daemon_path, 'w') as fp:
fp.write(service_txt)
except Exception as e:
print(f'Failed to create daemon, error: {e}')
Expand All @@ -118,13 +119,15 @@ def daemon_creator(python_path,config_path):
os.system('systemctl daemon-reload')
except Exception as e:
print(f'Failed to load daemon, error: {e}')
return daemon_path

def make_executable(python_path,config_path,path):

def make_executable(python_path, exec_path, config_path=None):
text = f"""#!/bin/bash
{python_path} -m mindsdb_server --config={config_path}
{python_path} -m mindsdb_server { "--config="+config_path if config_path else ""}
"""

with open(path, 'w') as fp:
with open(exec_path, 'w') as fp:
fp.write(text)

os.system(f'chmod +x {path}')
os.system(f'chmod +x {exec_path}')

0 comments on commit e7b135f

Please sign in to comment.