#!/bin/bash

bad_pkgs=""
for pkg in $(dpkg -l | grep gorynych | grep '^ii' | awk '{ print $2 }'); do
  init_d_scripts=$(dpkg -L $pkg | grep -q '/etc/ubic/service/gorynych/' && dpkg -L $pkg | grep "/etc/init.d/" | wc -l)
  if [ -n "$init_d_scripts" ] && [ $init_d_scripts -ne 1 ]; then
    bad_pkgs="$bad_pkgs // $pkg"
  fi
done

if [ -n "$bad_pkgs" ]; then
  echo "2; Bad init.d scripts in$bad_pkgs"
  exit 0
fi

echo "0; OK"
