Scripts
Auto-install of WordPress Theme from CLI
by Eric on Mar.25, 2010, under Blog, Scripts, wordpress
If you're like me, and you still like to install your WordPress themes from the command line (or you were 3/4 asleep and forgot WordPress now has a nice, easy-to-use auto-installer built into the admin interface), you know it can be a pain. You have to download the file, unzip it, make sure it's right, delete the archive, chwon the files, etc... It can be a pain.
So, I created a nice little script to take care of all of that. wpthemeget will take a download URL from the WordPress Themes directory (in the format of http://(www.)wordpress.org/extend/themes/download/themename.ver.zip (or .tar.gz, or .tgz)), and will download, unarchive, chown, and remove the downloaded file, with no muss or fuss... The output?:
root@fyre [.../wp-content/themes]# wpthemeget http://wordpress.org/extend/themes/ download/motion.1.0.4.zip
Downloading theme motion.1.0.4.zip...
Theme is a zip archive...
Unzipping... [COMPLETE]
...Removing downloaded archive file... removed `motion.1.0.4.zip'
...Chowning files... [COMPLETE]
...Installation Complete!
No muss, no fuss. The only caveat is that you have to be in your themes directory when you run it. Future versions probably won't have this requirement, but hey, I hacked this out when I was barely awake, on heavy medication, and repeatedly falling asleep at the keyboard. At one point, I had to delete something like 40 lines of "zzzzzzzzzzz......" because I fell asleep with my finger on the key. Fortunately, vi treated it as all one paragraph so '<esc> dd' did the job. The code for this little script is after the break. Grab it, chmod it to exec, and drop it in /usr/local/bin, and it'll be good to go anywhere on your system, for all your blogs. Happy blogging!
Default Mail Clean Script
by Eric on Mar.17, 2009, under Linux, Scripts
Here's a quick little script to clean the default mail accounts of mail on cPanel servers. Note that this only helps if you have already disabled the catchalls.
#!/bin/bash
###############################################
# CLEAN MAIL #
# v0.1 #
# #
# Cleans the mail from default accounts based #
# on cPanel usernames. Create a file in /root #
# called 'doit'. Add one cPanel username per #
# line. That should do nicely. Oh, this will #
# take a while, so run the sucker in screen, #
# mkay, Batman? #
###############################################
# Some dedis have LS_OPTIONS include -a...
# that would be bad for this script.
# so, we reset it.
LS_OPTIONS='-A'
# start the loop...
for i in `cat /root/doit`
do
# Delete from the new folder.
cd /home/$i/mail/new
# can't rm if there's too many, and by using
# an ls and awk, we avoid another loop.
ls -l | awk '{print "rm -fv "$9}'|bash
# Delete from the cur folder.
cd /home/$i/mail/cur
# Comment repetition carefully avoided, here ![]()
ls -l | awk '{print "rm -fv "$9}'|bash
done
# NINJAMOJO!
It's simple. Get a list of cPanel usernames, one per line, create a file in /root called 'doit', and slap the usernames in there. Then, 'bash cleanmail'.

Testing Random Randomness…
by Eric on Feb.10, 2009, under Scripts
A post at Manik 2.0 got me thinking on whether or not the $RANDOM variable in bash was really all that random. So, I created a little test script. It's quite simple. It accepts a command line argument for number of loops. Then, each loop, it assigns a random number to $RANDTEST, and then compares $RANDTEST to $RANDOM. Since $RANDOM changes every time, it should never, ever match.




