1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/etherpad_mypads_ynh.git synced 2024-09-03 18:36:09 +02:00

Usage de nvm

This commit is contained in:
Maniack Crudelis 2017-04-23 22:36:12 +02:00
parent b75f52b86f
commit 9570e5d810
6 changed files with 143 additions and 29 deletions

View file

@ -3,7 +3,7 @@
; Manifest
domain="domain.tld" (DOMAIN)
admin="john" (USER)
password="pass" (PASSWORD)
password="password"
language="en"
is_public=1 (PUBLIC|public=1|private=0)
abiword="0"
@ -24,7 +24,7 @@
; Manifest
domain="domain.tld" (DOMAIN)
admin="john" (USER)
password="pass" (PASSWORD)
password="password"
language="en"
is_public=1 (PUBLIC|public=1|private=0)
abiword="1"

View file

@ -6,6 +6,8 @@ After=network.target
Type=simple
User=__APP__
Group=__APP__
ExecStartPre=__NODEJS__
Environment="PATH=__ENV_PATH__"
ExecStart=__FINALPATH__/bin/safeRun.sh /var/log/__APP__/etherpad.log
[Install]

View file

@ -318,6 +318,93 @@ IS_PACKAGE_CHECK () { # Détermine une exécution en conteneur (Non testé)
return $(uname -n | grep -c 'pchecker_lxc')
}
#=================================================
# NODEJS
#=================================================
sudo_path () {
sudo env "PATH=$PATH" $@
}
# INFOS
# nvm utilise la variable PATH pour stocker le path de la version de node à utiliser.
# C'est ainsi qu'il change de version
# En attendant une généralisation de root, il est possible d'utiliser sudo aevc le helper temporaire sudo_path
# Il permet d'utiliser sudo en gardant le $PATH modifié
# ynh_install_nodejs installe la version de nodejs demandée en argument, avec nvm
# ynh_use_nodejs active une version de nodejs dans le script courant
# 3 variables sont mises à disposition, et 2 sont stockées dans la config de l'app
# - nodejs_path: Le chemin absolu de cette version de node
# Utilisé pour des appels directs à npm ou node.
# - nodejs_version: Simplement le numéro de version de nodejs pour cette application
# - nodejs_use_version: Un alias pour charger une version de node dans le shell courant.
# Utilisé pour démarrer un service ou un script qui utilise node ou npm
# Dans ce cas, c'est $PATH qui contient le chemin de la version de node. Il doit être propagé sur les autres shell si nécessaire.
nvm_install_dir="/opt/nvm"
ynh_use_nodejs () {
nodejs_path=$(ynh_app_setting_get $app nodejs_path)
nodejs_version=$(ynh_app_setting_get $app nodejs_version)
# And store the command to use a specific version of node. Equal to `nvm use version`
nodejs_use_version="source $nvm_install_dir/nvm.sh; nvm use \"$nodejs_version\""
# Desactive set -u for this script.
set +u
eval $nodejs_use_version
set -u
}
ynh_install_nodejs () {
local nodejs_version="$1"
local nvm_install_script="https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh"
local nvm_exec="source $nvm_install_dir/nvm.sh; nvm"
sudo mkdir -p "$nvm_install_dir"
# If nvm is not previously setup, install it
"$nvm_exec --version" > /dev/null 2>&1 || \
( cd "$nvm_install_dir"
echo "Installation of NVM"
sudo wget --no-verbose "$nvm_install_script" -O- | sudo NVM_DIR="$nvm_install_dir" bash > /dev/null)
# Install the requested version of nodejs
sudo su -c "$nvm_exec install \"$nodejs_version\" > /dev/null"
# Store the ID of this app and the version of node requested for it
echo "$YNH_APP_ID:$nodejs_version" | sudo tee --append "$nvm_install_dir/ynh_app_version"
# Get the absolute path of this version of node
nodejs_path="$(dirname "$(sudo su -c "$nvm_exec which \"$nodejs_version\"")")"
# Store nodejs_path and nodejs_version into the config of this app
ynh_app_setting_set $app nodejs_path $nodejs_path
ynh_app_setting_set $app nodejs_version $nodejs_version
ynh_use_nodejs
}
ynh_remove_nodejs () {
nodejs_version=$(ynh_app_setting_get $app nodejs_version)
# Remove the line for this app
sudo sed --in-place "/$YNH_APP_ID:$nodejs_version/d" "$nvm_install_dir/ynh_app_version"
# If none another app uses this version of nodejs, remove it.
if ! grep --quiet "$nodejs_version" "$nvm_install_dir/ynh_app_version"
then
sudo su -c "source $nvm_install_dir/nvm.sh; nvm deactivate; nvm uninstall \"$nodejs_version\" > /dev/null"
fi
# If none another app uses nvm, remove nvm and clean the root's bashrc file
if [ ! -s "$nvm_install_dir/ynh_app_version" ]
then
ynh_secure_remove "$nvm_install_dir"
sudo sed --in-place "/NVM_DIR/d" /root/.bashrc
fi
}
#=================================================
#=================================================
# FUTUR YNH HELPERS

View file

@ -84,11 +84,15 @@ ynh_app_setting_set $app port $port
if [ $abiword -eq 1 ]
then
ynh_install_app_dependencies npm nodejs-legacy abiword
else
ynh_install_app_dependencies npm nodejs-legacy
ynh_install_app_dependencies abiword
fi
#=================================================
# INSTALL NODEJS
#=================================================
ynh_install_nodejs 0.10
#=================================================
# CREATE A SQL BDD
#=================================================
@ -137,9 +141,11 @@ ynh_use_logrotate
# INSTALL ETHERPAD
#=================================================
# final_path doit appartenir à `admin` pour l'exécution de installDeps.sh (avec root, `hash` perd la trace de node installé via nvm)
sudo chown admin -R "$final_path"
# Installe les dépendances de etherpad et procède à l'intallation.
sudo "$final_path/bin/installDeps.sh" > $install_log 2>&1
sudo npm install forever -g >> $install_log 2>&1
"$final_path/bin/installDeps.sh" > $install_log 2>&1
sudo "$nodejs_path/npm" install forever -g >> $install_log 2>&1
#=================================================
# CONFIGURE ETHERPAD
@ -175,6 +181,9 @@ sudo chmod 600 $final_path/credentials.json # Restreint l'accès à credentials.
#=================================================
ynh_systemd_config
ynh_replace_string "__NODEJS__" "$nodejs_use_version" "/etc/systemd/system/$app.service"
ynh_replace_string "__ENV_PATH__" "$PATH" "/etc/systemd/system/$app.service"
sudo systemctl daemon-reload
#=================================================
# ENABLE SERVICE IN ADMIN PANEL
@ -189,22 +198,22 @@ sudo yunohost service add $app --log "/var/log/$app/etherpad.log"
script_dir="$PWD"
cd "$final_path"
sudo npm install ep_align >> $install_log 2>&1 # Add Left/Center/Right/Justify to lines of text in a pad
sudo npm install ep_author_hover >> $install_log 2>&1 # Framapad - Adds author names to span titles
sudo npm install ep_automatic_logut >> $install_log 2>&1 # Automatically disconnects user after some period of time (Prevent server overload)
sudo npm install ep_comments_page >> $install_log 2>&1 # Framapad - Adds comments on sidebar and link it to the text.
sudo npm install ep_countable >> $install_log 2>&1 # Framapad - Displays paragraphs, sentences, words and characters counts.
sudo npm install ep_delete_empty_pads >> $install_log 2>&1 # Framapad - Delete pads which were never edited
sudo npm install ep_font_color >> $install_log 2>&1 # Framapad - Apply colors to fonts
sudo npm install ep_headings2 >> $install_log 2>&1 # Framapad - Adds heading support to Etherpad Lite.
sudo npm install ep_markdown >> $install_log 2>&1 # Framapad - Edit and Export as Markdown in Etherpad
sudo npm install ep_mypads >> $install_log 2>&1 # Framapad - Groups and private pads for etherpad
sudo npm install ep_page_view >> $install_log 2>&1 # Framapad - Add support to do 'page view', with a toggle on/off option in Settings, also Page Breaks with Control Enter
sudo npm install ep_spellcheck >> $install_log 2>&1 # Framapad - Add support to do 'Spell checking'
sudo npm install ep_subscript_and_superscript >> $install_log 2>&1 # Framapad - Add support for Subscript and Superscript
sudo npm install ep_table_of_contents >> $install_log 2>&1 # Framapad - View a table of contents for your pad
# sudo npm install ep_unoconv # Framapad - Use unoconv instead of abiword to export pads.
sudo npm install ep_user_font_size >> $install_log 2>&1 # Framapad - User Pad Contents font size can be set in settings, this does not effect other peoples views
sudo "$nodejs_path/npm" install ep_align >> $install_log 2>&1 # Add Left/Center/Right/Justify to lines of text in a pad
sudo "$nodejs_path/npm" install ep_author_hover >> $install_log 2>&1 # Framapad - Adds author names to span titles
sudo "$nodejs_path/npm" install ep_automatic_logut >> $install_log 2>&1 # Automatically disconnects user after some period of time (Prevent server overload)
sudo "$nodejs_path/npm" install ep_comments_page >> $install_log 2>&1 # Framapad - Adds comments on sidebar and link it to the text.
sudo "$nodejs_path/npm" install ep_countable >> $install_log 2>&1 # Framapad - Displays paragraphs, sentences, words and characters counts.
sudo "$nodejs_path/npm" install ep_delete_empty_pads >> $install_log 2>&1 # Framapad - Delete pads which were never edited
sudo "$nodejs_path/npm" install ep_font_color >> $install_log 2>&1 # Framapad - Apply colors to fonts
sudo "$nodejs_path/npm" install ep_headings2 >> $install_log 2>&1 # Framapad - Adds heading support to Etherpad Lite.
sudo "$nodejs_path/npm" install ep_markdown >> $install_log 2>&1 # Framapad - Edit and Export as Markdown in Etherpad
sudo "$nodejs_path/npm" install ep_mypads >> $install_log 2>&1 # Framapad - Groups and private pads for etherpad
sudo "$nodejs_path/npm" install ep_page_view >> $install_log 2>&1 # Framapad - Add support to do 'page view', with a toggle on/off option in Settings, also Page Breaks with Control Enter
sudo "$nodejs_path/npm" install ep_spellcheck >> $install_log 2>&1 # Framapad - Add support to do 'Spell checking'
sudo "$nodejs_path/npm" install ep_subscript_and_superscript >> $install_log 2>&1 # Framapad - Add support for Subscript and Superscript
sudo "$nodejs_path/npm" install ep_table_of_contents >> $install_log 2>&1 # Framapad - View a table of contents for your pad
# sudo "$nodejs_path/npm" install ep_unoconv" # Framapad - Use unoconv instead of abiword to export pads.
sudo "$nodejs_path/npm" install ep_user_font_size >> $install_log 2>&1 # Framapad - User Pad Contents font size can be set in settings, this does not effect other peoples views
sudo chown -R $app: $final_path/node_modules
#=================================================

View file

@ -18,6 +18,7 @@ app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
port=$(ynh_app_setting_get $app port)
db_name=$(ynh_app_setting_get $app db_name)
abiword=$(ynh_app_setting_get $app abiword)
#=================================================
# STANDARD REMOVE
@ -41,7 +42,16 @@ fi
# REMOVE DEPENDENCIES
#=================================================
ynh_remove_app_dependencies
if [ "$abiword" -eq 1 ]
then
ynh_remove_app_dependencies
fi
#=================================================
# REMOVE NODEJS
#=================================================
ynh_remove_nodejs
#=================================================
# REMOVE THE SQL BDD

View file

@ -90,18 +90,24 @@ ynh_restore_file logrotate
# INSTALL DEPENDENCIES
#=================================================
if [ "$abiword" -eq 1 ]
if [ $abiword -eq 1 ]
then
ynh_install_app_dependencies npm nodejs-legacy abiword
else
ynh_install_app_dependencies npm nodejs-legacy
ynh_install_app_dependencies abiword
fi
#=================================================
# INSTALL NODEJS
#=================================================
ynh_install_nodejs 0.10
ynh_app_setting_set $app nodejs_path $nodejs_path
#=================================================
# INSTALL ETHERPAD DEPENDENCIES
#=================================================
sudo npm install forever -g >> $install_log 2>&1
ynh_use_nodejs
sudo "$nodejs_path/npm" install forever -g >> $install_log 2>&1
#=================================================
# ENABLE SERVICE IN ADMIN PANEL