File test_remote_smb.without_ping of Package yast2-printer
#! /bin/bash
#
# Test ability to connect to remote SMB server.
#
# Exits: 0 share on workgroup/host accepts print jobs
# 1 host $2 or share $3 not set
# 2 share does not accept a print job
# 16 give up empty-handed because smbclient not executable (no samba-client RPM installed?)
# The programs head, mkfifo, sleep, tr, rm are in the coreutils RPM and therefore assumed to exist.
#
# Johannes Meixner <jsmeix@suse.de>, 2000, 2002, 2007, 2008, 2009, 2010, 2011, 2014
# Jan Holesovsky <kendy@suse.cz>, 2000
# Jiri Srain <jsrain@suse.cz>, 2002
# $Id: test_remote_smb 43943 2008-01-28 13:38:58Z mzugec $
#set -x
# Make sure to have a clean environment:
export PATH="/sbin:/usr/sbin:/usr/bin:/bin"
export LC_ALL="POSIX"
export LANG="POSIX"
umask 022
# Disable bash file name globbing:
set -f
MY_NAME=${0##*/}
WORKGROUP=$1
HOST=$2
SHARE=$3
if test -z "$HOST" -o -z "$SHARE"
then echo -en "\nUsage:\n$MY_NAME WORKGROUP HOST SHARE [USER] [PASSWORD] [TIMEOUT]\n" 1>&2
exit 1
fi
USER=$4
PASSWORD=$5
TIMEOUT="$6"
[ -z "$TIMEOUT" ] && TIMEOUT=10
# Use the binaries of the operating system (no aliases, functions, /usr/local/):
export SMBCLIENT=$( type -ap smbclient | head -n 1 )
# Test whether smbclient is executable:
if test -z "$SMBCLIENT"
then # Give up empty-handed when smbclient is not executable:
echo -en "\nGiving up empty-handed because 'smbclient' not executable (no 'samba-client' RPM installed?)\n" 1>&2
exit 16
fi
# Test whether the SMB share on the server accepts print jobs:
echo -en "\nTesting share '$SHARE' on '$WORKGROUP/$HOST':\n"
test -z "$PASSWORD" && PASSWORD="-N"
if echo -en "\r" | $SMBCLIENT "//$HOST/$SHARE" "$PASSWORD" -c "print -" -U "$USER" -W "$WORKGROUP"
then echo -en "\nShare '$SHARE' on '$WORKGROUP/$HOST' accepts print jobs\n"
exit 0
fi
# The smbclient test failed:
echo -en "\nShare '$SHARE' on '$WORKGROUP/$HOST' does not accept print jobs."
echo -en "\n(Network issue or wrong host/workgroup/share or no server running or firewall active there?)\n\n"
exit 2