2015-02-16 23:19:37 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Retrieve arguments
|
|
|
|
domain=$1
|
|
|
|
path=$2
|
|
|
|
user=$3
|
|
|
|
is_public=$4
|
|
|
|
|
|
|
|
# Check user parameter
|
|
|
|
sudo yunohost user list --json | grep -q "\"username\": \"$user\""
|
|
|
|
if [[ ! $? -eq 0 ]]; then
|
|
|
|
echo "Wrong user"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
sudo yunohost app setting friendica admin_user -v $user
|
|
|
|
|
2015-02-16 23:27:29 +01:00
|
|
|
final_path=/var/www/friendica
|
|
|
|
|
2015-02-16 23:19:37 +01:00
|
|
|
# Check domain/path availability
|
|
|
|
sudo yunohost app checkurl $domain$path -a friendica
|
|
|
|
if [[ ! $? -eq 0 ]]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Get admin mail
|
|
|
|
admin_mail=$(sudo yunohost user info $user | grep "mail:" | cut -d' ' -f2)
|
|
|
|
|
|
|
|
# Get code
|
|
|
|
version=$(cat upstream_version)
|
|
|
|
git clone -b "${version}" 'https://github.com/friendica/friendica.git'
|
|
|
|
sudo chown -R admin friendica
|
|
|
|
sudo cp -ar friendica $final_path
|
|
|
|
|
|
|
|
# Generate random password
|
|
|
|
|
|
|
|
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')
|
|
|
|
|
|
|
|
# Use 'friendica' as database name and user
|
|
|
|
db_user=friendica
|
|
|
|
|
|
|
|
# Initialize database and store mysql password for upgrade
|
|
|
|
sudo yunohost app initdb $db_user -p $db_pwd
|
|
|
|
sudo yunohost app setting friendica mysqlpwd -v $db_pwd
|
|
|
|
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
|
|
|
|
|
|
|
final_path=/var/www/friendica
|
|
|
|
|
|
|
|
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/friendica.conf
|
|
|
|
|
|
|
|
# configure friendica
|
|
|
|
|
|
|
|
sudo cp $final_path/htconfig.php $final_path/.htconfig.php
|
|
|
|
|
|
|
|
sudo sed -i "s@your.mysqlhost.com@localhost@g" $final_path/.htconfig.php
|
|
|
|
sudo sed -i "s@mysqlusername@$db_user@g" $final_path/.htconfig.php
|
|
|
|
sudo sed -i "s@mysqldatabasename@$db_user@g" $final_path/.htconfig.php
|
|
|
|
sudo sed -i "s@mysqlpassword@$db_pwd@g" $final_path/.htconfig.php
|
|
|
|
sudo sed -i "s/\['admin_email'\] = '';/\['admin_email'\] = '$admin_mail';/g" $final_path/.htconfig.php
|
|
|
|
|
|
|
|
# init db
|
|
|
|
|
|
|
|
mysql -u $db_user -p$db_pwd $db_user < $final_path/database.sql
|
|
|
|
|
|
|
|
# Ldap auth
|
|
|
|
|
|
|
|
wget -O ldapauth.php https://raw.githubusercontent.com/friendica/friendica-addons/master/ldapauth/ldapauth.php > /dev/null 2>&1
|
|
|
|
echo "Copy ldapauth.php to $final_path/addon/ldapauth..."
|
|
|
|
mkdir -p $final_path/addon/ldapauth
|
|
|
|
sudo cp ldapauth.php $final_path/addon/ldapauth
|
|
|
|
|
|
|
|
# Ldap auth config
|
|
|
|
|
|
|
|
sudo su -c "cat ../conf/conf.php >> $final_path/.htconfig.php"
|
|
|
|
|
|
|
|
# set permission
|
|
|
|
|
|
|
|
sudo chown -R www-data:www-data $final_path
|
|
|
|
|
|
|
|
# Reload Nginx and regenerate SSOwat conf
|
|
|
|
|
|
|
|
sudo service nginx reload
|
|
|
|
sudo yunohost app setting friendica skipped_uris -v "/"
|
|
|
|
sudo yunohost app ssowatconf
|
|
|
|
|
|
|
|
#protect URIs
|
|
|
|
|
|
|
|
if [ $is_public = "No" ];
|
|
|
|
then
|
|
|
|
sudo yunohost app setting friendica protected_uris -v "/"
|
|
|
|
sudo yunohost app ssowatconf
|
|
|
|
fi
|