Improve hostname detectiong for SCP and Automatic Profile Switching [was: Shell Integration determined hostnames on Debian and Ubuntu Linux hosts not working with mDNS]
Note: Revised the issue title to be more descriptive of the problem
Revised Summary: The shell integration script calculates hostnames for non-domain linux hosts that do not work with mDNS (multiCast DNS) a.k.a. users in non-DNS environment. Non-DNS environments are common when working with test VMs and programming embedded devices (like Raspberry Pis or BeagleBoards)
There are two variants of this problem (for non-domain hosts):
- Debian Linux hosts will have a hostname in the format
HOSTNAME.localdomain
- Ubuntu Linux hosts will have a hostname in the format
HOSTNAME
(this is technically correct, but on a non-DNS system, it should default to.local
as OSX does.)
These hostnames result in the hostname not resolving with mDNS, which breaks SCP functionality, and makes defining the hostname for automatic profile switching
a challenge. mDNS requires a .local
suffix (which IS properly identified on OSX).
Reproduction Steps
- SSH into a Debian or Ubuntu Linux host with that does not have a domain setup and install the shell integration script (bash)
- start a new SSH session
- Note the SCP command in the right-click menu displays a HOSTNAME ending in ".localdomain" (on debian), or without a suffix (on Ubuntu)
- Attempting to use the SCP command fails with a "could not connect error"
- The 'File Transfer Summary' also displays a HOSTNAME ending in ".localdomain"
- Auto Profile switching does not work correctly on these hosts
Likely Cause:
- It appears
iterm2_hostname
is set via thehostname -f
command (in line 258 of the Bash Shell Integration Script) - On Debian,
hostname -f
returns aHOSTNAME.localdomain
if the domain is not set - On Ubuntu,
hostname -f
returns aHOSTNAME
if the domain is not set - Both of these differ from OSX, where hosts without a domain have a ".local" suffix
Possible Workaround:
I added the following code to my Shell integration script (line 252) used on all of my hosts. It's been working for the last month on all platforms (OSX, Debian, Ubuntu)
if [ -z "$iterm2_hostname" ]; then
if [ "$(domainname 2> /dev/null)" = "(none)" ]; then # no domain set
# domainname=(none) implies an OS where 'hostname -f' ends in ".localdomain" or null
iterm2_hostname="$(hostname -s).local"
else
# domainname set or on OS where 'hostname -f' ends in ".local"
iterm2_hostname=$(hostname -f)
fi
fi
Version Info:
- iTerm 2.9.20160209 (nightly) - has been broken since I started using the beta about a month ago.
- OSX Yosemite 10.10.5 - shell extensions installed
- Target Hosts exhibiting bad behavior - Debian Linux 8.2 (Jessie) & Raspian (Rasberry Pi version of Debian)