#! /bin/bash

FILE="/preferences"

OLDIFS=$IFS
IFS=$'\t'$'\n'
echo "##### preferencen-File für easyvdr #####" > $FILE
for packet in $(dpkg -l); do
  NAME=$(echo $packet | grep ^ii | cut -b5-36)
  VERS=$(echo $packet | grep ^ii | cut -b38-77)
  if [ -n "$NAME" ]; then
    echo "Package: $NAME" >> $FILE
    echo "Pin: version $VERS" >> $FILE
    echo "Pin-Priority: 1005" >> $FILE
    echo >> $FILE
  fi
done
IFS=$OLDIFS