scripts/mir-setup/README: update with link to new doc on wiki
[mir.git] / dbscripts / extra / hashpasswords.sh
1 #!/bin/bash
2
3 # DON'T RUN THIS SCRIPT UNLESS YOU KNOW WHAT YOU ARE DOING
4 #
5 # bash script to md5-hash all passwords: RUN ONLY ONCE!
6 # md5sum needs to be installed
7
8 # this script is not enough to use md5-hashed passwords: an
9 # appropriate localizer needs to be set up as well.
10
11
12 usage () {
13   echo "usage: $0 dbname"
14 }
15
16 if [ $# -ne 1 ]; then
17   usage 
18   exit;
19 fi;
20
21
22 # to get a backslash in the first pass sql script
23 s1="\\"
24 # to get a backslash in the second pass sql script
25 s2="\\\\"
26 # to get an escaped backslash in the second pass sql script:
27 s3="\\\\\\\\"
28
29  
30 SCRIPT_FILE="/tmp/hashpasswords.$$.sql"
31
32 psql $1 -P format=unaligned -t -X -F "" -c \
33   "select '${s2}set hashedpassword ${s1}'${s2}${s1}'${s1}' \`echo -n \"'||password||'\" | md5sum \`   \
34             \"${TEXT_SOURCE_PATH}\$(basename \"' || trim($2) || '\")\"\` ${s1}'${s2}${s1}'\\'\n',  \
35                 'update webdb_users set password=:hashedpassword where id = '||id from webdb_users" > $SCRIPT_FILE
36
37
38 # execute the script
39 #psql -f ${SCRIPT_FILE} -d template1
40 cat $SCRIPT_FILE
41
42 rm ${SCRIPT_FILE}