1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/calibreweb_ynh.git synced 2024-09-03 18:16:20 +02:00
This commit is contained in:
Krakinou 2019-01-21 23:56:30 +01:00
parent 4066aa02e6
commit 9978725fc0
4 changed files with 87 additions and 48 deletions

View file

@ -1,52 +1,49 @@
#!/bin/bash #!/bin/bash
# Source YunoHost helpers # Source YunoHost helpers
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#reste à insérer la gestion des répertoires
app=calibreweb #pour récupérer l'app_id, on prend le nom du fichier puis on retire les 3 premiers caratères
app=`basename "$0"`
app=${app:3}
source /etc/yunohost/apps/$app/scripts/_common.sh
username=$1 username=$1
mail=$2 mail=$2
pass_clear=$3 pass_clear=$3
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get $app final_path)
get_db() { public_library=$(ynh_app_setting_get "$app" public_library)
# $1 = nom de la table #User are duplicated in the database only if library is public
# cette ligne de malade : if [ public_library -eq 1 ]; then
# 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) #1 get admin user and id from database
# 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 #we take the admin user as we're sure there is at least this one
# 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 admin=$(ynh_app_setting_get $app admin)
} admin_id=$(sqlite3 $final_path/app.db "SELECT id FROM user WHERE nickname='$admin'")
###################################### ######################################
#1 get admin user and id from database #get user table structure
###################################### ######################################
#we take the admin user as we're sure there is at least this one table_schema=$(get_db "user")
admin=$(ynh_app_setting_get $app admin) ######################################
echo "admin : $admin" #Build new entry for user
admin_id=$(sqlite3 $final_path/app.db "SELECT id FROM user WHERE nickname='$admin'") ######################################
insert_user=$table_schema
###################################### insert_user="${insert_user/id/null}" #so that a new entry is created
#get user table structure insert_user="${insert_user/nickname/\'$username\'}"
###################################### insert_user="${insert_user/role/0}" #standard role
table_schema=$(get_db "user") 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 thanks to LDAP, ones never knows...
###################################### insert_user="${insert_user/email/\'$mail\'}"
#Build new entry for user
###################################### #######################################
insert_user=$table_schema # Insert New entry in database
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 sqlite3 $final_path/app.db "INSERT INTO user ($table_schema) SELECT $insert_user FROM user WHERE ID = $admin_id;"
pass_hash=$(python /etc/yunohost/apps/$app/conf/generate_password_hash.py "$pass_clear" $final_path/vendor) fi
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;"

View file

@ -2,7 +2,11 @@
# Source YunoHost helpers # Source YunoHost helpers
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
app=calibreweb #pour récupérer l'app_id, on prend le nom du fichier puis on retire les 3 premiers caratères
app=`basename "$0"`
app=${app:3}
source /etc/yunohost/apps/$app/scripts/_common.sh
username=$1 username=$1
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get $app final_path)
del_tables_user="book_read_link remote_auth_token downloads shelf bookmark" del_tables_user="book_read_link remote_auth_token downloads shelf bookmark"
@ -12,7 +16,6 @@ del_id() {
#$1=table #$1=table
#$2=id_type #$2=id_type
#$3=id #$3=id
sqlite3 $final_path/app.db "DELETE FROM $1 WHERE $2='$3'" sqlite3 $final_path/app.db "DELETE FROM $1 WHERE $2='$3'"
} }
@ -20,16 +23,14 @@ del_id() {
user_id=$(sqlite3 $final_path/app.db "SELECT id from user WHERE nickname='$username'") 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'") shelf_id=$(sqlite3 $final_path/app.db "SELECT id from shelf WHERE user_id='$user_id'")
#Delete all entry with dependencies for user #Delete all entry with dependencies for user
#pas de check sur l'existence de l'utilisateur car fonctionne sans
for i in $del_tables_shelf for i in $del_tables_shelf
do do
echo "$i"
del_id "$i" "shelf" $shelf_id del_id "$i" "shelf" $shelf_id
done done
for i in $del_tables_user for i in $del_tables_user
do do
echo "$i"
del_id "$i" "user_id" $user_id del_id "$i" "user_id" $user_id
done done

View file

@ -4,6 +4,16 @@ PKG_DEPENDENCIES="sqlite3 python-pip imagemagick"
DOSSIER_MEDIA=/home/yunohost.multimedia DOSSIER_MEDIA=/home/yunohost.multimedia
create_dir=0 create_dir=0
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 $final_path/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
}
#================================================= #=================================================
# EXPERIMENTAL HELPERS # EXPERIMENTAL HELPERS

View file

@ -28,6 +28,10 @@ language=$YNH_APP_ARG_LANGUAGE
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
upload=$6 upload=$6
public_library=$7 public_library=$7
#if app is public, we assume library is public
if [ $is_public -eq 1 ]; then
public_library=1
fi
#================================================= #=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
@ -178,6 +182,33 @@ eval sqlite3 $final_path/app.db "$conf"
#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
#Creation des autres utilisateurs
if [ $public_library -eq 1 ]; then
table_schema=$(get_db "user")
for i in $(ynh_user_list); do
if [ $i = $admin ]; then continue; fi
mail=$(ynh_user_get_info $i 'mail')
######################################
#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/\'$i\'}"
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 thanks to 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 = 1;"
done
fi
#================================================= #=================================================
# SECURE FILES AND DIRECTORIES # SECURE FILES AND DIRECTORIES
#================================================= #=================================================