Monday, February 16, 2009

Running PHP on the Eee PC

Info from following URLs:
http://wiki.eeeuser.com/howto:lamp
http://www.apachefriends.org/en/xampp-linux.html

Programming has been my hobby since my secondary school days and still is, though I mainly use PHP and Javascript nowadays - Free, Open, Platform Independent. In fact, I still code my webpages wholly in Notepad :P
I have some PHP scripts of my own which I would want to use offline. I have XAMPP Lite on my Tablet PC (www.portableapps.com) which is a portable Apache web server package with PHP and MySQL. This enables me to test/run my PHP scripts offline. Now it's my Eee PC's turn :)
    Steps:
  1. Press Ctrl-Alt-T to open the terminal console.
  2. Type "sudo apt-get install apache2" to install the Apache 2 web server.
  3. Type "sudo kwrite /etc/apache2/httpd.conf", add the 2 lines below and save (1st line is to fix the server domain, 2nd line is to fix a bug for the Eee PC):

    ServerName localhost
    EnableSendfile Off

  4. Type "sudo apt-get install php5" to install PHP 5.
  5. Create a shortcut bash script for Apache. Type "sudo kwrite /usr/bin/apache", add the following lines and save:

    #!/bin/bash
    sudo /etc/init.d/apache2 $@

  6. Type "sudo chmod 755 /usr/bin/apache" to set the correct permissions.
  7. To start Apache, type "apache start". To stop, type "apache stop"
  8. Put your webpages in /var/www. You will need to use "sudo cp" to copy the files inside.
  9. To test, open your web browser and type "http://localhost"

Another way would be to install XAMPP for Linux (or LAMP as it was previously known), but it takes up 55MB compared to 12MB above. I do not usually use MySQL so it would be better to save my Eee PC's disk space by not installing it.

(^ v ^)

Tuesday, February 10, 2009

Detecting whether AC power is on

Info from following URL:
  http://mychael.gotdns.com/blog/2008/06/showing-battery-life-in-awesome-with-lua/

    Recently, another recording on my Eee PC was cut off because the AC power was not switched on. I found the URL above and modified the bash script NOT to launch Audacity unless power is switched on.
    Steps:
  1. Press Ctrl-Alt-T to open the terminal console.
  2. I had previously set the Audacity icon in my Favorites to launch "audacity-checklist".
    So in this case, I would type "sudo kwrite /usr/bin/audacity-checklist".
  3. Delete the line that runs the command "audacity" and replace with the following (the awk command is on one line):

    #check if power is switched on and prevent launching if not so.
    powerStatus=$(awk '{ print $2 }' /proc/acpi/ac_adapter/AC0/state)

    if [ $powerStatus != "on-line"]
    then
       kdialog --msgbox "POWER IS NOT SWITCHED ON! \n\n Audacity will not launch."
    else
       audacity
    fi

    exit 0

  4. Try running the bash script with the power switched on and with it turned off.
(^ v ^)

Tuesday, January 6, 2009

Symbolic Links

Info from following URLs:
  http://www.linuxforums.org/forum/linux-newbie/37135-creating-symbolic-links-using-ln-command.html

    Recently I sent an email to the Audacity Team to see if Audacity's temp directory could be set using commandline parameters. Below is an extract of my email and Richard Ash's reply.

>
> I'm using the Asus Eee PC and using the Debian
> distribution of Audacity for the Xandros OS. I set my
> temp directory to the SD Card in the card slot, but in
> Linux, there is no drive name - it goes by the name of
> the card, so if I change cards, Audacity can't find
> the temp directory anymore.
>
> Example:
> My card is labelled Kingston.
> When I go into /home/user/MMC-SD, I see the folder
> Kingston
>
> My card is labelled Toshiba.
> When I go into /home/user/MMC-SD, I see the folder
> Toshiba.
>
---/* Reply */
Why not create a symlink from a convenient directory that doesn't change
to the currently inserted flash card. So for example with each different
card inserted create a symlink from /home/user/.audacity_temp
to /home/user/MMC-SD//.audacity_temp as required. You can then
set audacity to always use /home/user/.audacity_temp as the temporary
directory, and the data will end up on whichever card is in use.
Richard
---

    Kudos to Richard for such an ingenious reply! As mentioned before, I'm not the only one using my Eee PC for recording, so there is the possibility that the person handling my Eee PC might just insert his own SD Card, in which case the problem above would surface. I edited the bash script for launching Audacity in my Easy Mode GUI as shown below (see earlier posts on KDialog and Easy Mode GUI on how to set the shortcut):


#!/bin/bash
#create symbolic link from SD Card to /home/user.
#create .audacity_temp/ in SD Card if it does not exist.

#Get name of SD Card in card slot
DIRECTORY="/home/user/MMC-SD"
for file in $DIRECTORY/*
do
firstdir=$file
break
done

#check if .audacity_temp/ exists in SD Card
firstdir=$firstdir'/.audacity_temp'
if !(test -d $firstdir)
then
echo making
sudo mkdir $firstdir
fi

#create symbolic link to /home/user/.audacity_temp.
#Must remove old link 1st
rm /home/user/.audacity_temp
ln -s $firstdir /home/user/.audacity_temp

#checklist
title="Audio Recording Checklist"
msg1="1) Is the power plugged in and SWITCHED ON?"
msg2="2) Is the mic volume around 1/4 level? (volume icon at bottom right of screen)"
msg3="3) When recording is done, go to File, 'Export as MP3'."
myMsg=$title'\n'$msg1'\n'$msg2'\n'$msg3
kdialog --msgbox "$myMsg"

audacity
exit 0


    The creating of the symbolic link (or symlink or soft link) is done using the command "ln". Now I have a symlink in /home/user called .audacity_temp which shows the link when my mouse cursor hovers over it in File Manager (go to View -> Show Hidden Files to see it)

(^ v ^)