#! /bin/bash # vim: set tabstop=4 shiftwidth=4 expandtab filetype=sh: # A2SERVER master setup script, last update 15-Feb-2015 # it downloads and executes several scripts related to the setup of # netatalk configured for Apple II use on Debian, Raspbian, or Ubuntu. # more info is at http://appleii.ivanx.com/a2server # to download and execute, type: # wget appleii.ivanx.com/a2server/setup; source setup a2serverVersion="125" function askYesNo() # Ask a yes/no question of the user, with potential default # stdin: Info text for the user # arg1: Prompt text # arg2: Default; 0 for yes, 1 for no, anything else for no default # returns: 0 for yes, 1 for no { local default case "$2" in 0) default="y" ;; 1) default="n" ;; *) default="" ;; esac if [ -n "$autoAnswerDefault" -a -n "$default" ]; then return $2 fi echo cat - echo while :; do echo -n "$1 " [ -n "$default" ] && echo -n "[$default] " read case "$REPLY" in [Yy]*) return 0 ;; [Nn]*) return 1 ;; "") [ -n "$default" ] && return $2 ;; *) echo "Please answer yes or no." ;; esac done } # 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 if [[ -f /usr/local/etc/A2SERVER-version ]]; then echo "A2SERVER version available: $a2serverVersion" echo "A2SERVER version installed: $(cat /usr/local/etc/A2SERVER-version)" fi skipRepoUpdate= autoAnswerDefault= setupNetBoot= setupWindowsSharing= updateRasppleII= while [[ $1 ]]; do if [[ $1 == "-r" ]]; then shift skipRepoUpdate="-r" touch /tmp/a2server-packageReposUpdated elif [[ $1 == "-y" ]]; then shift autoAnswerDefault="-y" touch /tmp/a2server-autoAnswerDefault elif [[ $1 == "-b" ]]; then shift setupNetBoot="-b" touch /tmp/a2server-setupNetBoot elif [[ $1 == "-w" ]]; then shift setupWindowsSharing="-w" touch /tmp/a2server-setupWindowsSharing elif [[ $1 == "-os" || $1 == "os" ]]; then # elif [[ ${1,,} == "rasppleii" || ${1,,} == "raspple" || ${1,,} == "rasappleii" || ${1,,} == "rasapple" || ${1,,} == "raspple2" || ${1,,} == "rasapple2" ]]; then shift updateRasppleII=1 elif [[ $1 == "-v" ]]; then shift if [[ ! -f /usr/local/etc/A2SERVER-version ]]; then echo "A2SERVER version available: $a2serverVersion" echo "A2SERVER version installed: none" fi [[ $0 == "-bash" ]] && return 1 || exit 1 elif [[ $1 ]]; then echo "options:" echo "-v: display installed and available versions, then exit" echo "-y: auto-answer default 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)" if [[ $isRpi ]]; then echo "-os: update Raspbian OS, A2CLOUD, A2SERVER, and Apple II Pi" fi [[ $0 == "-bash" ]] && return 1 || exit 1 fi done if [[ $updateRasppleII ]]; then echo "A2SERVER: Updating Raspple II (takes up to an hour)..." wget -qO /tmp/raspbian-update "http://appleii.ivanx.com/a2server/files/raspbian-update.txt" source /tmp/raspbian-update a2cloud a2server $autoAnswerYes $skipRepoUpdate [[ $0 == "-bash" ]] && return 0 || exit 0 fi if { [[ -f /usr/local/etc/A2SERVER-version ]] && (( $(cat /usr/local/etc/A2SERVER-version) < 110 )); }; then 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." fi a2server_update=0 doSetup=1 unsupportedOS=1 if [[ $isRpi ]]; then #supported Raspbian? (16-Feb-15, 20-Jun-14, 09-Jan-14, etc) fwhash=$(zcat /usr/share/doc/raspberrypi-bootloader/changelog.Debian.gz | grep -m 1 'as of' | awk '{print $NF}') [[ ($fwhash == "8aca5762") || ($fwhash == "462f3e3f476f7b6") || ($fwhash == "c32bc633039cd9") || ($fwhash == "9d34d0475f9") || ($fwhash == "d4f5315cfac4e") || ($fwhash == "6f4a90c8cb8817f") || ($fwhash == "5dd9b4962e") || ($fwhash == "17c8799375") ]] && unsupportedOS=0 elif [[ "$(lsb_release -rs 2> /dev/null)" == "12.04" ]]; then #Ubuntu 12.04? unsupportedOS=0 elif [[ "$(lsb_release -rs 2> /dev/null)" == "7.3" || "$(lsb_release -rs 2> /dev/null)" == "7.6" || "$(lsb_release -rs 2> /dev/null)" == "7.8" ]]; then # tested Debian? unsupportedOS=0 fi if (( unsupportedOS )); then echo echo "WARNING: A2SERVER and its installer scripts have not been tested on this" echo "operating system version. Continuing is probably fine, but might not be." echo "Worst case could make your operating system no longer work properly," echo "or cause data to be lost." echo "More information is at http://appleii.ivanx.com/a2server." fi doSetup=1 if [[ ! -f /usr/local/etc/a2server-help.txt ]] || (( $a2server_update )); then askYesNo "Ready to set up A2SERVER?" 0 <; chomp; print crypt($_, $ARGV[0])' "${userPw%"${userPw#\$*\$*\$}"}")" ]] && isApple2Pw=1 || isApple2Pw= [[ $userPw == "$(echo 'raspberry' | perl -e '$_ = ; chomp; print crypt($_, $ARGV[0])' "${userPw%"${userPw#\$*\$*\$}"}")" ]] && isRaspberryPw=1 || isRaspberryPw= 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 askYesNo "Do you want to change the password for user \"$USER\" to \"apple2\" now?" 0 < /dev/null if [[ ! -f /usr/local/etc/A2SERVER-version ]] \ || (( $(cat /usr/local/etc/A2SERVER-version) < "$a2serverVersion" )); then echo "$a2serverVersion" | sudo tee /usr/local/etc/A2SERVER-version &> /dev/null fi source /usr/local/etc/a2server-aliases # 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/') # 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." echo echo echo "A2SERVER setup is complete! Go connect from your Apple II!" echo elif [[ -f /tmp/rpiUpdate ]]; then askYesNo "Restart now?" 0 < /dev/null unset doSetup 2> /dev/null rm /tmp/a2server-autoAnswerDefault 2> /dev/null rm /tmp/a2server-packageReposUpdated 2> /dev/null rm /tmp/a2server-setupNetBoot 2> /dev/null rm /tmp/a2server-setupWindowsSharing 2> /dev/null rm setup &> /dev/null