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

Update version (#25)

* Update app.src

* Update manifest.json

* Update _common.sh

* Update install
This commit is contained in:
frju365 2018-08-22 10:27:30 +02:00 committed by GitHub
parent b849e651d7
commit b9e35a919e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 146 additions and 65 deletions

View file

@ -1,5 +1,5 @@
SOURCE_URL=https://github.com/xwiki-labs/cryptpad/archive/2.0.0.tar.gz
SOURCE_SUM=bc84e3b48ea97ecf679adf9aa0146e8328392c5a035f7f1efbc004a10118d3d9
SOURCE_URL=https://github.com/xwiki-labs/cryptpad/archive/2.5.0.tar.gz
SOURCE_SUM=afc572cb43b0c5882b7373287dd65e221ed30805f158b9fcd86d42ce21bdac05
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true

View file

@ -6,7 +6,7 @@
"en": "Encrypted Pad",
"fr": "Créateur de pad chiffré."
},
"version": "1.27.0",
"version": "2.5.0",
"url": "https://cryptpad.fr/",
"license": "AGPL-3.0-or-later",
"maintainer": {

View file

@ -3,7 +3,7 @@
#=================================================
# COMMON VARIABLES
#=================================================
nodejs_version=9
nodejs_version=8.11.4
#=================================================
# BACKUP
@ -31,24 +31,16 @@ CHECK_SIZE () { # Vérifie avant chaque backup que l'espace est suffisant
# EXPERIMENTAL HELPERS
#=================================================
# INFOS
# 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
# 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
# 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 à 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.
n_install_dir="/opt/node_n"
node_version_path="/opt/node_n/n/versions/node"
# N_PREFIX est le dossier de n, il doit être chargé dans les variables d'environnement pour n.
node_version_path="$n_install_dir/n/versions/node"
# N_PREFIX is the directory of n, it needs to be loaded as a environment variable.
export N_PREFIX="$n_install_dir"
# Install Node version management
#
# [internal]
#
# usage: ynh_install_n
ynh_install_n () {
echo "Installation of N - Node.js version management" >&2
# Build an app.src for n
@ -62,34 +54,52 @@ SOURCE_SUM=2ba3c9d4dd3c7e38885b37e02337906a1ee91febe6d5c9159d89a9050f2eea8f" > "
PREFIX=$N_PREFIX make install 2>&1)
}
# Load the version of node for an app, and set variables.
#
# ynh_use_nodejs has to be used in any app scripts before using node for the first time.
#
# 2 variables are available:
# - $nodejs_path: The absolute path of node for the chosen version.
# - $nodejs_version: Just the version number of node for this app. Stored as 'nodejs_version' in settings.yml.
# And 2 alias stored in variables:
# - $nodejs_use_version: An old variable, not used anymore. Keep here to not break old apps
# NB: $PATH will contain the path to node, it has to be propagated to any other shell which needs to use it.
# That's means it has to be added to any systemd script.
#
# usage: ynh_use_nodejs
ynh_use_nodejs () {
nodejs_version=$(ynh_app_setting_get $app nodejs_version)
load_n_path="[[ :$PATH: == *\":$n_install_dir/bin:\"* ]] || PATH=\"$n_install_dir/bin:$PATH\"; N_PREFIX="$n_install_dir""
nodejs_use_version="$n_install_dir/bin/n -q $nodejs_version"
# "Load" a version of node
eval $load_n_path; $nodejs_use_version
nodejs_use_version="echo \"Deprecated command, should be removed\""
# Get the absolute path of this version of node
nodejs_path="$(n bin $nodejs_version)"
nodejs_path="$node_version_path/$nodejs_version/bin"
# Make an alias for node use
ynh_node_exec="eval $load_n_path; n use $nodejs_version"
# Load the path of this version of node in $PATH
[[ :$PATH: == *":$nodejs_path"* ]] || PATH="$nodejs_path:$PATH"
}
# Install a specific version of nodejs
#
# n (Node version management) uses the PATH variable to store the path of the version of node it is going to use.
# That's how it changes the version
#
# ynh_install_nodejs will install the version of node provided as argument by using n.
#
# usage: ynh_install_nodejs [nodejs_version]
# | arg: nodejs_version - Version of node to install.
# If possible, prefer to use major version number (e.g. 8 instead of 8.10.0).
# The crontab will handle the update of minor versions when needed.
ynh_install_nodejs () {
# Use n, https://github.com/tj/n to manage the nodejs versions
nodejs_version="$1"
local n_install_script="https://git.io/n-install"
# Create $n_install_dir
mkdir -p "$n_install_dir"
# Load n path in PATH
CLEAR_PATH="$n_install_dir/bin:$PATH"
# Remove /usr/local/bin in PATH in case of node has already setup.
# Remove /usr/local/bin in PATH in case of node prior installation
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
# Move an existing node binary, to avoid to block n.
@ -97,7 +107,7 @@ ynh_install_nodejs () {
test -x /usr/bin/npm && mv /usr/bin/npm /usr/bin/npm_n
# If n is not previously setup, install it
if ! test n --version > /dev/null 2>&1
if ! test $(n --version > /dev/null 2>&1)
then
ynh_install_n
fi
@ -119,7 +129,7 @@ ynh_install_nodejs () {
real_nodejs_version=$(find $node_version_path/$nodejs_version* -maxdepth 0 | sort --version-sort | tail --lines=1)
real_nodejs_version=$(basename $real_nodejs_version)
# Create a symbolic link for this major version. If the file doesn't already exist
# Create a symbolic link for this major version if the file doesn't already exist
if [ ! -e "$node_version_path/$nodejs_version" ]
then
ln --symbolic --force --no-target-directory $node_version_path/$real_nodejs_version $node_version_path/$nodejs_version
@ -137,27 +147,40 @@ ynh_install_nodejs () {
ynh_use_nodejs
}
# Remove the version of node used by the app.
#
# This helper will check if another app uses the same version of node,
# if not, this version of node will be removed.
# If no other app uses node, n will be also removed.
#
# usage: ynh_remove_nodejs
ynh_remove_nodejs () {
ynh_use_nodejs
nodejs_version=$(ynh_app_setting_get $app nodejs_version)
# Remove the line for this app
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 no other app uses this version of nodejs, remove it.
if ! grep --quiet "$nodejs_version" "$n_install_dir/ynh_app_version"
then
n rm $nodejs_version
$n_install_dir/bin/n rm $nodejs_version
fi
# If none another app uses n, remove n
# If no other app uses n, remove n
if [ ! -s "$n_install_dir/ynh_app_version" ]
then
ynh_secure_remove "$n_install_dir"
ynh_secure_remove "/usr/local/n"
sed --in-place "/N_PREFIX/d" /root/.bashrc
fi
}
# Set a cron design to update your node versions
#
# [internal]
#
# This cron will check and update all minor node versions used by your apps.
#
# usage: ynh_cron_upgrade_node
ynh_cron_upgrade_node () {
# Build the update script
cat > "$n_install_dir/node_update.sh" << EOF
@ -196,6 +219,62 @@ EOF
chmod +x "/etc/cron.daily/node_update"
}
#=================================================
# Start or restart a service and follow its booting
#
# usage: ynh_check_starting "Line to match" [Log file] [Timeout] [Service name]
#
# | arg: Line to match - The line to find in the log to attest the service have finished to boot.
# | arg: Log file - The log file to watch
# | arg: Service name
# /var/log/$app/$app.log will be used if no other log is defined.
# | arg: Timeout - The maximum time to wait before ending the watching. Defaut 300 seconds.
ynh_check_starting () {
local line_to_match="$1"
local service_name="${4:-$app}"
local app_log="${2:-/var/log/$service_name/$service_name.log}"
local timeout=${3:-300}
ynh_clean_check_starting () {
# Stop the execution of tail.
kill -s 15 $pid_tail 2>&1
ynh_secure_remove "$templog" 2>&1
}
echo "Starting of $service_name" >&2
systemctl stop $service_name
local templog="$(mktemp)"
# Following the starting of the app in its log
tail -F -n0 "$app_log" > "$templog" &
# Get the PID of the tail command
local pid_tail=$!
systemctl start $service_name
local i=0
for i in `seq 1 $timeout`
do
# Read the log until the sentence is found, that means the app finished to start. Or run until the timeout
if grep --quiet "$line_to_match" "$templog"
then
echo "The service $service_name has correctly started." >&2
break
fi
echo -n "." >&2
sleep 1
done
if [ $i -eq $timeout ]
then
echo "The service $service_name didn't fully started before the timeout." >&2
fi
echo ""
ynh_clean_check_starting
}
#=================================================
# EXEC_LOGIN_AS Helper
# Execute a command as another user with login

View file

@ -54,67 +54,69 @@ ynh_app_setting_set $app path_url "$path_url"
# FIND AND OPEN A PORT
#=================================================
port=$(ynh_find_port 3000) # Cherche un port libre.
# Find a free port
port=$(ynh_find_port 3000)
# Open this port
yunohost firewall allow --no-upnp TCP $port 2>&1
ynh_app_setting_set $app port $port
#=================================================
# INSTALL NODEJS
#=================================================
ynh_install_nodejs $nodejs_version
ynh_install_nodejs $node_version
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app
#=================================================
# SPECIFIC SETUP
#=================================================
# HANDLE LOG FILES AND LOGROTATE
#=================================================
# Créer le dossier de log
mkdir -p /var/log/$app
touch /var/log/$app/$app.log
chown $app -R /var/log/$app
# Setup logrotate
ynh_use_logrotate
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_app_setting_set $app final_path $final_path
ynh_setup_source "$final_path" # Download, check integrity and uncompress the source from app.src
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
# Set files ownership during installation
chown $app:$app $final_path -R
chmod 755 $final_path -R
#=================================================
# Files owned by root, www-data can just read
#=================================================
sudo chown $app:$app $final_path -R
sudo chmod 755 $final_path -R
#=================================================
# NGINX CONFIGURATION
#=================================================
if [ "$path_url" != "/" ]
then
ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf"
fi
ynh_replace_string "__PATH__/" "${path_url%/}/" "../conf/nginx.conf"
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# ADD SYSTEMD SERVICE
# SETUP SYSTEMD
#=================================================
ynh_replace_string "__NODE__" "$nodejs_path" "../conf/systemd.service"
ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service"
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service"
# Create a dedicated systemd config
ynh_add_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"
ynh_replace_string "__NODE__" "$nodejs_path" "/etc/systemd/system/$app.service"
#=================================================
# Créer le dossier de log
#=================================================
sudo mkdir -p /var/log/$app
sudo touch /var/log/$app/osjs.log
install_log=/var/log/$app/installation.log
sudo touch $install_log
sudo chown $app -R /var/log/$app
sudo chown admin -R $install_log
#=================================================
# INSTALL CRYPTPAD