Bug 17006: (follow-up) set_password expects a hashref
[koha.git] / debian / scripts / koha-foreach
index 6bda414..9682f14 100755 (executable)
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-
 set -e
 
+# Read configuration variable file if it is present
+[ -r /etc/default/koha-common ] && . /etc/default/koha-common
+
+# include helper functions
+if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
+    . "/usr/share/koha/bin/koha-functions.sh"
+else
+    echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
+    exit 1
+fi
+
+chdir="no"
+starting_dir=$(pwd)
+
 listopts=""
 while [ ! -z "$1" ]
 do
     case "$1" in
+        --chdir) chdir="yes";;
         --email) listopts="$listopts --email";;
       --noemail) listopts="$listopts --noemail";;
       --enabled) listopts="$listopts --enabled";;
+     --disabled) listopts="$listopts --disabled";;
+          --sip) listopts="$listopts --sip";;
+        --nosip) listopts="$listopts --nosip";;
+        --plack) listopts="$listopts --plack";;
+      --noplack) listopts="$listopts --noplack";;
+  --letsencrypt) listopts="$listopts --letsencrypt" ;;
+--noletsencrypt) listopts="$listopts --noletsencrypt" ;;
               *) break;;
     esac
     shift
 done
-            
+
 for name in $(koha-list $listopts)
 do
-    (
-    exec 3>&1
-    sudo -u "$name-koha" \
-    env PERL5LIB=/usr/share/koha/lib \
-        KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" \
-        "$@" 2>&1 >&3 | sed -e "s/^/$name: /" >&2 3>&-
-    exec 3>&-
-    ) | sed -e "s/^/$name: /"
+    # Replace the __instancename__ placeholder for the instance name (Bug 8566)
+    cmd=`echo "$@" | sed -e s/__instancename__/${name}/g`
 
-done
+    if [ "${cmd}" != "" ]; then
+
+        # Change to the instance's home dir if required
+        [ "$chdir" != "no" ] && eval cd ~$name"-koha"
 
+        koha-shell ${name} -c "${cmd}"
+
+        # Go back to the original dir if required
+        [ "$chdir" != "no" ] && cd "$starting_dir"
+    fi
+done