mirror of
https://github.com/YunoHost-Apps/turtl_ynh.git
synced 2024-09-03 20:26:35 +02:00
First commit
This commit is contained in:
commit
9246a2c027
13 changed files with 985 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
*~
|
||||||
|
*.sw[op]
|
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2017 Framasoft
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
15
README.md
Normal file
15
README.md
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
# Turtl app for YunoHost
|
||||||
|
|
||||||
|
- [Yunohost project](https://yunohost.org)
|
||||||
|
- [Turtl website](https://turtlapp.com/)
|
||||||
|
|
||||||
|
 Turtl.
|
||||||
|
|
||||||
|
**WARNING**: this is a work in progress, test it at your own risks!
|
||||||
|
|
||||||
|
===
|
||||||
|
|
||||||
|
Turtl lets you take notes, bookmark websites, and store documents for sensitive projects.
|
||||||
|
From sharing passwords with your coworkers to tracking research on an article you're writing, Turtl keeps it all safe from everyone but you and those you share with.
|
||||||
|
|
||||||
|
You will need apps to use Turtl. Get them from <https://turtlapp.com/download/>.
|
4
conf/ccl-init.lisp
Normal file
4
conf/ccl-init.lisp
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#-quicklisp
|
||||||
|
(let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname))))
|
||||||
|
(when (probe-file quicklisp-init)
|
||||||
|
(load quicklisp-init)))
|
12
conf/logrotate.conf
Normal file
12
conf/logrotate.conf
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
/var/log/turtl/turtl.log
|
||||||
|
{
|
||||||
|
rotate 7
|
||||||
|
daily
|
||||||
|
missingok
|
||||||
|
notifempty
|
||||||
|
delaycompress
|
||||||
|
compress
|
||||||
|
postrotate
|
||||||
|
service turtl restart
|
||||||
|
endscript
|
||||||
|
}
|
6
conf/nginx.conf
Normal file
6
conf/nginx.conf
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
location __PATH__ {
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_pass http://127.0.0.1:__PORT____PATH__;
|
||||||
|
#--PRIVATE--# Include SSOWAT user panel.
|
||||||
|
include conf.d/yunohost_panel.conf.inc;
|
||||||
|
}
|
BIN
conf/rethinkdb_2.3.6_armhf.deb
Normal file
BIN
conf/rethinkdb_2.3.6_armhf.deb
Normal file
Binary file not shown.
2
conf/rsyslogd.conf
Normal file
2
conf/rsyslogd.conf
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
if $programname == 'ccl' then /var/log/turtl/turtl.log
|
||||||
|
if $programname == 'ccl' then ~
|
1
conf/turtl.list
Normal file
1
conf/turtl.list
Normal file
|
@ -0,0 +1 @@
|
||||||
|
deb http://http.debian.net/debian jessie-backports main
|
55
manifest.json
Normal file
55
manifest.json
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
{
|
||||||
|
"name": "Turtl",
|
||||||
|
"id": "turtl",
|
||||||
|
"packaging_format": 1,
|
||||||
|
"description": {
|
||||||
|
"en": "Turtl lets you take notes, bookmark websites, and store documents for sensitive projects. From sharing passwords with your coworkers to tracking research on an article you're writing, Turtl keeps it all safe from everyone but you and those you share with.",
|
||||||
|
"fr": "Turtl vous permet de prendre des notes, de mettre en marque-page des adresses Web et de stocker des documents pour des projets sensibles. Du partage de mots de passe avec vos collègues au suivi des recherches pour un article que vous écrivez, Turtl empêche quiconque d'y accéder, sauf vous et ceux que vous partagez."
|
||||||
|
},
|
||||||
|
"url": "https://turtlapp.com/",
|
||||||
|
"license": "MIT",
|
||||||
|
"maintainer": {
|
||||||
|
"name": "Luc Didry",
|
||||||
|
"email": "luc@framasoft.org",
|
||||||
|
"url": "https://framasoft.org"
|
||||||
|
},
|
||||||
|
"requirements": {
|
||||||
|
"yunohost": ">> 2.4.0"
|
||||||
|
},
|
||||||
|
"multi_instance": false,
|
||||||
|
"services": [
|
||||||
|
"turtl"
|
||||||
|
],
|
||||||
|
"arguments": {
|
||||||
|
"install" : [
|
||||||
|
{
|
||||||
|
"name": "domain",
|
||||||
|
"type": "domain",
|
||||||
|
"ask": {
|
||||||
|
"en": "Choose a domain for your turtl server",
|
||||||
|
"fr": "Choisissez un domaine pour votre serveur turtl"
|
||||||
|
},
|
||||||
|
"example": "domain.org"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "path",
|
||||||
|
"type": "path",
|
||||||
|
"ask": {
|
||||||
|
"en": "Choose a path for Turtl",
|
||||||
|
"fr": "Choisissez un chemin pour Turtl"
|
||||||
|
},
|
||||||
|
"example": "/turtl",
|
||||||
|
"default": "/"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "is_public",
|
||||||
|
"type": "boolean",
|
||||||
|
"ask": {
|
||||||
|
"en": "Is it a public server? (should we announce it?)",
|
||||||
|
"fr": "Est-ce un serveur public ? (devons-nous l'annoncer ?)"
|
||||||
|
},
|
||||||
|
"default": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
626
scripts/_common.sh
Normal file
626
scripts/_common.sh
Normal file
|
@ -0,0 +1,626 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
#=================================================
|
||||||
|
# TESTING
|
||||||
|
#=================================================
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Remove a file or a directory securely
|
||||||
|
#
|
||||||
|
# usage: ynh_secure_remove path_to_remove
|
||||||
|
# | arg: path_to_remove - File or directory to remove
|
||||||
|
ynh_secure_remove () {
|
||||||
|
path_to_remove=$1
|
||||||
|
forbidden_path=" \
|
||||||
|
/var/www \
|
||||||
|
/home/yunohost.app"
|
||||||
|
|
||||||
|
if [[ "$forbidden_path" =~ "$path_to_remove" \
|
||||||
|
# Match all path or subpath in $forbidden_path
|
||||||
|
|| "$path_to_remove" =~ ^/[[:alnum:]]+$ \
|
||||||
|
# Match all first level path from / (Like /var, /root, etc...)
|
||||||
|
|| "${path_to_remove:${#path_to_remove}-1}" = "/" ]]
|
||||||
|
# Match if the path finish by /. Because it's seems there is an empty variable
|
||||||
|
then
|
||||||
|
echo "Avoid deleting of $path_to_remove." >&2
|
||||||
|
else
|
||||||
|
if [ -e "$path_to_remove" ]
|
||||||
|
then
|
||||||
|
sudo rm -R "$path_to_remove"
|
||||||
|
else
|
||||||
|
echo "$path_to_remove doesn't deleted because it's not exist." >&2
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
ynh_setup_source () {
|
||||||
|
src_url=$(cat ../conf/app.src | grep SOURCE_URL | cut -d= -f2-)
|
||||||
|
src_checksum=$(cat ../conf/app.src | grep SOURCE_SUM | cut -d= -f2-)
|
||||||
|
arch_format=$(cat ../conf/app.src | grep ARCH_FORMAT | cut -d= -f2-)
|
||||||
|
local_source="/opt/yunohost-apps-src/$YNH_APP_ID/source.$arch_format"
|
||||||
|
|
||||||
|
if test -e "$local_source"
|
||||||
|
then # Use the local source file if it is present
|
||||||
|
cp $local_source source.$arch_format
|
||||||
|
else # If not, download the source
|
||||||
|
wget -nv -O source.$arch_format $src_url
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check the control sum
|
||||||
|
echo "$src_checksum source.$arch_format" \
|
||||||
|
| md5sum -c --status || ynh_die "Corrupt source"
|
||||||
|
|
||||||
|
# Extract source into the app dir
|
||||||
|
sudo mkdir -p "$final_path"
|
||||||
|
if [ $(echo "$arch_format" | tr '[:upper:]' '[:lower:]') = "zip" ]
|
||||||
|
then # Zip format
|
||||||
|
# Using of a temp directory, because unzip doesn't manage --strip-components
|
||||||
|
temp_dir=$(mktemp -d)
|
||||||
|
unzip -quo source.zip -d "$temp_dir"
|
||||||
|
sudo cp -a $temp_dir/*/. "$final_path"
|
||||||
|
ynh_secure_remove "$temp_dir"
|
||||||
|
elif [ $(echo "$arch_format" | tr '[:upper:]' '[:lower:]') = "tar.gz" ]; then
|
||||||
|
sudo tar -x -f source.tar.gz -C "$final_path" --strip-components 1
|
||||||
|
else
|
||||||
|
ynh_die "Format d'archive non reconnu."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Apply patches
|
||||||
|
if test -f ../sources/patches/*.patch; then
|
||||||
|
(cd "$DEST" \
|
||||||
|
&& for p in ${PKG_DIR}/patches/*.patch; do \
|
||||||
|
sudo patch -p1 < $p; done) \
|
||||||
|
|| ynh_die "Unable to apply patches"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Add supplementary files
|
||||||
|
if test -e "../sources/extra_files"; then
|
||||||
|
sudo cp -a ../sources/extra_files/. "$final_path"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
ynh_backup_abstract () {
|
||||||
|
# A intégrer à ynh_backup directement.
|
||||||
|
ynh_backup "$@"
|
||||||
|
echo "$2" "$1" >> backup_list
|
||||||
|
}
|
||||||
|
|
||||||
|
ynh_restore_file () {
|
||||||
|
file_and_dest=$(grep "^$1" backup_list)
|
||||||
|
backup_file=${file_and_dest%% *}
|
||||||
|
backup_dest=${file_and_dest#* }
|
||||||
|
if [ -f "$backup_dest" ]; then
|
||||||
|
ynh_die "There is already a file at this path: $backup_dest"
|
||||||
|
fi
|
||||||
|
if test -d "$backup_file"; then
|
||||||
|
sudo cp -a "$backup_file/." "$backup_dest"
|
||||||
|
else
|
||||||
|
sudo cp -a "$backup_file" "$backup_dest"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
ynh_fpm_config () {
|
||||||
|
finalphpconf="/etc/php5/fpm/pool.d/$app.conf"
|
||||||
|
ynh_compare_checksum_config "$finalphpconf" 1
|
||||||
|
sudo cp ../conf/php-fpm.conf "$finalphpconf"
|
||||||
|
ynh_replace_string "__NAMETOCHANGE__" "$app" "$finalphpconf"
|
||||||
|
ynh_replace_string "__FINALPATH__" "$final_path" "$finalphpconf"
|
||||||
|
ynh_replace_string "__USER__" "$app" "$finalphpconf"
|
||||||
|
sudo chown root: "$finalphpconf"
|
||||||
|
ynh_store_checksum_config "$finalphpconf"
|
||||||
|
|
||||||
|
if [ -e "../conf/php-fpm.ini" ]
|
||||||
|
then
|
||||||
|
finalphpini="/etc/php5/fpm/conf.d/20-$app.ini"
|
||||||
|
ynh_compare_checksum_config "$finalphpini" 1
|
||||||
|
sudo cp ../conf/php-fpm.ini "$finalphpini"
|
||||||
|
sudo chown root: "$finalphpini"
|
||||||
|
ynh_store_checksum_config "$finalphpini"
|
||||||
|
fi
|
||||||
|
|
||||||
|
sudo systemctl reload php5-fpm
|
||||||
|
}
|
||||||
|
|
||||||
|
ynh_remove_fpm_config () {
|
||||||
|
ynh_secure_remove "/etc/php5/fpm/pool.d/$app.conf"
|
||||||
|
ynh_secure_remove "/etc/php5/fpm/conf.d/20-$app.ini"
|
||||||
|
sudo systemctl reload php5-fpm
|
||||||
|
}
|
||||||
|
|
||||||
|
ynh_nginx_config () {
|
||||||
|
finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
ynh_compare_checksum_config "$finalnginxconf" 1
|
||||||
|
sudo cp ../conf/nginx.conf "$finalnginxconf"
|
||||||
|
|
||||||
|
# To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable.
|
||||||
|
# Substitute in a nginx config file only if the variable is not empty
|
||||||
|
if test -n "${path_url:-}"; then
|
||||||
|
ynh_replace_string "__PATH__" "$path_url" "$finalnginxconf"
|
||||||
|
fi
|
||||||
|
if test -n "${domain:-}"; then
|
||||||
|
ynh_replace_string "__DOMAIN__" "$domain" "$finalnginxconf"
|
||||||
|
fi
|
||||||
|
if test -n "${port:-}"; then
|
||||||
|
ynh_replace_string "__PORT__" "$port" "$finalnginxconf"
|
||||||
|
fi
|
||||||
|
if test -n "${app:-}"; then
|
||||||
|
ynh_replace_string "__NAME__" "$app" "$finalnginxconf"
|
||||||
|
fi
|
||||||
|
if test -n "${final_path:-}"; then
|
||||||
|
ynh_replace_string "__FINALPATH__" "$final_path" "$finalnginxconf"
|
||||||
|
fi
|
||||||
|
ynh_store_checksum_config "$finalnginxconf"
|
||||||
|
|
||||||
|
sudo systemctl reload nginx
|
||||||
|
}
|
||||||
|
|
||||||
|
ynh_remove_nginx_config () {
|
||||||
|
ynh_secure_remove "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
sudo systemctl reload nginx
|
||||||
|
}
|
||||||
|
|
||||||
|
ynh_store_checksum_config () {
|
||||||
|
config_file_checksum=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_'
|
||||||
|
ynh_app_setting_set $app $config_file_checksum $(sudo md5sum "$1" | cut -d' ' -f1)
|
||||||
|
}
|
||||||
|
|
||||||
|
ynh_compare_checksum_config () {
|
||||||
|
current_config_file=$1
|
||||||
|
compress_backup=${2:-0} # If $2 is empty, compress_backup will set at 0
|
||||||
|
config_file_checksum=checksum_${current_config_file//[\/ ]/_} # Replace all '/' and ' ' by '_'
|
||||||
|
checksum_value=$(ynh_app_setting_get $app $config_file_checksum)
|
||||||
|
if [ -n "$checksum_value" ]
|
||||||
|
then # Proceed only if a value was stocked into the app config
|
||||||
|
if ! echo "$checksum_value $current_config_file" | sudo md5sum -c --status
|
||||||
|
then # If the checksum is now different
|
||||||
|
backup_config_file="$current_config_file.backup.$(date '+%d.%m.%y_%Hh%M,%Ss')"
|
||||||
|
if [ $compress_backup -eq 1 ]
|
||||||
|
then
|
||||||
|
sudo tar --create --gzip --file "$backup_config_file.tar.gz" "$current_config_file" # Backup the current config file and compress
|
||||||
|
backup_config_file="$backup_config_file.tar.gz"
|
||||||
|
else
|
||||||
|
sudo cp -a "$current_config_file" "$backup_config_file" # Backup the current config file
|
||||||
|
fi
|
||||||
|
echo "Config file $current_config_file has been manually modified since the installation or last upgrade. So it has been duplicated in $backup_config_file" >&2
|
||||||
|
echo "$backup_config_file" # Return the name of the backup file
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
ynh_systemd_config () {
|
||||||
|
finalsystemdconf="/etc/systemd/system/$app.service"
|
||||||
|
ynh_compare_checksum_config "$finalsystemdconf" 1
|
||||||
|
sudo cp ../conf/systemd.service "$finalsystemdconf"
|
||||||
|
|
||||||
|
# To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable.
|
||||||
|
# Substitute in a nginx config file only if the variable is not empty
|
||||||
|
if test -n "${final_path:-}"; then
|
||||||
|
ynh_replace_string "__FINALPATH__" "$final_path" "$finalsystemdconf"
|
||||||
|
fi
|
||||||
|
if test -n "${app:-}"; then
|
||||||
|
ynh_replace_string "__APP__" "$app" "$finalsystemdconf"
|
||||||
|
fi
|
||||||
|
ynh_store_checksum_config "$finalsystemdconf"
|
||||||
|
|
||||||
|
sudo chown root: "$finalsystemdconf"
|
||||||
|
sudo systemctl enable $app
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
}
|
||||||
|
|
||||||
|
ynh_remove_systemd_config () {
|
||||||
|
finalsystemdconf="/etc/systemd/system/$app.service"
|
||||||
|
if [ -e "$finalsystemdconf" ]; then
|
||||||
|
sudo systemctl stop $app
|
||||||
|
sudo systemctl disable $app
|
||||||
|
ynh_secure_remove "$finalsystemdconf"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CHECKING
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
CHECK_DOMAINPATH () { # Vérifie la disponibilité du path et du domaine.
|
||||||
|
sudo yunohost app checkurl $domain$path_url -a $app
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK_FINALPATH () { # Vérifie que le dossier de destination n'est pas déjà utilisé.
|
||||||
|
final_path=/var/www/$app
|
||||||
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
||||||
|
}
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# DISPLAYING
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
NO_PRINT () { # Supprime l'affichage dans stdout pour la commande en argument.
|
||||||
|
set +x
|
||||||
|
$@
|
||||||
|
set -x
|
||||||
|
}
|
||||||
|
|
||||||
|
WARNING () { # Écrit sur le canal d'erreur pour passer en warning.
|
||||||
|
$@ >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
SUPPRESS_WARNING () { # Force l'écriture sur la sortie standard
|
||||||
|
$@ 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
QUIET () { # Redirige la sortie standard dans /dev/null
|
||||||
|
$@ > /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
ALL_QUIET () { # Redirige la sortie standard et d'erreur dans /dev/null
|
||||||
|
$@ > /dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
BACKUP_FAIL_UPGRADE () {
|
||||||
|
WARNING echo "Upgrade failed."
|
||||||
|
app_bck=${app//_/-} # Replace all '_' by '-'
|
||||||
|
if sudo yunohost backup list | grep -q $app_bck-pre-upgrade$backup_number; then # Vérifie l'existence de l'archive avant de supprimer l'application et de restaurer
|
||||||
|
sudo yunohost app remove $app # Supprime l'application avant de la restaurer.
|
||||||
|
sudo yunohost backup restore --ignore-hooks $app_bck-pre-upgrade$backup_number --apps $app --force # Restore the backup if upgrade failed
|
||||||
|
ynh_die "The app was restored to the way it was before the failed upgrade."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
BACKUP_BEFORE_UPGRADE () { # Backup the current version of the app, restore it if the upgrade fails
|
||||||
|
backup_number=1
|
||||||
|
old_backup_number=2
|
||||||
|
app_bck=${app//_/-} # Replace all '_' by '-'
|
||||||
|
if sudo yunohost backup list | grep -q $app_bck-pre-upgrade1; then # Vérifie l'existence d'une archive déjà numéroté à 1.
|
||||||
|
backup_number=2 # Et passe le numéro de l'archive à 2
|
||||||
|
old_backup_number=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
sudo yunohost backup create --ignore-hooks --apps $app --name $app_bck-pre-upgrade$backup_number # Créer un backup différent de celui existant.
|
||||||
|
if [ "$?" -eq 0 ]; then # Si le backup est un succès, supprime l'archive précédente.
|
||||||
|
if sudo yunohost backup list | grep -q $app_bck-pre-upgrade$old_backup_number; then # Vérifie l'existence de l'ancienne archive avant de la supprimer, pour éviter une erreur.
|
||||||
|
QUIET sudo yunohost backup delete $app_bck-pre-upgrade$old_backup_number
|
||||||
|
fi
|
||||||
|
else # Si le backup a échoué
|
||||||
|
ynh_die "Backup failed, the upgrade process was aborted."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
HUMAN_SIZE () { # Transforme une taille en Ko en une taille lisible pour un humain
|
||||||
|
human=$(numfmt --to=iec --from-unit=1K $1)
|
||||||
|
echo $human
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK_SIZE () { # Vérifie avant chaque backup que l'espace est suffisant
|
||||||
|
file_to_analyse=$1
|
||||||
|
backup_size=$(sudo du --summarize "$file_to_analyse" | cut -f1)
|
||||||
|
free_space=$(sudo df --output=avail "/home/yunohost.backup" | sed 1d)
|
||||||
|
|
||||||
|
if [ $free_space -le $backup_size ]
|
||||||
|
then
|
||||||
|
WARNING echo "Espace insuffisant pour sauvegarder $file_to_analyse."
|
||||||
|
WARNING echo "Espace disponible: $(HUMAN_SIZE $free_space)"
|
||||||
|
ynh_die "Espace nécessaire: $(HUMAN_SIZE $backup_size)"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# PACKAGE CHECK BYPASSING...
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
IS_PACKAGE_CHECK () { # Détermine une exécution en conteneur (Non testé)
|
||||||
|
return $(uname -n | grep -c 'pchecker_lxc')
|
||||||
|
}
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
#=================================================
|
||||||
|
# FUTUR YNH HELPERS
|
||||||
|
#=================================================
|
||||||
|
# Importer ce fichier de fonction avant celui des helpers officiel
|
||||||
|
# Ainsi, les officiels prendront le pas sur ceux-ci le cas échéant
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Normalize the url path syntax
|
||||||
|
# Handle the slash at the beginning of path and its absence at ending
|
||||||
|
# Return a normalized url path
|
||||||
|
#
|
||||||
|
# example: url_path=$(ynh_normalize_url_path $url_path)
|
||||||
|
# ynh_normalize_url_path example -> /example
|
||||||
|
# ynh_normalize_url_path /example -> /example
|
||||||
|
# ynh_normalize_url_path /example/ -> /example
|
||||||
|
# ynh_normalize_url_path / -> /
|
||||||
|
#
|
||||||
|
# usage: ynh_normalize_url_path path_to_normalize
|
||||||
|
# | arg: url_path_to_normalize - URL path to normalize before using it
|
||||||
|
ynh_normalize_url_path () {
|
||||||
|
path_url=$1
|
||||||
|
test -n "$path_url" || ynh_die "ynh_normalize_url_path expect a URL path as first argument and received nothing."
|
||||||
|
if [ "${path_url:0:1}" != "/" ]; then # If the first character is not a /
|
||||||
|
path_url="/$path_url" # Add / at begin of path variable
|
||||||
|
fi
|
||||||
|
if [ "${path_url:${#path_url}-1}" == "/" ] && [ ${#path_url} -gt 1 ]; then # If the last character is a / and that not the only character.
|
||||||
|
path_url="${path_url:0:${#path_url}-1}" # Delete the last character
|
||||||
|
fi
|
||||||
|
echo $path_url
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create a database, an user and its password. Then store the password in the app's config
|
||||||
|
#
|
||||||
|
# User of database will be store in db_user's variable.
|
||||||
|
# Name of database will be store in db_name's variable.
|
||||||
|
# And password in db_pwd's variable.
|
||||||
|
#
|
||||||
|
# usage: ynh_mysql_generate_db user name
|
||||||
|
# | arg: user - Owner of the database
|
||||||
|
# | arg: name - Name of the database
|
||||||
|
ynh_mysql_generate_db () {
|
||||||
|
db_pwd=$(ynh_string_random) # Generate a random password
|
||||||
|
ynh_mysql_create_db "$2" "$1" "$db_pwd" # Create the database
|
||||||
|
ynh_app_setting_set $app mysqlpwd $db_pwd # Store the password in the app's config
|
||||||
|
}
|
||||||
|
|
||||||
|
# Remove a database if it exist and the associated user
|
||||||
|
#
|
||||||
|
# usage: ynh_mysql_remove_db user name
|
||||||
|
# | arg: user - Proprietary of the database
|
||||||
|
# | arg: name - Name of the database
|
||||||
|
ynh_mysql_remove_db () {
|
||||||
|
if mysqlshow -u root -p$(sudo cat $MYSQL_ROOT_PWD_FILE) | grep -q "^| $2"; then # Check if the database exist
|
||||||
|
echo "Remove database $2" >&2
|
||||||
|
ynh_mysql_drop_db $2 # Remove the database
|
||||||
|
ynh_mysql_drop_user $1 # Remove the associated user to database
|
||||||
|
else
|
||||||
|
echo "Database $2 not found" >&2
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Correct the name given in argument for mariadb
|
||||||
|
#
|
||||||
|
# Avoid invalid name for your database
|
||||||
|
#
|
||||||
|
# Exemple: dbname=$(ynh_make_valid_dbid $app)
|
||||||
|
#
|
||||||
|
# usage: ynh_make_valid_dbid name
|
||||||
|
# | arg: name - name to correct
|
||||||
|
# | ret: the corrected name
|
||||||
|
ynh_make_valid_dbid () {
|
||||||
|
dbid=${1//[-.]/_} # Mariadb doesn't support - and . in the name of databases. It will be replace by _
|
||||||
|
echo $dbid
|
||||||
|
}
|
||||||
|
|
||||||
|
# Manage a fail of the script
|
||||||
|
#
|
||||||
|
# Print a warning to inform that the script was failed
|
||||||
|
# Execute the ynh_clean_setup function if used in the app script
|
||||||
|
#
|
||||||
|
# usage of ynh_clean_setup function
|
||||||
|
# This function provide a way to clean some residual of installation that not managed by remove script.
|
||||||
|
# To use it, simply add in your script:
|
||||||
|
# ynh_clean_setup () {
|
||||||
|
# instructions...
|
||||||
|
# }
|
||||||
|
# This function is optionnal.
|
||||||
|
#
|
||||||
|
# Usage: ynh_exit_properly is used only by the helper ynh_abort_if_errors.
|
||||||
|
# You must not use it directly.
|
||||||
|
ynh_exit_properly () {
|
||||||
|
exit_code=$?
|
||||||
|
if [ "$exit_code" -eq 0 ]; then
|
||||||
|
exit 0 # Exit without error if the script ended correctly
|
||||||
|
fi
|
||||||
|
|
||||||
|
trap '' EXIT # Ignore new exit signals
|
||||||
|
set +eu # Do not exit anymore if a command fail or if a variable is empty
|
||||||
|
|
||||||
|
echo -e "!!\n $app's script has encountered an error. Its execution was cancelled.\n!!" >&2
|
||||||
|
|
||||||
|
if type -t ynh_clean_setup > /dev/null; then # Check if the function exist in the app script.
|
||||||
|
ynh_clean_setup # Call the function to do specific cleaning for the app.
|
||||||
|
fi
|
||||||
|
|
||||||
|
ynh_die # Exit with error status
|
||||||
|
}
|
||||||
|
|
||||||
|
# Exit if an error occurs during the execution of the script.
|
||||||
|
#
|
||||||
|
# Stop immediatly the execution if an error occured or if a empty variable is used.
|
||||||
|
# The execution of the script is derivate to ynh_exit_properly function before exit.
|
||||||
|
#
|
||||||
|
# Usage: ynh_abort_if_errors
|
||||||
|
ynh_abort_if_errors () {
|
||||||
|
set -eu # Exit if a command fail, and if a variable is used unset.
|
||||||
|
trap ynh_exit_properly EXIT # Capturing exit signals on shell script
|
||||||
|
}
|
||||||
|
|
||||||
|
# Define and install dependencies with a equivs control file
|
||||||
|
# This helper can/should only be called once per app
|
||||||
|
#
|
||||||
|
# usage: ynh_install_app_dependencies dep [dep [...]]
|
||||||
|
# | arg: dep - the package name to install in dependence
|
||||||
|
ynh_install_app_dependencies () {
|
||||||
|
dependencies=$@
|
||||||
|
manifest_path="../manifest.json"
|
||||||
|
if [ ! -e "$manifest_path" ]; then
|
||||||
|
manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place
|
||||||
|
fi
|
||||||
|
version=$(sudo python3 -c "import sys, json;print(json.load(open(\"$manifest_path\"))['version'])") # Retrieve the version number in the manifest file.
|
||||||
|
dep_app=${app//_/-} # Replace all '_' by '-'
|
||||||
|
|
||||||
|
if ynh_package_is_installed "${dep_app}-ynh-deps"; then
|
||||||
|
echo "A package named ${dep_app}-ynh-deps is already installed" >&2
|
||||||
|
else
|
||||||
|
cat > ./${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build
|
||||||
|
Section: misc
|
||||||
|
Priority: optional
|
||||||
|
Package: ${dep_app}-ynh-deps
|
||||||
|
Version: ${version}
|
||||||
|
Depends: ${dependencies// /, }
|
||||||
|
Architecture: all
|
||||||
|
Description: Fake package for ${app} (YunoHost app) dependencies
|
||||||
|
This meta-package is only responsible of installing its dependencies.
|
||||||
|
EOF
|
||||||
|
ynh_package_install_from_equivs ./${dep_app}-ynh-deps.control \
|
||||||
|
|| ynh_die "Unable to install dependencies" # Install the fake package and its dependencies
|
||||||
|
ynh_app_setting_set $app apt_dependencies $dependencies
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Remove fake package and its dependencies
|
||||||
|
#
|
||||||
|
# Dependencies will removed only if no other package need them.
|
||||||
|
#
|
||||||
|
# usage: ynh_remove_app_dependencies
|
||||||
|
ynh_remove_app_dependencies () {
|
||||||
|
dep_app=${app//_/-} # Replace all '_' by '-'
|
||||||
|
ynh_package_autoremove ${dep_app}-ynh-deps # Remove the fake package and its dependencies if they not still used.
|
||||||
|
}
|
||||||
|
|
||||||
|
# Use logrotate to manage the logfile
|
||||||
|
#
|
||||||
|
# usage: ynh_use_logrotate [logfile]
|
||||||
|
# | arg: logfile - absolute path of logfile
|
||||||
|
#
|
||||||
|
# If no argument provided, a standard directory will be use. /var/log/${app}
|
||||||
|
# You can provide a path with the directory only or with the logfile.
|
||||||
|
# /parentdir/logdir/
|
||||||
|
# /parentdir/logdir/logfile.log
|
||||||
|
#
|
||||||
|
# It's possible to use this helper several times, each config will added to same logrotate config file.
|
||||||
|
ynh_use_logrotate () {
|
||||||
|
if [ "$#" -gt 0 ]; then
|
||||||
|
if [ "$(echo ${1##*.})" == "log" ]; then # Keep only the extension to check if it's a logfile
|
||||||
|
logfile=$1 # In this case, focus logrotate on the logfile
|
||||||
|
else
|
||||||
|
logfile=$1/.log # Else, uses the directory and all logfile into it.
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
logfile="/var/log/${app}/.log" # Without argument, use a defaut directory in /var/log
|
||||||
|
fi
|
||||||
|
cat > ./${app}-logrotate << EOF # Build a config file for logrotate
|
||||||
|
$logfile {
|
||||||
|
# Rotate if the logfile exceeds 100Mo
|
||||||
|
size 100M
|
||||||
|
# Keep 12 old log maximum
|
||||||
|
rotate 12
|
||||||
|
# Compress the logs with gzip
|
||||||
|
compress
|
||||||
|
# Compress the log at the next cycle. So keep always 2 non compressed logs
|
||||||
|
delaycompress
|
||||||
|
# Copy and truncate the log to allow to continue write on it. Instead of move the log.
|
||||||
|
copytruncate
|
||||||
|
# Do not do an error if the log is missing
|
||||||
|
missingok
|
||||||
|
# Not rotate if the log is empty
|
||||||
|
notifempty
|
||||||
|
# Keep old logs in the same dir
|
||||||
|
noolddir
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
sudo mkdir -p $(dirname "$logfile") # Create the log directory, if not exist
|
||||||
|
cat ${app}-logrotate | sudo tee -a /etc/logrotate.d/$app > /dev/null # Append this config to the others for this app. If a config file already exist
|
||||||
|
}
|
||||||
|
|
||||||
|
# Remove the app's logrotate config.
|
||||||
|
#
|
||||||
|
# usage: ynh_remove_logrotate
|
||||||
|
ynh_remove_logrotate () {
|
||||||
|
if [ -e "/etc/logrotate.d/$app" ]; then
|
||||||
|
sudo rm "/etc/logrotate.d/$app"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Find a free port and return it
|
||||||
|
#
|
||||||
|
# example: port=$(ynh_find_port 8080)
|
||||||
|
#
|
||||||
|
# usage: ynh_find_port begin_port
|
||||||
|
# | arg: begin_port - port to start to search
|
||||||
|
ynh_find_port () {
|
||||||
|
port=$1
|
||||||
|
test -n "$port" || ynh_die "The argument of ynh_find_port must be a valid port."
|
||||||
|
while netcat -z 127.0.0.1 $port # Check if the port is free
|
||||||
|
do
|
||||||
|
port=$((port+1)) # Else, pass to next port
|
||||||
|
done
|
||||||
|
echo $port
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create a system user
|
||||||
|
#
|
||||||
|
# usage: ynh_system_user_create user_name [home_dir]
|
||||||
|
# | arg: user_name - Name of the system user that will be create
|
||||||
|
# | arg: home_dir - Path of the home dir for the user. Usually the final path of the app. If this argument is omitted, the user will be created without home
|
||||||
|
ynh_system_user_create () {
|
||||||
|
if ! ynh_system_user_exists "$1" # Check if the user exists on the system
|
||||||
|
then # If the user doesn't exist
|
||||||
|
if [ $# -ge 2 ]; then # If a home dir is mentioned
|
||||||
|
user_home_dir="-d $2"
|
||||||
|
else
|
||||||
|
user_home_dir="--no-create-home"
|
||||||
|
fi
|
||||||
|
sudo useradd $user_home_dir --system --user-group $1 --shell /usr/sbin/nologin || ynh_die "Unable to create $1 system account"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Delete a system user
|
||||||
|
#
|
||||||
|
# usage: ynh_system_user_delete user_name
|
||||||
|
# | arg: user_name - Name of the system user that will be create
|
||||||
|
ynh_system_user_delete () {
|
||||||
|
if ynh_system_user_exists "$1" # Check if the user exists on the system
|
||||||
|
then
|
||||||
|
echo "Remove the user $1" >&2
|
||||||
|
sudo userdel $1
|
||||||
|
else
|
||||||
|
echo "The user $1 was not found" >&2
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Curl abstraction to help with POST requests to local pages (such as installation forms)
|
||||||
|
#
|
||||||
|
# $domain and $path_url should be defined externally (and correspond to the domain.tld and the /path (of the app?))
|
||||||
|
#
|
||||||
|
# example: ynh_local_curl "/install.php?installButton" "foo=$var1" "bar=$var2"
|
||||||
|
#
|
||||||
|
# usage: ynh_local_curl "page_uri" "key1=value1" "key2=value2" ...
|
||||||
|
# | arg: page_uri - Path (relative to $path_url) of the page where POST data will be sent
|
||||||
|
# | arg: key1=value1 - (Optionnal) POST key and corresponding value
|
||||||
|
# | arg: key2=value2 - (Optionnal) Another POST key and corresponding value
|
||||||
|
# | arg: ... - (Optionnal) More POST keys and values
|
||||||
|
ynh_local_curl () {
|
||||||
|
# Define url of page to curl
|
||||||
|
full_page_url=https://localhost$path_url$1
|
||||||
|
|
||||||
|
# Concatenate all other arguments with '&' to prepare POST data
|
||||||
|
POST_data=""
|
||||||
|
for arg in "${@:2}"
|
||||||
|
do
|
||||||
|
POST_data="${POST_data}${arg}&"
|
||||||
|
done
|
||||||
|
# (Remove the last character, which is an unecessary '&')
|
||||||
|
POST_data=${POST_data::-1}
|
||||||
|
|
||||||
|
# Curl the URL
|
||||||
|
curl -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 --data "$POST_data" "$full_page_url" 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Substitute/replace a string by another in a file
|
||||||
|
#
|
||||||
|
# usage: ynh_replace_string match_string replace_string target_file
|
||||||
|
# | arg: match_string - String to be searched and replaced in the file
|
||||||
|
# | arg: replace_string - String that will replace matches
|
||||||
|
# | arg: target_file - File in which the string will be replaced.
|
||||||
|
ynh_replace_string () {
|
||||||
|
delimit=@
|
||||||
|
match_string=${1//${delimit}/"\\${delimit}"} # Escape the delimiter if it's in the string.
|
||||||
|
replace_string=${2//${delimit}/"\\${delimit}"}
|
||||||
|
workfile=$3
|
||||||
|
|
||||||
|
sudo sed --in-place "s${delimit}${match_string}${delimit}${replace_string}${delimit}g" "$workfile"
|
||||||
|
}
|
181
scripts/install
Executable file
181
scripts/install
Executable file
|
@ -0,0 +1,181 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
source _common.sh
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# MANAGE FAILURE OF THE SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée.
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
domain=$YNH_APP_ARG_DOMAIN
|
||||||
|
path=$YNH_APP_ARG_PATH
|
||||||
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CHECK THE DEBIAN'S CODENAME
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
codename=$(lsb_release -a 2>/dev/null | grep Codename | cut -f 2)
|
||||||
|
test -z "$codename" && (ynh_die "codename empty")
|
||||||
|
if [ $codename != 'jessie' ]
|
||||||
|
then
|
||||||
|
ynh_die "Sorry, it can only be installed on Debian Jessie"
|
||||||
|
fi
|
||||||
|
archi=$(uname -m)
|
||||||
|
pwd=$(pwd)
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# FIND AND OPEN A PORT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
port=$(ynh_find_port 8181) # Cherche un port libre.
|
||||||
|
ynh_app_setting_set $app port $port
|
||||||
|
|
||||||
|
# Store infos in YunoHost config
|
||||||
|
ynh_app_setting_set $app domain ${domain}
|
||||||
|
ynh_app_setting_set $app path ${path}
|
||||||
|
ynh_app_setting_set $app is_public ${is_public}
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# DEPENDENCIES
|
||||||
|
#=================================================
|
||||||
|
# Install Clozure Common Lisp
|
||||||
|
cd /opt
|
||||||
|
if [ $archi == "armv7l" ]
|
||||||
|
then
|
||||||
|
wget -q ftp://ftp.clozure.com/pub/release/1.11/ccl-1.11-linuxarm.tar.gz
|
||||||
|
tar xf ccl-1.11-linuxarm.tar.gz
|
||||||
|
else
|
||||||
|
wget -q ftp://ftp.clozure.com/pub/release/1.11/ccl-1.11-linuxx86.tar.gz
|
||||||
|
tar xf ccl-1.11-linuxx86.tar.gz
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd ccl
|
||||||
|
if [ $(grep -c "flags.* lm .*" /proc/cpuinfo) -eq 0 ]
|
||||||
|
then
|
||||||
|
cp scripts/ccl /usr/bin/ccl
|
||||||
|
else
|
||||||
|
cp scripts/ccl64 /usr/bin/ccl
|
||||||
|
fi
|
||||||
|
sed -e "s@CCL_DEFAULT_DIRECTORY=/usr/local/src/ccl@CCL_DEFAULT_DIRECTORY=/opt/ccl@" -i /usr/bin/ccl
|
||||||
|
|
||||||
|
# Install some dependencies
|
||||||
|
cd $pwd
|
||||||
|
sudo cp -a ../conf/turtl.list /etc/apt/sources.list.d/
|
||||||
|
if [ $archi == "armv7l" ]
|
||||||
|
then
|
||||||
|
gpg --keyserver pgpkeys.mit.edu --recv-key 7638D0442B90D010
|
||||||
|
gpg -a --export 7638D0442B90D010 | sudo apt-key add -
|
||||||
|
fi
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get -qq -y install build-essential
|
||||||
|
sudo apt-get -qq -t jessie-backports -y install libuv1-dev
|
||||||
|
|
||||||
|
# Install QuickLisp
|
||||||
|
sudo cp -a ../conf/ccl-init.lisp ~www-data/.ccl-init.lisp
|
||||||
|
mkdir ~www-data/quicklisp ~www-data/.cache/
|
||||||
|
chown www-data: ~www-data/quicklisp ~www-data/.cache/ ~www-data/.ccl-init.lisp
|
||||||
|
|
||||||
|
wget -q https://beta.quicklisp.org/quicklisp.lisp -O /tmp/quicklisp.lisp
|
||||||
|
wget -q https://beta.quicklisp.org/quicklisp.lisp.asc -O /tmp/quicklisp.lisp.asc
|
||||||
|
gpg --keyserver pgpkeys.mit.edu --recv-key 307965AB028B5FF7
|
||||||
|
gpg --verify /tmp/quicklisp.lisp.asc /tmp/quicklisp.lisp
|
||||||
|
|
||||||
|
su -c 'echo -e "(quicklisp-quickstart:install)\n(quit)" | ccl --load /tmp/quicklisp.lisp' -s /bin/bash www-data
|
||||||
|
|
||||||
|
echo "(pushnew \"./\" asdf :*central-registry* :test #'equal)" >> ~www-data/.ccl-init.lisp
|
||||||
|
|
||||||
|
rm -f /tmp/quicklisp /tmp/quicklisp.lisp.asc
|
||||||
|
|
||||||
|
# Install RethinkDB
|
||||||
|
if [ $archi == "armv7l" ]
|
||||||
|
then
|
||||||
|
sudo dpkg -i ../conf/rethinkdb_2.3.6_armhf.deb
|
||||||
|
else
|
||||||
|
release=$(lsb_release -cs)
|
||||||
|
echo "deb http://download.rethinkdb.com/apt $release main" | sudo tee /etc/apt/sources.list.d/rethinkdb.list
|
||||||
|
wget -qO- https://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add -
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get -qq -y install rethinkdb
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "http-port=8091" > /etc/rethinkdb/instances.d/turtl.conf
|
||||||
|
service rethinkdb restart
|
||||||
|
|
||||||
|
# Install RethinkDB tools (needed for backup)
|
||||||
|
apt-get install python-pip
|
||||||
|
pip install rethinkdb
|
||||||
|
|
||||||
|
# Install Turtl
|
||||||
|
cd /var/www
|
||||||
|
mkdir turtl/data -p
|
||||||
|
cd turtl
|
||||||
|
git clone https://github.com/turtl/api.git
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CONFIGURE TURTL
|
||||||
|
#=================================================
|
||||||
|
cd api
|
||||||
|
|
||||||
|
# Copions le modèle de fichier de configuration
|
||||||
|
cp config/config.default.lisp config/config.lisp
|
||||||
|
|
||||||
|
# Modifie la configuration de turtl
|
||||||
|
sed -e "s@\*server-port\* 8181@*server-port* $port@" \
|
||||||
|
-e "s@\*server-bind\* nil@*server-bind* \"127.0.0.1\"@" \
|
||||||
|
-e "s@\*production-error-handling\* nil@*production-error-handling* t@" \
|
||||||
|
-e "s@\*site-url\* \"http://turtl.dev:8181\"@*site-url* \"https://$domain\"@" \
|
||||||
|
-e "s@\*smtp-host\* nil@*smtp-host* \"localhost\"@" \
|
||||||
|
-e "s@\*display-errors\* t@*display-errors* nil@" \
|
||||||
|
-e "s@\*local-upload\* nil@*local-upload* \"/var/www/turtl/data\"@" \
|
||||||
|
-e "s@\*local-upload-url\* nil@*local-upload-url* \"https://$domain\"@" \
|
||||||
|
-i config/config.lisp
|
||||||
|
|
||||||
|
if [ $path != '/' ]
|
||||||
|
then
|
||||||
|
sed -e "s@\*api-path\* \"\"@\*api-path\* \"$path\"@" -i config/config.lisp
|
||||||
|
fi
|
||||||
|
|
||||||
|
ynh_store_checksum_config "config/config.lisp" # Enregistre la somme de contrôle du fichier de config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# LOG HANDLING
|
||||||
|
#=================================================
|
||||||
|
cd $pwd
|
||||||
|
sudo cp ../conf/rsyslogd.conf /etc/rsyslog.d/turtl.conf
|
||||||
|
sudo service rsyslog restart
|
||||||
|
sudo cp ../conf/logrotate.conf /etc/logrotate.d/turtl
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# ENABLE SERVICE IN ADMIN PANEL
|
||||||
|
#=================================================
|
||||||
|
# Add service to Yunohost monitoring
|
||||||
|
sudo yunohost service add turtl --log "/var/log/turtl/turtl.log"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# NGINX
|
||||||
|
#=================================================
|
||||||
|
# Copy Nginx conf
|
||||||
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||||
|
|
||||||
|
# Change variables in Nginx configuration
|
||||||
|
if [ $is_public -eq 1 ];
|
||||||
|
then
|
||||||
|
ynh_app_setting_set "$app" unprotected_uris "$path"
|
||||||
|
fi
|
||||||
|
sudo sed -i "s@__PATH__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
||||||
|
sudo sed -i "s@__PORT__@$port@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
||||||
|
|
||||||
|
# Reload Nginy
|
||||||
|
sudo service nginx reload
|
60
scripts/remove
Executable file
60
scripts/remove
Executable file
|
@ -0,0 +1,60 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC STARTING
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
source _common.sh
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
|
domain=$(ynh_app_setting_get "$app" domain)
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# STANDARD REMOVE
|
||||||
|
#=================================================
|
||||||
|
# DISABLE SERVICE IN ADMIN PANEL
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Retire le service du monitoring de Yunohost.
|
||||||
|
if sudo yunohost service status | grep -q turtl # Test l'existence du service dans Yunohost
|
||||||
|
then
|
||||||
|
echo "Remove turtl service"
|
||||||
|
sudo yunohost service remove turtl
|
||||||
|
fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC REMOVE
|
||||||
|
#=================================================
|
||||||
|
# REMOVE TURTL
|
||||||
|
#=================================================
|
||||||
|
# Remove sources
|
||||||
|
sudo rm -rf "/var/www/$app/"
|
||||||
|
# Remove dependencies
|
||||||
|
sudo pip uninstall rethinkdb -y
|
||||||
|
ynh_secure_remove "/etc/rethinkdb/instances.d/turtl.conf"
|
||||||
|
sudo rm -rf "/var/lib/rethinkdb/turtl"
|
||||||
|
ynh_package_remove libuv1-dev rethinkdb
|
||||||
|
sudo rm -rf "/var/lib/rethinkdb/turtl"
|
||||||
|
sudo rm -rf "/var/www/.cache/"
|
||||||
|
sudo rm -rf "/var/www/quicklisp/"
|
||||||
|
sudo rm -rf "/opt/ccl/"
|
||||||
|
ynh_secure_remove "/var/www/.ccl-init.lisp"
|
||||||
|
ynh_secure_remove "/usr/bin/ccl"
|
||||||
|
ynh_secure_remove "/etc/logrotate.d/turtl"
|
||||||
|
ynh_secure_remove "/etc/rsyslog.d/turtl.conf"
|
||||||
|
sudo service rsyslog restart
|
||||||
|
# Remove source.list
|
||||||
|
ynh_secure_remove "/etc/apt/sources.list.d/turtl.list"
|
||||||
|
# Remove nginx configuration file
|
||||||
|
ynh_secure_remove "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
|
||||||
|
# Reload nginx service
|
||||||
|
sudo service nginx reload
|
Loading…
Add table
Reference in a new issue