2015-10-04 07:12:32 +00:00
#! /bin/bash
2016-10-25 19:09:52 +00:00
# vim: set tabstop=4 shiftwidth=4 noexpandtab filetype=sh:
2015-10-04 07:12:32 +00:00
2015-11-17 13:36:22 +00:00
# A2SERVER master setup script, last update 17-Nov-15
2015-10-03 12:25:44 +00:00
# it downloads and executes several scripts related to the setup of
2015-11-17 13:36:22 +00:00
# netatalk configured for Apple II use on Debian or Raspbian.
2015-12-24 04:02:17 +00:00
# more info is at http://ivanx.com/a2server
2015-10-03 12:25:44 +00:00
# to download and execute, type:
2015-12-24 04:02:17 +00:00
# wget ivanx.com/a2server/setup; source setup
2015-10-03 12:25:44 +00:00
2016-10-27 09:13:58 +00:00
a2serverVersion="1.5.1"
2015-10-03 12:25:44 +00:00
2016-10-27 20:31:00 +00:00
a2sDevel="$( dirname "${BASH_SOURCE[0]}" )/.."
if [[ -f "$a2sDevel/.a2server_source" ]]; then
pushd $a2sDevel >/dev/null
a2sDevel="$PWD"
2016-10-27 13:35:20 +00:00
popd >/dev/null
else
2016-10-27 20:31:00 +00:00
a2sDevel=
2016-10-27 13:35:20 +00:00
fi
2015-10-04 08:23:53 +00:00
# Ensure URL we'll use ends in a /
case "$A2SERVER_SCRIPT_URL" in
*/) scriptURL="$A2SERVER_SCRIPT_URL" ;;
2016-10-27 13:35:20 +00:00
*) scriptURL="${A2SERVER_SCRIPT_URL:-https://raw.githubusercontent.com/RasppleII/a2server/release}/" ;;
2015-10-04 08:23:53 +00:00
esac
2015-12-24 04:02:17 +00:00
case "$A2SERVER_BINARY_URL" in
*/) binaryURL="$A2SERVER_BINARY_URL" ;;
*) binaryURL="${A2SERVER_BINARY_URL:-http://ivanx.com/a2server/files}/" ;;
esac
useExternalURL=1
[[ $A2SERVER_NO_EXTERNAL ]] && useExternalURL=
2015-10-04 08:23:53 +00:00
2015-10-03 12:25:44 +00:00
isRpi=
[[ -f /usr/bin/raspi-config ]] && isRpi=1
isDebian=
2016-10-27 15:17:31 +00:00
if [[ "$(lsb_release -ds)" = Debian* ]]; then
debianVersion="$(lsb_release -rs)"
if [[ "$debianVersion" -ge 7 || $debianVersion == [a-z]* ]]; then
isDebian=1
2016-10-27 07:55:16 +00:00
fi
fi
2015-10-03 12:25:44 +00:00
2016-10-27 09:13:58 +00:00
if [[ -f /usr/local/etc/A2SERVER-version ]]; then
read installedVersion </usr/local/etc/A2SERVER-version
if [[ $installedVersion != *.*.* ]]; then
# Deal with old three-digit version
installedVersion="${installedVersion:0:1}.${installedVersion:1:1}.${installedVersion:2}"
fi
2015-10-03 12:25:44 +00:00
fi
2016-01-29 12:22:54 +00:00
echo "A2SERVER version available: $a2serverVersion"
echo "A2SERVER version installed: ${installedVersion:=None}"
2015-10-03 12:25:44 +00:00
2016-10-27 17:57:41 +00:00
function a2sCmpInstalled() {
local iMajor iMinor iRev
local cMajor cMinor cRev
[[ -z "$installedVersion" ]] && return 0 # No, not installed
[[ -z "$1" ]] && return 1
iMajor=${installedVersion%%.*}
iMinor=${installedVersion#*.}
iMinor=${iMinor%%.*}
iRev=${installedVersion##*.}
cMajor=${2%%.*}
cMinor=${2#*.}
cMinor=${cMinor%%.*}
cRev=${2##*.}
case "$1" in
lt|le)
if [[ "$iMajor" -lt "$cMajor" ]]; then
return 0
elif [[ "$iMajor" -eq "$cMajor" ]]; then
if [[ "$iMinor" -lt "$cMinor" ]]; then
return 0
elif [[ "$iMinor" -eq "$cMinor" ]]; then
if [[ "$iRev" -le "$cRev" ]]; then
if [[ "$1" == "le" || "$iRev" -lt "$cRev" ]]; then
return 0
fi
fi
fi
fi
;;
gt|ge)
if [[ "$iMajor" -gt "$cMajor" ]]; then
return 0
elif [[ "$iMajor" -eq "$cMajor" ]]; then
if [[ "$iMinor" -gt "$cMinor" ]]; then
return 0
elif [[ "$iMinor" -eq "$cMinor" ]]; then
if [[ "$iRev" -ge "$cRev" ]]; then
if [[ "$1" == "ge" || "$iRev" -gt "$cRev" ]]; then
return 0
fi
fi
fi
fi
;;
eq)
if [[ "$iMajor" -eq "$cMajor" ]]; then
if [[ "$iMinor" -eq "$cMinor" ]]; then
if [[ "$iRev" -eq "$cRev" ]]; then
return 0
fi
fi
fi
;;
esac
return 1
}
2015-12-24 04:02:17 +00:00
echo
2016-05-28 14:11:26 +00:00
[[ $scriptURL != *"ivanx.com"* && $scriptURL != *"raw.githubusercontent.com/RasppleII/a2server"* ]] && echo "Using script URL: $scriptURL"
2015-12-24 04:02:17 +00:00
[[ $binaryURL != *"ivanx.com"* ]] && echo "Using binary URL: $binaryURL"
2016-01-15 19:08:45 +00:00
[[ ! $useExternalURL ]] && echo -e "Not using external URLs. Downloads must be available from:\n ${binaryURL}external/appleii/\n ${binaryURL}external/source/\n (See the A2SERVER developer page for more information.)"
2015-12-24 04:02:17 +00:00
2015-10-03 12:25:44 +00:00
skipRepoUpdate=
autoAnswerYes=
2016-01-15 19:08:45 +00:00
installAll=
2015-10-03 12:25:44 +00:00
setupNetBoot=
setupWindowsSharing=
2016-01-03 21:06:40 +00:00
compileAlways=
2015-10-03 12:25:44 +00:00
updateRasppleII=
2016-10-27 20:31:00 +00:00
rm -rf /tmp/a2server-install
2015-11-09 14:40:44 +00:00
rm /tmp/a2server-* 2> /dev/null
2015-10-03 12:25:44 +00:00
while [[ $1 ]]; do
2016-10-25 19:09:52 +00:00
if [[ $1 == "-r" ]]; then
shift
skipRepoUpdate="-r"
touch /tmp/a2server-packageReposUpdated
elif [[ $1 == "-i" ]]; then
shift
installAll="-i"
elif [[ $1 == "-y" ]]; then
shift
autoAnswerYes="-y"
touch /tmp/a2server-autoAnswerYes
elif [[ $1 == "-b" ]]; then
shift
setupNetBoot="-b"
touch /tmp/a2server-setupNetBoot
elif [[ $1 == "-w" ]]; then
shift
setupWindowsSharing="-w"
touch /tmp/a2server-setupWindowsSharing
elif [[ $1 == "-c" ]]; then
shift
compileAlways="-c"
touch /tmp/a2server-compileAlways
elif [[ $1 == "-os" || $1 == "os" ]]; then
shift
updateRasppleII=1
elif [[ $1 == "-v" ]]; then
shift
# Version was already printed
2016-10-27 07:55:16 +00:00
if [[ $0 == "-bash" ]]; then
return 1
else
exit 1
fi
2016-10-25 19:09:52 +00:00
elif [[ $1 ]]; then
echo "options:"
echo "-v: display installed and available versions, then exit"
echo "-i: reinstall A2SERVER software (but not Apple II software)"
echo "-y: auto-answer yes to all prompts"
echo "-r: don't update package repositories"
echo "-b: auto-setup network boot (use with -y)"
echo "-w: auto-setup Windows file sharing (use with -y)"
echo "-c: compile non-package items, rather than downloading binaries"
if [[ $isRpi ]]; then
echo "-os: update Raspbian OS, A2CLOUD, A2SERVER, and Apple II Pi"
fi
2016-10-27 07:55:16 +00:00
if [[ $0 == "-bash" ]]; then
return 1
else
exit 1
fi
2016-10-25 19:09:52 +00:00
fi
2015-10-03 12:25:44 +00:00
done
if [[ $updateRasppleII ]]; then
2016-10-25 19:09:52 +00:00
echo "A2SERVER: Updating Raspple II (takes up to an hour)..."
wget -qO /tmp/raspbian-update "${A2SERVER_SCRIPT_URL}scripts/raspbian-update.txt"
source /tmp/raspbian-update a2cloud a2server $autoAnswerYes $skipRepoUpdate
2016-10-27 07:55:16 +00:00
if [[ $0 == "-bash" ]]; then
return 0
else
exit 0
fi
2015-10-03 12:25:44 +00:00
fi
2016-10-27 17:57:41 +00:00
if a2sCmpInstalled lt 1.1.0; then
2016-10-25 19:09:52 +00:00
echo
echo "WARNING: The current A2SERVER installer scripts haven't been tested for"
echo "updating the earlier version of A2SERVER that you have. A fresh install"
echo "is suggested. Continuing is not recommended and could make A2SERVER"
echo "no longer work properly, or cause data to be lost."
2015-10-03 12:25:44 +00:00
fi
a2server_update=0
doSetup=1
2016-10-27 17:57:41 +00:00
if a2sCmpInstalled lt 1.5.0; then
2016-10-25 19:09:52 +00:00
a2server_update=1
2016-01-17 22:16:35 +00:00
fi
2015-10-03 12:25:44 +00:00
unsupportedOS=1
if [[ $isRpi ]]; then #supported Raspbian? (16-Feb-15, 20-Jun-14, 09-Jan-14, etc)
2016-10-25 19:09:52 +00:00
fwhash=$(zcat /usr/share/doc/raspberrypi-bootloader/changelog.Debian.gz | grep -m 1 'as of' | awk '{print $NF}')
fwsupported="-8aca5762- -462f3e3f476f7b6- -c32bc633039cd9- -9d34d0475f9-
-d4f5315cfac4e- -6f4a90c8cb8817f- -5dd9b4962e- -17c8799375-
-960832a6c2590635216c296b6ee0bebf67b21d50-
-2a329e0c7d8ea19c085bac5633aa4fccee0f21be-"
[[ "$fwsupported" == *-$fwhash-* ]] && unsupportedOS=
2015-12-24 04:02:17 +00:00
elif [[ $isDebian ]]; then # supported Debian?
2016-10-25 19:09:52 +00:00
debianVersion=$(cat /etc/debian_version)
debianSupported="-8.2- -7.9- -7.8- -7.6- -7.3-"
[[ $debianSupported == *-$debianVersion-* ]] && unsupportedOS=
2015-12-24 04:02:17 +00:00
fi
if [[ $unsupportedOS && $isRpi ]]; then
2016-10-25 19:09:52 +00:00
echo
echo "A2SERVER and its installer scripts have been tested on Raspbian Wheezy and"
echo "Jessie, though not this specific firmware version ($fwhash). Just FYI."
unsupportedOS=
2015-12-24 04:02:17 +00:00
elif [[ $unsupportedOS && $isDebian ]]; then
2016-10-25 19:09:52 +00:00
echo
echo "A2SERVER and its installer scripts have been tested on Debian 7 and 8,"
echo "though not this specific point release ($debianVersion). Just FYI."
unsupportedOS=
2015-10-03 12:25:44 +00:00
fi
2015-12-24 04:02:17 +00:00
if [[ $unsupportedOS ]]; then
2016-10-25 19:09:52 +00:00
echo
echo "WARNING: A2SERVER and its installer scripts have only been tested on"
echo "Debian and Raspbian. Continuing is probably fine, but might not be."
echo "Theoretical worst case would be your operating system no longer works"
echo "properly or data is lost, so consider backing up first."
2015-10-03 12:25:44 +00:00
fi
doSetup=1
2016-01-17 18:16:21 +00:00
if [[ $installAll || ! -f /usr/local/etc/a2server-help.txt ]] || (( $a2server_update )); then
2016-10-25 19:09:52 +00:00
echo
echo "Setting up A2SERVER will take up to 60 minutes, during which"
echo "you'll see a bunch of stuff spit out across the screen."
echo
if [[ ! $autoAnswerYes ]]; then
echo -n "Ready to set up A2SERVER? "
read
[[ ${REPLY:0:1} == "y" || ${REPLY:0:1} == "Y" ]]; doSetup=$(( 1 - $? ))
fi
2015-10-03 12:25:44 +00:00
fi
if (( $doSetup )); then
2016-10-25 19:09:52 +00:00
echo
echo "a2server-setup modifies files and performs actions as the root user."
echo "For details, visit http://ivanx.com/a2server."
echo
if [[ ! $autoAnswerYes ]]; then
echo -n "Continue? "
read
[[ ${REPLY:0:1} == "y" || ${REPLY:0:1} == "Y" ]]; doSetup=$(( 1 - $? ))
fi
if (( $doSetup )); then
2016-10-27 13:35:20 +00:00
origDir="$PWD"
rm -rf /tmp/a2server-install &>/dev/null
mkdir -p /tmp/a2server-install
2016-10-27 07:55:16 +00:00
isApple2Pw=
isRaspberryPw=
2016-10-25 19:09:52 +00:00
userPw=$(sudo grep "^$USER" /etc/shadow | cut -f 2 -d ':')
2016-10-27 07:55:16 +00:00
[[ $userPw == "$(echo 'apple2' | perl -e '$_ = <STDIN>; chomp; print crypt($_, $ARGV[0])' "${userPw%"${userPw#\$*\$*\$}"}")" ]] && isApple2Pw=1
[[ $userPw == "$(echo 'raspberry' | perl -e '$_ = <STDIN>; chomp; print crypt($_, $ARGV[0])' "${userPw%"${userPw#\$*\$*\$}"}")" ]] && isRaspberryPw=1
2016-10-25 19:09:52 +00:00
password="your password"
[[ $isApple2Pw ]] && password="'apple2'"
[[ $isRaspberryPw ]] && password="'raspberry'"
[[ $isRpi ]] && a2server="your Raspberry Pi" || a2server="A2SERVER"
if [[ ! $isApple2Pw && ! -f /usr/local/etc/A2SERVER-version ]]; then
if [[ ! $autoAnswerYes ]]; then
echo
echo "To ensure that all client computers are able to connect to"
echo "${a2server} using the same password, you probably want"
echo "to change your user password to 'apple2'."
echo
echo -n "Do you want to change the password for user '$USER' to 'apple2' now? "
read
fi
if [[ $autoAnswerYes || ${REPLY:0:1} == "Y" || ${REPLY:0:1} == "y" ]]; then
echo "A2SERVER: changing password for user '$USER' to 'apple2'..."
echo "$USER:apple2" | sudo chpasswd
fi
fi
echo
echo "During this installation, enter ${password} if prompted for passwords."
echo
sudo true
echo
echo "A2SERVER: Downloading scripts..."
2016-10-27 20:31:00 +00:00
read -d '' a2sSubScripts <<-EOF
2016-10-27 13:35:20 +00:00
a2server-1-storage.txt
a2server-2-tools.txt
a2server-3-sharing.txt
a2server-5-netboot.txt
a2server-6-samba.txt
a2server-7-console.txt
EOF
2016-10-27 20:31:00 +00:00
if [[ -n "$a2sDevel" ]]; then
a2sScriptDir="$a2sDevel/scripts"
else
a2sScriptDir="/tmp/a2server-install/scripts"
mkdir -p "$a2sScriptDir"
for _script in $a2sSubScripts; do
wget -q -O "$a2sScriptDir/$_script" "${scriptURL}scripts/$_script"
chmod ugo+x "$a2sScriptDir/$_script"
2016-10-27 13:35:20 +00:00
done
echo "A2SERVER: Scripts have been downloaded. Installing..."
2016-10-27 20:31:00 +00:00
fi
2016-10-27 13:35:20 +00:00
2016-10-27 20:31:00 +00:00
if [[ $installAll ]]; then
sudo rm -f /usr/local/etc/A2SERVER-version /usr/local/bin/nulib2 /usr/local/bin/unar /usr/local/sbin/macipgw /usr/local/bin/ciopfs /usr/local/etc/netatalk/afppasswd /usr/local/etc/netatalk/a2boot/p8 /usr/local/etc/netatalk/a2boot/ProDOS16\ Image
fi
2016-10-25 19:09:52 +00:00
2016-10-27 20:31:00 +00:00
for _script in $a2sSubScripts; do
"$a2sScriptDir/$_script"
done
2016-10-25 19:09:52 +00:00
2016-10-27 20:31:00 +00:00
if [[ -z "$a2sDevel" ]]; then
for _script in $a2sSubScripts; do
rm -f "$a2sScriptDir/$_script"
2016-10-27 13:35:20 +00:00
done
2016-10-25 19:09:52 +00:00
fi
2016-10-27 13:35:20 +00:00
rm -f /tmp/a2server-packageReposUpdated
2016-10-25 19:09:52 +00:00
if [[ ! -f /usr/local/etc/A2SERVER-version ]] \
|| (( $(head -c 3 /usr/local/etc/A2SERVER-version) < ${a2serverVersion:0:3} )); then
echo "$a2serverVersion" | sudo tee /usr/local/etc/A2SERVER-version &> /dev/null
fi
source /usr/local/etc/a2serverrc
# 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/')
echo
# all done, see if AppleTalk is available and notify either way
if [[ $(ps aux | grep [a]talkd) ]]; then
echo "You now have a fully functional file server for Apple II clients."
echo "On an Apple IIe, it should be accessible via \"Log In\" on the"
echo "Workstation Card software. For IIgs users, it should be accessible"
echo "via the AppleShare control panel."
if [[ -f /srv/A2SERVER/A2FILES/System/Start.GS.OS ]]; then
echo
echo "You can network boot GS/OS."
echo "On a ROM 01 IIgs, set slot 1 (printer port), or slot 2 (modem port)"
echo "to Your Card, and slot 7 to AppleTalk, and Startup Slot to 7 or Scan."
echo "On a ROM 3 IIgs, set slot 1 or 2, and Startup Slot, to AppleTalk."
fi
if [[ -f /srv/A2SERVER/A2FILES/BASIC.System ]]; then
echo
echo "You can network boot ProDOS 8. On an Apple IIe, put your Workstation Card"
echo "in a slot above your disk controller card, or type PR#X with open-apple"
echo "held down, with X being the slot of your Workstation Card."
echo 'On a IIgs, press "8" during the initial procession of periods.'
fi
echo
echo "A2SERVER setup is complete! Go connect from your Apple II!"
echo
elif [[ -f /tmp/rpiUpdate ]]; then
echo "A2SERVER is now configured, but Apple II clients will not be able"
echo "to connect until you restart your Raspberry Pi."
echo
if [[ ! $autoAnswerYes ]]; then
echo -n "Restart now? "
read
fi
if [[ $autoAnswerYes || ${REPLY:0:1} == "Y" || ${REPLY:0:1} == "y" ]]; then
sudo shutdown -r now
echo
echo "A2SERVER: Preparing to restart..."
while :; do sleep 60; done
fi
rm /tmp/rpiUpdate
echo
elif [[ $kernelMajorRelease -eq 3 && $kernelMinorRelease -ge 12 && $kernelMinorRelease -le 15 ]]; then
echo "A2SERVER is now configured, but Apple II clients cannot connect"
echo "because of a kernel-crashing bug in Linux kernel 3.12 through 3.15."
echo "You have kernel version $kernelMajorRelease.$kernelMinorRelease."
echo "A2SERVER has disabled AppleTalk networking to prevent crashes."
echo "Please use kernel 3.11 or earlier, or kernel 3.16 or later."
echo
else
echo "A2SERVER is now configured, but Apple II clients cannot connect because"
echo "AppleTalk networking is unavailable. Please make sure that"
echo "your Linux distribution has a loadable AppleTalk kernel module or"
echo "has AppleTalk built into the kernel, and restart your server."
echo "Or, if you previously disabled AppleTalk in A2SERVER, re-enable it"
echo "by typing 'appletalk-on'."
echo
fi
if [[ -f /tmp/noMacIP ]]; then
echo
echo "MacIP connections may be unavailable. If you know how, try"
echo "recompiling the AppleTalk kernel module with IPDDP options disabled."
echo
rm /tmp/noMacIP
fi
if [[ -f /tmp/singleUser ]]; then
if [[ ! $autoAnswerYes ]]; then
echo
echo "Your Raspberry Pi was started in single-user mode in order to"
echo -n "fix a problem. You should restart to operate normally. Restart now? "
read
fi
if [[ $autoAnswerYes || ${REPLY:0:1} == "Y" || ${REPLY:0:1} == "y" ]]; then
sudo shutdown -r now
echo
echo "A2SERVER: Preparing to restart..."
while :; do sleep 60; done
fi
rm /tmp/singleUser
echo
fi
echo
echo "Type 'system-shutdown' to turn off A2SERVER."
echo "Type 'a2server-setup' to configure network boot."
echo "Type 'a2server-help' for a list of other commands."
fi
2015-10-03 12:25:44 +00:00
fi
unset a2server_update 2> /dev/null
unset doSetup 2> /dev/null
2016-10-27 13:35:20 +00:00
rm -rf /tmp/a2server-install &>/dev/null
2016-10-25 19:09:52 +00:00
rm -f /tmp/a2server-* 2> /dev/null
rm -f setup &> /dev/null