Mercurial > hgrepos > hgweb.cgi > s4
annotate scripts/add-user-csv.sh @ 577:67ecd5901590
Inhibit non-group admin from cloning group
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Fri, 14 Jun 2019 09:27:11 +0900 |
parents | 7ab2ceb1b8dd |
children | f68f13fb226b |
rev | line source |
---|---|
544 | 1 #!/bin/sh |
2 | |
545
7cd9e895fa09
Supply usage when no argument supplied
HIROSE Yuuji <yuuji@gentei.org>
parents:
544
diff
changeset
|
3 if [ -z "$1" ]; then |
7cd9e895fa09
Supply usage when no argument supplied
HIROSE Yuuji <yuuji@gentei.org>
parents:
544
diff
changeset
|
4 cat<<-EOF >&2 |
7cd9e895fa09
Supply usage when no argument supplied
HIROSE Yuuji <yuuji@gentei.org>
parents:
544
diff
changeset
|
5 Usage: ./add-user-csv.sh CSVfile >&2 |
7cd9e895fa09
Supply usage when no argument supplied
HIROSE Yuuji <yuuji@gentei.org>
parents:
544
diff
changeset
|
6 Csv file should be the form of: |
7cd9e895fa09
Supply usage when no argument supplied
HIROSE Yuuji <yuuji@gentei.org>
parents:
544
diff
changeset
|
7 username(email),notify-email,gecos,IniPassword |
563
7ab2ceb1b8dd
$DISABLED controls password disabling
HIROSE Yuuji <yuuji@gentei.org>
parents:
560
diff
changeset
|
8 Set $DISABLED for setting disabled password |
545
7cd9e895fa09
Supply usage when no argument supplied
HIROSE Yuuji <yuuji@gentei.org>
parents:
544
diff
changeset
|
9 EOF |
7cd9e895fa09
Supply usage when no argument supplied
HIROSE Yuuji <yuuji@gentei.org>
parents:
544
diff
changeset
|
10 exit 1 |
7cd9e895fa09
Supply usage when no argument supplied
HIROSE Yuuji <yuuji@gentei.org>
parents:
544
diff
changeset
|
11 fi |
7cd9e895fa09
Supply usage when no argument supplied
HIROSE Yuuji <yuuji@gentei.org>
parents:
544
diff
changeset
|
12 |
544 | 13 target=$(cd `dirname "$1"`; pwd)/`basename $1` |
563
7ab2ceb1b8dd
$DISABLED controls password disabling
HIROSE Yuuji <yuuji@gentei.org>
parents:
560
diff
changeset
|
14 encp=${DISABLED:+DisabledPassword} |
544 | 15 |
16 cd `dirname $0`/.. | |
17 if ! . ./s4-funcs.sh; then | |
18 echo "Cannot find s4-funcs.sh, which should be located in $mydir/.." | |
19 exit 1 | |
20 fi | |
21 | |
22 sq $db<<-EOF | | |
23 .mode csv | |
24 CREATE TEMPORARY TABLE _newuser(user,email,gecos,inipswd); | |
25 .import $target _newuser | |
26 .mode list | |
27 .sepa , | |
28 SELECT * FROM _newuser n | |
29 WHERE NOT EXISTS (SELECT * FROM user WHERE name=n.user); | |
30 EOF | |
31 while IFS=, read user email gecos inipswd | |
32 do | |
563
7ab2ceb1b8dd
$DISABLED controls password disabling
HIROSE Yuuji <yuuji@gentei.org>
parents:
560
diff
changeset
|
33 encpswd=${encp:-`mycrypt "$inipswd" 'StOpmE'`} |
544 | 34 case "$user" in |
35 *\'*) echo "Skipping [$user]" | |
36 continue ;; | |
37 *@*) ;; # OK | |
38 *) echo "Skipping [$user] because of lacking email pattern" >&2 | |
39 continue ;; | |
40 esac | |
41 # echo "$user" "$user" "$inipswd" "$encpswd" | |
42 query "INSERT INTO user VALUES('$user');" && | |
43 echo Adding $user | |
44 dbsetbyid user "$user" email "$email" | |
45 dbsetbyid user "$user" gecos "$gecos" | |
46 dbsetbyid user "$user" pswd "$encpswd" | |
47 done |