mirror of
https://github.com/YunoHost-Apps/monica_ynh.git
synced 2024-09-03 19:46:23 +02:00
update nodejs helpers and installation
This commit is contained in:
parent
3508e67e35
commit
9e0b03ffe6
2 changed files with 48 additions and 40 deletions
|
@ -112,81 +112,88 @@ sudo_path () {
|
||||||
}
|
}
|
||||||
|
|
||||||
# INFOS
|
# INFOS
|
||||||
# nvm utilise la variable PATH pour stocker le path de la version de node à utiliser.
|
# n (Node version management) utilise la variable PATH pour stocker le path de la version de node à utiliser.
|
||||||
# C'est ainsi qu'il change de version
|
# 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
|
# En attendant une généralisation de root, il est possible d'utiliser sudo avec le helper temporaire sudo_path
|
||||||
# Il permet d'utiliser sudo en gardant le $PATH modifié
|
# 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_install_nodejs installe la version de nodejs demandée en argument, avec n
|
||||||
# ynh_use_nodejs active une version de nodejs dans le script courant
|
# 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
|
# 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
|
# - nodejs_path: Le chemin absolu de cette version de node
|
||||||
# Utilisé pour des appels directs à npm ou node.
|
# Utilisé pour des appels directs à node.
|
||||||
# - nodejs_version: Simplement le numéro de version de nodejs pour cette application
|
# - 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.
|
# - 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
|
# 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.
|
# 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"
|
n_install_dir="/opt/node_n"
|
||||||
ynh_use_nodejs () {
|
ynh_use_nodejs () {
|
||||||
nodejs_path=$(ynh_app_setting_get $app nodejs_path)
|
|
||||||
nodejs_version=$(ynh_app_setting_get $app nodejs_version)
|
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`
|
load_n_path="[[ :$PATH: == *\":$n_install_dir/bin:\"* ]] || PATH+=\":$n_install_dir/bin\""
|
||||||
nodejs_use_version="source $nvm_install_dir/nvm.sh; nvm use \"$nodejs_version\""
|
|
||||||
|
|
||||||
# Desactive set -u for this script.
|
nodejs_use_version="n $nodejs_version"
|
||||||
set +u
|
|
||||||
eval $nodejs_use_version
|
# "Load" a version of node
|
||||||
set -u
|
eval $load_n_path; $nodejs_use_version
|
||||||
|
eval $load_n_path; sudo env "PATH=$PATH" $nodejs_use_version
|
||||||
|
|
||||||
|
# Get the absolute path of this version of node
|
||||||
|
nodejs_path="$(n bin $nodejs_version)"
|
||||||
|
|
||||||
|
# Make an alias for node use
|
||||||
|
ynh_node_exec="eval $load_n_path; n use $nodejs_version"
|
||||||
|
sudo_ynh_node_exec="eval $load_n_path; sudo env \"PATH=$PATH\" n use $nodejs_version"
|
||||||
}
|
}
|
||||||
|
|
||||||
ynh_install_nodejs () {
|
ynh_install_nodejs () {
|
||||||
|
# Use n, https://github.com/tj/n to manage the nodejs versions
|
||||||
local nodejs_version="$1"
|
local nodejs_version="$1"
|
||||||
local nvm_install_script="https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh"
|
local n_install_script="https://git.io/n-install"
|
||||||
|
|
||||||
local nvm_exec="source $nvm_install_dir/nvm.sh; nvm"
|
# Create $n_install_dir
|
||||||
|
sudo mkdir -p "$n_install_dir"
|
||||||
|
|
||||||
sudo mkdir -p "$nvm_install_dir"
|
# Load n path in PATH
|
||||||
|
PATH+=":$n_install_dir/bin"
|
||||||
|
|
||||||
# If nvm is not previously setup, install it
|
# If n is not previously setup, install it
|
||||||
"$nvm_exec --version" > /dev/null 2>&1 || \
|
n --version > /dev/null 2>&1 || \
|
||||||
( cd "$nvm_install_dir"
|
( echo "Installation of N - Node.js version management" >&2; \
|
||||||
echo "Installation of NVM"
|
curl -sL $n_install_script | sudo N_PREFIX="$n_install_dir" bash -s -- -y $nodejs_version )
|
||||||
sudo wget --no-verbose "$nvm_install_script" -O- | sudo NVM_DIR="$nvm_install_dir" bash > /dev/null)
|
|
||||||
|
|
||||||
# Install the requested version of nodejs
|
# Install the requested version of nodejs (except for the first installation of n, which installed the requested version of node.)
|
||||||
sudo su -c "$nvm_exec install \"$nodejs_version\" > /dev/null"
|
sudo env "PATH=$PATH" n $nodejs_version
|
||||||
|
|
||||||
|
# Use the real installed version. Sometimes slightly different
|
||||||
|
nodejs_version=$(node --version | cut -c2-)
|
||||||
|
|
||||||
# Store the ID of this app and the version of node requested for it
|
# 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"
|
echo "$YNH_APP_ID:$nodejs_version" | sudo tee --append "$n_install_dir/ynh_app_version"
|
||||||
|
|
||||||
# Get the absolute path of this version of node
|
# Store nodejs_version into the config of this app
|
||||||
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_app_setting_set $app nodejs_version $nodejs_version
|
||||||
|
|
||||||
ynh_use_nodejs
|
ynh_use_nodejs
|
||||||
}
|
}
|
||||||
|
|
||||||
ynh_remove_nodejs () {
|
ynh_remove_nodejs () {
|
||||||
nodejs_version=$(ynh_app_setting_get $app nodejs_version)
|
ynh_use_nodejs
|
||||||
|
|
||||||
# Remove the line for this app
|
# Remove the line for this app
|
||||||
sudo sed --in-place "/$YNH_APP_ID:$nodejs_version/d" "$nvm_install_dir/ynh_app_version"
|
sudo sed --in-place "/$YNH_APP_ID:$nodejs_version/d" "$n_install_dir/ynh_app_version"
|
||||||
|
|
||||||
# If none another app uses this version of nodejs, remove it.
|
# If none another app uses this version of nodejs, remove it.
|
||||||
if ! grep --quiet "$nodejs_version" "$nvm_install_dir/ynh_app_version"
|
if ! grep --quiet "$nodejs_version" "$n_install_dir/ynh_app_version"
|
||||||
then
|
then
|
||||||
sudo su -c "source $nvm_install_dir/nvm.sh; nvm deactivate; nvm uninstall \"$nodejs_version\" > /dev/null"
|
n rm $nodejs_version
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If none another app uses nvm, remove nvm and clean the root's bashrc file
|
# If none another app uses n, remove n
|
||||||
if [ ! -s "$nvm_install_dir/ynh_app_version" ]
|
if [ ! -s "$n_install_dir/ynh_app_version" ]
|
||||||
then
|
then
|
||||||
ynh_secure_remove "$nvm_install_dir"
|
ynh_secure_remove "$n_install_dir"
|
||||||
sudo sed --in-place "/NVM_DIR/d" /root/.bashrc
|
sudo sed --in-place "/N_PREFIX/d" /root/.bashrc
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,7 @@ ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
||||||
|
|
||||||
# install nodejs
|
# install nodejs
|
||||||
ynh_install_nodejs 6.10.3
|
ynh_install_nodejs 6.10.3
|
||||||
|
ynh_package_install g++
|
||||||
|
|
||||||
# extract monica into $final_path
|
# extract monica into $final_path
|
||||||
extract_monica $final_path
|
extract_monica $final_path
|
||||||
|
@ -94,10 +95,10 @@ sudo sed -i "s/yunodomain/$domain/g" $final_path/.env
|
||||||
sudo sed -i "s,yunopath,${path_url},g" $final_path/.env
|
sudo sed -i "s,yunopath,${path_url},g" $final_path/.env
|
||||||
|
|
||||||
# Install nodejs packages
|
# Install nodejs packages
|
||||||
cd $final_path && sudo_path "$nodejs_path/npm" install -g npm@4 pnpm
|
cd $final_path && sudo_path npm install npm@4 pnpm
|
||||||
cd $final_path && sudo_path "$nodejs_path/pnpm" install
|
cd $final_path && sudo_path pnpm install
|
||||||
cd $final_path && sudo_path "$nodejs_path/pnpm" install -g bower gulp
|
cd $final_path && sudo_path pnpm install bower gulp
|
||||||
cd $final_path && sudo_path "$nodejs_path/bower" install -f --allow-root
|
cd $final_path && sudo_path bower install -f --allow-root
|
||||||
|
|
||||||
# setup application config
|
# setup application config
|
||||||
cd $final_path && sudo /usr/bin/php7.0 artisan -q migrate --force
|
cd $final_path && sudo /usr/bin/php7.0 artisan -q migrate --force
|
||||||
|
|
Loading…
Add table
Reference in a new issue