1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/jupyterlab_ynh.git synced 2024-09-03 19:26:35 +02:00

Inline bash functions

This commit is contained in:
Jules Bertholet 2021-05-31 14:25:53 -04:00
parent 7e3e324bb7
commit 09ec7626ba
7 changed files with 137 additions and 84 deletions

View file

@ -15,70 +15,6 @@ jupyterlab_version="3.0.16"
# PERSONAL HELPERS # PERSONAL HELPERS
#================================================= #=================================================
function load_settings {
app=$YNH_APP_INSTANCE_NAME
domain="$(ynh_app_setting_get --app=$app --key=domain)"
path_url="$(ynh_app_setting_get --app=$app --key=path)"
admin="$(ynh_app_setting_get --app=$app --key=admin)"
final_path="$(ynh_app_setting_get --app=$app --key=final_path)"
port="$(ynh_app_setting_get --app=$app --key=port)"
port_hub="$(ynh_app_setting_get --app=$app --key=port_hub)"
port_http_proxy="$(ynh_app_setting_get --app=$app --key=port_http_proxy)"
enable_terminal="$(ynh_app_setting_get --app=$app --key=enable_terminal)"
enable_extensions="$(ynh_app_setting_get --app=$app --key=enable_extensions)"
}
function python_setup {
set_permissions
pushd "$final_path"
sudo -u $app PIPENV_VENV_IN_PROJECT="enabled" PIPENV_SKIP_LOCK=true python3 -m pipenv install jupyterlab==$jupyterlab_version jupyterhub notebook jupyter-server jupyterhub-ldapauthenticator pyzmq sudospawner --three 2>&1
sudo -u $app python3 -m pipenv run jupyterhub upgrade-db 2>&1
popd
}
function set_permissions {
# Set permissions to app files
mkdir -p "$final_path/.venv"
chown -R $app:$app "$final_path"
chmod -R g=u,g-w,o-rwx "$final_path"
setfacl -nR -m g:$app.main:rx -m d:g:$app.main:rx "$final_path/.venv"
setfacl -n -m g:$app.main:x "$final_path"
}
function add_configs {
mkdir -p "$final_path/config"
path="${path_url%/}"
ynh_add_config --template="jupyterhub_config.py" --destination="$final_path/config/jupyterhub_config.py"
ynh_add_config --template="jupyter_server_config.py" --destination="$final_path/config/jupyter_server_config.py"
ynh_add_config --template="app-sudoers" --destination="/etc/sudoers.d/$app-sudoers"
ynh_add_config --template="sudospawner-singleuser" --destination="$final_path/.venv/bin/sudospawner-singleuser"
set_config_permissions
}
function build_local_labs {
ynh_use_nodejs
for user in $(ynh_user_list); do
local JUPYTERLAB_DIR="$(getent passwd $user | cut -d: -f6)/.local/share/$app/lab"
local node_path="$nodejs_path:$(sudo -u $user sh -c 'echo $PATH')"
sudo -u $user env "PATH=$node_path" "$final_path/.venv/bin/jupyter" lab build --app-dir="$JUPYTERLAB_DIR"
done
}
function set_config_permissions {
chmod 550 "$final_path/.venv/bin/sudospawner-singleuser"
set_permissions
chown root:root /etc/sudoers.d/$app-sudoers
chmod 440 /etc/sudoers.d/$app-sudoers
}
#================================================= #=================================================
# EXPERIMENTAL HELPERS # EXPERIMENTAL HELPERS
#================================================= #=================================================

View file

@ -25,7 +25,17 @@ ynh_abort_if_errors
#================================================= #=================================================
ynh_print_info --message="Loading installation settings..." ynh_print_info --message="Loading installation settings..."
load_settings app=$YNH_APP_INSTANCE_NAME
domain="$(ynh_app_setting_get --app=$app --key=domain)"
path_url="$(ynh_app_setting_get --app=$app --key=path)"
admin="$(ynh_app_setting_get --app=$app --key=admin)"
final_path="$(ynh_app_setting_get --app=$app --key=final_path)"
port="$(ynh_app_setting_get --app=$app --key=port)"
port_hub="$(ynh_app_setting_get --app=$app --key=port_hub)"
port_http_proxy="$(ynh_app_setting_get --app=$app --key=port_http_proxy)"
enable_terminal="$(ynh_app_setting_get --app=$app --key=enable_terminal)"
enable_extensions="$(ynh_app_setting_get --app=$app --key=enable_extensions)"
#================================================= #=================================================
# DECLARE DATA AND CONF FILES TO BACKUP # DECLARE DATA AND CONF FILES TO BACKUP

View file

@ -24,7 +24,17 @@ new_path=$YNH_APP_NEW_PATH
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." ynh_script_progression --message="Loading installation settings..."
load_settings app=$YNH_APP_INSTANCE_NAME
domain="$(ynh_app_setting_get --app=$app --key=domain)"
path_url="$(ynh_app_setting_get --app=$app --key=path)"
admin="$(ynh_app_setting_get --app=$app --key=admin)"
final_path="$(ynh_app_setting_get --app=$app --key=final_path)"
port="$(ynh_app_setting_get --app=$app --key=port)"
port_hub="$(ynh_app_setting_get --app=$app --key=port_hub)"
port_http_proxy="$(ynh_app_setting_get --app=$app --key=port_http_proxy)"
enable_terminal="$(ynh_app_setting_get --app=$app --key=enable_terminal)"
enable_extensions="$(ynh_app_setting_get --app=$app --key=enable_extensions)"
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
@ -106,7 +116,20 @@ fi
domain=$new_domain domain=$new_domain
path=${new_path%/} path=${new_path%/}
add_configs mkdir -p "$final_path/config"
ynh_add_config --template="jupyterhub_config.py" --destination="$final_path/config/jupyterhub_config.py"
ynh_add_config --template="jupyter_server_config.py" --destination="$final_path/config/jupyter_server_config.py"
ynh_add_config --template="app-sudoers" --destination="/etc/sudoers.d/$app-sudoers"
ynh_add_config --template="sudospawner-singleuser" --destination="$final_path/.venv/bin/sudospawner-singleuser"
chmod 550 "$final_path/.venv/bin/sudospawner-singleuser"
chown -R $app:$app "$final_path"
chmod -R g=u,g-w,o-rwx "$final_path"
setfacl -nR -m g:$app.main:rx -m d:g:$app.main:rx "$final_path/.venv"
setfacl -n -m g:$app.main:x "$final_path"
chown root:root "/etc/sudoers.d/$app-sudoers"
chmod 440 "/etc/sudoers.d/$app-sudoers"
#================================================= #=================================================
# GENERIC FINALISATION # GENERIC FINALISATION

View file

@ -98,9 +98,17 @@ ynh_script_progression --message="Setting up source files..." --weight=64
ynh_app_setting_set --app=$app --key=final_path --value=$final_path ynh_app_setting_set --app=$app --key=final_path --value=$final_path
mkdir -p $final_path # Set permissions to app files
mkdir -p "$final_path/.venv"
chown -R $app:$app "$final_path"
chmod -R g=u,g-w,o-rwx "$final_path"
setfacl -nR -m g:$app.main:rx -m d:g:$app.main:rx "$final_path/.venv"
setfacl -n -m g:$app.main:x "$final_path"
python_setup pushd "$final_path"
sudo -u $app PIPENV_VENV_IN_PROJECT="enabled" PIPENV_SKIP_LOCK=true python3 -m pipenv install jupyterlab==$jupyterlab_version jupyterhub notebook jupyter-server jupyterhub-ldapauthenticator pyzmq sudospawner --three 2>&1
sudo -u $app python3 -m pipenv run jupyterhub upgrade-db 2>&1
popd
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
@ -126,7 +134,13 @@ ynh_add_systemd_config
# MODIFY A CONFIG FILE # MODIFY A CONFIG FILE
#================================================= #=================================================
add_configs mkdir -p "$final_path/config"
path="${path_url%/}"
ynh_add_config --template="jupyterhub_config.py" --destination="$final_path/config/jupyterhub_config.py"
ynh_add_config --template="jupyter_server_config.py" --destination="$final_path/config/jupyter_server_config.py"
ynh_add_config --template="app-sudoers" --destination="/etc/sudoers.d/$app-sudoers"
ynh_add_config --template="sudospawner-singleuser" --destination="$final_path/.venv/bin/sudospawner-singleuser"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
@ -135,16 +149,26 @@ add_configs
#================================================= #=================================================
# Set permissions to app files # Set permissions to app files
set_permissions chmod 550 "$final_path/.venv/bin/sudospawner-singleuser"
chown -R $app:$app "$final_path"
chmod -R g=u,g-w,o-rwx "$final_path"
setfacl -nR -m g:$app.main:rx -m d:g:$app.main:rx "$final_path/.venv"
setfacl -n -m g:$app.main:x "$final_path"
chown root:root "/etc/sudoers.d/$app-sudoers"
chmod 440 "/etc/sudoers.d/$app-sudoers"
#================================================= #=================================================
# BUILD USER LABS # BUILD USER LABS
#================================================= #=================================================
ynh_script_progression --message="Building Jupyter lab for each user..." --weight=10 ynh_script_progression --message="Building Jupyter lab for each user..." --weight=10
# Set permissions to app files
if [ $enable_extensions -eq 1 ]; then if [ $enable_extensions -eq 1 ]; then
build_local_labs ynh_use_nodejs
for user in $(ynh_user_list); do
JUPYTERLAB_DIR="$(getent passwd $user | cut -d: -f6)/.local/share/$app/lab"
node_path="$nodejs_path:$(sudo -u $user sh -c 'echo $PATH')"
sudo -u $user env "PATH=$node_path" "$final_path/.venv/bin/jupyter" lab build --app-dir="$JUPYTERLAB_DIR"
done
fi fi
#================================================= #=================================================

View file

@ -14,7 +14,17 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1 ynh_script_progression --message="Loading installation settings..." --weight=1
load_settings app=$YNH_APP_INSTANCE_NAME
domain="$(ynh_app_setting_get --app=$app --key=domain)"
path_url="$(ynh_app_setting_get --app=$app --key=path)"
admin="$(ynh_app_setting_get --app=$app --key=admin)"
final_path="$(ynh_app_setting_get --app=$app --key=final_path)"
port="$(ynh_app_setting_get --app=$app --key=port)"
port_hub="$(ynh_app_setting_get --app=$app --key=port_hub)"
port_http_proxy="$(ynh_app_setting_get --app=$app --key=port_http_proxy)"
enable_terminal="$(ynh_app_setting_get --app=$app --key=enable_terminal)"
enable_extensions="$(ynh_app_setting_get --app=$app --key=enable_extensions)"
#================================================= #=================================================
# STANDARD REMOVE # STANDARD REMOVE

View file

@ -25,7 +25,17 @@ ynh_abort_if_errors
#================================================= #=================================================
ynh_script_progression --message="Loading settings..." --weight=1 ynh_script_progression --message="Loading settings..." --weight=1
load_settings app=$YNH_APP_INSTANCE_NAME
domain="$(ynh_app_setting_get --app=$app --key=domain)"
path_url="$(ynh_app_setting_get --app=$app --key=path)"
admin="$(ynh_app_setting_get --app=$app --key=admin)"
final_path="$(ynh_app_setting_get --app=$app --key=final_path)"
port="$(ynh_app_setting_get --app=$app --key=port)"
port_hub="$(ynh_app_setting_get --app=$app --key=port_hub)"
port_http_proxy="$(ynh_app_setting_get --app=$app --key=port_http_proxy)"
enable_terminal="$(ynh_app_setting_get --app=$app --key=enable_terminal)"
enable_extensions="$(ynh_app_setting_get --app=$app --key=enable_extensions)"
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
@ -65,7 +75,13 @@ ynh_restore_file --origin_path="$final_path"
#================================================= #=================================================
# Restore permissions on app files # Restore permissions on app files
set_permissions mkdir -p "$final_path/.venv"
chown -R $app:$app "$final_path"
chmod -R g=u,g-w,o-rwx "$final_path"
setfacl -nR -m g:$app.main:rx -m d:g:$app.main:rx "$final_path/.venv"
setfacl -n -m g:$app.main:x "$final_path"
#================================================= #=================================================
# SPECIFIC RESTORATION # SPECIFIC RESTORATION

View file

@ -14,7 +14,17 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." --weight=3 ynh_script_progression --message="Loading installation settings..." --weight=3
load_settings app=$YNH_APP_INSTANCE_NAME
domain="$(ynh_app_setting_get --app=$app --key=domain)"
path_url="$(ynh_app_setting_get --app=$app --key=path)"
admin="$(ynh_app_setting_get --app=$app --key=admin)"
final_path="$(ynh_app_setting_get --app=$app --key=final_path)"
port="$(ynh_app_setting_get --app=$app --key=port)"
port_hub="$(ynh_app_setting_get --app=$app --key=port_hub)"
port_http_proxy="$(ynh_app_setting_get --app=$app --key=port_http_proxy)"
enable_terminal="$(ynh_app_setting_get --app=$app --key=enable_terminal)"
enable_extensions="$(ynh_app_setting_get --app=$app --key=enable_extensions)"
#================================================= #=================================================
# CHECK VERSION # CHECK VERSION
@ -111,10 +121,17 @@ if [ "$upgrade_type" == "UPGRADE_APP" ]
then then
ynh_script_progression --message="Upgrading source files..." --weight=160 ynh_script_progression --message="Upgrading source files..." --weight=160
# Download, check integrity, uncompress and patch the source from app.src # Set permissions to app files
mkdir -p $final_path mkdir -p "$final_path/.venv"
chown -R $app:$app "$final_path"
chmod -R g=u,g-w,o-rwx "$final_path"
setfacl -nR -m g:$app.main:rx -m d:g:$app.main:rx "$final_path/.venv"
setfacl -n -m g:$app.main:x "$final_path"
python_setup pushd "$final_path"
sudo -u $app PIPENV_VENV_IN_PROJECT="enabled" PIPENV_SKIP_LOCK=true python3 -m pipenv install jupyterlab==$jupyterlab_version jupyterhub notebook jupyter-server jupyterhub-ldapauthenticator pyzmq sudospawner --three 2>&1
sudo -u $app python3 -m pipenv run jupyterhub upgrade-db 2>&1
popd
fi fi
#================================================= #=================================================
@ -123,7 +140,13 @@ fi
# STORE THE CONFIG FILE CHECKSUM # STORE THE CONFIG FILE CHECKSUM
#================================================= #=================================================
add_configs mkdir -p "$final_path/config"
path="${path_url%/}"
ynh_add_config --template="jupyterhub_config.py" --destination="$final_path/config/jupyterhub_config.py"
ynh_add_config --template="jupyter_server_config.py" --destination="$final_path/config/jupyter_server_config.py"
ynh_add_config --template="app-sudoers" --destination="/etc/sudoers.d/$app-sudoers"
ynh_add_config --template="sudospawner-singleuser" --destination="$final_path/.venv/bin/sudospawner-singleuser"
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
@ -142,16 +165,27 @@ ynh_add_systemd_config
#================================================= #=================================================
# Set permissions on app files # Set permissions on app files
set_permissions chmod 550 "$final_path/.venv/bin/sudospawner-singleuser"
chown -R $app:$app "$final_path"
chmod -R g=u,g-w,o-rwx "$final_path"
setfacl -nR -m g:$app.main:rx -m d:g:$app.main:rx "$final_path/.venv"
setfacl -n -m g:$app.main:x "$final_path"
chown root:root "/etc/sudoers.d/$app-sudoers"
chmod 440 "/etc/sudoers.d/$app-sudoers"
#================================================= #=================================================
# BUILD USER LABS # BUILD USER LABS
#================================================= #=================================================
ynh_script_progression --message="Building Jupyter lab for each user..." --weight=10 ynh_script_progression --message="Building Jupyter lab for each user..." --weight=10
# Set permissions to app files
if [ $enable_extensions -eq 1 ]; then if [ $enable_extensions -eq 1 ]; then
build_local_labs ynh_use_nodejs
for user in $(ynh_user_list); do
JUPYTERLAB_DIR="$(getent passwd $user | cut -d: -f6)/.local/share/$app/lab"
node_path="$nodejs_path:$(sudo -u $user sh -c 'echo $PATH')"
sudo -u $user env "PATH=$node_path" "$final_path/.venv/bin/jupyter" lab build --app-dir="$JUPYTERLAB_DIR"
done
fi fi
#================================================= #=================================================