Chit chat

======

Converting the nslu2 back to the original firmware. Oops, delaying that idea.

Lost a drive that was using arch linux.  Worked fine the last time I used it. Replaced it with a drive that has Debian. At least the machine is still being used.  Not a good week also lot a Raspberry Pi.

Had to put on a new ends on a few network cables. Once you  have done enough of them, you never forget the wo-o-wg-bl-wbl-g-wbr-br aka

white-orange orange white-green blue white-blue green white-brown brown

Moved some c source files over to the pogoplug and tested compiling some c code.

Brother is getting the android 5 update. Android 5 without hardwire access is a fail.

Getting close to 1.5 million views at http://www.instructables.com/member/computothought

—————————————–

To convert a web page for use with the arduino, you will need to add a preface and an ending to each line of code.

Original code:

<html>
<body>
This is a text message.
</body>
</html>

Using vim add a beginning with: :%s!^!client.println(\”!

client.println(“<html>
client.println(“<body>
client.println(“This is a text message.
client.println(“</body>
client.println(“</html>

Then using vim add an ending with: :%s/$/\”);/

client.println(“<html>”);
client.println(“<body>”);
client.println(“This is a text message.”);
client.println(“</body>”);
client.println(“</html>”);

Result:

Also:

client.println(“”);
client.println(“This is a test of the arduino.”);
client.println(“”);
client.println(“<pre>”);
client.println(”                                 ___________”);
client.println(”                                [___________]”);
client.println(”                                 {=========}”);
client.println(”                               .-*         *-.”);
client.println(”                              /               \\”);
client.println(”                             /_________________\\”);
client.println(”                             |   _  _   _      |”);
client.println(”                             ||\\(_ |_)||_)||\\ ||”);
client.println(”            ,.–.   ,.–.    ||~\\_)|  || \\|| \\||”);
client.println(”           // \\  \\ // \\  \\   |_________________|”);
client.println(”           \\\\  \\ / \\\\  \\ /   |                 |”);
client.println(”            `*–*   `*–*    ‘—————–‘”);
client.println(“</pre>”);

Your code should now work within an ethernet sketch. The rest is up to your imagination.

—————————————–

Try at your own risk. Your system could be damaged.

Plug goes into a sound card output. Of course, you will need an AM capable radio to receive the transmissions. Dial needs to be set at or near 100x10khz. There was several strong competing stations where we tested this project.

—————————————–

Decided to make a sd card with arch linux using these instructions:

SD Card Creation
Replace sdX in the following instructions with the device name for the SD card as it appears on your computer.

  1. Start fdisk to partition the SD card:
    fdisk /dev/sdX
  2. At the fdisk prompt, delete old partitions and create a new one:
    1. Type o. This will clear out any partitions on the drive.
    2. Type p to list partitions. There should be no partitions left.
    3. Type n, then p for primary, 1 for the first partition on the drive, press ENTER to accept the default first sector, then type +100M for the last sector.
    4. Type t, then c to set the first partition to type W95 FAT32 (LBA).
    5. Type n, then p for primary, 2 for the second partition on the drive, and then press ENTER twice to accept the default first and last sector.
    6. Write the partition table and exit by typing w.
  3. Create and mount the FAT filesystem:
    mkfs.vfat /dev/sdX1 mkdir boot mount /dev/sdX1 boot
  4. Create and mount the ext4 filesystem:
    mkfs.ext4 /dev/sdX2 mkdir root mount /dev/sdX2 root
  5. Download and extract the root filesystem (as root, not via sudo):
    wget http://archlinuxarm.org/os/ArchLinuxARM-rpi-latest.tar.gz
  6.  sudo apt-get install bsdtar
  7. bsdtar -xpf ArchLinuxARM-rpi-latest.tar.gz -C root sync
  8. Move boot files to the first partition:
    mv root/boot/* boot
  9. Unmount the two partitions:
    umount boot root
  10. Insert the SD card into the Raspberry Pi, connect ethernet, and apply 5V power.
  11. Use the serial console or SSH to the IP address given to the board by your router. The default root password is ‘root’.
  12. Once you log in be sure to update the  system with pacman -Syu

—————————————–

You can take software from years even decades ago and still reuse it. For example, found some accounting source code originally written as early as the 1970’s that can be compiled and used on present day systems. Albeit that the software needs some polish to be presentable by today’s standards, it still works just as well.

Account setup:

Then you can enter some data:

Lastly, you can views the results of your entries say in a simple t-account format:

The datafile:

$ cat bizness

02052015               XX X X X X X XXXXXXXXassets             XXXXXXXXXXXXXXXliabilities        XXXXXXXXXXXXXXXcapital            XXXXXXXXXXXXXXXincome             XXXXXXXXXXXXXXXexpenses           XXXXXXXXXXXXXXXunused             XXXXXXXXXXXXXXXunused             XXXXXXXXXXXXXXXincome/expense sum.XXXXXXXXXXXXXXXCash               d�D c Cd@�D czCc�c D

cHCXXXXXXXXSupplies           d C    c�BXXXXXXXXXXXXXEquipment          dzDXXXXXXXXXXXXXXAccounts payable   czd DXXXXXXXXXXXXXNotes Payable      XXXXXXXXXXXXXXXCapital – owner    c�DXXXXXXXXXXXXXXDrawing – owner

dHCXXXXXXXXXXXXXXFee income         c@�DXXXXXXXXXXXXXXRent               dzCXXXXXXXXXXXXXXSupplies expense       d�BXXXXXXXXXXXXXXTelephone Expense  d�BXXXXXXXXXXXXXX

What software can you put back to work?

—————————————–
With more and more people using the command line, changing permissions is a must. Chmod (chmod) is used to change permissions of a file. Do not use it that much except when setting permissions on the .ssh folder or on a web server application directories

i.e.
$ sudo chmod -R 755 appdirectory

or

$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/*

Explanation examples:

Permissions Command
User Group World
rwx rwx rwx chmod 777 filename
rwx rwx r-x chmod 775 filename
rwx r-x r-x chmod 755 filename
rw- rw- r– chmod 664 filename
rw- r– r– chmod 644 filename

r = readable  w = writable x = executable  – = no permission

Here is another way of looking at it:

ugw function
400 r– read by owner
040 -r- read by group
004 –r read by anybody (other)
200 w– write by owner
020 -w- write by group
002 –w write by anybody
100 x– execute by owner
010 -x- execute by group
001 –x execute by anybody

To get a combination, just add them up. For example, to get read, write, execute by owner, read, execute, by group, and execute by anybody, you would add 400+200+100+040+010+001 to give 751.

There is also a nice web based calculator you can use on a web page of your own making: http://wsabstract.com/script/script2/chmodcal.shtml

Note: Some people like to use:
chmod ugo=rwx myfile
Where the nerds use:
chmod 777 myfile

—————————————–

Some experimental mysql database setup scripts. Should be able to use then with Mariadb. (USE AT YOUR OWN RISK!)Original script:#!/bin/bash EXPECTED_ARGS=3 E_BADARGS=65 MYSQL=`which mysql`
#Danger do not use GRANT ALL ON *.*
Q1=”CREATE DATABASE IF NOT EXISTS $1;” Q2=”GRANT ALL ON *.* TO ‘$2’@’localhost’ IDENTIFIED BY ‘$3’;” Q3=”FLUSH PRIVILEGES;” SQL=”${Q1}${Q2}${Q3}” if [ $# -ne $EXPECTED_ARGS ] then echo “Usage: $0 dbname dbuser dbpass” exit $E_BADARGS fi $MYSQL -uroot -p -e “$SQL”To use it, just run:
./createdb testdb testuser secretpassSomeone’s modified script:#!/bin/bash

BTICK=’`’
EXPECTED_ARGS=3
E_BADARGS=65
MYSQL=`which mysql`
Q1=”CREATE DATABASE IF NOT EXISTS ${BTICK}$1${BTICK};”
Q2=”GRANT ALL ON ${BTICK}$1${BTICK}.* TO ‘$2’@’localhost’ IDENTIFIED BY ‘$3′;”
Q3=”FLUSH PRIVILEGES;”
SQL=”${Q1}${Q2}${Q3}”
if [ $# -ne $EXPECTED_ARGS ]
then
echo “Usage: $0 dbname dbuser dbpass”
exit $E_BADARGS
fi
$MYSQL -uroot -p -e “$SQL”Using a little whiptail:

#!/bin/bash

USERNAME=$(whiptail –title “Mysql username” –inputbox “What is your Mysql username?” 10 60 $USER 3>&1 1>&2 2>&3)

exitstatus=$?
if [ $exitstatus = 0 ]; then
echo “Your pet name is:” $USERNAME
else
echo “You chose Cancel.” ; exit
fi

PASSWORD=$(whiptail –title “Mysql password” –passwordbox “Enter your password and choose Ok to continue.” 10 60 3>&1 1>&2 2>&3)

exitstatus=$?
if [ $exitstatus = 0 ]; then
echo “Your password is: XXXXXXXX”
else
echo “You chose Cancel.” ; exit
fi

DBNAME=$(whiptail –title “Database name” –inputbox “What is database name?” 10 60 DBNAME 3>&1 1>&2 2>&3)

exitstatus=$?
if [ $exitstatus = 0 ]; then
echo “Your pet name is:” $DBNAME
else
echo “You chose Cancel.” ; exit
fi
DBUSERNAME=$(whiptail –title “Database username” –inputbox “What is your database user name?” 10 60 DATABASEUSERNAME 3>&1 1>&2 2>&3)

exitstatus=$?
if [ $exitstatus = 0 ]; then
echo “Your pet name is:” $DBUSERNAME
else
echo “You chose Cancel.” ; exit
fi
DBHOST=$(whiptail –title “Database host name” –inputbox “What is your database host name?” 10 60 DBHOST 3>&1 1>&2 2>&3)

exitstatus=$?
if [ $exitstatus = 0 ]; then
echo “Your pet name is:” $DBHOST
else
echo “You chose Cancel.” ; exit
fi

DBPASSWORD=$(whiptail –title “Database password” –passwordbox “What is your database password?” 10 60 DBPASSWORD 3>&1 1>&2 2>&3)

exitstatus=$?
if [ $exitstatus = 0 ]; then
echo “Your password is : XXXXXXXX”
else
echo “You chose Cancel.” ; exit
fi

MYSQL=`which mysql`

Q1=”CREATE DATABASE IF NOT EXISTS $DBNAME;”
Q2=”GRANT ALL ON $DBNAME.* TO ‘$DBUSERNAME’@’$DBHOST’ IDENTIFIED BY ‘$DBPASSWORD’;”
Q3=”FLUSH PRIVILEGES;”
SQL=”${Q1}${Q2}${Q3}”

$MYSQL -u $USER -p $PASSWORD -e “$SQL”

—————————————–

More on whiptail:

A message box shows any arbitrary text message with a confirmation button to continue. whiptail –title “<message box title>” –msgbox “<text to show>” <height> <width>

Example:

#!/bin/bash

whiptail –title “Message Box” –msgbox “Create a message box with whiptail. Choose Ok to continue.” 10 60

Screenshot from 2015-02-07 12:22:20

Create a Yes/No Box

One common user input is Yes or No. This is when a Yes/No dialog box can be used. whiptail –title “<dialog box title>” –yesno “<text to show>” <height> <width>

Example:

#!/bin/bash
if (whiptail –title “Yes/No Box” –yesno “Do you like computers (yes/no)?” 10 60)
then echo “Yes, you like computers. Exit status was $?.”
else echo “No, you do not like computers. Exit status was $?.”
fi

Optionally, you can customize the text for Yes and No buttons with “–yes-button” and “–no-button” options.

Example:

#!/bin/bash

if (whiptail –title “Test Yes/No Box” –yes-button “Free software” –no-button “Closed software” –yesno “Which do you like better?” 10 60)

then echo “You chose free software Exit status was $?.”

else echo “You chose closed software. Exit status was $?.”

fi

Screenshot from 2015-02-07 12:44:13

Example:

#!/bin/bash

if (whiptail –title “Test Yes/No Box” –yes-button “Free software” –no-button “Closed software” –yesno “Which do you like better?” 10 60)

then echo “You chose free software Exit status was $?.”

else echo “You chose closed software. Exit status was $?.”

fi

You saw the freeform and the password boxes in the previous section.

Create a Menu Box

When you want to ask a user to choose one among any arbitrary number of choices, you can use a menu box. whiptail –title “<menu title>” –menu “<text to show>” <height> <width> <menu height> [ <tag> <item> ] . . .

Example:

#!/bin/bash

OPTION=$(whiptail –title “Menu Dialog” –menu “Choose your option” 15 60 4 \ “1” “Grilled ham” \ “2” “Swiss Cheese” \ “3” “Charcoal cooked Chicken thighs” \ “4” “Baked potatos” 3>&1 1>&2 2>&3)

exitstatus=$?

if [ $exitstatus = 0 ];

then echo “Your chosen option:” $OPTION

else echo “You chose Cancel.”

fi

Screenshot from 2015-02-07 12:13:57

Create a Radiolist Dialog

A radiolist box is similar to a menu box in the sense that you can choose only option among a list of available options. Unlike a menu box, however, you can indicate which option is selected by default by specifying its status. whiptail –title “<radiolist title>” –radiolist “<text to show>” <height> <width> <list height> [ <tag> <item> <status> ] . . .

Example:

#!/bin/bash

DISTROS=$(whiptail –title “Test Checklist Dialog” –radiolist \ “What is the Linux distro of your choice?” 15 60 4 \ “Debian” “Stable Debian” ON \ “Ubuntu” “Copycat Debian” OFF \ “Centos” “Copycate Redhat” OFF \ “Mint” “Copycat Ubuntu/Debian” OFF 3>&1 1>&2 2>&3)

exitstatus=$?
if [ $exitstatus = 0 ];

then echo “The chosen distro is:” $DISTROS

else echo “You chose Cancel.”

fi

Screenshot from 2015-02-07 12:04:52

Create a Checklist Dialog

A checklist dialog is useful when you want to ask a user to choose more than one option among a list of options, which is in contrast to a radiolist box which allows only one selection. whiptail –title “<checklist title>” –checklist “<text to show>” <height> <width> <list height> [ <tag> <item> <status> ] . . .

Example:

#!/bin/bash

DISTROS=$(whiptail –title “Test Checklist Dialog” –checklist \ “Choose preferred Linux distros” 15 60 4 \ “Debian” “Stable Debian” ON \ “Ubuntu” “Debian copycat” OFF \ “Centos” “Redhat copycat” ON \ “Mint” “Copycat Ubuntu/Debian” OFF 3>&1 1>&2 2>&3)

exitstatus=$?

if [ $exitstatus = 0 ];

then echo “Your favorite distros are:” $DISTROS

else echo “You chose Cancel.”

fi

Screenshot from 2015-02-07 11:50:35

Create a Progress Bar

Another user-friendly dialog box is a progress bar. whiptail reads from standard input a percentage number (0 to 100) and displays a meter inside a gauge box accordingly. whiptail –gauge “<test to show>” <height> <width> <inital percent>

#!/bin/bash
PCT=0
(
while test $PCT != 100;
do
PCT=`expr $PCT + 10`;
echo $PCT;
sleep 1;
done; ) | whiptail --title "GAUGE" --gauge "Hi, this is a gauge widget" 20 70 0

Screenshot from 2015-02-07 11:40:30

By now, you must see how easy it is to create useful dialog boxes in an interactive shell script. Next time you need to write a shell script for someone, why don’t you try whiptail?

—————————————–

Another simple pasta favorite (fettucine made from scratch).

SUNP0031

Good day.

 

Advertisements