110 lines
3.0 KiB
Plaintext
110 lines
3.0 KiB
Plaintext
|
#!/bin/bash
|
||
|
# file: gsl__auth_manager
|
||
|
# Folder: /var/lib/gsl/scripts
|
||
|
# By echolib
|
||
|
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
||
|
|
||
|
#=======================================================================
|
||
|
# Manage Authors from DOMAIN
|
||
|
#=======================================================================
|
||
|
gsl__authors_check() {
|
||
|
gsl_save_dir_ndd=`grep "$gsl_find_domain" "$gsl_file_db_domains"`
|
||
|
gsl_file_auth_ndd="$gsl_save_dir_ndd/$gsl_filename_auth"
|
||
|
|
||
|
! [[ -f "$gsl_file_auth_ndd" ]] \
|
||
|
&& touch "$gsl_file_auth_ndd"
|
||
|
}
|
||
|
|
||
|
#=======================================================================
|
||
|
# List Authors from DOMAIN
|
||
|
#=======================================================================
|
||
|
gsl__authors_list() {
|
||
|
gsl__authors_check
|
||
|
|
||
|
[[ -z `grep '[^[:space:]]' "$gsl_file_auth_ndd"` ]] \
|
||
|
&& echo "! No Registred authors yet." \
|
||
|
&& return
|
||
|
|
||
|
case "$1" in
|
||
|
check)
|
||
|
return
|
||
|
;;
|
||
|
esac
|
||
|
|
||
|
echo -e "\n# Authors Registred:"
|
||
|
while read -r "line_nbr" "author"
|
||
|
do
|
||
|
echo " $line_nbr: $author"
|
||
|
done < <(cat -n "$gsl_file_auth_ndd")
|
||
|
}
|
||
|
|
||
|
#=======================================================================
|
||
|
# Add Author(s) for DOMAIN to authors.db in Profile User
|
||
|
#=======================================================================
|
||
|
gsl__authors_add() {
|
||
|
gsl__authors_check
|
||
|
gsl__authors_list
|
||
|
|
||
|
printf '\n%s\n%s\n%s\n \n' \
|
||
|
"# You can add one or more Authors" \
|
||
|
" Use comma (,) delimiter (i.e. Joe Foo,Jane)" \
|
||
|
" || empty field to cancel"
|
||
|
|
||
|
echo -ne "# Add author(s) name : " && IFS="," read -a gsl_new_authors
|
||
|
[[ "$gsl_new_authors" ]] || return
|
||
|
|
||
|
gsl_nbr_authors=${#gsl_new_authors[@]}
|
||
|
for i in `seq 0 $(( gsl_nbr_authors - 1 ))`
|
||
|
do
|
||
|
echo "${gsl_new_authors[i]}" >> "$gsl_file_auth_ndd" && \
|
||
|
gsl__logs_print \
|
||
|
"$gsl_log_i" \
|
||
|
"Author" \
|
||
|
"Added" \
|
||
|
"${gsl_new_authors[i]} for domain $gsl_find_domain" \
|
||
|
"$gsl_file_auth_ndd"
|
||
|
done
|
||
|
|
||
|
gsl__authors_list
|
||
|
}
|
||
|
|
||
|
#=======================================================================
|
||
|
# Remove Author(s) for DOMAIN from authors.db in Profile User
|
||
|
#=======================================================================
|
||
|
gsl__authors_remove() {
|
||
|
gsl__authors_check
|
||
|
gsl__authors_list
|
||
|
|
||
|
printf '\n%s\n%s\n%s\n \n' \
|
||
|
"# You can REMOVE one or more Authors" \
|
||
|
" Enter numbers (space delimiter)" \
|
||
|
" || empty field to cancel"
|
||
|
|
||
|
read -rp "! Which numbers author to REMOVE ? " gsl_rm_authors
|
||
|
gsl_rm_authors=($gsl_rm_authors)
|
||
|
|
||
|
gsl_nbr_authors=`cat $gsl_file_auth_ndd | wc -l`
|
||
|
for line in ${gsl_rm_authors[@]}
|
||
|
do
|
||
|
[[ $line =~ ^[0-9]+$ ]] || continue
|
||
|
(( $line < 1 )) && continue
|
||
|
(( $line > $gsl_nbr_authors )) && continue
|
||
|
|
||
|
if [[ $rm_line ]];then
|
||
|
! (( $line == 1 )) && line=$(( line - 1 ))
|
||
|
fi
|
||
|
gsl_rm_author=`awk -v n="$line" 'NR == n' "$gsl_file_auth_ndd"`
|
||
|
sed -i "${line}d" "$gsl_file_auth_ndd" && \
|
||
|
gsl__logs_print \
|
||
|
"$gsl_log_i" \
|
||
|
"Author" \
|
||
|
"Removed" \
|
||
|
"$gsl_rm_author for domain $gsl_find_domain" \
|
||
|
"$gsl_file_auth_ndd"
|
||
|
echo " - Removed > $gsl_rm_author <"
|
||
|
rm_line=true
|
||
|
done
|
||
|
|
||
|
gsl__authors_list
|
||
|
}
|