diff --git a/init-server.py b/init-server.py index bc1d391..d912872 100755 --- a/init-server.py +++ b/init-server.py @@ -8,8 +8,8 @@ from ssh_lib.config import scripts from ssh_lib.kernel import set_cpu_governor, setup_kernel_settings from ssh_lib.nginx import certbot, nginx from ssh_lib.pkg_base import pkg_base, pkg_clean, pkg_upgrade -from ssh_lib.planetiler import PLANETILER_DIR, install_planetiler -from ssh_lib.utils import add_user, put, setup_time +from ssh_lib.planetiler import TILE_GEN_BIN, install_planetiler +from ssh_lib.utils import add_user, put, setup_time, sudo_cmd def prepare_shared(c): @@ -26,14 +26,25 @@ def prepare_shared(c): def prepare_tile_creator(c): install_planetiler(c) + put( c, - scripts / 'tile_creator' / 'run_planet.sh', - PLANETILER_DIR, + scripts / 'tile_creator' / 'prepare-virtualenv.sh', + TILE_GEN_BIN, permissions='755', owner='ofm', ) + put( + c, + scripts / 'tile_creator' / 'run_planet.sh', + TILE_GEN_BIN, + permissions='755', + owner='ofm', + ) + + sudo_cmd(c, f'cd {TILE_GEN_BIN} && source prepare-virtualenv.sh', user='ofm') + def prepare_http_host(c): nginx(c) @@ -73,7 +84,7 @@ def main(hostname, user, port, tile_creator, http_host): port=port, ) - # prepare_shared(c) + prepare_shared(c) if tile_creator: prepare_tile_creator(c) diff --git a/scripts/tile_creator/prepare-virtualenv.sh b/scripts/tile_creator/prepare-virtualenv.sh new file mode 100755 index 0000000..7ebc930 --- /dev/null +++ b/scripts/tile_creator/prepare-virtualenv.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +find . -name "*.egg-info" -exec rm -rf {} + +find . -name __pycache__ -exec rm -rf {} + + +# deactivate +rm -rf venv +python3 -m venv venv + +venv/bin/pip -V + +venv/bin/pip install -U pip wheel setuptools +venv/bin/pip install git+https://github.com/mapbox/mbutil.git@544c76e + + + + diff --git a/ssh_lib/pkg_base.py b/ssh_lib/pkg_base.py index 65eff6d..37a73dd 100644 --- a/ssh_lib/pkg_base.py +++ b/ssh_lib/pkg_base.py @@ -38,11 +38,14 @@ def pkg_base(c): pkg_list = [ 'wget', 'gpg', + 'git', 'gnupg-agent', - 'python3', 'nload', 'iftop', 'snapd', + # + 'python3', + 'python3-venv', ] apt_get_install(c, ' '.join(pkg_list)) diff --git a/ssh_lib/planetiler.py b/ssh_lib/planetiler.py index 93d7be3..88ec878 100644 --- a/ssh_lib/planetiler.py +++ b/ssh_lib/planetiler.py @@ -3,8 +3,8 @@ from ssh_lib.utils import apt_get_install, apt_get_update PLANETILER_VERSION = '0.7.0' -PLANETILER_DIR = '/data/planetiler/bin' -PLANETILER_PATH = f'{PLANETILER_DIR}/planetiler.jar' +TILE_GEN_BIN = '/data/ofm/tile_gen/bin' +PLANETILER_PATH = f'{TILE_GEN_BIN}/planetiler.jar' def install_planetiler(c): diff --git a/ssh_lib/utils.py b/ssh_lib/utils.py index 9ae24c1..2f8ddf2 100644 --- a/ssh_lib/utils.py +++ b/ssh_lib/utils.py @@ -36,9 +36,9 @@ def append_str(c, remote_path, str_): c.sudo(f'rm -f {tmp_path}') -def sudo_cmd(c, cmd): +def sudo_cmd(c, cmd, user=None): cmd = cmd.replace('"', '\\"') - c.sudo(f'bash -c "{cmd}"') + c.sudo(f'bash -c "{cmd}"', user=user) def set_permission(c, path, permissions=None, owner=None, group=None):