1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/hubzilla_ynh.git synced 2024-09-03 19:26:21 +02:00
hubzilla_ynh/scripts/install

135 lines
4.9 KiB
Text
Raw Normal View History

#!/bin/bash
2017-02-15 17:53:40 +01:00
source .fonctions # Charge les fonctions génériques habituellement utilisées dans le script
CLEAN_SETUP () {
# Nettoyage des résidus d'installation non pris en charge par le script remove.
# Pas de nettoyage supplémentaire nécessaire ici...
echo ""
}
TRAP_ON # Active trap pour arrêter le script si une erreur est détectée.
# Retrieve arguments
2017-02-15 17:53:40 +01:00
app=$YNH_APP_INSTANCE_NAME
2017-02-15 17:53:40 +01:00
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
email=$YNH_APP_ARG_EMAIL
upload=$YNH_APP_ARG_UPLOAD
2017-02-17 15:45:54 +01:00
is_public=$YNH_APP_ARG_IS_PUBLIC
# Source app helpers
source /usr/share/yunohost/helpers
2017-02-15 17:53:40 +01:00
# Vérifie que les variables ne sont pas vides.
CHECK_VAR "$app" "app name not set"
2017-02-15 17:53:40 +01:00
CHECK_USER "$admin" # Vérifie la validité de l'user admin
2017-02-15 17:53:40 +01:00
CHECK_PATH # Vérifie et corrige la syntaxe du path.
CHECK_DOMAINPATH # Vérifie la disponibilité du path et du domaine.
2017-02-15 17:53:40 +01:00
# Créer le repertoire de destination et stocke son emplacement.
CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilisé.
sudo mkdir "$final_path"
ynh_app_setting_set $app final_path $final_path
2017-02-15 17:53:40 +01:00
# Enregistre les infos dans la config YunoHost
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path
ynh_app_setting_set $app admin $admin
2017-02-17 15:43:21 +01:00
ynh_app_setting_set $app email $email
ynh_app_setting_set $app upload $upload
2017-02-17 15:45:54 +01:00
ynh_app_setting_set $app is_public $is_public
# Install dependencies
sudo apt-get update
sudo apt-get install -y -qq php5-cli php5-imagick php5-gd php5-mcrypt
2017-02-15 17:53:40 +01:00
# Create db
db_user=$app
2017-02-15 17:53:40 +01:00
db_user=${db_user//-/_} # mariadb ne supporte pas les - dans les noms de base de données. Ils sont donc remplacé par des _
db_pwd=$(ynh_string_random)
CHECK_VAR "$db_pwd" "db_pwd empty"
ynh_mysql_create_db "$db_user" "$db_user" $db_pwd
ynh_app_setting_set $app db_pwd $db_pwd
ynh_app_setting_set $app db_user $db_user
2017-02-15 18:27:33 +01:00
# We download the sources and check the md5sum
# 1 - hubzilla
hubzilla_file=`sudo cat ../sources/hubzilla/source_file`;
2017-02-17 14:04:56 +01:00
sudo wget -nv -i ../sources/hubzilla/source_url -O ${hubzilla_file}.zip
2017-02-15 18:37:43 +01:00
sudo md5sum -c ../sources/hubzilla/source_md5 --status || (echo "Corrupt source" >&2 && false)
sudo unzip -q ${hubzilla_file}.zip -d ../sources/hubzilla/
2017-02-17 14:04:56 +01:00
sudo cp -r ../sources/hubzilla/${hubzilla_file}/. $final_path
2017-02-15 18:27:33 +01:00
# 2 - Addons
2017-02-15 18:37:43 +01:00
addons_file=`sudo cat ../sources/hubzilla-addons/source_file`;
2017-02-17 14:04:56 +01:00
sudo wget -nv -i ../sources/hubzilla-addons/source_url -O ${addons_file}.zip
2017-02-15 18:37:43 +01:00
sudo md5sum -c ../sources/hubzilla-addons/source_md5 --status || (echo "Corrupt source" >&2 && false)
sudo unzip -q ${addons_file}.zip -d ../sources/hubzilla-addons/
2017-02-17 14:04:56 +01:00
sudo mkdir $final_path/addon
sudo cp -r ../sources/hubzilla-addons/${addons_file}/. $final_path/addon
2017-02-15 18:27:33 +01:00
# 3 - some extra folders
sudo mkdir -p "${final_path}/store/[data]/smarty3"
sudo chmod -R 777 $final_path/store
# Import database schema
2017-02-15 17:53:40 +01:00
sudo mysql -u$db_user -p$db_pwd $db_user < $final_path/install/schema_mysql.sql
# Copy the template install/htconfig.sample.php to .htconfig.php
sudo cp $final_path/install/htconfig.sample.php $final_path/.htconfig.php
# Use sed to add the database information to .htconfig.php
sudo sed -i "s/your.mysqlhost.com/localhost/g" $final_path/.htconfig.php
2017-02-15 17:53:40 +01:00
sudo sed -i "s/mysqlpassword/$db_pwd/g" $final_path/.htconfig.php
sudo sed -i "s/mysqlusername/$db_user/g" $final_path/.htconfig.php
2017-02-15 17:53:40 +01:00
sudo sed -i "s/mysqldatabasename/$db_user/g" $final_path/.htconfig.php
sudo sed -i "s/mysite.example/$domain/g" $final_path/.htconfig.php
sudo sed -i "s/if the auto install failed, put a unique random string here/$(ynh_string_random)$(ynh_string_random)$(ynh_string_random)/g" $final_path/.htconfig.php
sudo sed -i "s/ADMIN_EMAIL_REPLACE/$email/g" $final_path/.htconfig.php
# Set www-data to owner
2017-02-15 18:37:43 +01:00
sudo chown -R www-data:www-data $final_path
# Modify Nginx configuration file and copy it to Nginx conf directory
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf
2017-02-15 18:09:01 +01:00
sed -i "s@YNH_WWW_ALIAS@$final_path@g" ../conf/nginx.conf
sed -i "s@UPLOADTOCHANGE@$upload@g" ../conf/nginx.conf
2017-02-15 18:09:01 +01:00
nginxconf=/etc/nginx/conf.d/$domain.d/$app.conf
sudo cp ../conf/nginx.conf $nginxconf
sudo chown root: $nginxconf
sudo chmod 600 $nginxconf
# Modify php.ini to allow exec() function and increase the upload size limits
2017-02-17 21:57:47 +01:00
#sudo sed -i 's/pcntl_exec//g' /etc/php5/fpm/php.ini
2017-02-15 18:09:01 +01:00
sed -i "s@UPLOADTOCHANGE@$upload@g" ../conf/php-fpm.conf
sed -i "s@NAMETOCHANGE@$app@g" ../conf/php-fpm.conf
2017-02-15 18:09:01 +01:00
phpfpmconf=/etc/php5/fpm/pool.d/$app.conf
sudo cp ../conf/php-fpm.conf $phpfpmconf
sudo chown root: $phpfpmconf
sudo chmod 644 $phpfpmconf
# Set up poller
sed -i "s@YNH_WWW_PATH@$final_path@g" ../conf/poller-cron
sudo cp ../conf/poller-cron /etc/cron.d/$app
2017-02-17 15:45:54 +01:00
# Make app public if necessary
is_public=$(ynh_app_setting_get $app is_public)
if [ "$is_public" = "Yes" ];
then
ynh_app_setting_set $app skipped_uris "/"
else
ynh_app_setting_set $app protected_uris "/"
fi
# Reload services
sudo service php5-fpm reload || true
sudo service nginx reload || true
sudo yunohost app ssowatconf