Posts Tagged scripts

Forever Updating

I find little time these days and I noticed with some annoyance that I was behind with my WordPress updates. I run a number of sites (13 WordPress sites alone) and updating from 2.5 -> 2.5.1 is sort of painful and tedious.

So I made a script (most of the domain names are removed but you could add to the list):

sites=(illusoryfollies.com
       flanaganclan.com
       sarahflanagan.com)
 
base_path="/var/www/vhosts"
wordpress_download_url="http://wordpress.org/latest.tar.gz"
wordpress_download_file="latest.tar.gz"
wordpress_download_directory="wordpress"
wordpress_database_update_url="wp-admin/upgrade.php?step=1&backto=%2Fwp-admin%2F"
jailed_directory="httpdocs"
temp_directory="wp-temp"
 
number_of_sites=${#sites[@]}
 
 
echo "Updating $number_of_sites websites with the latest version of Wordpress."
 
for current_site in ${sites[@]}
do
  echo "Now processing $current_site..."
  echo "  Setting up directories..."
  if [ -e $base_path/$current_site/$jailed_directory ]
  then
    echo "  !!Detected a jail'ed website..."
    mkdir -p $base_path/$current_site/$jailed_directory/$temp_directory
    cd $base_path/$current_site/$jailed_directory/$temp_directory
  else
    mkdir -p $base_path/$current_site/$temp_directory
    cd $base_path/$current_site/$temp_directory
  fi
 
  echo "  Downloading latest version of Wordpress..."
  wget -q $wordpress_download_url
  echo "  Uncompressing..."
  tar zxfv $wordpress_download_file > /dev/null
  cd $wordpress_download_directory
  echo "  Copying into existing directory..."
  cp -r * ../..
  cd ../..
  echo "  Updating database..."
  wget -q "http://$current_site/$wordpress_database_update_url" -O /dev/null
  echo "  Cleaning up..."
  rm -rf $temp_directory
  echo "Done processing $current_site."
  echo ""
 
done

Now it takes about 15 seconds to update everyone’s site and it even performs the “Database Upgrade” step (at least for now).

Automation is a good thing. Speaking of which, I’m interested in Capistrano but I still haven’t really done anything with it. It looks like fun… I’ll have to add a post if I have any luck experimenting with it.

, , , ,

No Comments

Making Cygwin more handy

I enjoy having Cygwin installed on Windows and often like to use the shell commands (grep, find, etc.). However, it’s inconvenient to spawn a new terminal window and slog through the often-complex Windows directory structure. Based off of some websites I found, I now have a way to make this work…

Create a batch script file in your Cygwin /bin folder (for me, this is C:\Cygwin\bin) with the following:

@cd /d %1
 
@bash --rcfile BASCHRC -i

Create a file called “bashcontext.reg” and save the following text into it:

[HKEY_CLASSES_ROOT\Directory\shell\bash]
@="Open Bash shell here"
 
[HKEY_CLASSES_ROOT\Directory\shell\bash\command]
@="C:\\Cygwin\\bin\\runBash.bat \"%1\""
 
[HKEY_CLASSES_ROOT\Drive\shell\bash]
@="Open Bash shell here"
 
[HKEY_CLASSES_ROOT\Drive\shell\bash\command]
@="C:\\Cygwin\\bin\\runBash.bat \"%1\""
 
[HKEY_CLASSES_ROOT\*\shell\bash]
@="Open Bash shell here"
 
[HKEY_CLASSES_ROOT\*\shell\bash\command]
@="C:\\Cygwin\\bin\\runBash.bat \"%1\""

You can add the registry information by double-clicking the file to run it.

Now on every directory you have a “Open Bash shell here” option that will take you there immediately. Handy!

Here’s a screenshot showing my cluttered context menu:

clutteredcontext.png

, , , , ,

1 Comment

More Bash Scripts

I need to copy all of my FLAC files out of my directory tree but preserve the folder structure that they were in… Here’s my script.

Unfortunately, it’s not a “perfect” solution as there are issues when handling special characters in files (especially newline characters). However, since my file really just have spaces in them, that’s all this was designed to beat.

SOURCEDIR="/var/mirror/Data/Audio/My CD Archive"
TARGETDIR="/var/mirror/FLAC"
 
mkdir "$TARGETDIR"
 
find "$SOURCEDIR" -type d | while read DIR; do
  if [[ "$DIR" != "$SOURCEDIR" ]]; then
    SHORTDIR=`echo $DIR | sed 's/.*///g'`
    mkdir "$TARGETDIR/$SHORTDIR"
    echo "Now in $DIR"
    find "$DIR" -name "*.flac" | while read FILE; do
      SHORTFILE=`echo $FILE | sed 's/.*///g'`
      echo "Now moving $SHORTFILE"
      mv "$FILE" "$TARGETDIR/$SHORTDIR"
    done
    echo "--------------------"
    sleep 1
  fi
done

, , ,

1 Comment

Fun with Javascript

1. Browse to a site like Amazon.

2. Enter the following into your browser address window

javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.images; DIL=DI.length; function A(){for(i=0; i-DIL; i++){DIS=DI[ i ].style; DIS.position='absolute'; DIS.left=Math.sin (R*x1+i*x2+x3)*x4+x5; DIS.top=Math.cos(R*y1+i*y2+y3)*y4+y5}R++}setInterval('A()',5); void(0);

3. Hit Enter and watch the weirdness.

, ,

4 Comments