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
2016-09-01 08:31:03 +02:00

117 lines
4.1 KiB
Bash
Executable file

#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
# Retrieve arguments
domain=$1
path=$2
admin_user=$3
# Load common variables and helpers
. ./_common.sh
# Source app helpers
. /usr/share/yunohost/helpers
# Check user parameter if not empty
if [[ $admin_user != '' ]]; then
sudo yunohost user list --json | grep -qi "\"username\": \"$admin_user\""
if [[ ! $? -eq 0 ]]; then
echo "Wrong user"
exit 1
fi
sudo yunohost app setting freshrss admin_user -v $admin_user
fi
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a freshrss
if [[ ! $? -eq 0 ]]; then
exit 1
fi
# Generate random DES key & password
deskey=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
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')
app_salt=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{40\}\).*/\1/p')
# Use 'freshrss' as database name and user
db_user=freshrss
# Initialize database and store mysql password for upgrade
sudo yunohost app initdb $db_user -p $db_pwd
sudo yunohost app setting freshrss mysqlpwd -v $db_pwd
# Copy files to the right place
sudo mkdir -p $FINAL_PATH
extract_freshrss "$FINAL_PATH"
sudo cp -a ../conf/config.php $FINAL_PATH/data
sudo cp ../sources/install_ynh.sql $FINAL_PATH/app/SQL/install_ynh.sql
# Change variables in freshrss configuration
sudo sed -i "s/yunouser/$db_user/g" $FINAL_PATH/data/config.php
sudo sed -i "s/yunopass/$db_pwd/g" $FINAL_PATH/data/config.php
sudo sed -i "s/yunobase/$db_user/g" $FINAL_PATH/data/config.php
sudo sed -i "s/yunosalt/$app_salt/g" $FINAL_PATH/data/config.php
sudo sed -i "s@yunopath@$path@g" $FINAL_PATH/data/config.php
if [[ $admin_user != '' ]]; then
sudo sed -i "s/yunoadminuser/$admin_user/g" $FINAL_PATH/data/config.php
else
sudo sed -i '/yunoadminuser/d' $FINAL_PATH/data/config.php
fi
# Add users
#check wallabag
if [[ $(sudo yunohost app list -f wallabag | /bin/grep -q "installed: True") -eq 0 ]]; then
echo "Detected wallabag"
wallabagPath=$(sudo yunohost app setting wallabag path)
wallabagUrl=$domain$wallabagPath
sharingWallabag="'sharing' => \n\tarray( \n\t\t0 => \n\t\tarray(\n\t\t\t'type' => 'wallabag',\n\t\t\t'name' => 'Wallabag',\n\t\t\t'url' => 'https://$wallabagUrl',\n\t\t),"
sharingEnable=1
fi
freshrss_users=$(ldapsearch -h localhost -b ou=users,dc=yunohost,dc=org -x objectClass=mailAccount uid | grep uid: | sed 's/uid: //' | xargs)
for myuser in $freshrss_users
do
#copy sql
sudo cp ../sources/install_ynh.sql /tmp/$myuser-install.sql
#change username in sql
sudo sed -i "s/YnoUser/$myuser/g" /tmp/$myuser-install.sql
#create tables
mysql -u $db_user -p$db_pwd $db_user < /tmp/$myuser-install.sql
#remove temp sql
sudo rm /tmp/$myuser-install.sql
#copy default conf
sudo cp -r $FINAL_PATH/data/users/_/ $FINAL_PATH/data/users/$myuser
sudo mv $FINAL_PATH/data/users/$myuser/config.default.php $FINAL_PATH/data/users/$myuser/config.php
if [[ $sharingEnable -eq 1 ]]; then
sudo sed -i "s@'sharing'\ =>\ array\ (@$sharingWallabag@g" $FINAL_PATH/data/users/$myuser/config.php
fi
done
# Delete install directive
sudo rm $FINAL_PATH/data/do-install.txt
# 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
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/freshrss.conf
#install php5-cli
sudo apt-get update
sudo apt-get install -y php5-cli php5-gmp
#install update cron
echo "*/10 * * * * www-data /usr/bin/php $FINAL_PATH/app/actualize_script.php >/tmp/FreshRSS.log 2>&1" > /tmp/cronfreshrss
sudo mv /tmp/cronfreshrss /etc/cron.d/freshrss
sudo chown root /etc/cron.d/freshrss
# Set permissions to freshrss directory
sudo chown -R www-data: $FINAL_PATH/data/
sudo chown -R www-data: $FINAL_PATH/extensions/
#skip api directory
sudo yunohost app setting freshrss skipped_uris -v /api/greader.php
# Reload Nginx and regenerate SSOwat conf
sudo service nginx reload
sudo yunohost app ssowatconf