Skip to content

Commit

Permalink
MAJ script + backup
Browse files Browse the repository at this point in the history
  • Loading branch information
Maniack Crudelis committed Nov 22, 2015
1 parent 260ddda commit c519126
Show file tree
Hide file tree
Showing 53 changed files with 602 additions and 26,049 deletions.
8 changes: 4 additions & 4 deletions conf/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
location PATHTOCHANGE {
alias ALIASTOCHANGE ;
location __PATH__ {
alias __FINALPATH__ ;
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}
index index.php;
try_files $uri $uri/ index.php;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass unix:/var/run/php5-fpm-__NAMETOCHANGE__.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_FILENAME $request_filename;
}

# Include SSOWAT user panel.
Expand Down
392 changes: 392 additions & 0 deletions conf/php-fpm.conf

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions conf/php-fpm.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
; upload_max_filesize=100M
; post_max_size=100M
; max_execution_time=60
2 changes: 2 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"version": "1.6",
"url": "http://leed.idleman.fr/",
"licence": "free",
"maintainer": {
"name": "Maniack Crudelis",
"email": "maniackc_dev@crudelis.fr"
Expand Down Expand Up @@ -41,6 +42,7 @@
},
{
"name": "password",
"type": "password",
"ask": {
"en": "Set the administrator password Leed",
"fr": "Définissez le mot de passe administrateur de Leed"
Expand Down
23 changes: 23 additions & 0 deletions scripts/backup
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Récupère les infos de l'application.
app=leed
final_path=$(sudo yunohost app setting $app final_path)
domain=$(sudo yunohost app setting $app domain)


# The parameter $1 is the backup directory location
# which will be compressed afterward
backup_dir=$1/apps/$app
sudo mkdir -p "$backup_dir"

# Backup sources & data
sudo cp -a $final_path/. $backup_dir/sources

# Copy Nginx and YunoHost parameters to make the script "standalone"
sudo cp -a /etc/yunohost/apps/$app/. $backup_dir/yunohost
sudo cp -a /etc/nginx/conf.d/$domain.d/$app.conf $backup_dir/nginx.conf

# Copy dedicated php-fpm process to backup folder
sudo cp -a /etc/php5/fpm/pool.d/$app.conf $backup_dir/php-fpm.conf
sudo cp -a /etc/php5/fpm/conf.d/20-$app.ini $backup_dir/php-fpm.ini
110 changes: 77 additions & 33 deletions scripts/install
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ user_pwd=$4
language=$5
market=$6
is_public=$7
app=leed

# Check if admin exists
# Vérifie la validité de l'user admin
sudo yunohost user list --json | grep -q "\"username\": \"$admin\""
if [[ ! $? -eq 0 ]]; then
echo "Wrong admin"
exit 1
fi

# Check domain/path availability
sudo yunohost app checkurl $domain$path -a leed
# Vérifie la disponibilité du path et du domaine.
sudo yunohost app checkurl $domain$path -a $app
if [[ ! $? -eq 0 ]]; then
exit 1
fi
Expand All @@ -28,62 +29,102 @@ if [[ -z $user_pwd ]]; then
exit 1
fi

# Add settings to YunoHost
sudo yunohost app setting leed admin -v $admin
sudo yunohost app setting leed language -v $language
sudo yunohost app setting leed domain -v $domain
# 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"
exit 1
fi

# Generate random password
db_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
# Vérifie la présence du / en début de path
if [ $(echo $path | cut -c1) != "/" ]; then
path="/$path"
fi

# Use 'leed' as database name and user
db_user=leed

# Initialize database and store mysql password for upgrade
# 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=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
# 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.
sudo yunohost app initdb $db_user -p $db_pwd
sudo yunohost app setting leed mysqlpwd -v $db_pwd
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

# Décompresse la source
tar -x -f ../sources/leed.tar.gz
# Copie les fichiers sources
sudo cp -a leed/. "$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

# Copy files to right place
final_path=/var/www/leed
sudo mkdir -p $final_path
sudo cp -a ../sources/* $final_path
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/leed.conf

# Set right permissions for curl install
sudo chown -R www-data: $final_path

# Change variables in Leed configuration
sudo sed -i "s@PATHTOCHANGE@$path@g" /etc/nginx/conf.d/$domain.d/leed.conf
sudo sed -i "s@ALIASTOCHANGE@$final_path/@g" /etc/nginx/conf.d/$domain.d/leed.conf

# Rend la page d'install publique pour curl
sudo yunohost app setting leed 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 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 #yunoleed" | sudo tee -a /etc/hosts
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 leed market -v "$market"
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

# Files owned by root, www-data can just read
sudo mkdir $final_path/cache

# 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 can write on plugins and cache

# 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)

Expand All @@ -92,18 +133,21 @@ 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/leed
sudo cp ../conf/cron_leed /etc/cron.d/$app

# Make app private if necessary
sudo yunohost app setting leed is_public -v "$is_public"
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 leed unprotected_uris -d
sudo yunohost app setting $app unprotected_uris -d
# Rend la page d'actualisation accessible pour le script cron.
sudo yunohost app setting leed skipped_uris -v "/action.php"
sudo yunohost app setting $app skipped_uris -v "/action.php"
sudo yunohost app ssowatconf
fi

# Clean hosts
sudo sed -i '/yunoleed/d' /etc/hosts
sudo sed -i '/#leed/d' /etc/hosts

# Recharge la configuration php5-fpm
# sudo service php5-fpm reload
34 changes: 21 additions & 13 deletions scripts/remove
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
#!/bin/bash

db_user=leed
db_name=leed
app=leed

# Récupère les infos de l'application.
root_pwd=$(sudo cat /etc/yunohost/mysql)
domain=$(sudo yunohost app setting leed domain)
admin=$(sudo yunohost app setting leed admin)
path=$(sudo yunohost app setting leed path)

# Suppression de la base de donnée et son user
mysql -u root -p$root_pwd -e "DROP DATABASE $db_name ; DROP USER $db_user@localhost ;"
# Suppression du dossier
sudo rm -rf /var/www/leed
domain=$(sudo yunohost app setting $app domain)

# Utilise '$app' comme nom d'utilisateur et de base de donnée
db_user=$app
mysql -u root -p$root_pwd -e "DROP DATABASE $db_user ; DROP USER $db_user@localhost ;"

# Suppression du dossier de l'application
sudo rm -rf /var/www/$app

# Suppression de la configuration nginx
sudo rm -f /etc/nginx/conf.d/$domain.d/leed.conf
sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf

# Retirer le cron
sudo rm -f /etc/cron.d/leed
sudo rm -f /etc/cron.d/$app

# Suppression de la configuration du pool php-fpm
sudo rm -f /etc/php5/fpm/pool.d/$app.conf
sudo rm -f /etc/php5/fpm/conf.d/20-$app.ini

# Reload Nginx and regenerate SSOwat conf
# Recharge la configuration Nginx et php5-fpm
sudo service nginx reload
# sudo service php5-fpm reload
# Régénère la configuration de SSOwat
sudo yunohost app ssowatconf
25 changes: 25 additions & 0 deletions scripts/restore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Récupère les infos de l'application.
app=leed
final_path=$(sudo yunohost app setting $app final_path)
domain=$(sudo yunohost app setting $app domain)

# The parameter $1 is the uncompressed restore directory location
backup_dir=$1/apps/$app

# Restore sources & data
sudo cp -a $backup_dir/sources/. $final_path

# Restore Nginx and YunoHost parameters
sudo cp -a $backup_dir/yunohost/. /etc/yunohost/apps/$app
sudo cp -a $backup_dir/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf

# Copy dedicated php-fpm process from backup folder to the right location
sudo cp -a $backup_dir/php-fpm.conf /etc/php5/fpm/pool.d/$app.conf
sudo cp -a $backup_dir/php-fpm.ini /etc/php5/fpm/conf.d/20-$app.ini
# And restart service
sudo service php5-fpm reload

# Restart webserver
sudo service nginx reload

0 comments on commit c519126

Please sign in to comment.