|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/bin/sh |
|
|
2 |
# |
| 3 |
# koha-passwd -- show a Koha instance's password |
| 4 |
# Copyright 2014 KohaAloha, Ltd |
| 5 |
# |
| 6 |
# This program is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
|
| 20 |
set -e |
| 21 |
|
| 22 |
|
| 23 |
die() |
| 24 |
{ |
| 25 |
echo "$@" 1>&2 |
| 26 |
exit 1 |
| 27 |
} |
| 28 |
|
| 29 |
warn() |
| 30 |
{ |
| 31 |
echo "$@" 1>&2 |
| 32 |
} |
| 33 |
|
| 34 |
is_instance() |
| 35 |
{ |
| 36 |
local instancename=$1 |
| 37 |
|
| 38 |
if find /etc/koha/sites -mindepth 1 -maxdepth 1 \ |
| 39 |
-type d -printf '%f\n'\ |
| 40 |
| grep -q -x $instancename ; then |
| 41 |
return 0 |
| 42 |
else |
| 43 |
return 1 |
| 44 |
fi |
| 45 |
} |
| 46 |
|
| 47 |
usage() |
| 48 |
{ |
| 49 |
local scriptname=$0 |
| 50 |
cat <<EOF |
| 51 |
Displays a Koha instance's password. |
| 52 |
|
| 53 |
Usage: $scriptname instancename1 instancename2... |
| 54 |
|
| 55 |
EOF |
| 56 |
} |
| 57 |
|
| 58 |
# Parse command line. |
| 59 |
[ $# -ge 1 ] || ( usage ; die "Missing instance name..." ) |
| 60 |
|
| 61 |
|
| 62 |
for name in "$@" |
| 63 |
do |
| 64 |
if is_instance $name ; then |
| 65 |
xmlstarlet sel -t -v 'yazgfs/config/pass' /etc/koha/sites/$name/koha-conf.xml |
| 66 |
else |
| 67 |
warn "Unknown instance $name." |
| 68 |
fi |
| 69 |
done |
| 70 |
|
| 71 |
exit 0 |