mirror of
https://github.com/YunoHost-Apps/my_webapp_ynh.git
synced 2024-09-03 19:46:26 +02:00
75 lines
2 KiB
Bash
75 lines
2 KiB
Bash
#!/bin/bash
|
|
|
|
# Retrieve arguments
|
|
domain=$1
|
|
path=$2
|
|
user=$3
|
|
is_public=$4
|
|
final_path=/var/www/my_webapp
|
|
|
|
# Check domain/path availability
|
|
sudo yunohost app checkurl $domain$path -a my_webapp
|
|
if [[ ! $? -eq 0 ]]; then
|
|
exit 1
|
|
fi
|
|
|
|
# Check user
|
|
ls /home | grep $user
|
|
if [[ ! $? -eq 0 ]]; then
|
|
echo "Wrong user"
|
|
exit 1
|
|
fi
|
|
sudo yunohost app setting my_webapp ftp_user -v $user
|
|
|
|
# Check port availability
|
|
sudo yunohost app checkport 21
|
|
if [[ ! $? -eq 0 ]]; then
|
|
exit 1
|
|
fi
|
|
|
|
# Open port in firewall
|
|
sudo yunohost firewall allow TCP 21 > /dev/null 2>&1
|
|
|
|
# Install debian dependencies
|
|
sudo apt-get install pure-ftpd-ldap -y -qq
|
|
|
|
# Change user ID in configurations
|
|
sed -i "s@FTPUSER@$user@g" ../conf/ldap.conf
|
|
sed -i "s@FTPDIR@$final_path@g" ../conf/ldap.conf
|
|
sed -i "s@FTPUSER@$user@g" ../sources/index.html
|
|
sed -i "s@HOST@$domain@g" ../sources/index.html
|
|
|
|
# Copy files to the right place
|
|
sudo mkdir -p $final_path
|
|
sudo cp ../sources/index.html $final_path/
|
|
|
|
# Set permissions
|
|
sudo chmod 775 -R $final_path
|
|
sudo chown -hR $user:www-data $final_path
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
|
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
|
|
sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/my_webapp.conf
|
|
|
|
# Make app public if necessary
|
|
sudo yunohost app setting my_webapp is_public -v "$is_public"
|
|
if [ $is_public = "Yes" ];
|
|
then
|
|
sudo yunohost app setting my_webapp skipped_uris -v "/"
|
|
fi
|
|
|
|
# Adapt PureFTPd configuration
|
|
sudo cp ../conf/ldap.conf /etc/pure-ftpd/db/
|
|
sudo sh -c 'echo "yes" > /etc/pure-ftpd/conf/NoAnonymous'
|
|
sudo sh -c 'echo "yes" > /etc/pure-ftpd/conf/ChrootEveryone'
|
|
sudo sh -c 'echo "no" > /etc/pure-ftpd/conf/UnixAuthentication'
|
|
sudo sh -c 'echo "50000 50100" > /etc/pure-ftpd/conf/PassivePortRange'
|
|
|
|
# Register service to YunoHost monitoring
|
|
sudo yunohost app service pure-ftpd-ldap --log "/var/log/pure-ftpd/transfer.log"
|
|
|
|
# Reload Nginx, restart PureFTPd and regenerate SSOwat conf
|
|
sudo service nginx reload
|
|
sudo service pure-ftpd-ldap restart
|
|
sudo yunohost app ssowatconf
|