1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/bozon_ynh.git synced 2024-09-03 18:16:09 +02:00
bozon_ynh/scripts/install

102 lines
2.8 KiB
Text
Raw Normal View History

2016-03-23 19:30:43 +01:00
#! /bin/bash
app=bozon
#retrieve arguments
domain=$1
path=$2
admin=$3
password=$4
is_public=$5
default_lang=$6
# Remove trailing slash
[ "$path" != "/" ] && path=${path%/}
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a $app
if [[ ! $? -eq 0 ]]; then
exit 1
fi
# Check user
sudo yunohost user list --json | grep -q "\"username\": \"$admin\""
if [[ ! $? -eq 0 ]]; then
echo "Wrong user"
exit 1
fi
# Save app settings
sudo yunohost app setting $app admin -v "$admin"
sudo yunohost app setting $app is_public -v "$is_public"
sudo yunohost app setting $app domain -v "$domain"
sudo yunohost app setting $app path -v "$path"
2016-03-24 20:10:52 +01:00
# Create path for copying
2016-03-23 19:30:43 +01:00
final_path=/var/www/$app
sudo mkdir -p $final_path
2016-03-24 20:10:52 +01:00
# Copy files to final folder and set permissions
2016-03-23 19:30:43 +01:00
sudo cp -R ../sources/* $final_path/
sudo find $final_path -type f -name ".htaccess" | xargs sudo rm
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
2016-03-24 20:10:52 +01:00
# Configure config file
sudo sed -i "s@'en'@$default_lang'@g" $final_path/config.php
# Configure nginx settings
2016-03-23 19:30:43 +01:00
folder_path=${path%/}
sudo sed -i "s@YNH_EXAMPLE_PATH@$path@g" ../conf/nginx.conf
# If path is only / (without subfolder), add trailing slash to alias
alias_path=$final_path
[ "$path" == '/' ] && alias_path=$alias_path'/'
sudo sed -i "s@YNH_EXAMPLE_ALIAS@$alias_path@g" ../conf/nginx.conf
sudo sed -i "s@YNH_EXAMPLE_FOLDER@$folder_path@g" ../conf/nginx.conf
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
2016-03-24 20:10:52 +01:00
# Temporary set public accessible
2016-03-23 19:30:43 +01:00
sudo yunohost app setting $app unprotected_uris -v "/"
# Restart services
sudo service nginx reload
sudo yunohost app ssowatconf
2016-03-24 20:10:52 +01:00
# Temporary add domain name to /etc/hosts
2016-03-23 19:30:43 +01:00
sudo sed -i "1 i\127.0.0.1 $domain #bozon_hosts" /etc/hosts
#make request to install app
#get the html page
2016-03-24 20:10:52 +01:00
#curl_path=$([ "$path" == "/" ] || echo $path)
2016-03-23 19:30:43 +01:00
#curl -kL -o install_page.html https://$domain$curl_path/index.php?p=admin >/dev/null 2>&1
#get the token for form validation
#token=$(cat install_page.html | grep "input" | grep "token" | tail -1 | cut -d' ' -f3 | cut -d'"' -f2)
#send http POST values
2016-03-24 20:10:52 +01:00
curl -k -X POST \
2016-03-23 19:30:43 +01:00
--data-urlencode "login=$admin" \
2016-03-23 21:30:34 +01:00
--data-urlencode "pass=$password" \
--data-urlencode "confirm=$password" \
2016-03-24 20:10:52 +01:00
https://$domain$curl_path/index.php?p=login > /dev/null 2>&1
2016-03-23 19:30:43 +01:00
#remove domain name from /etc/hosts
sudo sed -i "/#bozon_hosts/d" /etc/hosts
# If app is private, remove url to SSOWat conf from skipped_uris
if [ "$is_public" = "No" ];
then
sudo yunohost app setting $app unprotected_uris -d
fi
2016-03-24 20:10:52 +01:00
# Adding admin to the allowed users
2016-03-23 19:30:43 +01:00
sudo yunohost app addaccess $app -u $admin
2016-03-24 20:10:52 +01:00
# Allow only allowed users to access admin panel
sudo yunohost app setting bozon protected_uris -v "index.php?p=login"
2016-03-23 19:30:43 +01:00
# Restart services
sudo service nginx reload
sudo yunohost app ssowatconf