14cfe33f037c71496c6987963cb3c8d286818577
[koha.git] / debian / scripts / koha-reset-passwd
1 #!/bin/sh
2 #
3 # koha-reset-passwd -- reset password for a user in a Koha instance
4 # Copyright 2010  Catalyst IT, Ltd
5 # Copyright 2019  Theke Solutions
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20
21 set -e
22
23 # include helper functions
24 if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
25     . "/usr/share/koha/bin/koha-functions.sh"
26 else
27     echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
28     exit 1
29 fi
30
31 usage()
32 {
33     local scriptname=$0
34     cat <<EOF
35 Resets the password for the specified user on the Koha instance.
36
37 Usage: $scriptname instancename userid
38
39 Note: The generated password will be printed.
40 EOF
41 }
42
43 set_password()
44 {
45     local instancename=$1
46     local userid=$2
47
48     # Optionally use alternative paths for a dev install
49     adjust_paths_dev_install $1
50
51     if [ "$DEV_INSTALL" = "" ]; then
52         KOHA_BINDIR=$KOHA_HOME/bin
53     else
54         KOHA_BINDIR=$KOHA_HOME/misc
55     fi
56
57     if sudo -u "$instancename-koha" -H \
58         env PERL5LIB=$PERL5LIB \
59         KOHA_CONF="/etc/koha/sites/$instancename/koha-conf.xml" \
60         $KOHA_BINDIR/admin/set_password.pl --userid $userid ; then
61
62         return 0
63     else
64         return 1
65     fi
66 }
67
68 if [ $# -lt 2 ]; then
69     usage
70     die "Wrong parameters"
71 fi
72
73 instance="$1"
74 shift
75
76 for userid in "$@"
77 do
78     set_password $instance $userid
79 done
80
81 exit 0