2014-06-12 13:28:57 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Retrieve arguments
|
|
|
|
domain=$1
|
|
|
|
path=$2
|
2014-06-13 07:30:00 +02:00
|
|
|
admin_user=$3
|
|
|
|
upload_password=$4
|
2014-06-12 13:28:57 +02:00
|
|
|
|
|
|
|
# Check domain/path availability
|
|
|
|
sudo yunohost app checkurl $domain$path -a yourls
|
|
|
|
if [[ ! $? -eq 0 ]]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-06-13 09:47:35 +02:00
|
|
|
# Check that admin user is an existing account
|
|
|
|
sudo yunohost user list --json | grep -q "\"username\": \"$admin_user\""
|
|
|
|
if [[ ! $? -eq 0 ]]; then
|
|
|
|
echo "Error : the chosen admin user does not exist"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-06-12 18:16:54 +02:00
|
|
|
# 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 'yourls' as database name and user
|
|
|
|
db_user=yourls
|
|
|
|
|
|
|
|
# Initialize database and store mysql password for upgrade
|
|
|
|
sudo yunohost app initdb $db_user -p $db_pwd
|
|
|
|
sudo yunohost app setting yourls mysqlpwd -v $db_pwd
|
|
|
|
|
|
|
|
|
2014-06-12 13:28:57 +02:00
|
|
|
# Copy files to the right place
|
|
|
|
final_path=/var/www/yourls
|
|
|
|
sudo mkdir -p $final_path
|
2014-06-12 18:16:54 +02:00
|
|
|
sudo cp -a ../sources/* $final_path
|
|
|
|
|
2014-06-13 07:30:00 +02:00
|
|
|
# Change variable in yourls configuration
|
|
|
|
sudo cp ../conf/config.php $final_path/user/config.php
|
|
|
|
sudo sed -i "s/yunouser/$db_user/g" $final_path/user/config.php
|
|
|
|
sudo sed -i "s/yunopass/$db_pwd/g" $final_path/user/config.php
|
|
|
|
sudo sed -i "s/yunobase/$db_user/g" $final_path/user/config.php
|
2014-06-13 11:34:41 +02:00
|
|
|
sudo sed -i "s/yunodomain/$domain/g" $final_path/user/config.php
|
2014-06-13 07:30:00 +02:00
|
|
|
sudo sed -i "s/yourlsuser/$admin_user/g" $final_path/user/config.php
|
|
|
|
sudo sed -i "s/yourlspass/$upload_password/g" $final_path/user/config.php
|
2014-06-13 15:11:54 +02:00
|
|
|
sudo sed -i "s/yourlspath/$path/g" $final_path/user/config.php
|
2014-06-12 13:28:57 +02:00
|
|
|
|
2014-06-13 11:34:41 +02:00
|
|
|
|
2014-06-12 13:28:57 +02:00
|
|
|
# Set permissions
|
2014-06-13 07:30:00 +02:00
|
|
|
sudo chown -R www-data: $final_path
|
|
|
|
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
|
|
|
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf*
|
2014-06-13 10:41:02 +02:00
|
|
|
sed -i "s@ALIASTOCHANGE@$final_path/admin@g" ../conf/nginx.conf*
|
2014-06-13 09:47:35 +02:00
|
|
|
nginxconf=/etc/nginx/conf.d/$domain.d/yourls.conf
|
|
|
|
sudo cp ../conf/nginx.conf $nginxconf
|
|
|
|
sudo chown root: $nginxconf
|
|
|
|
sudo chmod 600 $nginxconf
|
2014-06-13 07:30:00 +02:00
|
|
|
|
|
|
|
# Reload Nginx and regenerate SSOwat conf
|
|
|
|
sudo service nginx reload
|
|
|
|
sudo yunohost app ssowatconf
|