mirror of
https://github.com/YunoHost-Apps/calibreweb_ynh.git
synced 2024-09-03 18:16:20 +02:00
Add user
This commit is contained in:
parent
4066aa02e6
commit
9978725fc0
4 changed files with 87 additions and 48 deletions
|
@ -1,52 +1,49 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Source 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
|
||||
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;"
|
||||
public_library=$(ynh_app_setting_get "$app" public_library)
|
||||
#User are duplicated in the database only if library is public
|
||||
if [ public_library -eq 1 ]; then
|
||||
######################################
|
||||
#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)
|
||||
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 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 = $admin_id;"
|
||||
fi
|
|
@ -2,7 +2,11 @@
|
|||
# Source 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
|
||||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
del_tables_user="book_read_link remote_auth_token downloads shelf bookmark"
|
||||
|
@ -12,7 +16,6 @@ del_id() {
|
|||
#$1=table
|
||||
#$2=id_type
|
||||
#$3=id
|
||||
|
||||
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'")
|
||||
shelf_id=$(sqlite3 $final_path/app.db "SELECT id from shelf WHERE user_id='$user_id'")
|
||||
|
||||
|
||||
#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
|
||||
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
|
||||
|
||||
|
|
|
@ -4,6 +4,16 @@ PKG_DEPENDENCIES="sqlite3 python-pip imagemagick"
|
|||
DOSSIER_MEDIA=/home/yunohost.multimedia
|
||||
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
|
||||
|
|
|
@ -28,6 +28,10 @@ language=$YNH_APP_ARG_LANGUAGE
|
|||
app=$YNH_APP_INSTANCE_NAME
|
||||
upload=$6
|
||||
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
|
||||
|
@ -178,6 +182,33 @@ eval sqlite3 $final_path/app.db "$conf"
|
|||
#sqlite3 $final_path/app.db "UPDATE user SET password='$pass' WHERE ID=1"
|
||||
#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
|
||||
#=================================================
|
||||
|
|
Loading…
Add table
Reference in a new issue