From 12baeb5e6319f4cc2ef2b71d7cdb38efc01bc34d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Bourr=C3=A9?= Date: Wed, 2 Jan 2019 19:11:56 +0100 Subject: [PATCH] Fix arm install, fix ipv6, add hub port, prepare update script --- conf/jupyterhub_config.py | 4 +- scripts/_common.sh | 81 +++++++++++++++++++++++++++++++++++++-- scripts/install | 13 +++---- scripts/remove | 6 +++ 4 files changed, 92 insertions(+), 12 deletions(-) diff --git a/conf/jupyterhub_config.py b/conf/jupyterhub_config.py index 47f6839..3a26dff 100644 --- a/conf/jupyterhub_config.py +++ b/conf/jupyterhub_config.py @@ -92,7 +92,7 @@ c.JupyterHub.authenticator_class = 'ldapauthenticator.LDAPAuthenticator' ## The public facing URL of the whole JupyterHub application. # # This is the address on which the proxy will bind. Sets protocol, ip, base_url -c.JupyterHub.bind_url = 'http://0.0.0.0:__PORT____PATH__' +c.JupyterHub.bind_url = 'http://:__PORT____PATH__' ## Whether to shutdown the proxy when the Hub shuts down. # @@ -203,7 +203,7 @@ c.JupyterHub.bind_url = 'http://0.0.0.0:__PORT____PATH__' # "unix+http://%2Fsrv%2Fjupyterhub%2Fjupyterhub.sock" # # .. versionadded:: 0.9 -#c.JupyterHub.hub_bind_url = '' +c.JupyterHub.hub_bind_url = 'http://127.0.0.1:__PORT_HUB__' ## The ip or hostname for proxies and spawners to use for connecting to the Hub. # diff --git a/scripts/_common.sh b/scripts/_common.sh index e4b60e3..8d8bdc4 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -13,11 +13,11 @@ final_path="/opt/$app" # NOTE: `uname -m` is more accurate and universal than `arch` # See https://en.wikipedia.org/wiki/Uname if [ -n "$(uname -m | grep 64)" ]; then - miniconda_architecture="x86_64" + miniconda_architecture="x86-64" elif [ -n "$(uname -m | grep 86)" ]; then miniconda_architecture="x86" elif [ -n "$(uname -m | grep arm)" ]; then - miniconda_architecture="armv7l" + miniconda_architecture="arm" else ynh_die "Unable to detect your achitecture, please open a bug describing \ your hardware and the result of the command \"uname -m\"." 1 @@ -46,6 +46,7 @@ config_jupyterlab() { ynh_replace_string "__URL__" "https://$domain" $jupyterlab_conf_path ynh_replace_string "__PATH__" "${path_url%/}" $jupyterlab_conf_path ynh_replace_string "__PORT__" "$port" $jupyterlab_conf_path + ynh_replace_string "__PORT_HUB__" "$port_hub" $jupyterlab_conf_path ynh_replace_string "__FINAL_PATH__" "$final_path" $jupyterlab_conf_path ynh_replace_string "__ADMIN__" "$admin" $jupyterlab_conf_path @@ -78,8 +79,82 @@ add_systemd_config () { } #================================================= -# REMOVE THE CONFIGURATION FILE FOR GITLAB +# REMOVE THE CONFIGURATION FILE FOR JUPYTERLAB #================================================= remove_config_jupyterlab() { ynh_secure_remove "$config_path/jupyterhub_config.py" } + +#================================================= +# UPDATE SOURCES FILES +#================================================= +update_src_version() { + source ./upgrade.d/upgrade.sh + cp ../conf/arm.src.default ../conf/arm.src + ynh_replace_string "__VERSION__" "$berryconda3_version" "../conf/arm.src" + ynh_replace_string "__MD5_SUM__" "$berryconda3_arm_source_md5" "../conf/arm.src" + + cp ../conf/x86-64.src.default ../conf/x86-64.src + ynh_replace_string "__VERSION__" "$miniconda3_version" "../conf/x86-64.src" + ynh_replace_string "__MD5_SUM__" "$miniconda3_x86_64_source_md5" "../conf/x86-64.src" + + cp ../conf/x86.src.default ../conf/x86.src + ynh_replace_string "__VERSION__" "$miniconda3_version" "../conf/x86.src" + ynh_replace_string "__MD5_SUM__" "$miniconda3_x86_source_md5" "../conf/x86.src" +} + +#================================================= +# INSTALL JUPYTERLAB +#================================================= +# This function is inspired by the ynh_setup_source function, adapted to deal with .sh files +setup_source() { + local src_id=${1:-app} # If the argument is not given, source_id equals "app" + + update_src_version # Update source file + + # Load value from configuration file (see above for a small doc about this file + # format) + local src_url=$(grep 'SOURCE_URL=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) + local src_sum=$(grep 'SOURCE_SUM=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) + local src_sumprg=$(grep 'SOURCE_SUM_PRG=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) + local src_format=$(grep 'SOURCE_FORMAT=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) + local src_extract=$(grep 'SOURCE_EXTRACT=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) + local src_in_subdir=$(grep 'SOURCE_IN_SUBDIR=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) + local src_filename=$(grep 'SOURCE_FILENAME=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) + + # Default value + src_sumprg=${src_sumprg:-sha256sum} + src_in_subdir=${src_in_subdir:-true} + src_format=${src_format:-tar.gz} + src_format=$(echo "$src_format" | tr '[:upper:]' '[:lower:]') + src_extract=${src_extract:-true} + if [ "$src_filename" = "" ] ; then + src_filename="${src_id}.${src_format}" + fi + local local_src="/opt/yunohost-apps-src/${YNH_APP_ID}/${src_filename}" + + if test -e "$local_src" + then # Use the local source file if it is present + cp $local_src $src_filename + else # If not, download the source + local out=`wget -nv -O $src_filename $src_url 2>&1` || ynh_print_err $out + fi + + # Check the control sum + echo "${src_sum} ${src_filename}" | ${src_sumprg} -c --status \ + || ynh_die "Corrupt source" + + bash $src_filename -b -p $final_path + + export "PATH=$final_path/bin/:$PATH" + + if [ "$src_id" = "arm" ] + then + conda install jupyterlab=$jupyterlab_version notebook nodejs -y + pip install jupyterhub jupyterhub-ldapauthenticator + else + conda install -c conda-forge jupyterlab=$jupyterlab_version jupyterhub notebook jupyterhub-ldapauthenticator nodejs -y + fi + + npm install -g configurable-http-proxy +} \ No newline at end of file diff --git a/scripts/install b/scripts/install index 1508f8d..4ac9f28 100644 --- a/scripts/install +++ b/scripts/install @@ -60,9 +60,12 @@ ynh_app_setting_set $app is_public $is_public # Find free ports port=$(ynh_find_port 8080) +port_hub=$(ynh_find_port 8081) yunohost firewall allow --no-upnp TCP $port 2>&1 +yunohost firewall allow --no-upnp TCP $port_hub 2>&1 ynh_app_setting_set $app port $port +ynh_app_setting_set $app port_hub $port_hub #================================================= # NGINX CONFIGURATION @@ -82,11 +85,7 @@ config_jupyterlab # DOWNLOAD, CHECK AND INSTALL JUPYTERLAB #================================================= -wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-$miniconda_architecture.sh - -bash Miniconda3-latest-Linux-$miniconda_architecture.sh -b -p $final_path - -$final_path/bin/conda install -c conda-forge jupyterhub notebook jupyterlab jupyterhub-ldapauthenticator -y +setup_source $miniconda_architecture #================================================= # SPECIFIC SETUP @@ -94,8 +93,8 @@ $final_path/bin/conda install -c conda-forge jupyterhub notebook jupyterlab jupy # ADD HUB EXTENSION #================================================= -$final_path/bin/jupyter labextension install @jupyterlab/hub-extension -$final_path/bin/jupyter lab build +jupyter labextension install @jupyterlab/hub-extension +jupyter lab build chown $admin -R $final_path/share/jupyter diff --git a/scripts/remove b/scripts/remove index 5e23647..075c5d2 100644 --- a/scripts/remove +++ b/scripts/remove @@ -20,6 +20,7 @@ source ./_common.sh app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get "$app" domain) port=$(ynh_app_setting_get "$app" port) +port_hub=$(ynh_app_setting_get "$app" port_hub) #================================================= # STANDARD REMOVE @@ -67,6 +68,11 @@ then echo "Close port $port" >&2 yunohost firewall disallow TCP $port 2>&1 fi +if yunohost firewall list | grep -q "\- $port_hub$" +then + echo "Close port $port_hub" >&2 + yunohost firewall disallow TCP $port_hub 2>&1 +fi #================================================= # REMOVE NGINX CONFIGURATION