Scripts cleanup

This commit is contained in:
opi 2016-07-04 21:16:34 +02:00
parent 9c7a55e0c0
commit 5acde5fb76
6 changed files with 86 additions and 119 deletions

View File

@ -41,7 +41,7 @@
"default": "/searx"
},
{
"name": "public_site",
"name": "is_public",
"ask": {
"en": "Is it a public Searx site ?",
"fr": "Est-ce un site public ?"

View File

@ -1,4 +1,5 @@
#!/bin/bash
app="searx"
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
set -e
@ -6,30 +7,15 @@ set -e
# Source YNH helpers
. /usr/share/yunohost/helpers
# This is a multi-instance app, meaning it can be installed several times independently
# The id of the app as stated in the manifest is available as $YNH_APP_ID
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
# The app instance name is available as $YNH_APP_INSTANCE_NAME
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
# - ynhexample__{N} for the subsequent installations, with N=3,4, ...
# The app instance name is probably what you are interested the most, since this is
# guaranteed to be unique. This is a good unique identifier to define installation path,
# db names, ...
app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments
domain=$(sudo yunohost app setting $app domain)
# Backup directory location for the app from where the script is executed and
# which will be compressed afterward
backup_dir=$YNH_APP_BACKUP_DIR
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
is_public=$(ynh_app_setting_get "$app" is_public)
# Backup sources & data
ynh_backup "/opt/yunohost/$app" "sources"
# Copy Nginx conf
sudo mkdir -p ./conf
ynh_backup "/etc/uwsgi/apps-available/$app.ini" "conf/searx.ini"
ynh_backup "/opt/yunohost/$app/searx/settings.yml" "conf/settings.yml"
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx.conf"

View File

@ -1,27 +1,25 @@
#!/bin/bash
app="searx"
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
set -e
# Source app helpers
. /usr/share/yunohost/helpers
# Retrieve arguments
domain=$1
path=$2
is_public=$3
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_IS_PUBLIC
# Remove trailing slash to path
path=${path%/}
#force location to be / or /foo
location=${path:-/}
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a searx
if [[ ! $? -eq 0 ]]; then
exit 1
fi
# Path need a trailing slash, and location does not.
# See conf/nginx.conf* usage
location=$path
if [[ ! $path == */ ]]; then
# no trailing slash, so add it
path=$path/
fi
if [[ ! "$location" == "/" ]]; then
# remove possible trailing slash
location=${location%/}
fi
sudo yunohost app checkurl $domain$path -a $app \
|| (echo "Path not available: $domain$path" && exit 1)
# Save specific settings
sudo yunohost app setting searx is_public -v $is_public
@ -46,7 +44,7 @@ then
sudo swapon $tmp_swap_file
fi
final_path=/opt/yunohost/searx
final_path=/opt/yunohost/$app
# Init virtualenv
if [ ! -d $final_path ];
@ -79,17 +77,17 @@ sudo useradd searx -d $final_path
sudo chown searx:searx -R $final_path
# Copy uwsgi config
sudo cp ../conf/searx.ini /etc/uwsgi/apps-available/
sudo ln -s /etc/uwsgi/apps-available/searx.ini /etc/uwsgi/apps-enabled/
sudo cp ../conf/searx.ini /etc/uwsgi/apps-available/$app.ini
sudo ln -s /etc/uwsgi/apps-available/searx.ini /etc/uwsgi/apps-enabled/$app.ini
# Modify Nginx configuration file and copy it to Nginx conf directory
sed -i "s@YNH_WWW_LOCATION@$location@g" ../conf/nginx.conf*
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf*
if [ "$path" != "/" ];
then
sudo cp ../conf/nginx.conf-noroot /etc/nginx/conf.d/$domain.d/searx.conf
sudo cp ../conf/nginx.conf-noroot /etc/nginx/conf.d/$domain.d/$app.conf
else
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/searx.conf
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
fi
# Fix permission
@ -99,11 +97,10 @@ fi
## Reload Nginx and regenerate SSOwat conf
sudo service nginx reload
sudo service uwsgi restart
sudo yunohost service add uwsgi -l /var/log/uwsgi/app/searx.log
sudo yunohost service add uwsgi -l /var/log/uwsgi/app/$app.log
if [ "$is_public" = "Yes" ];
then
sudo yunohost app setting searx unprotected_uris -v "/"
sudo yunohost app setting $app unprotected_uris -v "/"
fi
sudo yunohost app ssowatconf

View File

@ -1,14 +1,25 @@
#!/bin/bash
app="searx"
domain=$(sudo yunohost app setting searx domain)
# Source app helpers
. /usr/share/yunohost/helpers
sudo rm -Rf /opt/yunohost/searx
sudo rm -f /etc/uwsgi/apps-enabled/searx.ini
sudo rm -f /etc/uwsgi/apps-available/searx.ini
sudo rm -f /etc/nginx/conf.d/$domain.d/searx.conf
# Retrieve arguments
domain=$(ynh_app_setting_get "$app" domain)
# Remove files
sudo rm -Rf /opt/yunohost/$app
sudo rm -f /etc/uwsgi/apps-enabled/$app.ini
sudo rm -f /etc/uwsgi/apps-available/$app.ini
sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf
# Remove services
sudo service uwsgi stop
sudo killall uwsgi
sudo service uwsgi start
sudo service nginx reload
sudo yunohost app ssowatconf
# Remove user
sudo userdel searx
# Reload Nginx
sudo service nginx reload

View File

@ -1,4 +1,5 @@
#!/bin/bash
app="searx"
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
set -e
@ -6,22 +7,15 @@ set -e
# Source YNH helpers
. /usr/share/yunohost/helpers
# This is a multi-instance app, meaning it can be installed several times independently
# The id of the app as stated in the manifest is available as $YNH_APP_ID
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
# The app instance name is available as $YNH_APP_INSTANCE_NAME
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
# - ynhexample__{N} for the subsequent installations, with N=3,4, ...
# The app instance name is probably what you are interested the most, since this is
# guaranteed to be unique. This is a good unique identifier to define installation path,
# db names, ...
app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
is_public=$(ynh_app_setting_get "$app" is_public)
# Get old parameter of the app
domain=$(sudo yunohost app setting $app domain)
path=$(sudo yunohost app setting $app path)
is_public=$(sudo yunohost app setting $app is_public)
# Remove trailing slash to path
path=${path%/}
#force location to be / or /foo
location=${path:-/}
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a $app
@ -30,7 +24,7 @@ if [[ ! $? -eq 0 ]]; then
exit 1
fi
final_path=/opt/yunohost/searx
final_path=/opt/yunohost/$app
if [ -d $final_path ]; then
echo "There is already a directory: $final_path " | sudo tee /dev/stderr
exit 1
@ -45,21 +39,8 @@ fi
# Run install script
# sudo bash -c "./install $domain $path $is_public $app"
# Path need a trailing slash, and location does not.
# See conf/nginx.conf* usage
location=$path
if [[ ! $path == */ ]]; then
# no trailing slash, so add it
path=$path/
fi
if [[ ! "$location" == "/" ]]; then
# remove possible trailing slash
location=${location%/}
fi
# Save specific settings
sudo yunohost app setting searx is_public -v $is_public
sudo yunohost app setting $app is_public -v $is_public
# Check depends installation
sudo apt-get install git build-essential libxslt-dev python-dev python-virtualenv python-pybabel zlib1g-dev libffi-dev libssl-dev python-lxml uwsgi uwsgi-plugin-python -y
@ -82,7 +63,7 @@ then
fi
# Restore sources
final_path=/opt/yunohost/searx
final_path=/opt/yunohost/$app
sudo cp -a "./sources" $final_path
# Init virtualenv
@ -110,14 +91,13 @@ sudo ln -s "/etc/uwsgi/apps-available/$app.ini" /etc/uwsgi/apps-enabled/
# Nginx conf
sudo cp "conf/nginx.conf" $nginx_conf
## Reload Nginx and regenerate SSOwat conf
sudo service nginx reload
sudo service uwsgi restart
sudo yunohost service add uwsgi -l /var/log/uwsgi/app/searx.log
if [ "$is_public" = "Yes" ];
then
sudo yunohost app setting searx unprotected_uris -v "/"
fi
sudo yunohost app ssowatconf
## Reload services
sudo service nginx reload
sudo service uwsgi restart
sudo yunohost service add uwsgi -l /var/log/uwsgi/app/$app.log

View File

@ -1,21 +1,21 @@
#!/bin/bash
app="searx"
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
set -e
# Source app helpers
. /usr/share/yunohost/helpers
# Retrieve arguments
domain=$(sudo yunohost app setting searx domain)
path=$(sudo yunohost app setting searx path)
is_public=$(sudo yunohost app setting searx is_public)
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
is_public=$(ynh_app_setting_get "$app" is_public)
# Path need a trailing slash, and location does not.
# See conf/nginx.conf usage
location=$path
if [[ ! $path == */ ]]; then
# no trailing slash, so add it
path=$path/
fi
if [[ ! "$location" == "/" ]]; then
# remove possible trailing slash
location=${location%/}
fi
# Remove trailing slash to path
path=${path%/}
#force location to be / or /foo
location=${path:-/}
# Check depends installation
sudo apt-get install git build-essential libxslt-dev python-dev python-virtualenv python-pybabel zlib1g-dev libffi-dev libssl-dev python-lxml uwsgi uwsgi-plugin-python -y
@ -36,7 +36,7 @@ then
sudo swapon $tmp_swap_file
fi
final_path=/opt/yunohost/searx
final_path=/opt/yunohost/$app
sudo cp -r ../sources/* $final_path
sudo bash -c "source $final_path/bin/activate && pip install -r $final_path/requirements-ynh.txt --upgrade"
@ -47,12 +47,6 @@ then
sudo rm -f $tmp_swap_file
fi
# Remove trailing "/" for next commands if installing on a subpath
if [ "$path" != "/" ];
then
path=${path%/}
fi
#Configuration Searx
sudo cp ../conf/settings.yml $final_path/searx/
sudo sed -i -e "s/ultrasecretkey/`openssl rand -hex 16`/g" $final_path/searx/settings.yml
@ -70,30 +64,29 @@ fi
sudo chown searx:searx -R $final_path
# Copy uwsgi config
sudo cp ../conf/searx.ini /etc/uwsgi/apps-available/
sudo cp ../conf/searx.ini /etc/uwsgi/apps-available/$app.ini
# Modify Nginx configuration file and copy it to Nginx conf directory
sed -i "s@YNH_WWW_LOCATION@$location@g" ../conf/nginx.conf*
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf*
if [ "$path" != "/" ];
then
sudo cp ../conf/nginx.conf-noroot /etc/nginx/conf.d/$domain.d/searx.conf
sudo cp ../conf/nginx.conf-noroot /etc/nginx/conf.d/$domain.d/$app.conf
else
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/searx.conf
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
fi
# Fix permission
#sudo find $final_path/ -type d -exec chmod 2755 {} \;
#sudo find $final_path/ -type f -exec chmod g+r,o+r {} \;
## Reload Nginx and regenerate SSOwat conf
sudo service nginx reload
sudo service uwsgi restart
if [ "$is_public" = "Yes" ];
then
sudo yunohost app setting searx skipped_uris -d
sudo yunohost app setting searx unprotected_uris -v "/"
fi
sudo yunohost app ssowatconf
## Reload services
sudo service nginx reload
sudo service uwsgi restart