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.
Adding a graphical environment<br />
59<br />
When you view the output of a comm<strong>and</strong> in the terminal, you are actually looking at two<br />
streams: st<strong>and</strong>ard out (stdout) <strong>and</strong> st<strong>and</strong>ard error (stderr). If you wish to split stdout <strong>and</strong> stderr,<br />
you can redirect them separately using the syntax 1>/path/stdout-filename 2>/<br />
path/stderr-filename. For example, the following would search for all shared library files<br />
<strong>and</strong> save the list to a file <strong>and</strong> throw away error messages about inaccessible directories: find /<br />
-name '*.so' 1>/sharedlibs.txt 2>/dev/null.<br />
Immediately following our grep comm<strong>and</strong>, we find a double vertical pipe that is<br />
used as a logical OR. The OR evaluates to true if the expression on either side of the<br />
double vertical pipe returns true (success). OR uses a technique known as shortcircuiting.<br />
If the first expression is true, the second is never executed. In our case,<br />
if the package was found, the expression deb_pkgs¼"${deb_pkgs}${pkg} " that<br />
appends the package to our list of packages to install is never executed.<br />
The next code segment builds a list of packages to be installed:<br />
unset deb_pkgs<br />
pkg¼"lxde-core"<br />
check_dpkg<br />
pkg¼"slim"<br />
check_dpkg<br />
if [ "x${board}" ¼ "xAM33XX" ] ; then<br />
pkg¼"xserver-xorg-video-modesetting"<br />
check_dpkg<br />
fi<br />
pkg¼"xserver-xorg"<br />
check_dpkg<br />
pkg¼"x11-xserver-utils"<br />
check_dpkg<br />
The first line in this segment unset deb_pkgs clears the variable holding our list<br />
of packages to be installed. The remaining lines in this segment set the pkg variable<br />
<strong>and</strong> then call check_dpkg repeatedly. The only thing new is an if statement that is<br />
used to install a video-modesetting package on the appropriate hardware (such as<br />
the BeagleBone Black).<br />
The if statement might look a bit funny if you aren’t used to working <strong>with</strong><br />
shell scripts. The general syntax of an if statement is if [ condition ] ; then followed<br />
by a number of comm<strong>and</strong>s <strong>and</strong> closed <strong>with</strong> an fi (if spelled backward).<br />
Be very careful <strong>with</strong> whitespace in if statements in shell scripts. The whitespace<br />
before <strong>and</strong> after each of the square brackets is not optional. You might wonder about<br />
the strange condition statement "x${board}" ¼ "xAM33XX" being used in this script.<br />
Prefixing our variable <strong>and</strong> target string <strong>with</strong> an x is a common trick that prevents<br />
accidental modification of our shell variable board. Incidentally, while we have<br />
indented the code inside the if statement to make it more readable, doing so is<br />
optional.