1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/freshrss_ynh.git synced 2024-09-03 18:36:33 +02:00
freshrss_ynh/scripts/install
2019-01-04 19:06:10 +01:00

112 lines
3.5 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
domain=$YNH_APP_ARG_DOMAIN
path=${YNH_APP_ARG_PATH}
admin_user=$YNH_APP_ARG_ADMIN
# Setup variables
app=$YNH_APP_INSTANCE_NAME
db_user=$app
db_name=$app
FINAL_PATH="/var/www/$app"
# Normalize the url path syntax
path=$(ynh_normalize_url_path $path)
# Check user parameter if not empty
if [[ $admin_user != '' ]]; then
ynh_user_exists $admin_user || ynh_die "Wrong user"
fi
# Check web path availability
ynh_webpath_available $domain $path
# Register (book) web path
ynh_webpath_register $app $domain $path
#install php dependencies
install_freshrss_dependencies
# Generate random DES key & password
deskey=$(ynh_string_random)
db_pwd=$(ynh_string_random)
app_salt=$(ynh_string_random)
# keep settings for later
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app admin_user $admin_user
ynh_app_setting_set "$app" mysqlpwd "$db_pwd"
# Initialize database and store mysql password for upgrade
ynh_mysql_create_db "$db_name" "$db_user" "$db_pwd"
# Copy files to the right place
TMPDIR=$(mktemp -d)
sudo chmod 755 "$TMPDIR"
extract_freshrss "$TMPDIR"
$TMPDIR/cli/do-install.php --default_user $admin_user --auth_type http_auth --environment production --base_url $domain/$path --title FreshRSS --api_enabled --db-type mysql --db-host localhost --db-user $db_user --db-password $db_pwd --db-base $db_name
# Add users
for myuser in $(ynh_user_list)
do
user_token=$(ynh_string_random)
$TMPDIR/cli/create-user.php --user $myuser --language en --token $user_token --no-default-feeds
done
# Move temp dir to final dir
sudo mv $TMPDIR $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
sed -i "s@APPNAMETOCHANGE@$app@g" ../conf/nginx.conf
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
# Modify php-fpm configuration file and copy it to pools directory
php_conf=/etc/php/7.0/fpm/pool.d/$app.conf
sed -i "s@APPNAMETOCHANGE@$app@g" ../conf/php-fpm.conf
sed -i "s@ALIASTOCHANGE@$FINAL_PATH/@g" ../conf/php-fpm.conf
sudo cp ../conf/php-fpm.conf $php_conf
sudo chown root: $php_conf
sudo chmod 644 $php_conf
#update hook for multi instance
sed -i "s@APPNAMETOCHANGE@$app@g" ../hooks/post_app_addaccess
sed -i "s@APPNAMETOCHANGE@$app@g" ../hooks/post_user_create
sed -i "s@APPNAMETOCHANGE@$app@g" ../hooks/post_user_delete
#install update cron
# Add cron job
cron_path="/etc/cron.d/$app"
sed -i "s@#DESTDIR#@${FINAL_PATH}@g" ../conf/freshrss.cron
sudo cp ../conf/freshrss.cron "$cron_path"
sudo chmod 644 "$cron_path"
# Set permissions to freshrss directory
sudo chown -R root:root $FINAL_PATH
sudo chown -R www-data: $FINAL_PATH/data/
sudo chown -R www-data: $FINAL_PATH/extensions/
#skip api directory
ynh_app_setting_set "$app" unprotected_uris "/api/"
# Reload Nginx and regenerate SSOwat conf
sudo service nginx reload
sudo service php7.0-fpm reload
sudo yunohost app ssowatconf