Even though you may not own a Macbook, an iPhone/iPad or any other Apple device, you might still be the owner of a Time Capsule. I bought it when I was using a Macbook Pro. Time Capsule is wonderfully integrated with the various Apple devices and machines. Unfortunately, it becomes a pain to use Time Capsule under you boot GNU/Linux.
It is possible to manually mount a Time Capsule Volume on a directory. It is uncomfortable, isn’t it? Using Time Machine clones such as Déjà Dup, flyback or TimeVault becomes difficult. They may be automatically started by your Desktop Environment. However, they may give errors because of the still unmounted Time Capsule Volume.
- What if the mount point (e.g. /mnt/timecapsule) exists but it is empty because of the non-mounted Time Capsule? Such backup programs would backup in our hard disk!
- We could create a script th7at mounts Time Capsule on login.
What if we don’t always use our laptop at home? There must be a way to discover if a Time Capsule is present on the current network and mount it.
- The Time Capsule Volume must be unmounted when we logout, otherwise there will be an error if we are connected to a Wireless Network. Network volumes are sometimes unmounted after Network Manager is stopped, under some configurations.
I decided to handle these issues with a script, called timecapsule-handler (Download, gzip).
How to Download, Configure, and Run
I wrote this section especially for those unfamiliar with the GNU/Linux console. It is written keeping Ubuntu as reference distribution.
Experienced users may use any GNU/Linux distribution and they only need to know that:
- cifs-utils is needed in order to use the script
- The script should be under your $PATH and be invoked with root privileges (sudo)
- The script must be called just after network setup and before network teardown. Time Capsule likes clean umount.
First, download the script.
Edit the configuration variables with a text-editor. For your convenience, here is how to edit it with Ubuntu default graphical text editor:
You need to set values for the first three variables:
TIMECAPSULE_IP="" # e.g. "192.168.1.100" TIMECAPSULE_VOLUME="/Time\ Capsule" # also try "/Data" TIMECAPSULE_PASSWORD="YOURPASSWORDHERE" # prefix special characters, e.g. \! MOUNT_POINT=/mnt/timecapsule # no need to create the directory. No " here
Save the file, give it execution permissions and move it in a directory under your $PATH (e.g., /usr/local/bin).
chmod +x timecapsule-handler && sudo mv timecapsule-handler /usr/local/bin
Install the required cifs-utils package.
sudo apt-get install cifs-utils
That’s it. Here is how to use the script.
To mount Time Capsule, run:
To un-mount Time Capsule, run
Yes, it automatically detects everything.
How does it work?
Let’s observe it:
#!/bin/bash # # This program is free software. It comes without any warranty, to # the extent permitted by applicable law. You can redistribute it # and/or modify it under the terms of the Do What The Fuck You Want # To Public License, Version 2, as published by Sam Hocevar. See # http://sam.zoy.org/wtfpl/COPYING for more details. # # Version 3, enhanced for Ubuntu 13.X+, Fedora 19+, and similar distros. # Runs on all GNU/Linux distros (install cifs-utils) # Author: Daniel Graziotin
- https://ineed.coffee # Purpose: Check if there is a TimeCapsule in your network and mount it # for use it under Gnu/Linux. Unmount it if it is already mounted. # The mount point is created and destroyed after use (for prevent # automatic backup software to backup in the directory if the device # is not mounted) # Instructions: # 1) Install cifs-utils (sudo apt-get install cifs-utils) # 1) Change the first four variables according to your configuration. # 2) Run this program at boot when your network is already # set up. Also, run it on logoff to umount Time Capsule. TIMECAPSULE_IP="" # e.g. "192.168.1.100" TIMECAPSULE_VOLUME="/Time\ Capsule" # also try "/Data" TIMECAPSULE_PASSWORD="YOURPASSWORDHERE" # prefix special characters, e.g. \! MOUNT_POINT=/mnt/timecapsule # no need to create the directory IS_MOUNTED=`mount 2> /dev/null | grep "$MOUNT_POINT" | cut -d' ' -f3` TIMECAPSULE_PATH="//$TIMECAPSULE_IP$TIMECAPSULE_VOLUME" if [[ "$IS_MOUNTED" ]] ;then umount $MOUNT_POINT rmdir $MOUNT_POINT else CHECK_TIMECAPSULE=`smbclient --no-pass -L $TIMECAPSULE_IP 2>&1 > /dev/null | grep -m1 -i apple` if [[ "$CHECK_TIMECAPSULE" =~ "Apple" ]] ;then mkdir $MOUNT_POINT echo "mount.cifs $TIMECAPSULE_PATH $MOUNT_POINT -o pass=$TIMECAPSULE_PASSWORD,file_mode=0777,dir_mode=0777,sec=ntlm" | /bin/bash fi fi
At line 31, we simply look if Time Capsule is already mounted, by calling the
command. Typically, it will return something like:
$ mount proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) sys on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) udev on /dev type devtmpfs (rw,nosuid,relatime,size=10240k,nr_inodes=195863,mode=755) run on /run type tmpfs (rw,nosuid,nodev,relatime,size=10240k,mode=755) /dev/sda1 on / type ext4 (rw,noatime,nodiratime,discard,errors=remount-ro,commit=0) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000) shm on /dev/shm type tmpfs (rw,nosuid,nodev,relatime) tmpfs on /tmp type tmpfs (rw,nosuid,nodev) fusectl on /sys/fs/fuse/connections type fusectl (rw) gvfs-fuse-daemon on /home/dgraziotin/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=dgraziotin) //192.168.0.2/Time Capsule on /mnt/timecapsule type cifs (rw)
See the last line of the command? In line 31 of the script we search in the output of the
command the string $MOUNT_POINT (e.g, /mnt/timecapsule).
Then, between line 34 and line 36, if Time Capsule Volume is mounted, we umount it and delete the mount point using
to be sure to protect data if the umount is unsuccessful.
Otherwise, between line 37 and line 42, we use the
program to do a sort of ping of the device on the Network. If there is someone at the given IP, and this someone replies with something like “I am Time Capsule!”, we are sure to mount it. This is a typical output of the
$ smbclient --no-pass -L 192.168.0.2 Anonymous login successful Domain=[WORKGROUP] OS=[Apple Base Station] Server=[CIFS 4.32] Sharename Type Comment --------- ---- ------- IPC$ IPC Anonymous login successful Domain=[WORKGROUP] OS=[Apple Base Station] Server=[CIFS 4.32] Server Comment --------- ------- Workgroup Master --------- -------
The program gives a result within a second, that’s because the script is so fast in doing its job.
There may still be issues with my script. However, it would not do anything harmful to the system and fail silently in case of errors.
I hope that you may find it useful. Please report your experience in this post comments.
If for any reason the script does not work, I encourage you to try this older version.