Skip to content

opsi.orgheader image

opsi.org
Views
WinstScripts >>

pstatus

Document Actions
last edited 3 years ago by djockheck
#!/bin/sh
# dj, 18.07.06
# Unix-Script for opsi 2.5 to show an overview of installation-status
# It is recommended to create entrys in the /etc/hosts of the server
# that contain the user-information behind the machine.
# Sample-line aus /etc/hosts:
# 10.33.2.240     bw016051 # M. Mustermann, not shown Txt behind comma
#
# If you would like to use /etc/hosts for this script only (e.g. 
# DNS is used) you can tell your opsi-server
# that /etc/hosts is used secondary only:
# Sample from /etc/nsswitch.conf:
# hosts:          dns [notfound=continue] files
clear

export FOLDER=/opt/pcbin/pcpatch
export SETUP=`grep "=setup" ${FOLDER}/*.ini | grep -v pcproto | wc -l`
export DEINSTALL=`grep "=deinstall" ${FOLDER}/*.ini | grep -v pcproto | wc -l`
export FAILED=`grep "=failed" ${FOLDER}/*.ini | grep -v pcproto | wc -l`

if [ $SETUP != "0" ]; then 
  echo "Packages going to be setup:"
  echo  ===============================
  for hostinfo in `grep "=setup" ${FOLDER}/*.ini | grep -v pcproto`
  do
    export hostname=`echo $hostinfo | cut -d\: -f1 | cut -d\/ -f5 | cut -d\. -f1 | col -b`
    export produkt=`echo $hostinfo | cut -d\: -f2 | col -b` 
    export username=`cat /etc/hosts | grep $hostname" " | cut -d\# -f2 | cut -d\, -f1 | col -b`
    echo Host: $hostname, Prod: $produkt, User: $username
  done
  echo 
fi

if [ $DEINSTALL != "0" ]; then 
  echo "Packages going to be deinstalled:"
  echo  =================================
  for hostinfo in `grep "=deinstall" ${FOLDER}/*.ini | grep -v pcproto`
  do
    export hostname=`echo $hostinfo | cut -d\: -f1 | cut -d\/ -f5 | cut -d\. -f1 | col -b`
    export produkt=`echo $hostinfo | cut -d\: -f2 | col -b` 
    export username=`cat /etc/hosts | grep $hostname" " | cut -d\# -f2 | cut -d\, -f1 | col -b`
    echo Host: $hostname, Prod: $produkt, User: $username
  done
  echo 
fi

if [ $FAILED != "0" ]; then 
  echo "Packages failed:"
  echo  =================================
  for hostinfo in `grep "=failed" ${FOLDER}/*.ini | grep -v pcproto`
  do
    export hostname=`echo $hostinfo | cut -d\: -f1 | cut -d\/ -f5 | cut -d\. -f1 | col -b`
    export produkt=`echo $hostinfo | cut -d\: -f2 | col -b` 
    export username=`cat /etc/hosts | grep $hostname" " | cut -d\# -f2 | cut -d\, -f1 | col -b`
    echo Host: $hostname, Prod: $produkt, User: $username
  done
  echo 
fi

echo Summary:
echo ========
if [ $SETUP != "0" ]; then 
  echo -n "Packages to setup: "
  echo $SETUP
fi
if [ $DEINSTALL != "0" ]; then 
  echo -n "Packages to deinstall: "
  grep "=deinstall" ${FOLDER}/*.ini | grep -v pcproto | wc -l
fi
if [ $FAILED != "0" ]; then 
  echo -n "Packages to failed: "
  grep "=failed" ${FOLDER}/*.ini | grep -v pcproto | wc -l
fi