1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/ihatemoney_ynh.git synced 2024-09-03 19:26:15 +02:00

Use recommended helpers in scripts

Thanks to ynh-package-linter :-)
This commit is contained in:
Jocelyn Delalande 2017-03-18 19:14:28 +01:00
parent cd55bf42e2
commit b0ae7b8c77
2 changed files with 26 additions and 14 deletions

View file

@ -1,12 +1,20 @@
#!/bin/bash #!/bin/bash
set -eu set -eu
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Retrieve arguments # Retrieve arguments
domain=$1 domain=$YNH_APP_ARG_DOMAIN
path=$2 path=$YNH_APP_ARG_PATH
is_public=$3 is_public=$YNH_APP_ARG_IS_PUBLIC
app=ihatemoney app=ihatemoney
# Database settings
db_pwd=$(ynh_string_random)
db_name=$app
db_user=$app
# Constant arguments # Constant arguments
db_user=ihatemoney db_user=ihatemoney
secret_key=`openssl rand -base64 32` secret_key=`openssl rand -base64 32`
@ -14,15 +22,15 @@ mails_sender="no-reply@${domain}"
sudo yunohost app checkurl $domain$path -a ihatemoney sudo yunohost app checkurl $domain$path -a ihatemoney
if [[ ! $? -eq 0 ]]; then if [[ ! $? -eq 0 ]]; then
exit 1 ynh_die "${domain}${path} is not available"
fi fi
# Remove trailing "/" for next commands # Remove trailing "/" for next commands
path=${path%/} path=${path%/}
# Configure database # Configure database
db_pwd=`sudo yunohost app initdb $db_user` ynh_mysql_create_db "$db_name" "$db_user" "$db_pwd"
sudo yunohost app setting $app mysqlpwd -v $db_pwd ynh_app_setting_set $app mysqlpwd $db_pwd
# Delete db, user dirs and conf if exit with an error # Delete db, user dirs and conf if exit with an error
# inspired from https://github.com/Kloadut/owncloud_ynh/blob/master/scripts/install#L37 # inspired from https://github.com/Kloadut/owncloud_ynh/blob/master/scripts/install#L37
@ -31,19 +39,19 @@ function exit_properly
{ {
set +e set +e
root_pwd=$(sudo cat /etc/yunohost/mysql) root_pwd=$(sudo cat /etc/yunohost/mysql)
mysql -u root -p$root_pwd -e "DROP DATABASE ihatemoney ; DROP USER $db_user ;" mysql -u root -p$root_pwd -e "DROP DATABASE $db_name ; DROP USER $db_user ;"
sudo userdel ihatemoney sudo userdel ihatemoney
sudo rm -Rf /opt/yunohost/ihatemoney sudo rm -Rf /opt/yunohost/ihatemoney
sudo rm -Rf /etc/ihatemoney sudo rm -Rf /etc/ihatemoney
sudo rm /etc/nginx/conf.d/$domain.d/ihatemoney.conf sudo rm /etc/nginx/conf.d/$domain.d/ihatemoney.conf
sudo rm /etc/supervisor/conf.d/ihatemoney.conf sudo rm /etc/supervisor/conf.d/ihatemoney.conf
exit 1 ynh_die "Install script failed, aborted and rolled back the installation"
} }
trap exit_properly ERR trap exit_properly ERR
# Save app settings # Save app settings
sudo yunohost app setting $app domain -v $domain ynh_app_setting_set $app domain $domain
sudo yunohost app setting $app is_public -v "$is_public" ynh_app_setting_set $app is_public "$is_public"
# Install debian packages dependencies # Install debian packages dependencies
sudo apt-get install -y -qq python-dev python-virtualenv supervisor libmysqlclient-dev sudo apt-get install -y -qq python-dev python-virtualenv supervisor libmysqlclient-dev
@ -89,7 +97,7 @@ sudo ln -s /etc/ihatemoney/settings.py /opt/yunohost/ihatemoney/src/budget/setti
# If app is public, add url to SSOWat conf as skipped_uris # If app is public, add url to SSOWat conf as skipped_uris
if [[ "$is_public" -ne 0 ]]; if [[ "$is_public" -ne 0 ]];
then then
sudo yunohost app setting $app unprotected_uris -v "/" ynh_app_setting_set $app unprotected_uris "/"
fi fi
# Configure Nginx and reload # Configure Nginx and reload

View file

@ -1,13 +1,17 @@
#!/bin/bash #!/bin/bash
set -u set -u
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# supervisord and other Debian dependencies remain installed # supervisord and other Debian dependencies remain installed
# there is no way to know if they are used by other programs # there is no way to know if they are used by other programs
# Retrieve arguments # Retrieve arguments
domain=$(sudo yunohost app setting ihatemoney domain) app=ihatemoney
db_user=ihatemoney domain=$(ynh_app_setting_get $app domain)
db_name=ihatemoney db_user=$app
db_name=$app
root_pwd=$(sudo cat /etc/yunohost/mysql) root_pwd=$(sudo cat /etc/yunohost/mysql)
# Drop database # Drop database