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

209 lines
7.2 KiB
Text
Raw Normal View History

2015-03-19 20:49:50 +01:00
#!/bin/bash
2016-05-20 00:01:21 +02:00
ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2)
2015-03-19 20:49:50 +01:00
# Retrieve arguments
2016-05-20 00:01:21 +02:00
if [ $ynh_version = "2.4" ]
then
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC
always_encrypt=$YNH_APP_ARG_ALWAYS_ENCRYPT
app=$YNH_APP_INSTANCE_NAME
# Source app helpers
2016-06-04 23:09:27 +02:00
source /usr/share/yunohost/helpers
2016-05-20 00:01:21 +02:00
else
domain=$1
path=$2
admin=$3
is_public=$4
always_encrypt=$5
app=lutim
fi
script_dir=$PWD
2016-06-04 23:56:29 +02:00
# 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 "$is_public" && (echo "is_public not set" && touch /force_stop)
test -z "$always_encrypt" && (echo "always_encrypt not set" && touch /force_stop)
2016-05-20 00:01:21 +02:00
# 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!!"
if [ $ynh_version = "2.2" ]; then
/bin/bash $script_dir/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
2015-03-19 20:49:50 +01:00
2015-11-18 00:28:42 +01:00
# 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)
2015-03-19 20:49:50 +01:00
2015-11-18 00:28:42 +01:00
# Vérifie la disponibilité du path et du domaine.
sudo yunohost app checkurl $domain$path -a $app
# 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
2015-11-18 00:28:42 +01:00
fi
2015-03-27 21:02:59 +01:00
# Vérifie la présence du / en début de path
if [ $(echo $path | cut -c1) != "/" ]; then
path="/$path"
fi
2015-03-19 23:15:38 +01:00
# Vérifie l'absence du / en fin de path
2015-03-27 21:02:59 +01:00
pathRslash=$(echo "$path" | sed 's@/$@@')
2015-03-19 20:49:50 +01:00
2015-03-27 23:20:31 +01:00
# Modifie le domaine pour qu'il passe dans une regex
domain_regex=$(echo "$domain" | sed 's@-@.@g')
2015-11-18 00:28:42 +01:00
# Cherche un port libre.
2015-03-19 20:49:50 +01:00
port=8095
2016-06-04 23:40:44 +02:00
while ! sudo yunohost app checkport $port ; do
port=$((port+1))
2015-03-19 20:49:50 +01:00
done
2015-11-18 00:28:42 +01:00
# Enregistre les infos dans la config YunoHost
2015-03-19 20:49:50 +01:00
sudo yunohost app setting $app admin -v $admin
sudo yunohost app setting $app domain -v $domain
sudo yunohost app setting $app is_public -v $is_public
2015-03-26 13:07:01 +01:00
sudo yunohost app setting $app port -v $port
sudo yunohost app setting $app always_encrypt -v $always_encrypt
2015-03-19 20:49:50 +01:00
2015-11-18 00:28:42 +01:00
# Créer le repertoire de destination et stocke son emplacement.
sudo mkdir "$final_path"
sudo yunohost app setting $app final_path -v $final_path
2016-06-05 18:49:51 +02:00
# Télécharge la source
wget -nv --show-progress -i ../sources/source_url -O lutim.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)
2015-03-19 20:49:50 +01:00
# Décompresse la source
2016-06-05 18:49:51 +02:00
tar -x -f lutim.tar.gz
2015-11-18 00:28:42 +01:00
# Copie les fichiers sources
2016-06-05 18:49:51 +02:00
sudo cp -a $(cat ../sources/source_dir)/. "$final_path"
2015-11-18 00:28:42 +01:00
# Copie les fichiers additionnels ou modifiés.
2015-03-19 23:15:38 +01:00
sudo cp -a ../sources/ajouts/. "$final_path"
2015-11-18 00:28:42 +01:00
# Et copie le fichier de config nginx
2015-03-19 20:49:50 +01:00
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
2015-11-18 00:28:42 +01:00
2015-04-17 13:26:47 +02:00
# Installation de perlmagick, interface perl pour imagemagick et de carton, gestionnaire de dépendances perl
2015-05-02 13:33:03 +02:00
sudo apt-get update
2015-04-15 12:44:58 +02:00
sudo apt-get install carton perlmagick -qy
2015-03-19 20:49:50 +01:00
## Copie et configuration du fichier de conf.
2015-03-19 23:15:38 +01:00
sudo cp ../conf/lutim.conf.template "$final_path/lutim.conf"
sudo sed -i "s@__DOMAIN__@$domain@g" "$final_path/lutim.conf"
2015-03-27 21:33:54 +01:00
sudo sed -i "s@__PATH__@$path@g" "$final_path/lutim.conf"
2015-03-19 23:15:38 +01:00
sudo sed -i "s@__PORT__@$port@g" "$final_path/lutim.conf"
2015-03-27 20:28:32 +01:00
if [ "$always_encrypt" = "No" ]; then
2015-03-26 13:07:01 +01:00
always_encrypt=0
else
always_encrypt=1
fi
sudo sed -i "s@__ENCRYPT__@$always_encrypt@g" "$final_path/lutim.conf"
2015-03-19 20:49:50 +01:00
secret=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
2015-03-19 23:15:38 +01:00
sudo sed -i "s@__SECRET__@$secret@g" "$final_path/lutim.conf"
2016-06-05 00:53:04 +02:00
sudo yunohost app setting $app lutim.conf_file_md5 -v $(md5sum "$final_path/lutim.conf" | cut -d' ' -f1)
2015-03-19 20:49:50 +01:00
2016-03-31 22:41:54 +02:00
codename=$(lsb_release -a 2>/dev/null | grep Codename | cut -f 2)
sudo yunohost app setting $app codename -v $codename
if [ "$codename" = "wheezy" ]
then # On utilise le script init pour wheezy.
# Mise en place du script init
sudo cp ../conf/lutim.init /etc/init.d/lutim
sudo cp ../conf/lutim.default /etc/default/lutim
sudo chmod +x /etc/init.d/lutim
sudo chown root: /etc/init.d/lutim /etc/default/lutim
sudo sed -i "s@__FINALPATH__@$final_path/@g" /etc/default/lutim
## Démarrage auto du service
sudo update-rc.d lutim defaults
else # Et le script systemd à partir de jessie
# Mise en place du script systemd
sudo cp ../conf/lutim.service /etc/systemd/system/lutim.service
sudo chown root: /etc/systemd/system/lutim.service
sudo sed -i "s@__FINALPATH__@$final_path/@g" /etc/systemd/system/lutim.service
## Démarrage auto du service
sudo systemctl enable lutim.service
fi
2015-03-19 20:49:50 +01:00
## Mise en place des crons
sudo cp ../conf/cron_lutim /etc/cron.d/$app
sudo sed -i "s@__FINALPATH__@$final_path/@g" /etc/cron.d/$app
sudo chmod +x $final_path/script/lutim
2015-03-19 20:49:50 +01:00
2016-05-15 12:15:08 +02:00
# Configuration de logrotate
sed -i "s@__FINALPATH__@$final_path@g" ../conf/logrotate
sudo cp ../conf/logrotate /etc/logrotate.d/$app
2015-03-19 20:49:50 +01:00
# Installation de lutim via carton
2015-04-17 13:26:47 +02:00
sudo mkdir -p /var/log/$app/
2015-03-19 20:49:50 +01:00
cd $final_path
2015-03-26 13:07:01 +01:00
sudo carton install 2>&1 | sudo tee -a "/var/log/$app/setup_carton.log"
2015-03-19 20:49:50 +01:00
2015-08-19 21:33:40 +02:00
# Configure le path du dossier perl en fonction de l'architecture système
arch_dir=$(ls -1 $final_path/local/lib/perl5/ | grep linux-gnu)
if [ "$?" -ne 0 ]
then
echo "Impossible de trouver le dossier relatif à l'architecture système." | sudo tee -a "/var/log/$app/setup_carton.log"
fi
sudo sed -i "s@__ARCHDIR__@$arch_dir@g" "$final_path/script/lutim"
2015-03-19 20:49:50 +01:00
# Change variables in nginx configuration
2015-03-27 21:33:54 +01:00
sudo sed -i "s@__PATH__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf
2015-03-19 20:49:50 +01:00
sudo sed -i "s@__PORT__@$port@g" /etc/nginx/conf.d/$domain.d/$app.conf
# Make app public or private
sudo yunohost app setting $app skipped_uris -v "/"
if [ "$is_public" = "No" ];
2015-03-20 18:27:58 +01:00
then # Si l'app est privée, seul le visionnage des images reste public
2015-03-27 23:20:31 +01:00
sudo yunohost app setting $app protected_regex -v "$domain_regex$pathRslash/stats$","$domain_regex$pathRslash/manifest.webapp$","$domain_regex$pathRslash/$","$domain_regex$pathRslash/d/.*$","$domain_regex$pathRslash/m/.*$"
2015-03-19 20:49:50 +01:00
fi
2015-03-26 13:07:01 +01:00
# Making log symbolic link to /var/log
sudo touch /var/log/$app/production.log
sudo chown www-data: /var/log/$app/production.log
sudo ln -s /var/log/$app/production.log "$final_path/log/production.log"
2015-11-18 00:28:42 +01:00
# Configure les droits d'accès au fichiers
2015-03-19 20:49:50 +01:00
sudo chown -R www-data: $final_path
2016-03-31 22:41:54 +02:00
2015-03-19 20:49:50 +01:00
# Start lutim
2016-03-31 22:41:54 +02:00
sudo service lutim start
2015-03-19 20:49:50 +01:00
# Set right permissions on new files created at first start
2015-03-19 23:15:38 +01:00
sudo chown -R www-data: "$final_path"
2015-03-19 20:49:50 +01:00
2015-11-18 00:28:42 +01:00
2015-03-26 13:07:01 +01:00
# Add lutim as a service
sudo yunohost service add lutim -l $final_path/log/production.log
2015-11-18 00:28:42 +01:00
# Recharge la configuration Nginx
2015-03-19 20:49:50 +01:00
sudo service nginx reload
2015-11-18 00:28:42 +01:00
# Régénère la configuration de SSOwat
2015-03-19 20:49:50 +01:00
sudo yunohost app ssowatconf