Skip to content

Instantly share code, notes, and snippets.

@bisand
Last active January 4, 2018 21:46
Show Gist options
  • Save bisand/c0783e00b6c181929d3bdf26c040089f to your computer and use it in GitHub Desktop.
Save bisand/c0783e00b6c181929d3bdf26c040089f to your computer and use it in GitHub Desktop.
A script for installing Apple Time Machine server on a Raspberry Pi
#!/bin/bash
# Inspired by an article from:
# https://www.howtogeek.com/276468/how-to-use-a-raspberry-pi-as-a-networked-time-machine-drive-for-your-mac/
#
# 1. The first thing you need to do is prepare the external drive to work with Time Machine. Plug the drive into your Mac,
# then launch Disk Utility. Select your external drive, then click the “Erase” button.
# You’re going to want to format the drive as “Mac OS Extended”, also known as HFS+.
#
# 2. Next, we’re going to want to ensure that your Raspberry Pi, and every device, will have permission to control the drive.
# Head to the Finder, then right-click the drive in the sidebar. Click “Get Info”.
#
# 3. At the bottom of the window that opens, you’ll find the permission settings.
# Click the lock at bottom right, then enter your password. Next, check “Ignore ownership on this volume.”
# Make sure the group "everyone" has "Read & Write" privileges.
# And with that, you’re ready to connect your external drive to the Pi and run the install script.
#
# PS! Before you begin, make sure the partition and mount directory is correct.
# Usage: ./install-timemachine.sh [HFS+ partition] [mount point]
# Example: ./install-timemachine.sh /dev/sda2 /media/tm
if [ -z "$1" ]
then
echo "Please specify the Time Machine partition. I.e /dev/sda2"
echo "Usage: ./raspi-timemachine.sh [HFS+ partition] [mount point]"
echo "Example: ./raspi-timemachine.sh /dev/sda2 /media/tm"
exit 1
fi
if [ -z "$2" ]
then
echo "Please specify where you want to map the Time Machine partition. I.e /media/tm"
echo "Usage: ./raspi-timemachine.sh [HFS+ partition] [mount point]"
echo "Example: ./raspi-timemachine.sh /dev/sda2 /media/tm"
exit 1
fi
apt-get update
apt-get upgrade
apt-get -y install hfsprogs hfsplus
mkdir -p $2
echo "$1 $2 hfsplus force,rw,user,auto 0 0
" >> /etc/fstab
mount -a
apt-get -y install build-essential libevent-dev libssl-dev libgcrypt11-dev libkrb5-dev libpam0g-dev libwrap0-dev libdb-dev libtdb-dev avahi-daemon libavahi-client-dev libacl1-dev libldap2-dev libcrack2-dev systemtap-sdt-dev libdbus-1-dev libdbus-glib-1-dev libglib2.0-dev libio-socket-inet6-perl tracker libtracker-sparql-1.0-dev libtracker-miner-1.0-dev
service avahi-daemon stop
service netatalk stop
cd netatalk-3.1.11
make uninstall
rm -Rf netatalk-3.1.11*
wget http://prdownloads.sourceforge.net/netatalk/netatalk-3.1.11.tar.gz
tar -xf netatalk-3.1.11.tar.gz
cd netatalk-3.1.11
./configure \
--with-init-style=debian-systemd \
--without-libevent \
--without-tdb \
--with-cracklib \
--enable-krbV-uam \
--with-pam-confdir=/etc/pam.d \
--with-dbus-daemon=/usr/bin/dbus-daemon \
--with-dbus-sysconf-dir=/etc/dbus-1/system.d \
--with-tracker-pkgconfig-version=1.0
make
make install
netatalk -V
rm /etc/avahi/services/afpd.service
echo "<?xml version=\"1.0\" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM \"avahi-service.dtd\">
<service-group>
<name replace-wildcards=\"yes\">%h</name>
<service>
<type>_afpovertcp._tcp</type>
<port>548</port>
</service>
<service>
<type>_device-info._tcp</type>
<port>0</port>
<txt-record>model=TimeCapsule</txt-record>
</service>
</service-group>" >> /etc/avahi/services/afpd.service
rm /usr/local/etc/afp.conf
echo "[Global]
spotlight = no
mimic model = TimeCapsule6,106
[Homes]
basedir regex = /home
[Time Machine]
path = $2
time machine = yes" >> /usr/local/etc/afp.conf
service avahi-daemon start
service netatalk start
systemctl enable avahi-daemon
systemctl enable netatalk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment