mirror of
https://github.com/YunoHost-Apps/leed_ynh.git
synced 2024-09-03 19:26:32 +02:00
209 lines
6.9 KiB
Bash
209 lines
6.9 KiB
Bash
#!/bin/bash
|
|
|
|
ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2)
|
|
# Retrieve arguments
|
|
if [ $ynh_version = "2.4" ]
|
|
then
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
path=$YNH_APP_ARG_PATH
|
|
admin=$YNH_APP_ARG_ADMIN
|
|
user_pwd=$YNH_APP_ARG_PASSWORD
|
|
language=$YNH_APP_ARG_LANGUAGE
|
|
market=$YNH_APP_ARG_MARKET
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
# Source app helpers
|
|
source /usr/share/yunohost/helpers
|
|
else
|
|
domain=$1
|
|
path=$2
|
|
admin=$3
|
|
user_pwd=$4
|
|
language=$5
|
|
market=$6
|
|
is_public=$7
|
|
app=leed
|
|
fi
|
|
|
|
# Checks variables are not empty
|
|
test -z "$domain" && (echo "domain not set" && touch /force_stop)
|
|
test -z "$path" && (echo "path not set" && touch /force_stop)
|
|
test -z "$admin" && (echo "admin not set" && touch /force_stop)
|
|
test -z "$user_pwd" && (echo "user_pwd not set" && touch /force_stop)
|
|
test -z "$language" && (echo "language not set" && touch /force_stop)
|
|
test -z "$market" && (echo "market not set" && touch /force_stop)
|
|
test -z "$is_public" && (echo "is_public not set" && touch /force_stop)
|
|
|
|
|
|
# Delete files and db if exit with an error
|
|
EXIT_PROPERLY () {
|
|
trap ERR
|
|
echo -e "\e[91m \e[1m" # Shell in light red bold
|
|
echo -e "!!\n $app install's script has encountered an error. Installation was cancelled.\n!!"
|
|
|
|
echo -e "\e[22m" # Remove bold
|
|
|
|
# Clean hosts
|
|
sudo sed -i '/#leed/d' /etc/hosts
|
|
|
|
if [ $ynh_version = "2.2" ]; then
|
|
/bin/bash ./remove # Appel le script remove. En 2.2, ce comportement n'est pas automatique.
|
|
fi
|
|
exit 1
|
|
}
|
|
TRAP_ON () { # Activate signal capture
|
|
trap EXIT_PROPERLY ERR # Capturing exit signals on error
|
|
}
|
|
TRAP_OFF () { # Ignoring signal capture until TRAP_ON
|
|
# Pour une raison que j'ignore, la fonction TRAP_ON fonctionne très bien.
|
|
# Mais pas la fonction TRAP_OFF...
|
|
# Utiliser directement `trap '' ERR` dans le code pour l'utiliser, à la place de la fonction.
|
|
trap '' ERR # Ignoring exit signals
|
|
}
|
|
TRAP_ON
|
|
|
|
|
|
# Vérifie la validité de l'user admin
|
|
sudo yunohost user list --json | grep -q "\"username\": \"$admin\"" || (echo "Wrong admin" && touch /force_stop 2> /dev/null)
|
|
|
|
# Vérifie la disponibilité du path et du domaine.
|
|
sudo yunohost app checkurl $domain$path -a $app
|
|
|
|
# Vérifie que le mot de passe n'est pas vide.
|
|
if [[ -z $user_pwd ]]; then
|
|
echo "Mot de passe incorrect"
|
|
touch /force_stop 2> /dev/null
|
|
fi
|
|
|
|
# Vérifie que le dossier de destination n'est pas déjà utilisé.
|
|
final_path=/var/www/$app
|
|
if [ -e "$final_path" ]
|
|
then
|
|
echo "This path already contains a folder"
|
|
touch /force_stop 2> /dev/null
|
|
fi
|
|
|
|
# Vérifie la présence du / en début de path
|
|
if [ $(echo $path | cut -c1) != "/" ]; then
|
|
path="/$path"
|
|
fi
|
|
|
|
|
|
# Enregistre les infos dans la config YunoHost
|
|
sudo yunohost app setting $app admin -v $admin
|
|
sudo yunohost app setting $app language -v $language
|
|
sudo yunohost app setting $app domain -v $domain
|
|
|
|
# Génère un mot de passe aléatoire.
|
|
db_pwd=$(head -n20 /dev/urandom | tr -c -d 'A-Za-z0-9' | head -c20)
|
|
# Utilise '$app' comme nom d'utilisateur et de base de donnée
|
|
db_user=$app
|
|
# Initialise la base de donnée et stocke le mot de passe mysql.
|
|
if [ $ynh_version = "2.4" ]; then
|
|
ynh_mysql_create_db $db_user $db_user $db_pwd
|
|
else
|
|
sudo yunohost app initdb $db_user -p $db_pwd
|
|
fi
|
|
sudo yunohost app setting $app mysqlpwd -v $db_pwd
|
|
|
|
|
|
# Crée le repertoire de destination et stocke son emplacement.
|
|
sudo mkdir "$final_path"
|
|
sudo yunohost app setting $app final_path -v $final_path
|
|
|
|
# Télécharge la source
|
|
wget -nv --show-progress -i ../sources/source_url -O leed.tar.gz
|
|
# Vérifie la somme de contrôle de la source téléchargée.
|
|
md5sum -c ../sources/source_md5 --status || (echo "Corrupt source" && false)
|
|
# Décompresse la source
|
|
tar -x -f leed.tar.gz
|
|
# Copie les fichiers sources
|
|
sudo cp -a $(cat ../sources/source_dir)/. "$final_path"
|
|
# Copie les fichiers additionnels ou modifiés.
|
|
# sudo cp -a ../sources/ajouts/. "$final_path"
|
|
# Et copie le fichier de config nginx
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
|
|
# Modifie les variables dans le fichier de configuration nginx
|
|
sudo sed -i "s@__PATH__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
|
sudo sed -i "s@__FINALPATH__@$final_path@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
|
sudo sed -i "s@__NAMETOCHANGE__@$app@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
# Créer le fichier de configuration du pool php-fpm et le configure.
|
|
sed -i "s@__NAMETOCHANGE__@$app@g" ../conf/php-fpm.conf
|
|
sed -i "s@__FINALPATH__@$final_path@g" ../conf/php-fpm.conf
|
|
finalphpconf=/etc/php5/fpm/pool.d/$app.conf
|
|
sudo cp ../conf/php-fpm.conf $finalphpconf
|
|
sudo chown root: $finalphpconf
|
|
finalphpini=/etc/php5/fpm/conf.d/20-$app.ini
|
|
sudo cp ../conf/php-fpm.ini $finalphpini
|
|
sudo chown root: $finalphpini
|
|
sudo service php5-fpm reload
|
|
|
|
|
|
# Set right permissions for curl install
|
|
sudo chown -R www-data: $final_path
|
|
|
|
# Rend la page d'install publique pour curl
|
|
sudo yunohost app setting $app unprotected_uris -v "/" #L'usage de unprotected_uris a la place de skipped_uris permet de passer le header d'auth http
|
|
sudo yunohost app ssowatconf
|
|
|
|
# Reload Nginx
|
|
sudo service nginx reload
|
|
|
|
# Leed installation via curl
|
|
echo "127.0.0.1 $domain #leed" | sudo tee -a /etc/hosts
|
|
sleep 1
|
|
curl -k --data "install_changeLngLeed=$language&root=$domain$path&mysqlHost=localhost&mysqlLogin=$db_user&mysqlMdp=$db_pwd&mysqlBase=$db_user&mysqlPrefix=leed_&login=$admin&password=$user_pwd" https://$domain$path/install.php?installButton > /dev/null
|
|
|
|
# Activate Leed Market if necessary
|
|
sudo yunohost app setting $app market -v "$market"
|
|
if [ "$market" = "Yes" ];
|
|
then
|
|
sudo rm -R $final_path/plugins
|
|
sudo git clone https://github.com/ldleman/Leed-market.git $final_path/plugins
|
|
fi
|
|
|
|
|
|
# Configure les droits d'accès au fichiers
|
|
# -rw-r--r-- sur les fichiers
|
|
sudo find $final_path -type f | xargs sudo chmod 644
|
|
# drwxr-xr-x sur les dossiers
|
|
sudo find $final_path -type d | xargs sudo chmod 755
|
|
# Les fichiers appartiennent à root
|
|
sudo chown -R root: $final_path
|
|
|
|
# www-data doit avoir les droits d'écriture dans plugins et cache
|
|
sudo mkdir $final_path/cache
|
|
sudo chown -R www-data $final_path/cache $final_path/plugins
|
|
|
|
|
|
# Récupération du code de synchronisation
|
|
code_sync=$(mysql -h localhost -u $db_user -p$db_pwd -s $db_user -e 'SELECT value FROM leed_configuration WHERE `key`="synchronisationCode"' | sed -n 1p)
|
|
|
|
# Mise en place du cron pour la synchronisation
|
|
sed -i "s@__ADMIN__@$admin@g" ../conf/cron_leed
|
|
sed -i "s@__DOMAIN__@$domain@g" ../conf/cron_leed
|
|
sed -i "s@__PATH__@$path@g" ../conf/cron_leed
|
|
sed -i "s@__CODESYNC__@$code_sync@g" ../conf/cron_leed
|
|
sudo cp ../conf/cron_leed /etc/cron.d/$app
|
|
|
|
# Make app private if necessary
|
|
sudo yunohost app setting $app is_public -v "$is_public"
|
|
if [ "$is_public" = "No" ];
|
|
then
|
|
# Retire l'autorisation d'accès de la page d'install.
|
|
sudo yunohost app setting $app unprotected_uris -d
|
|
# Rend la page d'actualisation accessible pour le script cron.
|
|
sudo yunohost app setting $app skipped_uris -v "/action.php"
|
|
sudo yunohost app ssowatconf
|
|
fi
|
|
|
|
# Clean hosts
|
|
sudo sed -i '/#leed/d' /etc/hosts
|
|
|
|
# Recharge la configuration php5-fpm
|
|
# sudo service php5-fpm reload
|