Skip to content

Instantly share code, notes, and snippets.

@eblot
Created March 2, 2016 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eblot/01b1b4694652866b07d6 to your computer and use it in GitHub Desktop.
Save eblot/01b1b4694652866b07d6 to your computer and use it in GitHub Desktop.
ellcc install script for OSX
#!/bin/sh
export LC_ALL=C
TOP=`pwd`
ELLCC=`realpath $TOP/../..`
if [ `id -u` -ne 0 ] ; then
echo "You must be root to run this command. Be careful!" >&2
exit 1
fi
fuse=`which fuse-ext2`
if [ -z "${fuse}" ]; then
echo "Fuse-Ext2 not found." >&2
exit
fi
mkfs=`which mkfs.ext4`
if [ -z "${mkfs}" ]; then
# sbin tool, not in Homebrew regular PATH
if [ ! -x /usr/local/opt/e2fsprogs/sbin/mkfs.ext4 ]; then
echo "mkfs.ext4 not found. Check out e2fsprogs" >&2
exit 1
fi
mkfs="/usr/local/opt/e2fsprogs/sbin/mkfs.ext4"
fi
SD=""
for drive in `diskutil list | grep -E '^/dev/' | cut -d' ' -f1`; do
# internal or external SD drive are usually connected to a USB bus
protocol=`diskutil info "$drive" | grep 'Protocol' |\
cut -d: -f2 | sed 's/ //g'`
# SDD/HDD, even on external buses, are not reported as removeable
removeable=`diskutil info "$drive" | grep 'Removable Media' |\
cut -d: -f2 | sed 's/ //g'`
if [ "$protocol" = "USB" -a "$removeable" = "Yes" ]; then
SD="$drive"
NAME=`diskutil info "$drive" | grep 'Media Name' |\
cut -d: -f2 | sed 's/ //g'`
break
fi
done
if [ -z "$SD" ]; then
echo "No SD card found" >&2
fi
echo "Warning! This command will destroy all data on $SD ($NAME)."
/bin/echo -n "Continue? [yes/no] "
read answer
if [ "$answer" != "yes" ] ; then
echo "OK, aborting"
exit 1
fi
BOOT="${SD}s1"
ROOT="${SD}s2"
RAWROOT=`echo "${ROOT}" | sed 's^/dev/^/dev/r^'`
# Boot partition is already mounted
BOOT_MP="/Volumes/BOOT"
# Mount point cannot be located on the sparse bundle partition
ROOT_MP="${TOP}/root"
echo "Partitioning $SD"
# Create two FAT32 partition on a MBR part scheme
diskutil partitionDisk "$SD" 2 MBR fat32 BOOT 80M fat32 ROOT R || exit 1
# Second partition is about to be formatted as an EXT4 FS
diskutil umount "${ROOT}"
# Format the root FS (use raw access to speed up things)
yes | time ${mkfs} ${RAWROOT} || exit 1
touch ${ROOT_MP}/.local
echo "${fuse}"
${fuse} ${ROOT} ${ROOT_MP} -o rw+ || exit 1
sleep 1
if [ -f "${ROOT_MP}/.local" ]; then
ls -l ${ROOT_MP}/.local >&2
echo "Ext4 volume not mounted" >&2
exit 1
fi
touch ${ROOT_MP}/.test
if [ ! -f "${ROOT_MP}/.test" ]; then
echo "Unable to use EXT4 FS" >&2
umount ${ROOT}
rmdir ${ROOT_MP}
exit 1
fi
rm "${ROOT_MP}/.test"
echo "Copying files to SD card"
cp -Xr image/arm-linux-engeabihf/bcm2709/* ${BOOT_MP}
cp -X ${BOOT_MP}/vmlinuz-4.1.15-v7 ${BOOT_MP}/kernel7.img
cd image/arm-linux-engeabihf/
mkdir -p var etc
strip usr/ellcc/bin/*
tar cvfp - -X ${TOP}/exclude.lst bin etc lib sbin usr var | (cd ${ROOT_MP}; tar xfp -)
cp -XR $ELLCC/libecc/share/terminfo $ELLCC/libecc/share/tabset ${ROOT_MP}/root/usr/share
cd bcm2709/
rm -fr *.old
tar cvf - * | ( cd ${BOOT_MP} ; tar -xf - )
cd ../../..
cd etc
chmod oug+x rc.*
cp -XR * ${ROOT_MP}/etc/
cd ../sbin
mkdir -p ${ROOT_MP}/sbin
tar cvfp - * | ( cd ${ROOT_MP}/sbin/ ; tar xf - )
cd ../bin
chmod oug+x * || true
tar cvfp - * | ( cd ${ROOT_MP}/bin/ ; tar xf - )
cd ..
cp -X boot.rpi/* ${BOOT_MP}/
cd ${ROOT_MP} || exit 1
mkdir -p boot root dev proc sys tmp var/run var/log etc/dropbear
chown -R 0:0 *
mknod dev/tty0 c 4 0
chown 2:2 bin/*
chown 0:0 bin/su
chmod u+s bin/su
cd ..
umount ${ROOT}
rm ${ROOT_MP}/.local
fsck=`which fsck.ext4`
if [ -z "${mkfs}" ]; then
# sbin tool, not in Homebrew regular PATH
if [ ! -x /usr/local/opt/e2fsprogs/sbin/fsck.ext4 ]; then
echo "mkfs.ext4 not found. Check out e2fsprogs" >&2
else
fsck="/usr/local/opt/e2fsprogs/sbin/mkfs.ext4"
fi
fi
if [ -n "${fsck}" ]; then
echo "FSCK EXT4 partition"
${fsck} -f ${RAWROOT}
fi
diskutil umount ${BOOT}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment