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-16 11:11:52 +02:00

127 lines
4.6 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
db_name=freshrss
# Initialize database and store mysql password for upgrade
ynh_mysql_create_db "$db_name" "$db_user" "$db_pwd"
sudo yunohost app setting freshrss mysqlpwd -v $db_pwd
# Copy files to the right place
TMPDIR=$(ynh_mkdir_tmp)
extract_freshrss "$TMPDIR"
sudo cp -a ../conf/config.php $TMPDIR/data
sudo cp ../sources/install_ynh.sql $TMPDIR/app/SQL/install_ynh.sql
# Change variables in freshrss configuration
sudo sed -i "s/yunouser/$db_user/g" $TMPDIR/data/config.php
sudo sed -i "s/yunopass/$db_pwd/g" $TMPDIR/data/config.php
sudo sed -i "s/yunobase/$db_user/g" $TMPDIR/data/config.php
sudo sed -i "s/yunosalt/$app_salt/g" $TMPDIR/data/config.php
sudo sed -i "s@yunopath@$path@g" $TMPDIR/data/config.php
if [[ $admin_user != '' ]]; then
sudo sed -i "s/yunoadminuser/$admin_user/g" $TMPDIR/data/config.php
else
sudo sed -i '/yunoadminuser/d' $TMPDIR/data/config.php
fi
# Add users
#check wallabag
sharingEnable=0
if sudo yunohost app list --installed -f wallabag2 | grep -q id ; then
echo "Detected wallabag V2"
wallabagPath=$(sudo yunohost app setting wallabag2 path | sed 's#/*$##')
wallabagUrl=$domain$wallabagPath
sharingWallabag="'sharing' => \n\tarray( \n\t\t0 => \n\t\tarray(\n\t\t\t'type' => 'wallabagv2',\n\t\t\t'name' => 'Wallabag',\n\t\t\t'url' => 'https://$wallabagUrl',\n\t\t),"
sharingEnable=1
elif sudo yunohost app list --installed -f wallabag | grep -q id ; 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
ynh_mysql_connect_as "$db_user" "$db_pwd" "$db_name" \
< "/tmp/$myuser-install.sql"
#remove temp sql
sudo rm /tmp/$myuser-install.sql
#copy default conf
sudo cp -r $TMPDIR/data/users/_/ $TMPDIR/data/users/$myuser
sudo mv $TMPDIR/data/users/$myuser/config.default.php $TMPDIR/data/users/$myuser/config.php
if [[ $sharingEnable -eq 1 ]]; then
sudo sed -i "s@'sharing'\ =>\ array\ (@$sharingWallabag@g" $TMPDIR/data/users/$myuser/config.php
fi
done
# Delete install directive
sudo rm $TMPDIR/data/do-install.txt
# 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
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