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

113 lines
3.5 KiB
Text
Raw Normal View History

2014-07-23 15:52:50 +02:00
#!/bin/bash
2018-07-21 12:18:50 +02:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2016-09-01 08:31:03 +02:00
2018-07-21 12:18:50 +02:00
source _common.sh
source /usr/share/yunohost/helpers
2018-07-21 12:18:50 +02:00
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
2017-03-13 20:14:53 +01:00
domain=$YNH_APP_ARG_DOMAIN
2018-09-23 12:50:18 +02:00
path=${YNH_APP_ARG_PATH}
2017-03-13 20:14:53 +01:00
admin_user=$YNH_APP_ARG_ADMIN
2017-02-13 22:20:55 +01:00
# Setup variables
2017-03-05 17:17:14 +01:00
app=$YNH_APP_INSTANCE_NAME
2017-02-13 22:20:55 +01:00
db_user=$app
db_name=$app
2014-07-23 15:52:50 +02:00
2017-03-05 17:27:33 +01:00
FINAL_PATH="/var/www/$app"
2018-07-21 12:18:50 +02:00
# Normalize the url path syntax
path=$(ynh_normalize_url_path $path)
2014-09-21 11:52:46 +02:00
2015-02-08 18:55:48 +01:00
# Check user parameter if not empty
if [[ $admin_user != '' ]]; then
2017-02-13 22:20:55 +01:00
ynh_user_exists $admin_user || ynh_die "Wrong user"
2014-09-21 11:52:46 +02:00
fi
2018-07-21 12:18:50 +02:00
# Check web path availability
ynh_webpath_available $domain $path
# Register (book) web path
ynh_webpath_register $app $domain $path
2017-02-13 22:20:55 +01:00
2018-07-07 11:21:43 +02:00
#install php dependencies
install_freshrss_dependencies
2014-07-23 15:52:50 +02:00
# Generate random DES key & password
2017-01-22 14:50:51 +01:00
deskey=$(ynh_string_random)
db_pwd=$(ynh_string_random)
app_salt=$(ynh_string_random)
2017-02-13 22:20:55 +01:00
2018-07-21 12:18:50 +02:00
# 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"
2014-07-23 15:52:50 +02:00
# Initialize database and store mysql password for upgrade
2016-09-04 12:04:50 +02:00
ynh_mysql_create_db "$db_name" "$db_user" "$db_pwd"
2014-07-23 15:52:50 +02:00
# Copy files to the right place
2017-03-06 12:02:25 +01:00
TMPDIR=$(mktemp -d)
2017-03-13 20:19:27 +01:00
sudo chmod 755 "$TMPDIR"
2016-09-01 08:38:50 +02:00
extract_freshrss "$TMPDIR"
2017-02-12 11:34:30 +01:00
$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
2017-01-22 14:50:51 +01:00
2014-07-23 15:52:50 +02:00
# Add users
2017-02-13 22:37:16 +01:00
for myuser in $(ynh_user_list)
2014-07-23 15:52:50 +02:00
do
2017-01-22 14:50:51 +01:00
user_token=$(ynh_string_random)
2019-03-31 19:01:27 +02:00
$TMPDIR/cli/create-user.php --user $myuser --language en --token $user_token
2014-07-23 15:52:50 +02:00
done
# Move temp dir to final dir
sudo mv $TMPDIR $FINAL_PATH
2014-07-23 15:52:50 +02:00
# Modify Nginx configuration file and copy it to Nginx conf directory
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
2016-09-01 08:31:03 +02:00
sed -i "s@ALIASTOCHANGE@$FINAL_PATH/@g" ../conf/nginx.conf
2018-07-07 15:43:31 +02:00
sed -i "s@APPNAMETOCHANGE@$app@g" ../conf/nginx.conf
2017-03-05 17:27:33 +01:00
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
2014-07-23 15:52:50 +02:00
2018-07-07 15:43:31 +02:00
# 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
2014-07-23 15:52:50 +02:00
#install update cron
2017-02-13 22:20:55 +01:00
# 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"
2014-07-23 15:52:50 +02:00
# Set permissions to freshrss directory
2017-02-14 09:41:13 +01:00
sudo chown -R root:root $FINAL_PATH
2016-09-01 08:31:03 +02:00
sudo chown -R www-data: $FINAL_PATH/data/
sudo chown -R www-data: $FINAL_PATH/extensions/
#skip api directory
2019-01-04 18:57:21 +01:00
ynh_app_setting_set "$app" unprotected_uris "/api/"
2014-07-23 15:52:50 +02:00
# Reload Nginx and regenerate SSOwat conf
sudo service nginx reload
2018-07-07 15:43:31 +02:00
sudo service php7.0-fpm reload
sudo yunohost app ssowatconf