Bash Script TimThumb Update [cPanel/WHM]

If your dealing with a large WordPress instance, I hope you have shell. Using plugins like Timthumb Vulnerability Scanner on small installations is great, however, on large installations the server might 503.

I had previously used bash scripts to detect outdated TimThumb using simple grep command and outputting the finding to a .txt file which I could cross reference during the update process. It’s become cumbersome to do this, I wanted to grab the updated timthumb version from the Google Code repository and update the files. With a quick Google search, I fould this simple script for cPanel users that can be modified to your distro. Props to DropDeadDick.com for sharing his script. <3

#! /bin/bash
# Detects and updates timthumb.php to latest version for all cPanel users.
# dropdeaddick.com

latest=`lynx -source http://timthumb.googlecode.com/svn/trunk/timthumb.php |grep "define (‘VERSION’" $file |cut -f4 -d"’"`
if [ -z "$latest" ]; then
echo "could not get latest timthumb release, aborting!"
exit 1
fi
for user in `awk -F':’ ‘{ if ($3 > 499) print $0 }’ /etc/passwd | grep home | cut -d':’ -f1`; do
for file in `find /home*/$user/public_html/ -type f ( -name ‘thumb.php’ -o -name ‘timthumb.php’ ) 2>/dev/null | tr ‘ ‘ ‘%’`; do
file=`echo $file | tr ‘%’ ‘ ‘`
check=`grep -c "code.google.com/p/timthumb" "$file"`
if [ -z "$check" ]; then
break
fi
if [ "$check" -gt "0" ]; then
version=`grep "define (‘VERSION’" "$file" |cut -f4 -d"’"`
if [ "$version" != "$latest" ]; then
echo -e "e[1;31mWARNING version $versione[0m updating $file!"
# rm -f $file #delete current file before replacing.
wget -nv -t3 -T3 http://timthumb.googlecode.com/svn/trunk/timthumb.php -O "$file"
chown $user: "$file"
else
echo -e "e[1;32mOK version $versione[0m skipping $file"
fi
fi
done
done

I’d recommend creating an alias so that you can use it periodically. :]

How To REMOVE Crap In footer.php w. grep sed

penguin-beer

Lets get ride of garbage hard coded in premium themes. Only doing this because 1.) GPL and 2.) I paid for this theme, why is their copyright in it? :( Do I have to buy you a beer too? More than willing too. :]

grep -lr --include=footer.php "<p id="copyright">" /home/USERNAME/public_html/wp-content/themes | xargs sed -i 's#<p id="copyright"><?php printf( __([^;]*; ?></p>##g'

If this looks Greek to you, I’d recommend reading up on grep and sed documentation. There are great examples of how to use it with regex.

OCZ Vertex 2 60GB SATA II in ASUS UL80j

Today I’ve received the OCZSSD2-2VTXE60G Solid State Drive. I’ve purchase this SSD to install on my ASUS UL80j. My intent is to improve cold start times, wake up and overall power consumption. I would also like to potentially experiment with Google Chrome OS. For now my main OS of choice will be uBuntu 11.04, although I do have a Hackintosh install CD derping around.

Benchmarks

uBuntu 11.04 benchmarks with the OCZ Vertex 2 OCZSSD2-2VTXE60G 2.5″ 60GB SATA II MLC Internal Solid State Drive (SSD)

Update: Installed Windows 7 Ultimate 64-bit on this laptop and here are the ATTO benchmarks.

How To Setup LAMP on uBuntu 11.04 – Also, WordPress

In this article, we will work on setting up a LAMP environment for uBuntu 11.04. As an added bonus, I will setup WordPress 3.2 in the environment for you nerds. As you may notice in previous posts, I have a nice little lappy which allows me to dev on the run.

Installing LAMP onto uBuntu 11.04

First thing is first, we need to install tasksel then run it via terminal.

sudo apt-get install tasksel
sudo tasksel

Select LAMP Server and proceed to install it!

While you are installing LAMP, you will be prompted to set a password for MySQL root.

First of all, /var/www/ directory is set for root user only. We want to allow our IDE’s, such as Netbeans or Vi/Vim/Nano have permissions to write to this directory. So let’s sudo su and chown /var/www/

sudo su
chown yourusername:yourusername /var/www/
exit

At this point, let’s test to see if LAMP is running.

sudo vi /var/www/index.php

Within index.php just enter phpinfo(); to check if the PHP core fires an output!

&lt;?php phpinfo(); ?&gt;

Save index.php and exit.

When you visit http://localhost/index.php you should get an output. If you do not, you can try restarting apache2 with the following command:

sudo /etc/init.d/apache2 restart

Installing phpMyAdmin To Manage Your MySQL Databases on uBuntu 11.04

sudo apt-get install phpmyadmin

WordPress: World Famous 5 Minute Installation

Head over to WordPress.org and grab the latest version of WordPress. Extract the zip file to /var/www/wordpress

Visit http://localhost/phpmyadmin and create a database.

Under the Privileges tab, goto Add New User. Make sure under Global Privileges click Check All and hit Go.

Visit http://localhost/wordpress and setup your WordPress install! Bam! Your done!

Linuxfest Northwest 2011

Arriving at Bellingham Technical College a bit late, tired from late night geeking out on uBuntu. I arrive in a moist parking lot with a grungy overcast. I walk into “Build a Free As In Freedom Cloud” in Haskell 203 late. Old Spice should sponsor Linuxfest, the man next to me smelt of musk; as if he wrestled a bear into submission.

At 11am, Mark Hinkle took the stage discussing “Crash Course on Open Source Cloud Computing” – this man is a genius. Below is his slideshare.

During lunch, of course I opted for the ribs. I met an instructor at WWU and one of the computer science network admins (their names escape me.) It was interesting talking to them about distributed storage.

After lunch I sat in to listen to Adrian Pike’s Agile development concepts and practices for lean startups talk. It was interesting to hear his experience with project management and collaborating with people online. I think the most insightful bit of information was just how their team handles communication. He mentioned Kanban, Scrum, Basecamp, Test suites, etc.

Coincidentally the Amazon AWS talk was canceled. I am not sure why but I ran into two Amazon network technicals hanging out in the hall ways. I had to sit in on a Drupal talk which was semi informative.

The next thing that happened to me was sitting down next to an asian that had a Google Laptop CR-48. I later found out he actually works for Google and was sent to LinuxfestNW to sit in on the Cloud Networking talks. I’m assuming he’s an engineer. He was sitting with one of the Amazon network technicians. David Nalley talk about open source clouds was very informative and I’d love to experiment with the software he mentioned.

All in all, Linuxfest Northwest was just another nerdcore fest. It’s nice to meet / talk with others that understand the techno jargon.

uBuntu 11.04 On ASUS UL80j Laptop!

Running uBuntu 11.03 on ASUS UL80j

The ASUS UL80j is a light weight, ultra thin laptop that features Windows 7 Home Premium. It comes with an Intel i3 dual core 1.2ghz processor and 4GB of DDR3. Loading uBuntu 11.04 onto it was easy as cake. The laptop comes with a 500GB hard disk, I’ve split the partition 50-50.

Last week I began tinkering around with uBuntu 11.04 Beta before the official release, and I might say, this is the best release ever! I understand that veteran uBuntu users dislike the Unity interface, but I’ve grown to love it. Although I wish the task bar would be at the bottom. It is rather limiting being on the left hand side of the screen.

Issues At First

  • Unity GUI Does Not Work
  • Wifi LED Does Not Turn Off / On
  • Suspend / Hibernate Hangs
  • Runs Hot & Battery Doesn’t Last As Long As Win7

Getting Unity To Work

In order to get Unity to work properly I had to uninstall the Nvidia drivers. Once they were uninstalled, I restarted the system and Unity was up and running.

UPDATE: I’ve been digging around the uBuntu forums and found that the NVidia Optimus graphics card is not supported on uBuntu. There is a thread of customers complaining about the lack of support. If you stumbled upon this post and feel the need to raise your concerns, please visit Linux and Hybrid Graphics no Optimus support thread.

Fixing Wifi LED

If your blue Wifi LED light near your mouse pad isn’t working when you hit Fn + F2, here’s a quick fix. You will have to create two files and paste the following scripts.

sudo nano /etc/acpi/events/asus-wireless-switch

Paste the following code into this file:

event=hotkey ATKD 0000005d
action=/etc/acpi/asus-wireless-switch.sh

Next you will want to:

sudo nano /etc/acpi/asus-wireless-switch.sh

And paste this code into the file:

#!/bin/sh
# Toggle wireless device on Asus K52 laptops

WLANSTATUS=`cat /sys/class/ieee80211/phy*/rfkill*/state`

test -z $WLANSTATUS && exit 1

if [ $WLANSTATUS = 0 ]; then
echo 0 > /sys/devices/platform/asus_laptop/wlan
elif [ $WLANSTATUS = 1 ]; then
echo 1 > /sys/devices/platform/asus_laptop/wlan
fi

Next you will want to chmod +x asus-wireless-switch.sh and then restart acpi!

sudo chmod +x /etc/acpi/asus-wireless-switch.sh
sudo service acpid restart
sudo /etc/init.d/acpi-support restart

Fixing Suspend / Hibernation

My number one complaint wants Suspend / Hibernate. In order to resolve the Suspend / Hibernate issue, will have to create a file in /etc/pm/speed.d/. Note: For some reason, hibernate still doesn’t behave like I wish it would.

First create 20_custom_ehci_hcd in /etc/pm/sleep.d/

sudo nano /etc/pm/sleep.d/20_custom_ehci_hcd

Paste the following script and save.

#!/bin/sh
# File: "/etc/pm/sleep.d/20_custom-ehci_hcd".
case "${1}" in
hibernate|suspend)
# Unbind ehci_hcd for first device 0000:00:1a.0:
echo -n "0000:00:1a.0" | tee /sys/bus/pci/drivers/ehci_hcd/unbind
# Unbind ehci_hcd for second device 0000:00:1d.0:
echo -n "0000:00:1d.0" | tee /sys/bus/pci/drivers/ehci_hcd/unbind
;;
resume|thaw)
# Bind ehci_hcd for first device 0000:00:1a.0:
echo -n "0000:00:1a.0" | tee /sys/bus/pci/drivers/ehci_hcd/bind
# Bind ehci_hcd for second device 0000:00:1d.0:
echo -n "0000:00:1d.0" | tee /sys/bus/pci/drivers/ehci_hcd/bind
;;
esac

Now chmod +x the file.

sudo chmod +x 20_custom-ehci_hcd

Issues That Arise

Now that Suspend works fine, I’ve noticed if I keep my laptop on suspend for long periods of time the GUI won’t load upon wake up. The only work around I’ve figured out is to hit Ctrl + Alt + F1, login, and shutdown. Update: Another alternative to restarting the laptop is to restart gdm. Look below.

sudo shutdown -r now

If upon waking up and the GUI does not load hit Ctrl + Alt + F1. Type the following:

sudo /etc/init.d/gdm restart

Conclusion

With these simple fixes, I’m able to live with running uBuntu 11.04 on my ASUS UL80j. I have not been able to figure out a way to make the processor from running as hot as it does. I am thinking because the UL80j has two GPU’s (Intel & Nvidia Optimus), uBuntu automatically runs the Nvidia card instead of conserving power with the built in gpu. Another announce is the GUI not loading after the laptop has been in Suspend mode for over 24 hours.