10.09.2016 Views

Hacking_and_Penetration_Testing_with_Low_Power_Devices

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 3 Appendix: digging deeper into the setup script<br />

53<br />

# copy files to root filesystem<br />

# this primarily involves untaring a large file<br />

# some of the less insightful parts of this function have been\<br />

removed<br />

# for brevity<br />

populate_rootfs () {<br />

echo "Populating rootfs Partition"<br />

echo "Please be patient, this may take a few minutes, as\<br />

its transfering a lot of data.."<br />

echo "———————————————————————————"<br />

# create a temporary directory if it doesn’t exist<br />

if [ ! -d ${TEMPDIR}/disk ] ; then<br />

mkdir -p ${TEMPDIR}/disk<br />

fi<br />

partprobe ${media}<br />

# mount the root partition<br />

if ! mount -t ${ROOTFS_TYPE} ${media_prefix}2\<br />

${TEMPDIR}/disk; then<br />

echo "———————————————————————————"<br />

echo "Unable to mount ${media_prefix}2 at\<br />

${TEMPDIR}/disk to complete populating rootfs\<br />

Partition"<br />

echo "Please retry running the script, sometimes\<br />

rebooting your system helps."<br />

echo "———————————————————————————"<br />

exit<br />

fi<br />

if [ -f "${DIR}/${ROOTFS}" ] ; then<br />

# use correct flags for our file archive<br />

echo "${DIR}/${ROOTFS}" j grep ".tgz"\<br />

&& DECOM¼"xzf"<br />

echo "${DIR}/${ROOTFS}" j grep ".tar" && DECOM¼"xf"<br />

# pv displays a nice progress bar these lines use\<br />

it if available<br />

if which pv > /dev/null ; then<br />

pv "${DIR}/${ROOTFS}" j tar --numeric-owner\<br />

--preserve-permissions -${DECOM} - -C\<br />

${TEMPDIR}/disk/<br />

else<br />

echo "pv: not installed, using tar verbose\<br />

to show progress"<br />

tar --numeric-owner --preserve-permissions\<br />

--verbose -${DECOM} "${DIR}/${ROOTFS}" -C\<br />

${TEMPDIR}/disk/<br />

fi

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!