Sample ATV patchstick.sh Script

From Bubba.org

Jump to: navigation, search


ATV Patchstick Script

The following script is what I use on my ATV Patchstick in order to fully update an un-patched ATV unit.

Assumptions:

  1. Installer scripts are in the Patchstick partition under the installer.d directory.
  2. Anything you want copied to ~/frontrow on the Apple TV needs to be put on the Patchstick partition under the userspace directory.
  3. Below are the mounting locations that need to be referenced in your scripts.
    1. Patchstick will be mounted as /stuff on the Apple TV, so your installer scripts will need to reference this location for source files.
    2. OS Partition will be mounted as /OSBoot on the Apple TV, so your installer scripts will need to reference this when writing files to the OS partition.
    3. The User Space partition will be mounted as /userspace on the Apple TV.
#!/bin/bash
 
exec 2>/dev/console
exec 1>/dev/console
 
echo
echo "        --- AppleTV Patchstick by Bubba ---"
 
echo "        * mounting OSBoot partition"
mkdir /OSBoot
fsck.hfsplus -f /dev/sda3
mount -t hfsplus -o rw,force /dev/sda3 /OSBoot
 
# since all of our installer scripts reference /stuff, we need
# to set this up the bomb.
echo "       * symlinking /mnt/rootfs -> /stuff"
ln -s /mnt/rootfs /stuff
 
echo "       * mounting User partition"
mkdir /userspace
fsck.hfsplus -f /dev/sda4
mount -t hfsplus -o rw,force /dev/sda4 /userspace
 
echo "        * keeping the OSBoot partition r/w for plugins"
touch /OSBoot/.readwrite
 
# update data to frontrow home directory from /stuff/userspace 
# including hidden directories for binaries/data that needs to be carried
# over to the Customer/Media partition
if [ -d /userspace/Scratch/Users/frontrow ] && [ -d /stuff/userspace ]; then
	if [ -e /userspace/Scratch/Users/frontrow/.uspatch ] && [ ! -e /stuff/forceus ]; then
		echo "        * Skipping Userspace updates since ~/.uspatch exists.  Use forceus file on Patchstick to override."
	else 
		echo "        * Updating userspace data..."
		cp -Rfp /stuff/userspace/.[a-zA-Z]* /stuff/userspace/* /userspace/Scratch/Users/frontrow 1>> /OSBoot/.upgrade.log 2>&1
		touch /userspace/Scratch/Users/frontrow/.uspatch
		echo "        * Userspace Patching Successful!"
	fi
else
	echo "        * ERROR: Unable to mount /dev/sda4 to update frontrow home directory."
fi
 
# patch OS-related things.  
if [ -d /OSBoot/dev ] && [ -d /stuff/installer.d ]; then
	if [ -e /OSBoot/.ospatch ] && [ ! -e /stuff/forceos ]; then
		echo "        * Skipping OS patches since /.ospatch exists.  Use forceos file on Patchstick to override."
	else 
		for i in /stuff/installer.d/*; do
			echo "        * Installing ${i} ..."
			/bin/bash "${i}" 1>> /OSBoot/.upgrade.log 2>&1
		done
		touch /OSBoot/.ospatch
		echo "        * OS Patching Successful!"
	fi
else 
	echo "        * ERROR: Unable to mount /dev/sda3 to apply OS patches."
fi
 
sync &>/dev/null
umount /userspace
umount /OSBoot
echo "        * Please ssh into Apple TV and see /.upgrade.log and check for errors."
echo "        * To ssh: ssh [email protected]  Password: frontrow"
echo "        * Please unplug your Apple TV to reboot/reset the device."
sleep 100000