2015-03-19 20:49:50 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2015-04-16 11:48:36 +02:00
|
|
|
echo "Installation bloquée en raison d'un bug perl à l'installation de carton qui bloque le démarrage de postgrey."
|
|
|
|
echo "On cherche la solution..."
|
|
|
|
exit 1
|
|
|
|
|
2015-03-19 20:49:50 +01:00
|
|
|
# Retrieve arguments
|
|
|
|
domain=$1
|
|
|
|
path=$2
|
|
|
|
admin=$3
|
|
|
|
is_public=$4
|
2015-03-26 13:07:01 +01:00
|
|
|
always_encrypt=$5
|
2015-03-19 20:49:50 +01:00
|
|
|
app=lutim
|
|
|
|
|
|
|
|
# Check if admin exists
|
|
|
|
sudo yunohost user list --json | grep -q "\"username\": \"$admin\""
|
|
|
|
if [[ ! $? -eq 0 ]]; then
|
|
|
|
echo "Wrong admin"
|
|
|
|
exit 1
|
|
|
|
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-03-19 20:49:50 +01:00
|
|
|
# Check domain/path availability
|
|
|
|
sudo yunohost app checkurl $domain$path -a $app
|
|
|
|
if [[ ! $? -eq 0 ]]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Get an available port
|
|
|
|
port=8095
|
|
|
|
sudo yunohost app checkport $port
|
|
|
|
while [[ ! $? -eq 0 ]]; do
|
|
|
|
port=$((port+1))
|
|
|
|
sudo yunohost app checkport $port
|
|
|
|
done
|
|
|
|
|
|
|
|
# Check /var/www/$app path is available
|
|
|
|
final_path=/var/www/$app
|
|
|
|
if [ -e "$final_path" ]
|
|
|
|
then
|
|
|
|
echo "This path already contains a folder"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Add settings to YunoHost
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
# Copy files to right place
|
2015-03-19 23:15:38 +01:00
|
|
|
sudo mkdir -p "$final_path"
|
2015-03-19 20:49:50 +01:00
|
|
|
# Création archive source: tar -czp -f lutim.tar.gz lutim
|
|
|
|
# Décompresse la source
|
|
|
|
tar -x -f ../sources/lutim.tar.gz
|
2015-03-19 23:15:38 +01:00
|
|
|
sudo cp -a lutim/. "$final_path"
|
|
|
|
sudo cp -a ../sources/ajouts/. "$final_path"
|
2015-03-19 20:49:50 +01:00
|
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
|
|
|
|
# Installation du module perl carton
|
2015-03-26 13:07:01 +01:00
|
|
|
sudo mkdir -p /var/log/$app/
|
2015-03-19 20:49:50 +01:00
|
|
|
echo "Installation du module perl carton. Attention, étape très longue..."
|
2015-04-15 12:44:58 +02:00
|
|
|
## yes | sudo cpan Carton 2>&1 | sudo tee "/var/log/$app/setup_carton.log" > /dev/null
|
2015-03-19 20:49:50 +01:00
|
|
|
|
|
|
|
# Installation de perlmagick, interface perl pour imagemagick
|
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"
|
2015-03-19 20:49:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Mise en place des scripts init
|
|
|
|
sudo cp ../conf/lutim.init /etc/init.d/lutim
|
2015-03-26 13:07:01 +01:00
|
|
|
# sudo sed -i "s@__FINALPATH__@$final_path@g" /etc/init.d/lutim
|
2015-03-19 20:49:50 +01:00
|
|
|
sudo cp ../conf/lutim.default /etc/default/lutim
|
|
|
|
sudo chmod +x /etc/init.d/lutim
|
|
|
|
sudo chown root:root /etc/init.d/lutim /etc/default/lutim
|
|
|
|
sudo sed -i "s@__FINALPATH__@$final_path/@g" /etc/default/lutim
|
|
|
|
|
|
|
|
## 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
|
|
|
|
|
|
|
|
# Installation de lutim via carton
|
|
|
|
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
|
|
|
|
|
|
|
## Démarrage auto des scripts init
|
|
|
|
sudo update-rc.d lutim defaults
|
|
|
|
# sudo update-rc.d -f lutim remove
|
|
|
|
|
|
|
|
# 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 rm -f /var/www/$app/log/production.log
|
|
|
|
sudo ln -s /var/log/$app/production.log "$final_path/log/production.log"
|
|
|
|
|
2015-03-19 20:49:50 +01:00
|
|
|
# Set right permissions
|
|
|
|
sudo chown -R www-data: $final_path
|
|
|
|
# Start lutim
|
|
|
|
sudo /etc/init.d/lutim start
|
|
|
|
# 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-03-26 13:07:01 +01:00
|
|
|
# Add lutim as a service
|
|
|
|
sudo yunohost service add lutim -l $final_path/log/production.log
|
|
|
|
|
2015-03-19 20:49:50 +01:00
|
|
|
# Reload Nginx and regenerate SSOwat conf
|
|
|
|
sudo service nginx reload
|
|
|
|
sudo yunohost app ssowatconf
|