#!/bin/bash PRINTER_NAME=dummy0 PRINTER_DEV=/dev/null _fatal() { local str=$* echo "fatal: $str" exit 1 } _smb_printer_check() { local printer=$* smbclient -N -L localhost 2>&1 | grep $printer &> /dev/null return $? } _test_add_remove() { local reload_action=$1 `lpstat -p | grep $PRINTER_NAME > /dev/null` \ && _fatal "printer $PRINTER_NAME exists, cleanup needed" echo "testing printer addition with reload action: $reload_action..." lpadmin -p $PRINTER_NAME -E -v $PRINTER_DEV \ || _fatal "failed to add printer $PRINTER_NAME" `$reload_action &> /dev/null` || _fatal "$reload_action failed" sleep 1 # allow 1s for printer to appear _smb_printer_check $PRINTER_NAME \ || _fatal "new printer did not appear after reload" echo "- passed" echo "testing printer removal with reload action: $reload_action" lpadmin -x $PRINTER_NAME \ || _fatal "failed to remove printer $PRINTER_NAME" `$reload_action &> /dev/null` || _fatal "$reload_action failed" sleep 1 _smb_printer_check $PRINTER_NAME \ && _fatal "printer did not disappear after reload" echo "- passed" } PCAP_CACHE_TIME=`testparm -s --parameter-name="printcap cache time" 2>/dev/null` [ $? -eq 0 ] || _fatal "failed to get printcap cache time" _test_add_remove "smbcontrol smbd reload-config" _test_add_remove "killall -HUP smbd" _test_add_remove "sleep $PCAP_CACHE_TIME"