69 lines
1.9 KiB
Bash
69 lines
1.9 KiB
Bash
#!/bin/bash
|
|
|
|
# This script checks for the next free remote-admin pc and established a RDP session using xfreerdp to it.
|
|
# To use this script you need to create two files in your home directory
|
|
#
|
|
# .smbcredentials
|
|
# username=YOUR AD USERNAME
|
|
# password=YOUR AD PASSWORD
|
|
#
|
|
# .remote-admin
|
|
# USERNAME=administrator@zfd.forumzfd.de
|
|
# PASSWORD=AD ADMIN PASSWORD FROM BITWARDEN
|
|
#
|
|
# Make sure to proper chmod them (e.g. chmod 600)
|
|
#
|
|
# Add the following line to your /etc/fstab and edit YOUR_USERNAME
|
|
#
|
|
# //cluster-ho/Ampel /tmp/remote-ampel cifs credentials=/home/YOUR_USERNAME/.smbcredentials,user,noauto,workgroup=ZFD,dir_mode=0777,file_mode=0777,_netdev 0 0
|
|
#
|
|
# setuid might be necessary on /usr/sbin/mount.cifs. Set it as root with
|
|
#
|
|
# chmod u+s /usr/sbin/mount.cifs
|
|
|
|
AMPEL_MOUNT=/tmp/remote-ampel
|
|
|
|
if [ -f ~/.remote-admin ]; then
|
|
source ~/.remote-admin
|
|
else
|
|
echo ".remote-admin not found! Please create it!"
|
|
exit 4
|
|
fi
|
|
if [ ! -f ~/.smbcredentials ]; then
|
|
echo ".smbcredentials not found! Please create it!"
|
|
exit 5
|
|
fi
|
|
# Check for xfreerdp
|
|
if [ ! -f /usr/bin/xfreerdp ]; then
|
|
print "xfreerdp not found. Make sure it is installed"
|
|
exit 1
|
|
else # check for the mount point
|
|
mkdir -p $AMPEL_MOUNT
|
|
if grep -qs $AMPEL_MOUNT /proc/mounts; then
|
|
echo "$AMPEL_MOUNT already mounted."
|
|
else
|
|
echo "Trying to mount $AMPEL_MOUNT"
|
|
mount $AMPEL_MOUNT
|
|
if [ $? -eq 0 ]; then
|
|
echo "Mount successful."
|
|
else
|
|
echo "Mount failed. Check share"
|
|
exit 2
|
|
fi
|
|
fi
|
|
fi
|
|
sleep 2
|
|
for i in $(ls $AMPEL_MOUNT)
|
|
do
|
|
if [[ $i == *"FREE"* ]]; then
|
|
RDP=$(echo $i | cut -f1,2 -d'-')
|
|
echo "$RDP is free :)"
|
|
xfreerdp /u:$USERNAME /p:$PASSWORD /v:$RDP.zfd.forumzfd.de /dynamic-resolution
|
|
umount $AMPEL_MOUNT
|
|
echo 'Connection closed. Bye'
|
|
exit 0
|
|
fi
|
|
done
|
|
echo 'No Remote-Admin is free. :( Try again later.'
|
|
umount $AMPEL_MOUNT
|
|
exit 0
|