a2server/scripts/a2server-3-sharing.txt
T. Joseph Carter ff2da76e84 Get Ivan's precompiled binaries from his server
Ivan's precompiled binaries of nulib2, The Unarchiver, and netatalk for
Debian and Raspbian aren't going to be part of this repository, so I've
reverted to hardcoding Ivan's server as the source of those things.

We could perhaps download and compile nulib2 and The Unarchiver, and
we'd have to if the script doesn't recognize Debian/Raspbian.  Ideally
for those systems we'd download .deb packages with full and proper
dependency tracking, but we'd still need source for use on non-Debian
systems, should we ever develop support for those.  (OS X is a good
candidate for such a system?)
2015-10-04 02:04:52 -07:00

422 lines
20 KiB
Bash
Executable File

#!/bin/bash
# A2SERVER -- a virtual machine for sharing files to Apple II clients
# by Ivan X, ivan@ivanx.com
# Installs Netatalk 2.2.4 for debian/raspbian (Wheezy) or Ubuntu (12.04)
# last update: 3-Mar-15
# The lastest version of this document, and the ready-to-use premade
# virtual machine, will be at http://appleii.ivanx.com .
# Please send corrections and comments to ivan@ivanx.com
# Thanks to Steven Hirsch, Geoff Body, Peter Wong, Tony Diaz, and others
# at comp.sys.apple2 for the work they've done and insight they've
# offered which made it possible to put this together.
# --- Installing netatalk
# Ensure URL we'll use ends in a /
case "$A2SERVER_SCRIPT_URL" in
*/) scriptURL="$A2SERVER_SCRIPT_URL" ;;
*) scriptURL="${A2SERVER_SCRIPT_URL:-http://appleii.ivanx.com/a2server}/" ;;
esac
isRpi=
[[ -f /usr/bin/raspi-config ]] && isRpi=1
isDebian=
[[ ( -f /etc/debian_version ) && ( $(cut -c 1-2 < /etc/debian_version) == "7." ) && ( $(uname -m) == "i686" ) ]] && isDebian=1
# skip this if already done
if [[ -f /usr/local/etc/A2SERVER-version ]] && (( $(cat /usr/local/etc/A2SERVER-version) >= 101 )); then
echo "A2SERVER: Netatalk is already installed."
else
echo "A2SERVER: Installing Netatalk (this will take a while)..."
# stop Netatalk if running (during upgrade)
[[ $(ps --no-headers -C afpd) ]] && sudo /etc/init.d/netatalk stop
if [[ ! -f /tmp/a2server-packageReposUpdated ]]; then
# prepare for installing packages
sudo apt-get -y update
touch /tmp/a2server-packageReposUpdated
fi
compileFromSource=1
while [[ $isRpi || $isDebian ]]; do
# Install runtime libraries needed by Netatalk
if [[ $(apt-cache search '^libdb4.8$') ]]; then
sudo apt-get -y install libdb4.8
elif [[ $(apt-cache search '^libdb5.1$') ]]; then
sudo apt-get -y install libdb5.1
else
break
fi
if [[ $(apt-cache search '^libssl1.0.0$') ]]; then
sudo apt-get -y install libssl1.0.0
elif [[ $(apt-cache search '^libssl0.9.8$') ]]; then
sudo apt-get -y install libssl0.9.8
else
break
fi
if [[ $(apt-cache search '^libgcrypt11$') ]]; then
sudo apt-get -y install libgcrypt11
else
break
fi
# install Netatalk
if [[ $isRpi ]]; then
{ wget -qO- /tmp/netatalk.tgz "http://appleii.ivanx.com/a2server/files/netatalk224-rpi.tgz" | sudo tar Pzx; } 2> /dev/null
elif [[ $isDebian ]]; then
{ wget -qO- /tmp/netatalk.tgz "http://appleii.ivanx.com/a2server/files/netatalk224-debian7_x86.tgz" | sudo tar Pzx; } 2> /dev/null
fi
sudo mandb &> /dev/null
[[ -f /usr/local/sbin/atalkd ]] && compileFromSource=
break
done
if [[ $compileFromSource ]]; then
# Install development libraries needed by Netatalk
sudo apt-get -y install build-essential
if [[ $(apt-cache search '^libdb4.8-dev$') ]]; then
sudo apt-get -y install libdb4.8-dev
elif [[ $(apt-cache search '^libdb5.1-dev$') ]]; then
sudo apt-get -y install libdb5.1-dev
else
echo "A2SERVER: WARNING: unknown version of libdb-dev is being installed"
sudo apt-get -y install libdb-dev
fi
sudo apt-get -y install libssl-dev
sudo apt-get -y install libgcrypt11-dev
sudo apt-get clean
# get Netatalk
rm -rf /tmp/netatalk &> /dev/null
mkdir /tmp/netatalk
cd /tmp/netatalk
wget -q "http://downloads.sourceforge.net/project/netatalk/netatalk/2.2.4/netatalk-2.2.4.tar.gz"
tar zxf netatalk-2.2.4.tar.gz
cd netatalk-2.2.4
# Patch the source so file dates are preserved during a GS/OS folder copy,
# and the AsanteTalk bridge consistently starts up in AppleTalk Phase 2
# and the Dayna bridge doesn't crash GS/OS
# props to Steven Hirsch for these
sed -i ':a;N;$!ba;s/case FILPBIT_ATTR :\n *change_mdate = 1;\n/case FILPBIT_ATTR :\n/g' etc/afpd/file.c
sed -i 's/rtmp->rt_iface == iface/rtmp->rt_iface != iface/g' etc/atalkd/main.c
# prepare to build Netatalk
./configure --enable-debian --enable-ddp --enable-a2boot
# uninstall Netatalk if already installed
[[ -f /usr/local/sbin/afpd ]] && sudo make uninstall
# compile and install Netatalk
make
sudo make install
# to remove the Netatalk source code (optional), type:
cd
rm -rf /tmp/netatalk
fi
fi
# --- Configuring Netatalk
echo "A2SERVER: Configuring Netatalk..."
# if missing Netatalk startup file, download a fresh one
if [ ! -f /etc/init.d/netatalk ]; then
echo "A2SERVER: Downloading new Netatalk startup script..."
sudo wget -qO /etc/init.d/netatalk ${scriptURL}files/netatalk-init.d-clean.txt
fi
# make the Netatalk startup script work correctly
sudo sed -i 's/bin\/sh/bin\/bash/' /etc/init.d/netatalk
# enable AppleTalk networking support in Netatalk, and run in background
sudo sed -i 's/#ATALKD_RUN=no/ATALKD_RUN=yes/' /etc/default/netatalk
sudo sed -i 's/#ATALK_BGROUND=no/ATALK_BGROUND=yes/' /etc/default/netatalk
if [[ ! $(grep 'kernelRelease' /etc/init.d/netatalk) ]]; then
sudo sed -i 's@\(\tif \[ x\"$ATALKD_RUN\)@\n\t# check for valid AppleTalk kernel module\n\t[[ $ATALKD_RUN == "yes" ]] \&\& { kernelRelease=$(uname -r); kernelMajorRelease=$(cut -d "." -f 1 <<< $kernelRelease); kernelMinorRelease=$(cut -d "." -f 2 <<< $kernelRelease | sed '"'"'s/\\(^[0-9]*\\)[^0-9].*$/\\1/'"'"'); kernelPatchRelease=$(cut -d "." -f 3- <<< $kernelRelease | sed '"'"'s/\\(^[0-9]*\\)[^0-9].*$/\\1/'"'"'); [[ ( $kernelMajorRelease -eq 3 \&\& $kernelMinorRelease -ge 12 \&\& $kernelMinorRelease -le 15 ) \&\& ( ! ( -f /usr/bin/raspi-config \&\& $kernelMinorRelease -eq 12 \&\& $kernelPatchRelease -ge 25 ) ) \&\& ( ( ! -f /lib/modules/$kernelRelease/kernel/net/appletalk/appletalk.ko ) || $(sha1sum /lib/modules/$kernelRelease/kernel/net/appletalk/appletalk.ko | cut -f 1 -d " ") != "ecb239fc084c36de93f6926e7749b80f6024f269" ) ]] \&\& { ATALKD_RUN=no; echo "[AppleTalk networking is not available.]" 1>\&2; } }\n\n\1@' /etc/init.d/netatalk
fi
# enable network boot support in netatalk
sudo sed -i 's/timelord/a2boot/g' /etc/init.d/netatalk
sudo sed -i 's/TIMELORD/A2BOOT/g' /etc/init.d/netatalk
sudo sed -i 's/#A2BOOT_RUN=no/A2BOOT_RUN=yes/' /etc/default/netatalk
# allow Guest users to be able to network boot
sudo sed -i "s/#AFPD_GUEST=nobody/AFPD_GUEST=$USER/" /etc/default/netatalk
# (For a Guest user with different permissions than the compile-time user, create a
# Linux user, and then specify that user for AFPD_GUEST instead.)
# create a symbolic link to the startup configuration file in netatalk configuration folder
[[ -L /usr/local/etc/netatalk/netatalk.conf ]] \
|| sudo ln -s /etc/default/netatalk /usr/local/etc/netatalk/netatalk.conf
# create a symbolic link to the netatalk configuration folder in /etc
[[ -L /etc/netatalk ]] || sudo ln -s /usr/local/etc/netatalk /etc/netatalk
if [[ ! $(grep '^- -ddp.*uams_randnum.so' /usr/local/etc/netatalk/afpd.conf) ]]; then
# set up to allow Guest, Cleartext, RandNum, DHX, and DHX2 login
# disable DHX (DHCAST128) on Raspberry Pi, which refuses uams if the config string is too long
[[ -f /usr/bin/raspi-config ]] && dhx="" || dhx="uams_dhx.so,"
echo -n -e \
"- -ddp -tcp -uamlist uams_guest.so,uams_clrtxt.so,uams_randnum.so" \
| sudo tee -a /usr/local/etc/netatalk/afpd.conf > /dev/null
echo -e ",${dhx}uams_dhx2.so" \
| sudo tee -a /usr/local/etc/netatalk/afpd.conf > /dev/null
fi
# replace home folder share and end of file mark with share placeholders
sudo sed -i 's/^~/#share1\n\n#share2/' \
/usr/local/etc/netatalk/AppleVolumes.default
# disable default volume options for Mac OS X clients
sudo sed -i 's/^:DEFAULT/#:DEFAULT/' \
/usr/local/etc/netatalk/AppleVolumes.default
if [[ ! $(grep ^eth0 /usr/local/etc/netatalk/atalkd.conf) && ! $(grep ^wlan0 /usr/local/etc/netatalk/atalkd.conf) ]]; then
# enable netatalk on the default network interface
# needs -router and -zone to prevent GS/OS AppleShare CDEV crash when used
# with Dayna or Asante bridges
echo -e 'eth0 -router -phase 2 -net 1 -zone "A2SERVER"' \
| sudo tee -a /usr/local/etc/netatalk/atalkd.conf > /dev/null
fi
# Raspberry Pi
if [[ $isRpi ]]; then
# blink LED upon netatalk startup so you know when to attach power to an AsanteTalk bridge
if [[ ! $(grep 'led0' /etc/init.d/netatalk) ]]; then
sudo sed -i ':a;N;$!ba;s/fi\n}/fi\n\n # blink LED on Raspberry Pi\n ([[ -e \/sys\/class\/leds\/ACT ]] \&\& led=ACT || led=led0; echo none > \/sys\/class\/leds\/$led\/trigger; for i in {1..20}; do echo 1 > \/sys\/class\/leds\/$led\/brightness; sleep 0.25; echo 0 > \/sys\/class\/leds\/$led\/brightness; sleep 0.25; done; echo mmc0 > \/sys\/class\/leds\/$led\/trigger) \&\n}/' /etc/init.d/netatalk
fi
# set console port login to 4800 bps for usage with Apple II (using RPi console cable)
sudo sed -i 's/ttyAMA0 115200/ttyAMA0 4800/' /etc/inittab
# enable serial console login with USB-serial adapter
# 10-4-13: creates unwanted console messages if no adapter present,
# and physical port isn't predictable with more than one adapter present, so
# has been superseded by scanttyUSB supplied by A2CLOUD install
#if [[ ! $(grep 'ttyUSB0 19200' /etc/inittab) ]]; then
# echo -e "\n\n#for USB-to-serial adapter with Prolific PL2303 chipset\nT1:23:respawn:/sbin/getty -L ttyUSB0 19200 vt100" | sudo tee -a /etc/inittab > /dev/null
#fi
fi
# set up GSFILES share (for GS data files, not GSOS system)
# classic Mac OS file names are allowed (31 chars, mixed case, everything but colons)
sudo sed -i \
's/^#share1/\/media\/A2SHARED\/GSFILES\ GSFILES ea:ad/' \
/usr/local/etc/netatalk/AppleVolumes.default
[[ -d /media/A2SHARED/GSFILES ]] || mkdir -p /media/A2SHARED/GSFILES
# set up A2FILES share (for ProDOS 8 files, and GS/OS system)
# file names must be ProDOS 8 compliant (all caps, 15 chars, letters/numbers/periods only)
# lowercase filenames will be converted to upper automatically
# need for GS/OS system because it may refer to files by either upper or lower
sudo sed -i \
's/^#share2/\/media\/A2SHARED\/A2FILES\ A2FILES options:prodos\ casefold:toupper ea:ad/' \
/usr/local/etc/netatalk/AppleVolumes.default
[[ -d /media/A2SHARED/A2FILES ]] || mkdir -p /media/A2SHARED/A2FILES
if [[ ! -d /media/A2SHARED/A2FILES/.AppleDesktop ]]; then
cd /media/A2SHARED/A2FILES
mkdir .AppleDesktop
ln -s .AppleDesktop .APPLEDESKTOP
fi
# set up ADTDISKS share (ADTPro disk image folder, if A2CLOUD is installed)
# classic Mac OS file names are allowed (31 chars, mixed case, everything but colons)
if [[ -d /usr/local/adtpro/disks ]]; then # A2CLOUD/ADTPro installed
if [[ ! -d /media/A2SHARED/ADTDISKS ]]; then
ln -s /usr/local/adtpro/disks /media/A2SHARED/ADTDISKS
fi
if [[ ! $(grep ADTDISKS /usr/local/etc/netatalk/AppleVolumes.default) ]]; then
sudo sed -i 's@^# End of File@/media/A2SHARED/ADTDISKS ADTDISKS ea:ad\n\n# End of File@' /usr/local/etc/netatalk/AppleVolumes.default
fi
fi
# to make Netatalk start up when the server boots:
sudo update-rc.d netatalk defaults &> /dev/null
# --- Setting up users
# At this point, the server is usable for Guest access.
# skip if we've already done this
if [[ -f /usr/local/etc/netatalk/afppasswd ]]; then
echo "A2SERVER: Netatalk user logins have already been set up."
else
echo
echo "A2SERVER: Setting up AFP password 'apple2' for Apple II and Mac clients."
# echo "A2SERVER: Enter 'apple2' or another password of up to eight characters."
echo
# set registered user login using RandNum authentication
sudo afppasswd -c
sudo sed -i 's/^pi.*$/pi:6170706C65320000:****************:********/' /usr/local/etc/netatalk/afppasswd
# while [[ ! $(sudo afppasswd -a $USER) ]]; do
# true
# done
# (The afppasswd -c only needs to ever be done once. You can repeat
# the afppasswd -a to make Netatalk logins for other Linux users.)
fi
# Check AppleTalk kernel module for existence and validity
# get Kernel release (e.g. 3.6.11+) and version (e.g. #557)
kernelRelease=$(uname -r)
kernelMajorRelease=$(cut -d '.' -f 1 <<< $kernelRelease)
kernelMinorRelease=$(cut -d '.' -f 2 <<< $kernelRelease | sed 's/\(^[0-9]*\)[^0-9].*$/\1/')
kernelPatchRelease=$(cut -d '.' -f 3- <<< $kernelRelease | sed 's/\(^[0-9]*\)[^0-9].*$/\1/')
# if on kernel 3.12 through 3.15, check if we need to delete AppleTalk module to prevent kernel panics
if [[ $kernelMajorRelease -eq 3 && $kernelMinorRelease -ge 12 && $kernelMinorRelease -le 15 ]]; then
# if not RPi, or RPi without ivanx-fixed AppleTalk module, delete the module
if [[ ! ( $isRpi && $kernelMinorRelease -eq 12 && $kernelPatchRelease -ge 25 ) ]]; then
if [[ -f /lib/modules/$kernelRelease/kernel/net/appletalk/appletalk.ko ]]; then
if [[ $(sha1sum /lib/modules/$kernelRelease/kernel/net/appletalk/appletalk.ko | cut -f 1 -d ' ') != "ecb239fc084c36de93f6926e7749b80f6024f269" ]]; then
# stop Netatalk
sudo /etc/init.d/netatalk stop &> /dev/null
echo "A2SERVER: Deleting defective AppleTalk kernel module."
sudo rmmod appletalk 2> /dev/null
sudo rm -r /lib/modules/$kernelRelease/kernel/net/appletalk
# disable single-user mode on Pi (other Linux can use Recovery boot)
if [[ $isRpi && $(grep ' single' /boot/cmdline.txt 2> /dev/null) ]]; then
echo "A2SERVER: Disabling single-user mode for next boot."
sudo sed -i 's/ single//' /boot/cmdline.txt
touch /tmp/singleUser # so note to restart can display following install
fi
fi
fi
fi
fi
# --- Start Netatalk (if not running)
bground=
if [[ $(grep 'ATALK_BGROUND=yes' /etc/default/netatalk) ]]; then
bground=1
sudo sed -i 's/ATALK_BGROUND=yes/ATALK_BGROUND=no/' /etc/default/netatalk
fi
[[ $(ps --no-headers -C afpd) ]] || sudo /etc/init.d/netatalk start 2> /dev/null
echo
echo "A2SERVER: Netatalk is installed, configured, and running."
echo
# if atalkd isn't running (no AppleTalk), and this is a Rasbperry Pi:
if [[ ( ! $(ps aux | grep [a]talkd) ) && ( $isRpi ) ]]; then
# if AppleTalk module exists, try to load it
if [[ -f /lib/modules/$kernelRelease/kernel/net/appletalk/appletalk.ko ]]; then # module present, but not loaded?
sudo depmod
sudo modprobe appletalk
if [[ $(lsmod | grep appletalk) ]]; then
# if it loaded, restart netatalk
sudo sed -i "s/ATALKD_RUN=no/ATALKD_RUN=yes/" /etc/default/netatalk; sudo /etc/init.d/netatalk restart
else
# if we didn't load it successfully, delete it
sudo rm -r /lib/modules/$kernelRelease/kernel/net/appletalk
fi
fi
# if no AppleTalk module, try to download it from a2server site
if [[ ! -f /lib/modules/$kernelRelease/kernel/net/appletalk/appletalk.ko ]]; then # check for rpi kernel module
echo "A2SERVER: Attempting to install AppleTalk kernel module for Raspbian..."
wget -qO /tmp/appletalk.ko.gz ${scriptURL}files/appletalk-$kernelRelease.ko.gz
if [[ $? -eq 0 ]]; then
# if we found a prebuilt one on a2server site, install it and load it
gunzip -f /tmp/appletalk.ko.gz
sudo mkdir -p /lib/modules/$kernelRelease/kernel/net/appletalk
sudo mv /tmp/appletalk.ko /lib/modules/$kernelRelease/kernel/net/appletalk
sudo depmod
sudo modprobe appletalk
if [[ $(lsmod | grep appletalk) ]]; then
# if it loaded, restart netatalk
sudo sed -i "s/ATALKD_RUN=no/ATALKD_RUN=yes/" /etc/default/netatalk; sudo /etc/init.d/netatalk restart
else
# if we didn't load it successfully, remove it
sudo rm -r /lib/modules/$kernelRelease/kernel/net/appletalk 2> /dev/null
fi
fi
# if we still don't have AppleTalk, try to use rpi-update
rm /tmp/rpiUpdate 2> /dev/null
if [[ ! $(ps aux | grep [a]talkd) ]]; then
# use specific rpi-update commit (at https://github.com/Hexxeh/rpi-firmware/)
# from when AppleTalk was added/fixed, so we have a consistent firmware that
# we're loading until the next proper release of Raspbian that includes it
#
# 10-26-13: when AppleTalk was added to Raspbian:
# sudo rpi-update 9530adbe31fe6b8e05b3bd5cfadfc90f067f5362
# sudo modprobe appletalk 2> /dev/null
# if [[ $(lsmod | grep appletalk) ]]; then
# if it loaded, restart netatalk
# sudo sed -i "s/ATALKD_RUN=no/ATALKD_RUN=yes/" /etc/default/netatalk; sudo /etc/init.d/netatalk restart
# fi
#
# 07-23-14: when AppleTalk was fixed after kernel panics in Raspbian 2014-06-20 (kernel 3.12.22+)
sudo rm /boot/.firmware_revision
sudo rpi-update cfd9a203590737f9536de70a1e01db25a3e8e069
touch /tmp/rpiUpdate # so note to restart can display following install
fi
if [[ ! $(ps aux | grep [a]talkd) ]]; then
if [[ -f /tmp/rpiUpdate ]]; then
echo
echo "AppleTalk networking is installed but not yet active."
echo "When installation is complete, please restart your Raspberry Pi"
echo "when asked or by typing 'system-restart' at the Linux prompt"
echo "to allow Apple II computers to connect."
echo
else
echo
echo "AppleTalk networking could not be activated"
echo "for your Raspbian kernel version ($kernelRelease)."
echo "Please try restarting with 'system-restart'. If that doesn't work,"
echo "you're not going to be able to connect from an Apple II."
echo "See http://appleii.ivanx.com/a2server for help."
echo
fi
fi
fi
fi
if [[ $bground ]]; then
sudo sed -i 's/ATALK_BGROUND=no/ATALK_BGROUND=yes/' /etc/default/netatalk
fi
# --- Set up Avahi-Daemon (Bonjour/mDNS)
# thanks to: http://missingreadme.wordpress.com/2010/05/08/how-to-set-up-afp-filesharing-on-ubuntu
if [[ ! $(dpkg -l avahi-daemon 2> /dev/null | grep ^ii) || ! $(dpkg -l libnss-mdns 2> /dev/null | grep ^ii) ]]; then
echo "A2SERVER: Installing Avahi-Daemon (Bonjour/mDNS)..."
if [[ ! -f /tmp/a2server-packageReposUpdated ]]; then
# prepare for installing packages
sudo apt-get -y update
touch /tmp/a2server-packageReposUpdated
fi
sudo apt-get -y install avahi-daemon libnss-mdns &> /dev/null
fi
sudo sed -i 's/^\(hosts.*\)$/\1 mdns/' /etc/nsswitch.conf
if [[ ! -f /etc/avahi/services/afpd.service && ! -f /etc/avahi/services/afpd.service_disabled ]]; then
echo -e '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->\n<!DOCTYPE service-group SYSTEM "avahi-service.dtd">\n<service-group>\n <name replace-wildcards="yes">%h</name>\n <service>\n <type>_afpovertcp._tcp</type>\n <port>548</port>\n </service>\n <service>\n <type>_device-info._tcp</type>\n <port>0</port>\n <txt-record>model=MacPro</txt-record>\n </service>\n</service-group>' | sudo tee /etc/avahi/services/afpd.service > /dev/null
fi
sudo /etc/init.d/avahi-daemon restart &> /dev/null