mirror of
https://github.com/YunoHost-Apps/calibreweb_ynh.git
synced 2024-09-03 18:16:20 +02:00
Initial commit for hook
This commit is contained in:
parent
82fda027ec
commit
05c15e969c
5 changed files with 103 additions and 25 deletions
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Permet de générer le hash pour le password
|
# Permet de générer le hash pour le password
|
||||||
|
#Plus utilisé depuis la MAJ 0.92~ynh3 avec LDAP
|
||||||
import sys
|
import sys
|
||||||
path=sys.argv[2]
|
path=sys.argv[2]
|
||||||
sys.path.append(path)
|
sys.path.append(path)
|
||||||
|
|
52
hooks/post_user_create
Normal file
52
hooks/post_user_create
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Source YunoHost helpers
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
#reste à insérer la gestion des répertoires
|
||||||
|
|
||||||
|
app=calibreweb
|
||||||
|
username=$1
|
||||||
|
mail=$2
|
||||||
|
pass_clear=$3
|
||||||
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
|
|
||||||
|
get_db() {
|
||||||
|
# $1 = nom de la table
|
||||||
|
# cette ligne de malade :
|
||||||
|
# 1/ Recupere le schém de la table user
|
||||||
|
# 2/ En extrait les noms de champs (en prenant le premier mot après la tabulation)
|
||||||
|
# 3/ en supprime les clé UNIQUE, PRIMARY et CHECK dont on ne veut pas
|
||||||
|
# 4/ remplace la liste avec retour à la ligne par une liste séparé par des virgules
|
||||||
|
# 5/ Enlève la dernière virgule
|
||||||
|
sqlite3 ./app.db ".schema $1" | awk '/\t/ {print $1}' | grep -v -e "UNIQUE" -e "PRIMARY" -e "CHECK" -e "FOREIGN" | awk '{printf "%s, ", $0}' | head -c -2
|
||||||
|
}
|
||||||
|
|
||||||
|
######################################
|
||||||
|
#1 get admin user and id from database
|
||||||
|
######################################
|
||||||
|
#we take the admin user as we're sure there is at least this one
|
||||||
|
|
||||||
|
admin=$(ynh_app_setting_get $app admin)
|
||||||
|
echo "admin : $admin"
|
||||||
|
admin_id=$(sqlite3 $final_path/app.db "SELECT id FROM user WHERE nickname='$admin'")
|
||||||
|
|
||||||
|
######################################
|
||||||
|
#get user table structure
|
||||||
|
######################################
|
||||||
|
table_schema=$(get_db "user")
|
||||||
|
|
||||||
|
######################################
|
||||||
|
#Build new entry for user
|
||||||
|
######################################
|
||||||
|
insert_user=$table_schema
|
||||||
|
insert_user="${insert_user/id/null}" #so that a new entry is created
|
||||||
|
insert_user="${insert_user/nickname/\'$username\'}"
|
||||||
|
insert_user="${insert_user/role/0}" #standard role
|
||||||
|
pass_hash=$(python /etc/yunohost/apps/$app/conf/generate_password_hash.py "$pass_clear" $final_path/vendor)
|
||||||
|
insert_user="${insert_user/password/\$pass_hash}" #we get the same pass even if it's not use with LDAP, ones never knows...
|
||||||
|
insert_user="${insert_user/email/\'$mail\'}"
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Insert New entry in database
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
sqlite3 $final_path/app.db "INSERT INTO user ($table_schema) SELECT $insert_user FROM user WHERE ID = $admin_id;"
|
37
hooks/post_user_delete
Normal file
37
hooks/post_user_delete
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Source YunoHost helpers
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
app=calibreweb
|
||||||
|
username=$1
|
||||||
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
|
del_tables_user="book_read_link remote_auth_token downloads shelf bookmark"
|
||||||
|
del_tables_shelf="book_shelf_link"
|
||||||
|
|
||||||
|
del_id() {
|
||||||
|
#$1=table
|
||||||
|
#$2=id_type
|
||||||
|
#$3=id
|
||||||
|
|
||||||
|
sqlite3 $final_path/app.db "DELETE FROM $1 WHERE $2='$3'"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
user_id=$(sqlite3 $final_path/app.db "SELECT id from user WHERE nickname='$username'")
|
||||||
|
shelf_id=$(sqlite3 $final_path/app.db "SELECT id from shelf WHERE user_id='$user_id'")
|
||||||
|
|
||||||
|
|
||||||
|
#Delete all entry with dependencies for user
|
||||||
|
for i in $del_tables_shelf
|
||||||
|
do
|
||||||
|
echo "$i"
|
||||||
|
del_id "$i" "shelf" $shelf_id
|
||||||
|
done
|
||||||
|
for i in $del_tables_user
|
||||||
|
do
|
||||||
|
echo "$i"
|
||||||
|
del_id "$i" "user_id" $user_id
|
||||||
|
done
|
||||||
|
|
||||||
|
#delete user
|
||||||
|
del_id "user" "id" $user_id
|
|
@ -6,7 +6,7 @@
|
||||||
"en": "Calibre-web for Yunohost",
|
"en": "Calibre-web for Yunohost",
|
||||||
"fr": "Calibre-web pour Yunohost"
|
"fr": "Calibre-web pour Yunohost"
|
||||||
},
|
},
|
||||||
"version": "0.91~ynh2",
|
"version": "0.92~ynh3",
|
||||||
"url": "https://github.com/janeczku/calibre-web",
|
"url": "https://github.com/janeczku/calibre-web",
|
||||||
"license": "free",
|
"license": "free",
|
||||||
"maintainer": {
|
"maintainer": {
|
||||||
|
@ -14,7 +14,7 @@
|
||||||
"email": "misterl56@hotmail.com"
|
"email": "misterl56@hotmail.com"
|
||||||
},
|
},
|
||||||
"requirements": {
|
"requirements": {
|
||||||
"yunohost": ">= 2.7.14"
|
"yunohost": ">= 3.0.0"
|
||||||
},
|
},
|
||||||
"multi_instance": true,
|
"multi_instance": true,
|
||||||
"services": [
|
"services": [
|
||||||
|
@ -61,18 +61,18 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "language",
|
"name": "language",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"ask": {
|
"ask": {
|
||||||
"en": "Select a default language (you may change it later in the app)",
|
"en": "Select a default language (you may change it later in the app)",
|
||||||
"fr": "Choisissez une langue par défaut (vous pourrez la changer ultérieurement dans l'application)"
|
"fr": "Choisissez une langue par défaut (vous pourrez la changer ultérieurement dans l'application)"
|
||||||
},
|
},
|
||||||
"choices": [ "fr", "en", "es", "de"],
|
"choices": [ "fr", "en", "es", "de"],
|
||||||
"default": "fr"
|
"default": "fr"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "upload",
|
"name": "upload",
|
||||||
"type":"boolean",
|
"type":"boolean",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"ask": {
|
"ask": {
|
||||||
"en": "Do you want to allow uploading of books (you may change it later in the app)?",
|
"en": "Do you want to allow uploading of books (you may change it later in the app)?",
|
||||||
"fr": "Voulez vous autoriser l'upload de livres (vous pourrez le changer ultérieurement dans l'application)?"
|
"fr": "Voulez vous autoriser l'upload de livres (vous pourrez le changer ultérieurement dans l'application)?"
|
||||||
|
@ -81,22 +81,13 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "public_library",
|
"name": "public_library",
|
||||||
"type":"boolean",
|
"type":"boolean",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"ask": {
|
"ask": {
|
||||||
"en": "Do you want to allow access to the library to all Yunohost users?",
|
"en": "Do you want to allow access to the library to all Yunohost users?",
|
||||||
"fr": "Voulez vous autoriser l'accès à la bibliothèque à tous les utilisateurs Yunohost?"
|
"fr": "Voulez vous autoriser l'accès à la bibliothèque à tous les utilisateurs Yunohost?"
|
||||||
},
|
},
|
||||||
"default": false
|
"default": false
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "password",
|
|
||||||
"type": "password",
|
|
||||||
"ask": {
|
|
||||||
"en": "Set the administrator password",
|
|
||||||
"fr": "Définissez le mot de passe administrateur"
|
|
||||||
},
|
|
||||||
"example": "Averystrongpassword"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,9 +25,6 @@ path_url=$YNH_APP_ARG_PATH
|
||||||
admin=$YNH_APP_ARG_ADMIN
|
admin=$YNH_APP_ARG_ADMIN
|
||||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||||
language=$YNH_APP_ARG_LANGUAGE
|
language=$YNH_APP_ARG_LANGUAGE
|
||||||
ynh_print_OFF
|
|
||||||
pass=$YNH_APP_ARG_PASSWORD
|
|
||||||
ynh_print_ON
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
upload=$6
|
upload=$6
|
||||||
public_library=$7
|
public_library=$7
|
||||||
|
@ -161,7 +158,7 @@ chown -R $app:$app /var/log/$app
|
||||||
ynh_print_info "Setting up database and settings"
|
ynh_print_info "Setting up database and settings"
|
||||||
#we need to start and stop the service so that initial app.db file is created and that we can set default data
|
#we need to start and stop the service so that initial app.db file is created and that we can set default data
|
||||||
ynh_systemd_action -l "INFO in server: Starting Gevent server"
|
ynh_systemd_action -l "INFO in server: Starting Gevent server"
|
||||||
#systemctl start $app
|
|
||||||
#sleep required on low spec like raspberryPi
|
#sleep required on low spec like raspberryPi
|
||||||
sleep 2s
|
sleep 2s
|
||||||
ynh_systemd_action -a stop
|
ynh_systemd_action -a stop
|
||||||
|
@ -175,11 +172,11 @@ conf="\"UPDATE user SET $(. <(echo -E echo $(<../conf/init_calibre_db_user))) WH
|
||||||
eval sqlite3 $final_path/app.db "$conf"
|
eval sqlite3 $final_path/app.db "$conf"
|
||||||
|
|
||||||
#mise à jour du mot de passe (je ne sais pas pourquoi, je n'arrive pas à l'intégrer dans le fichier de conf, pb de " et ')
|
#mise à jour du mot de passe (je ne sais pas pourquoi, je n'arrive pas à l'intégrer dans le fichier de conf, pb de " et ')
|
||||||
ynh_print_OFF
|
#ynh_print_OFF
|
||||||
#had to set it on two lines or package_linter cries like a baby...
|
#had to set it on two lines or package_linter cries like a baby...
|
||||||
pass=$(python ../conf/generate_password_hash.py "$pass" $final_path/vendor)
|
#pass=$(python ../conf/generate_password_hash.py "$pass" $final_path/vendor)
|
||||||
sqlite3 $final_path/app.db "UPDATE user SET password='$pass' WHERE ID=1"
|
#sqlite3 $final_path/app.db "UPDATE user SET password='$pass' WHERE ID=1"
|
||||||
ynh_print_ON
|
#ynh_print_ON
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SECURE FILES AND DIRECTORIES
|
# SECURE FILES AND DIRECTORIES
|
||||||
|
|
Loading…
Add table
Reference in a new issue