1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/phpldapadmin_ynh.git synced 2024-09-03 19:56:45 +02:00
phpldapadmin_ynh/scripts/install
Développeur égaré ed3395ae1e ajustements + tests
2015-01-06 09:43:41 +01:00

73 lines
2.7 KiB
Bash
Executable file

#!/bin/bash
# Retrieve arguments
domain=$1
path=$2
admin=$3
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a phpldapadmin
if [[ ! $? -eq 0 ]]; then
exit 1
fi
# Check that admin user is an existing account
sudo yunohost user list --json | grep -q "\"username\": \"$admin\""
if [[ ! $? -eq 0 ]]; then
echo "Error : the chosen admin user does not exist"
exit 1
fi
# Copy files to the right place
version=$(cat upstream_version)
final_path=/var/www/phpldapadmin
sudo rm -rf $final_path
sudo mkdir -p $final_path
echo "Downloading phpLDAPadmin $version..."
sudo wget -O ../phpLDAPadmin.tar.gz http://sourceforge.net/projects/phpldapadmin/files/phpldapadmin-php5/$version/phpldapadmin-$version.tgz/download > /dev/null 2>&1
echo "Extracting to $final_path..."
sudo tar xvzf ../phpLDAPadmin.tar.gz -C .. > /dev/null 2>&1
sudo cp -r ../phpldapadmin-$version/* $final_path
# Create db
#echo "Setting up database..."
#db_user=phpldapadmin
#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')
#sed -i "s@YNH_PMA_USER@$db_user@g" ../conf/create_db.sql
#sudo yunohost app initdb $db_user -p $db_pwd
#mysql -u root -p$(sudo cat /etc/yunohost/mysql) < ../conf/create_db.sql
#mysql -u $db_user -p$db_pwd < ../conf/create_tables.sql
# mysql -u root -p$(sudo cat /etc/yunohost/mysql) < ../conf/create_tables.sql
#sudo yunohost app setting phpldapadmin mysqlpwd -v $db_pwd
# Configuration
echo "Configuring application..."
#sed -i "s@YNH_DOMAIN@$domain@g" ../conf/config.php
#sed -i "s@YNH_PMA_USER@$db_user@g" ../conf/config.php
#sed -i "s@YNH_PMA_PASSWORD@$db_pwd@g" ../conf/config.php
#sed -i "s@YNH_MYSQL_ROOT_PASSWORD@$(sudo cat /etc/yunohost/mysql)@g" ../conf/config.php
sudo cp ../conf/config.php $final_path/config/
sudo yunohost app addaccess phpldapadmin -u $admin
sudo yunohost app setting phpldapadmin admin -v $admin
# Files owned by root, www-data can just read
echo "Setting permission..."
sudo chown -R root: $final_path
sudo find $final_path -type f | xargs sudo chmod 644
sudo find $final_path -type d | xargs sudo chmod 755
# config.php contains sensitive data, restrict its access
sudo chown root:www-data $final_path/config/config.php
sudo chmod 640 $final_path/config/config.php
# Modify Nginx configuration file and copy it to Nginx conf directory
echo "Setting up nginx configuration..."
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf
sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf
nginxconf=/etc/nginx/conf.d/$domain.d/phpldapadmin.conf
sudo cp ../conf/nginx.conf $nginxconf
sudo chown root: $nginxconf
sudo chmod 600 $nginxconf
sudo service nginx reload
sudo yunohost app ssowatconf