1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/framagames_ynh.git synced 2024-09-03 18:36:28 +02:00
framagames_ynh/scripts/install

154 lines
5.1 KiB
Text
Raw Normal View History

2015-06-18 23:40:52 +02:00
#!/bin/bash
2016-12-24 12:38:35 +01:00
#set -eu
2015-06-18 23:40:52 +02:00
2016-12-24 12:38:35 +01:00
# Charge les fonctions génériques habituellement utilisées dans le script
#source fonctions
# Active trap pour arrêter le script si une erreur est détectée.
EXIT_PROPERLY () { # Provoque l'arrêt du script en cas d'erreur. Et nettoye les résidus.
exit_code=$?
if [ "$exit_code" -eq 0 ]; then
exit 0 # Quitte sans erreur si le script se termine correctement.
fi
trap '' EXIT
set +eu
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!!" >&2
if type -t CLEAN_SETUP > /dev/null; then # Vérifie l'existance de la fonction avant de l'exécuter.
CLEAN_SETUP # Appel la fonction de nettoyage spécifique du script install.
fi
# Compense le bug de ssowat qui ne supprime pas l'entrée de l'app en cas d'erreur d'installation.
sudo sed -i "\@\"$domain$path/\":@d" /etc/ssowat/conf.json
ynh_die
}
TRAP_ON () { # Activate signal capture
set -eu # Exit if a command fail, and if a variable is used unset.
trap EXIT_PROPERLY EXIT # Capturing exit signals on shell script
}
TRAP_ON
# Source app helpers
source /usr/share/yunohost/helpers
2015-06-18 23:40:52 +02:00
2016-12-24 12:38:35 +01:00
# Retrieve arguments
app=$YNH_APP_INSTANCE_NAME
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_IS_PUBLIC
2015-06-18 23:40:52 +02:00
2016-12-24 12:38:35 +01:00
# We check variables are not empty
CHECK_VAR () { # Vérifie que la variable n'est pas vide.
# $1 = Variable à vérifier
# $2 = Texte à afficher en cas d'erreur
test -n "$1" || (echo "$2" >&2 && false)
}
CHECK_VAR "$app" "app name not set"
# Check the path value and correct it (adds / at begining and removes it at the end)
CHECK_PATH () { # Vérifie la présence du / en début de path. Et son absence à la fin.
if [ "${path:0:1}" != "/" ]; then # Si le premier caractère n'est pas un /
path="/$path" # Ajoute un / en début de path
fi
if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then # Si le dernier caractère est un / et que ce n'est pas l$
path="${path:0:${#path}-1}" # Supprime le dernier caractère
fi
}
CHECK_PATH;
# Check domain and path availibility
CHECK_DOMAINPATH () { # Vérifie la disponibilité du path et du domaine.
sudo yunohost app checkurl $domain$path -a $app
}
CHECK_DOMAINPATH
# Check destination folder is not used already
CHECK_FINALPATH () { # 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" >&2
false
fi
}
CHECK_FINALPATH
2015-06-18 23:40:52 +02:00
final_path=/var/www/$app
2016-12-24 12:38:35 +01:00
# Define variables and Save app settings
ynh_app_setting_set "$app" domain "$domain"
#ynh_app_setting_set "$app" path "$path"
ynh_app_setting_set "$app" is_public "$is_public"
ynh_app_setting_set "$app" final_path "$final_path"
finalnginxconf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
ynh_app_setting_set "$app" finalnginxconf "$finalnginxconf"
2015-06-18 23:40:52 +02:00
2016-12-24 12:38:35 +01:00
finalphpconf="/etc/php5/fpm/pool.d/${app}.conf"
ynh_app_setting_set "$app" finalphpconf "$finalphpconf"
2015-06-18 23:40:52 +02:00
# Creation of folder
sudo mkdir -p $final_path
2016-12-24 14:54:11 +01:00
# We download the sources and go to latest revision
2017-01-17 19:59:41 +01:00
#URL=`sudo cat ../sources/source_url`;
#SHA1=`sudo cat ../sources/source_sha1`;
#sudo rm -rf ./gitsources
#sudo mkdir gitsources
#sudo chmod 777 gitsources
2016-12-24 14:54:11 +01:00
# We get the repository address
2017-01-17 19:59:41 +01:00
#sudo git clone $URL gitsources
2016-12-24 15:10:21 +01:00
# We reset to the latest known revision and copy the files to final_path
2017-01-17 19:59:41 +01:00
#cd gitsources
#sudo git reset --hard $SHA1
#sudo cp -a * $final_path
#cd ..
# We download the sources and check the md5sum
SHA1=`sudo cat ../sources/source_sha1`;
sed -i "s@SHA1TOCHANGE@$SHA1@g" ../sources/source_url
sed -i "s@SHA1TOCHANGE@$SHA1@g" ../sources/source_md5
sudo wget -nv -i ../sources/source_url -O framagames-${SHA1}.zip
sudo md5sum -c ../sources/source_md5 --status || (echo "Corrupt source" >&2 && false)
sudo unzip framagames-${SHA1}.zip -d ../sources/
2017-01-17 20:11:33 +01:00
sudo cp -R ../sources/framagames-${SHA1}/* $final_path
2016-12-24 14:54:11 +01:00
2015-06-18 23:40:52 +02:00
# Set permissions
sudo chmod 775 -R $final_path
2016-12-24 12:45:51 +01:00
sudo chown -hR www-data:www-data $final_path
2016-12-24 12:38:35 +01:00
# Modify Nginx configuration file and copy it to Nginx conf.d directory
2015-06-18 23:40:52 +02:00
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
2016-12-24 12:38:35 +01:00
sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf
sed -i "s@NAMETOCHANGE@$app@g" ../conf/nginx.conf
sudo cp ../conf/nginx.conf $finalnginxconf
2015-06-18 23:40:52 +02:00
2016-12-24 12:38:35 +01:00
# Modify php-fpm configuration file and copy it to php-fpm pool.d directory
sed -i "s@NAMETOCHANGE@$app@g" ../conf/php-fpm.conf
sed -i "s@FOLDERTOCHANGE@$final_path@g" ../conf/php-fpm.conf
2015-06-18 23:40:52 +02:00
sudo cp ../conf/php-fpm.conf $finalphpconf
sudo chown root: $finalphpconf
sudo chmod 644 $finalphpconf
# Make app public if necessary
2016-12-24 12:38:35 +01:00
is_public=$(ynh_app_setting_get $app is_public)
2015-06-18 23:40:52 +02:00
if [ "$is_public" = "Yes" ];
then
2016-12-24 12:38:35 +01:00
ynh_app_setting_set $app skipped_uris "/"
else
ynh_app_setting_set $app protected_uris "/"
2015-06-18 23:40:52 +02:00
fi
# Reload Nginx and regenerate SSOwat conf
2016-12-24 12:38:35 +01:00
sudo service php5-fpm reload
2015-06-18 23:40:52 +02:00
sudo service nginx reload
sudo yunohost app ssowatconf