Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
[enh] Use helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
zamentur committed Nov 28, 2018
1 parent e41c9a6 commit b749d3f
Show file tree
Hide file tree
Showing 10 changed files with 1,547 additions and 72 deletions.
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

42 changes: 27 additions & 15 deletions conf/nginx.conf
@@ -1,17 +1,29 @@
location PATHTOCHANGE {
alias ALIASTOCHANGE;
index index.html;
try_files $uri $uri/ /index.html;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTPS on;
}
}
#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
location __PATH__/ {

# Path to source
alias __FINALPATH__/ ;

# Force usage of https
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}

index index.php;

# Common parameter to increase upload size limit in conjunction with dedicated php-fpm file
#client_max_body_size 50M;

try_files $uri $uri/ /index.php;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php5-fpm-__NAME__.sock;

fastcgi_index index.php;
include fastcgi_params;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $request_filename;
}

location ~ ^PATHTOCHANGE/(data|config|\.ht|db_structure\.xml|README) {
deny all;
}
392 changes: 392 additions & 0 deletions conf/php-fpm.conf

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions conf/php-fpm.ini
@@ -0,0 +1,10 @@
; Common values to change to increase file upload limit
; upload_max_filesize = 50M
; post_max_size = 50M
; mail.add_x_header = Off

; Other common parameters
; max_execution_time = 600
; max_input_time = 300
; memory_limit = 256M
; short_open_tag = On
6 changes: 3 additions & 3 deletions manifest.json
Expand Up @@ -2,20 +2,20 @@
"name": "menu",
"id": "menu",
"packaging_format": 1,
"version": "1~ynh1",
"version": "1~ynh2",
"description": {
"en": "Display a public/private menu on all pages generated by YunoHost",
"fr": "Système permetant d'afficher un menu sur toutes les pages servis par l'instance yunohost"
},
"license": "AGPL-3.0",
"license": "CC-BY-SA-2.0",
"maintainer": {
"name": "ljf",
"email": "ljf+menu_ynh@reflexlibre.net",
"url": "https://reflexlibre.net"
},
"url": "https://github.com/YunoHost-Apps/menu_ynh",
"requirements": {
"yunohost": ">= 2.7.2"
"yunohost": ">= 2.7.14"
},
"multi_instance": false,
"services": [
Expand Down
63 changes: 63 additions & 0 deletions scripts/backup
@@ -0,0 +1,63 @@
#!/bin/bash

#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

source /usr/share/yunohost/helpers

#=================================================
# MANAGE SCRIPT FAILURE
#=================================================

ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors

#=================================================
# LOAD SETTINGS
#=================================================

app=$YNH_APP_INSTANCE_NAME

final_path=$(ynh_app_setting_get $app final_path)
domain=$(ynh_app_setting_get $app domain)
db_name=$(ynh_app_setting_get $app db_name)

#=================================================
# STANDARD BACKUP STEPS
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================

ynh_backup "$final_path"

#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================

ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"

#=================================================
# BACKUP THE PHP-FPM CONFIGURATION
#=================================================

ynh_backup "/etc/php5/fpm/pool.d/$app.conf"
ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini"

#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================

ynh_mysql_dump_db "$db_name" > db.sql

#=================================================
# SPECIFIC BACKUP
#=================================================
ynh_backup "/usr/share/moulinette/actionsmap/ynh_$app.yml"
ynh_backup "/usr/lib/moulinette/ynh_$app"
164 changes: 123 additions & 41 deletions scripts/install
@@ -1,52 +1,134 @@
#!/bin/bash

app="menu"
domain=$1
path=$2
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

source /usr/share/yunohost/helpers

# Check domain/path availability
sudo yunohost app checkurl $domain$path -a $app
if [[ ! $? -eq 0 ]]; then
exit 1
fi
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================

# Create database
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')
db_user=$app
sudo yunohost app initdb $db_user -p $db_pwd
sudo yunohost app setting $app mysqlpwd -v $db_pwd
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors

# Db installation
mysql -u $db_user -p$db_pwd $db_user < ../conf/create-mysql.sql
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================

domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH

app=$YNH_APP_INSTANCE_NAME

#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================

# Copy files to the right place
final_path=/var/www/$app
sudo mkdir -p $final_path
sed -i "s@YUNOPATH@//$domain$path/@g" ../sources/menu/menu.js
sudo cp -a ../sources/menu/* $final_path
sudo chown -R www-data: $final_path
test ! -e "$final_path" || ynh_die "This path already contains a folder"

# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)

# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path
ynh_webpath_register $app $domain $path_url

#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================

# Setup the admin web plugin
sudo cp -a ../sources/adminjs/menu /usr/share/yunohost/admin/modules/
ynh_app_setting_set $app domain "$domain"
ynh_app_setting_set $app path "$path_url"
ynh_app_setting_set $app path "$path_url"

#=================================================
# INSTALL DEPENDENCIES
#=================================================

ynh_install_app_dependencies python-mysqldb

#=================================================
# CREATE A MYSQL DATABASE
#=================================================

db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
ynh_mysql_setup_db $db_name $db_name

#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# Copy files to the right place
ynh_app_setting_set $app final_path $final_path
mkdir -p $final_path
sed -i "s@YUNOPATH@//$domain$path_url/@g" ../sources/menu/menu.js
cp -a ../sources/menu/* $final_path

# Setup the cli/api plugin
sudo cp -a ../sources/moulinette/actionsmap/ynh_$app.yml /usr/share/moulinette/actionsmap/
sudo mkdir /usr/lib/moulinette/ynh_$app
sudo cp -a ../sources/moulinette/*.py /usr/lib/moulinette/ynh_$app/
sudo cp -a ../sources/moulinette/locales /usr/lib/moulinette/ynh_$app/

# Setup dependence
sudo apt-get -y install python-mysqldb

# 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/$app.conf

# Reload Nginx and regenerate SSOwat conf
sudo service nginx reload
sudo yunohost app setting $app skipped_uris -v "/"
sudo yunohost app setting $app redirected_urls -v "{'/ynhpanel.js':'$path/menu.js'}"
sudo yunohost app ssowatconf
sudo service yunohost-api restart
cp -a ../sources/moulinette/actionsmap/ynh_$app.yml /usr/share/moulinette/actionsmap/
mkdir /usr/lib/moulinette/ynh_$app
cp -a ../sources/moulinette/*.py /usr/lib/moulinette/ynh_$app/
cp -a ../sources/moulinette/locales /usr/lib/moulinette/ynh_$app/

#=================================================
# SPECIFIC SETUP
#=================================================
# Db installation
ynh_mysql_execute_file_as_root ../conf/create-mysql.sql $db_name

#=================================================


#=================================================
# CREATE DEDICATED USER
#=================================================

# Create a system user
ynh_system_user_create $app

#=================================================
# PHP-FPM CONFIGURATION
#=================================================

# Create a dedicated php-fpm config
ynh_add_fpm_config
#=================================================
# NGINX CONFIGURATION
#=================================================

# Create a dedicated nginx config
ynh_add_nginx_config

#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================

# Set permissions to app files
chown -R root: $final_path


#=================================================
# SETUP SSOWAT
#=================================================

ynh_app_setting_set $app skipped_uris "/"
ynh_app_setting_set $app redirected_urls "{'/ynhpanel.js':'$path_url/menu.js'}"

#=================================================
# RELOAD NGINX
#=================================================

systemctl reload nginx
service yunohost-api restart &

0 comments on commit b749d3f

Please sign in to comment.