View | Details | Raw Unified | Return to bug 10094
Collapse All | Expand All

(-)a/debian/docs/koha-list.xml (-2 / +8 lines)
Lines 23-34 Link Here
23
23
24
  <refsynopsisdiv>
24
  <refsynopsisdiv>
25
    <cmdsynopsis>
25
    <cmdsynopsis>
26
      <command>koha-list</command> <arg><option>--enabled</option></arg> <arg><option>--email</option></arg> <arg><option>-h</option></arg>
26
      <command>koha-list</command> <arg><option>--enabled</option>|<option>--disabled</option></arg> <arg><option>--email</option>|<option>--noemail</option></arg> <arg><option>-h</option></arg>
27
    </cmdsynopsis>
27
    </cmdsynopsis>
28
  </refsynopsisdiv>
28
  </refsynopsisdiv>
29
  
29
  
30
  <refsect1><title>Options</title>
30
  <refsect1><title>Options</title>
31
  <para>The filtering options can be combined, and you probably want to do this (except --email and --noemail, that's just silly.)</para>
31
  <para>The filtering options can be combined, and you probably want to do this (except --email and --noemail,  or --enabled and --disabled, that's just silly.)</para>
32
  <variablelist> 
32
  <variablelist> 
33
    <varlistentry>
33
    <varlistentry>
34
      <term><option>--enabled</option></term>
34
      <term><option>--enabled</option></term>
Lines 37-42 Link Here
37
      </listitem>
37
      </listitem>
38
    </varlistentry>
38
    </varlistentry>
39
    <varlistentry>
39
    <varlistentry>
40
      <term><option>--disabled</option></term>
41
      <listitem>
42
        <para>Only show instances that are disabled.</para>
43
      </listitem>
44
    </varlistentry>
45
    <varlistentry>
40
      <term><option>--email</option></term>
46
      <term><option>--email</option></term>
41
      <listitem>
47
      <listitem>
42
        <para>Only show instances that have email enabled.</para>
48
        <para>Only show instances that have email enabled.</para>
(-)a/debian/scripts/koha-list (-24 / +125 lines)
Lines 1-6 Link Here
1
#!/bin/sh
1
#!/bin/sh
2
#
2
#
3
# koha-instances -- List all Koha instances.
3
# koha-list -- List all Koha instances.
4
# Copyright 2010  Catalyst IT, Ltd
4
# Copyright 2010  Catalyst IT, Ltd
5
# 
5
# 
6
# This program is free software: you can redistribute it and/or modify
6
# This program is free software: you can redistribute it and/or modify
Lines 19-27 Link Here
19
19
20
set -e
20
set -e
21
21
22
is_enabled() {
22
die()
23
{
24
    echo "$@" 1>&2
25
    exit 1
26
}
27
28
is_enabled()
29
{
30
    local instancename=$1
31
23
    if grep '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \
32
    if grep '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \
24
            "/etc/apache2/sites-available/$name" > /dev/null
33
            "/etc/apache2/sites-available/$instancename" > /dev/null
25
    then
34
    then
26
        return 1
35
        return 1
27
    else
36
    else
Lines 29-74 is_enabled() { Link Here
29
    fi
38
    fi
30
}
39
}
31
40
32
help() {
41
is_created()
42
{
43
    local instancename=$1
44
45
    if find /etc/koha/sites -mindepth 1 -maxdepth 1 \
46
                         -type d -printf '%f\n'\
47
          | grep -q $instancename
48
    then
49
        return 0
50
    else
51
        return 1
52
    fi
53
}
54
55
is_email_enabled()
56
{
57
    local instancename=$1
58
59
    if [ -e /var/lib/koha/$instancename/email.enabled ]; then
60
        return 0
61
    else
62
        return 1
63
    fi
64
}
65
66
get_instances()
67
{
68
    find /etc/koha/sites -mindepth 1 -maxdepth 1\
69
                         -type d -printf '%f\n' | sort
70
}
71
72
show_instances()
73
{
74
    local show=$1
75
    local show_email=$2
76
77
    for instance in $( get_instances ); do
78
        case $show in
79
          "all")
80
              show_instance_filter_email $instance $show_email;;
81
          "enabled")
82
              if is_enabled $instance; then
83
                  show_instance_filter_email $instance $show_email
84
              fi ;;
85
          "disabled")
86
              if ! is_enabled $instance; then
87
                  show_instance_filter_email $instance $show_email
88
              fi ;;
89
        esac
90
    done
91
}
92
93
show_instance_filter_email()
94
{
95
    local instancename=$1
96
    local show_email=$2;
97
98
    case $show_email in
99
        "all")
100
            echo $instancename ;;
101
        "enabled")
102
            if is_email_enabled $instancename; then
103
                echo $instancename
104
            fi ;;
105
        "disabled")
106
            if ! is_email_enabled $instancename; then
107
                echo $instancename
108
            fi ;;
109
    esac
110
}
111
112
set_show()
113
{
114
    local show_param=$1
115
116
    if [ "$show" = "all" ]; then
117
        show=$show_param
118
    else
119
        die "Error: --enabled and --disabled are mutually exclusive."
120
    fi
121
}
122
123
set_show_email()
124
{
125
    local email_param=$1
126
127
    if [ "$show_email" = "all" ]; then
128
        show_email=$email_param
129
    else
130
        die "Error: --email and --noemail are mutually exclusive."
131
    fi
132
}
133
134
usage()
135
{
136
    local scriptname=$0
137
33
    echo <<eoh
138
    echo <<eoh
34
Lists Koha instances, optionally only those that are enabled or have
139
Lists Koha instances, optionally only those that are enabled or have
35
email turned on.
140
email turned on.
36
    
141
    
37
Usage: $0 [--enabled] [--email] [-h]
142
Usage: $scriptname [--enabled|--disabled] [--email|--noemail] [-h]
38
Options:
143
Options:
39
    --enabled       only show instances that are enabled
144
    --enabled       only show instances that are enabled
145
    --disabled      only show instances that are disabled
40
    --email         only show instances that have email enabled
146
    --email         only show instances that have email enabled
41
    --noemail       only show instances that do not have email enabled
147
    --noemail       only show instances that do not have email enabled
42
    -h              this help
148
    -h              this help
43
149
44
The filtering options can be combined, and you probably want to do this
150
The filtering options can be combined, and you probably want to do this
45
(except --email and --noemail, that's just silly.)
151
(except --email and --noemail, or --enabled and --disabled, that's just silly.)
46
eoh
152
eoh
47
}
153
}
48
154
49
enabled=no
155
show="all"
50
email=no
156
show_email="all"
51
noemail=no
157
52
args=$(getopt -l enabled,email,noemail -o h -n $0 -- "$@")
158
args=$(getopt -l enabled,disabled,email,noemail -o h -n $0 -- "$@")
53
set -- $args
159
set -- $args
160
54
while [ ! -z "$1" ]
161
while [ ! -z "$1" ]
55
do
162
do
56
    case "$1" in
163
    case "$1" in
57
         -h) help; exit;;
164
         -h) usage; exit;;
58
    --email) email=yes;;
165
    --email) set_show_email "enabled" ;;
59
  --enabled) enabled=yes;;
166
  --noemail) set_show_email "disabled" ;;
60
  --noemail) noemail=yes;;
167
  --enabled) set_show "enabled" ;;
168
 --disabled) set_show "disabled" ;;
61
          *) break;;
169
          *) break;;
62
    esac
170
    esac
63
    shift
171
    shift
64
done
172
done
65
173
66
find /etc/koha/sites -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | 
174
show_instances $show $show_email
67
sort |
175
68
while read name
176
exit 0
69
do
70
    [ "$enabled" = yes ] && ! is_enabled "$name" && continue
71
    [ "$email" = yes ] && [ ! -e /var/lib/koha/$name/email.enabled ] && continue
72
    [ "$noemail" = yes ] && [ -e /var/lib/koha/$name/email.enabled ] && continue
73
    echo "$name"
74
done
75
- 

Return to bug 10094