Ignore:
Timestamp:
09/09/07 20:18:19 (6 years ago)
Author:
anarcat
Message:

move functions to a common directory to avoid code duplication

File:
1 edited

Legend:

Unmodified
Added
Removed
  • alternc/trunk/src/basedir_prot.sh

    r1772 r1919  
    1717 
    1818. /etc/alternc/local.sh 
     19. /usr/lib/alternc/functions.sh 
     20 
    1921if [ -z "$MYSQL_HOST" ] 
    2022then 
    2123    MYSQL_HOST="localhost" 
    2224fi 
    23  
    24 # imprime le nom d'usager associé au domaine 
    25 get_account_by_domain() { 
    26         # les admintools ne sont peut-être pas là 
    27         if [ -x "/usr/bin/get_account_by_domain" ] 
    28         then 
    29                 # only first field, only first line 
    30                 /usr/bin/get_account_by_domain "$1" | cut -d\  -f1 | cut -d' 
    31 ' -f 1 
    32         else 
    33                 # implantons localement ce que nous avons besoin, puisque admintools 
    34                 # n'est pas là 
    35                 mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS -D$MYSQL_DATABASE -B -N -e \ 
    36                 'SELECT a.login FROM membres a, sub_domaines b WHERE a.uid = b.compte AND \ 
    37                 CONCAT(IF(sub="", "", CONCAT(sub, ".")), domaine) = "'"$1"'" LIMIT 1;' 
    38         fi 
    39 } 
    40  
    41 # add the standard input to a given file, only if not already present 
    42 append_no_dupe() { 
    43         realfile="$1" 
    44         tmpfile=`mktemp` 
    45         trap "rm -f $tmpfile; exit 1" 1 2 15 
    46         cat > $tmpfile 
    47         if [ -r "$realfile" ] && 
    48                 (diff -q "$tmpfile" "$realfile" > /dev/null || \ 
    49                         diff -u "$tmpfile" "$realfile"  | grep '^ ' | sed 's/^ //' | diff -q - "$tmpfile" > /dev/null) 
    50         then 
    51                 ret=0 
    52         else 
    53                 ret=1 
    54                 cat "$tmpfile" >> "$realfile" 
    55         fi 
    56         rm -f "$tmpfile" 
    57         return "$ret" 
    58 } 
    59  
    60 add_dom_entry() { 
    61         # protect ourselves from interrupts 
    62         trap "rm -f ${override_f}.new; exit 1" 1 2 15 
    63         # ajouter une entrée, seulement s'il n'y en pas déjà, pour ce domaine 
    64         (echo "$1"; [ -r $override_f ] && cat $override_f) | \ 
    65         sort -u > ${override_f}.new && \ 
    66         cp ${override_f}.new ${override_f} && \ 
    67         rm ${override_f}.new 
    68 } 
    69  
    70 # la première lettre de l'avant-dernière partie du domaine (e.g. 
    71 # www.alternc.org -> a) 
    72 # 
    73 # argument: le domaine 
    74 # imprime: la lettre 
    75 init_dom_letter() { 
    76     echo "$1" | awk '{z=split($NF, a, ".") ; print substr(a[z-1], 1, 1)}' 
    77 } 
    7825 
    7926echo -n "adding open_base_dir protection for:" 
Note: See TracChangeset for help on using the changeset viewer.