/ scripts / periodic / 490.status-pkg-changes.in
490.status-pkg-changes.in
  1  #!/bin/sh -
  2  #
  3  # $FreeBSD$
  4  #
  5  
  6  if [ -r /etc/defaults/periodic.conf ]; then
  7  	. /etc/defaults/periodic.conf
  8  	source_periodic_confs
  9  fi
 10  
 11  list_pkgs() {
 12      local pkgargs="$1"
 13      local bak_file="$2"
 14      local rc
 15  
 16      bak=/var/backups
 17  
 18      [ -r $bak/$bak_file ] && mv -f $bak/$bak_file $bak/${bak_file}2
 19      ${pkgcmd} ${pkgargs} info > $bak/$bak_file
 20      rc=$?
 21  
 22      cmp -sz $bak/$bak_file $bak/${bak_file}2
 23      if [ $? -eq 1 ]; then
 24  	diff -U 0 $bak/${bak_file}2 $bak/${bak_file} | \
 25  	    grep '^[-+][^-+]' | sort -k 1.2
 26      fi
 27  
 28      return $rc
 29  }
 30  
 31  list_pkgs_all() {
 32      local rc
 33      local jails
 34      local bak_file
 35      local rc=0
 36  
 37      : ${daily_status_pkg_changes_chroots=$pkg_chroots}
 38      : ${daily_status_pkg_changes_jails=$pkg_jails}
 39  
 40      # We always show pkg changes for the base system, but only print a
 41      # banner line if we're also going to show pkg changes for any
 42      # chroots or jails.
 43  
 44      if [ -n "${daily_status_pkg_changes_chroots}" -o \
 45  	 -n "${daily_status_pkg_changes_jails}" ];
 46      then
 47  	echo "Host system:"
 48      fi
 49  
 50      list_pkgs '' pkg.bak
 51      [ $? -ne 0 ] && rc=1
 52  
 53      for c in $daily_status_pkg_changes_chroots ; do
 54  	echo
 55  	echo "chroot: $c"
 56  	bak_file="pkg.chroot-$(echo $c | tr -C a-zA-Z0-9.- _).bak"
 57  
 58  	list_pkgs "-c $c" $bak_file
 59  	[ $? -ne 0 ] && rc=1
 60      done
 61  
 62      case $daily_status_pkg_changes_jails in
 63  	\*)
 64  	    jails=$(jls -q -h name | sed -e 1d)
 65  	    ;;
 66  	'')
 67  	    jails=
 68  	    ;;
 69  	*)
 70  	    jails=$daily_status_pkg_changes_jails
 71  	    ;;
 72      esac
 73  
 74      for j in $jails ; do
 75  	echo
 76  	echo "jail: $j"
 77  	bak_file="pkg.jail-$(echo $j | tr -C a-zA-Z0-9.- _).bak"
 78  
 79  	list_pkgs "-j $j" $bak_file
 80  	[ $? -ne 0 ] && rc=1
 81      done
 82  	
 83      return $rc
 84  }
 85  
 86  case "$daily_status_pkg_changes_enable" in
 87  	[Yy][Ee][Ss])
 88  	pkgcmd=%prefix%/sbin/pkg
 89  
 90  	echo
 91  	echo 'Changes in installed packages:'
 92  
 93  	if ! ${pkgcmd} -N >/dev/null 2>&1 ; then
 94  		echo 'status-pkg-changes is enabled but pkg is not used'
 95  		rc=2
 96  	else
 97  	    list_pkgs_all
 98  	fi
 99  	;;
100  	*)
101  	rc=0
102  	;;
103  esac
104  
105  exit $rc