10.09.2016 Views

Hacking_and_Penetration_Testing_with_Low_Power_Devices

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Adding a graphical environment<br />

57<br />

board. Creating a variable to be used in the current shell is as simple as executing the<br />

comm<strong>and</strong> variable¼value. Value can be any arbitrary string. A string that includes<br />

whitespace can be enclosed in quotes. Single quotes tell the shell not to interpret<br />

the string. Enclosing a value <strong>with</strong>in double quotes will cause the shell to interpret wildcards<br />

(such as *) <strong>and</strong> shell variables. In our case, we are running a set of comm<strong>and</strong>s <strong>and</strong><br />

assigning the result to a variable using the syntax variable¼$(comm<strong>and</strong>). This is<br />

another neat trick you can use from <strong>with</strong>in a Linux shell. For example, the comm<strong>and</strong><br />

cat $(ls *.txt) will type out the contents of all txt files <strong>with</strong>in the current directory.<br />

Three different comm<strong>and</strong>s are executed inside the parentheses in the second line<br />

<strong>with</strong> the output of each comm<strong>and</strong> used as the input for the next. This process is<br />

known as piping. Not surprisingly, the j or vertical pipe is used to join these comm<strong>and</strong>s<br />

together. The cat /proc/cpuinfo comm<strong>and</strong> prints out the contents of the<br />

cpuinfo pseudo file.<br />

This information is then piped to the grep (GNU Regular Expression Parser) tool.<br />

Grep allows you to search for patterns. The special character ^anchors the search<br />

expression to the start of a line ($ is used at the end to anchor an expression to<br />

the end of a line). The comm<strong>and</strong> grep “^Hardware” prints out only lines that begin<br />

<strong>with</strong> “Hardware.”<br />

This line that identifies our board is then piped to our last comm<strong>and</strong> awk '{print<br />

$4}'. Notice the use of single parentheses. This is done to prevent the $4 <strong>and</strong> curly<br />

brackets from being interpreted by the shell. Awk is a pattern scanning <strong>and</strong> processing<br />

language that was developed in the late 1970s. It is still widely used today, often<br />

in combination <strong>with</strong> the stream editor sed. Awk comm<strong>and</strong>s are enclosed <strong>with</strong>in curly<br />

brackets. Our awk comm<strong>and</strong> simply prints the fourth word (set of characters separated<br />

by whitespace) from our line. The net of all this is that the board variable has<br />

been set appropriately in order to load the appropriate packages <strong>and</strong> create configuration<br />

files later in the script.<br />

The third <strong>and</strong> fourth lines are simple <strong>and</strong> straightforward. The comm<strong>and</strong> sudo<br />

apt-get update updates the local directory of available packages. The comm<strong>and</strong><br />

is prefixed <strong>with</strong> sudo because it requires root (administrative) privileges. After<br />

you run this comm<strong>and</strong> from a terminal, a number of messages starting <strong>with</strong> hit<br />

(checking a repository), get (actually download a list), <strong>and</strong> ign (ignore a repository<br />

previously updated) will be displayed. A shell prompt will be displayed when the<br />

comm<strong>and</strong> finishes. All installed packages are upgraded to the latest version by<br />

the sudo apt-get -y upgrade on the fourth line. The -y flag automatically answers<br />

yes to any prompts. Running this comm<strong>and</strong> from a terminal will cause a summary of<br />

what is to be updated <strong>and</strong> what will be held back to be displayed, then the packages to<br />

be updated will be fetched (the status message will start <strong>with</strong> get, followed by a number<br />

corresponding to the nth package to be updated during this operation), <strong>and</strong> finally<br />

the packages are reinstalled.<br />

The next few lines define a simple function. The syntax for creating functions is<br />

straightforward. Simply list a function name, followed by parentheses <strong>and</strong> then<br />

enclose the comm<strong>and</strong>s that make up the function in curly brackets. You can create

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

Saved successfully!

Ooh no, something went wrong!