RasppleII / a2server

AppleTalk server for Apple II computers
Other
31 stars 8 forks source link

Make command "showip" print the IP address of the NIC defined in atalkd.conf #58

Open mabam opened 7 years ago

mabam commented 7 years ago

In a2server/scripts/tools/a2server-aliases the command "showip" is defined as printing the IP address of eth0. However, if you define a different NIC for AppleTalk in atalkd.conf manually, you would want "showip" to print the IP address of that one (for example, the on-board NIC of the C.H.I.P. or Banana Pi are not able to transport AppleTalk, so one needs a USB-to-Ethernet adapter which will then be recognized as eth1).

I therefore suggest to have "showip" check atalkd.conf for its NIC first and then display the IP address of that NIC: '/sbin/ifconfig $(cat /etc/netatalk/atalkd.conf | tail -n 5 | grep "eth" | cut -d" " -f1) | grep "inet\ addr" | cut -d: -f2 | cut -d" " -f1'

Same goes for command "showmac". I suggest to change it into: '/sbin/ifconfig $(cat /etc/netatalk/atalkd.conf | tail -n 5 | grep "eth" | cut -d" " -f1) | grep "HWaddr" | cut -dH -f2 | cut -c7-23'

Also, it seems "ifconfig" as a command can't be used anymore. Instead it needs to be used with its path: "/sbin/ifconfig". Not sure whether that's the case (and correct path) for every system. This is an issue with the "showip", "showmac", "showip-wifi", and "showmac-wifi" commands.

knghtbrd commented 7 years ago

We're going to need to make that more robust anyway since my ethernet interface is named eno1, not eth0. If that hasn't hit Raspbian yet (haven't got a jessie machine in front of me just now), it will in stretch. It's probably time to make plans for that.

Additionally, the output of ifconfig has changed. That's going to cause problems too. And since the interface has changed, that's going to cause problems for netatalk too.

First, let's see if we can determine the default route's device:

tjcarter@rem:~$ ip route show | grep ^default | cut -f 5
default via 192.168.1.1 dev eno1 proto static metric 100

tjcarter@rem:~$ ip route show | grep ^default | cut -f 5 -d ' '
eno1

Now let's see if we can get a more useful output than the current ifconfig using that:

tjcarter@rem:~$ ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether <snip> brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.2/24 brd 192.168.1.255 scope global dynamic eno1
       valid_lft 81845sec preferred_lft 81845sec
    inet6 fe80::e28e:380b:9f6f:9845/64 scope link
       valid_lft forever preferred_lft forever

tjcarter@rem:~$ ip -o addr show
1: lo    inet 127.0.0.1/8 scope host lo\       valid_lft forever preferred_lft forever
1: lo    inet6 ::1/128 scope host \       valid_lft forever preferred_lft forever
2: eno1    inet 192.168.1.2/24 brd 192.168.1.255 scope global dynamic eno1\       valid_lft 81815sec preferred_lft 81815sec
2: eno1    inet6 fe80::e28e:380b:9f6f:9845/64 scope link \       valid_lft forever preferred_lft forever

tjcarter@rem:~$ ip -o -4 addr show
1: lo    inet 127.0.0.1/8 scope host lo\       valid_lft forever preferred_lft forever
2: eno1    inet 192.168.1.2/24 brd 192.168.1.255 scope global dynamic eno1\       valid_lft 81769sec preferred_lft 81769sec

tjcarter@rem:~$ ip -o -4 addr show | sed -e 's/[0-9]*: \([^ ]*\) *inet \([.0-9]*\).*$/\1 \2/'
lo 127.0.0.1
eno1 192.168.1.2

One could theoretically write something a little fancier that would include the IPv6 address (for both of the people out there who care about that) and use the route command above to extract just the default (eno1 in my case) interface.

I think I like this more because it allows you to configure your network however you want and have showip still be actually useful as a human-friendly command. Moreover, this can be useful to help us configure netatalk to use your preferred network, whatever it is, rather than hardcoding it.

Better still would be to configure netatalk to listen to all interfaces by default--but that's a separate consideration.

Edit: Split terminal commands up for legibility.

mabam commented 7 years ago

Thanks for that!

I've written a guide on how to build a NAS around a Banana Pi (as it has a SATA port) running A2SERVER. I've implemented your entries in that guide: http://www.emaculation.com/doku.php/appletalk_printserver_macos_and_osx#install_a2server

Also, to change eth0 to the default interface in atalkd.conf, I'm using this: sudo sed -i 's/^eth0/'"$(ip route show | grep ^default | cut -f 5 -d ' ')/" /etc/netatalk/atalkd.conf (Inspired by /etc/a2server-aliases.)

And – off topic – the guide also includes installing a PAP backend (with CUPS) for those still having a functioning LaserWriter that only speaks AppleTalk (like my LW 4/600 PS).

mabam commented 7 years ago

I figured that I had missed an important step from http://ivanx.com/a2server/a2server_installubuntu.html: I'm on an Ubuntu system and was supposed to amend the path variable to the executables: sudo sed -i '0,/-eq 0/s/-eq 0/-ge 0/' /etc/profile.

So, sorry for what I wrote in my initial post:

Also, it seems "ifconfig" as a command can't be used anymore. Instead it needs to be used with its path: "/sbin/ifconfig". Not sure whether that's the case (and correct path) for every system.

Just "ifconfig" is fine.