Skip to main content

howto

How-to: Upgrade Debian 4 to Debian 5

Posted in

One of the server providers that I use for some reason only likes to deploy Debian 4, even though 5 is out and stable. Here's how to easily upgrade from Etch to Lenny via SSH/command line.

Edit /etc/apt/sources.list:

deb <a href="http://ftp.us.debian.org/debian/" title="http://ftp.us.debian.org/debian/">http://ftp.us.debian.org/debian/</a> etch main contrib non-free
deb-src <a href="http://ftp.us.debian.org/debian/" title="http://ftp.us.debian.org/debian/">http://ftp.us.debian.org/debian/</a> etch main contrib non-free

deb <a href="http://security.debian.org/" title="http://security.debian.org/">http://security.debian.org/</a> etch/updates main contrib non-free
deb-src <a href="http://security.debian.org/" title="http://security.debian.org/">http://security.debian.org/</a> etch/updates main contrib non-free

deb <a href="http://volatile.debian.org/debian-volatile" title="http://volatile.debian.org/debian-volatile">http://volatile.debian.org/debian-volatile</a> etch/volatile main contrib non-free
deb-src <a href="http://volatile.debian.org/debian-volatile" title="http://volatile.debian.org/debian-volatile">http://volatile.debian.org/debian-volatile</a> etch/volatile main contrib non-free

Then do the following:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade

After this completes, edit /etc/apt/sources.list and replace all instances of "etch" with "lenny":

deb <a href="http://ftp.us.debian.org/debian/" title="http://ftp.us.debian.org/debian/">http://ftp.us.debian.org/debian/</a> lenny main contrib non-free
deb-src <a href="http://ftp.us.debian.org/debian/" title="http://ftp.us.debian.org/debian/">http://ftp.us.debian.org/debian/</a> lenny main contrib non-free

deb <a href="http://security.debian.org/" title="http://security.debian.org/">http://security.debian.org/</a> lenny/updates main contrib non-free
deb-src <a href="http://security.debian.org/" title="http://security.debian.org/">http://security.debian.org/</a> lenny/updates main contrib non-free

deb <a href="http://volatile.debian.org/debian-volatile" title="http://volatile.debian.org/debian-volatile">http://volatile.debian.org/debian-volatile</a> lenny/volatile main contrib non-free
deb-src <a href="http://volatile.debian.org/debian-volatile" title="http://volatile.debian.org/debian-volatile">http://volatile.debian.org/debian-volatile</a> lenny/volatile main contrib non-free

Now we go through the update/upgrade/dist-upgrade process again, and then reboot:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo shutdown -r now

How-to: Convert mysql to sqlite

Posted in

I had a need today to convert a mysql database into a sqlite3 database.

First, you need this script:

#!/bin/bash
if [ "x$1" == "x" ]; then
  echo "Usage: $0 <dumpname>"
  exit
fi

cat $1 |
grep -v ' KEY "' |
grep -v ' UNIQUE KEY "' |
grep -v ' PRIMARY KEY ' |
sed '/^SET/d' |
sed 's/ unsigned / /g' |
sed 's/ auto_increment/ primary key autoincrement/g' |
sed 's/ smallint([0-9]*) / integer /g' |
sed 's/ tinyint([0-9]*) / integer /g' |
sed 's/ int([0-9]*) / integer /g' |
sed 's/ character set [^ ]* / /g' |
sed 's/ enum([^)]*) / varchar(255) /g' |
sed 's/ on update [^,]*//g' |
sed 's/\\r\\n/\\n/g' |
sed 's/\\"/"/g' |
perl -e 'local $/;$_=<>;s/,\n\)/\n\)/gs;print "begin;\n";print;print "commit;\n"' |
perl -pe '
if (/^(INSERT.+?)\(/) {
  $a=$1;
  s/\\'
\''/'\'\''/g;
  s/\\n/\n/g;
  s/\),\(/\);\n$a\(/g;
}
' > $1.sql
cat $1.sql | sqlite3 $1.db > $1.err
ERRORS=`cat $1.err | wc -l`
if [ $ERRORS == 0 ]; then
  echo "Conversion completed without error. Output file: $1.db"
  rm $1.sql
  rm $1.err
else
  echo "There were errors during conversion.  Please review $1.err and $1.sql for details."
fi

Then, dump a copy of your database:

josh@josh-laptop-work:~/tmp$ mysqldump -u root -p --compatible=ansi --skip-opt generator > dumpfile

And now, run the conversion:

josh@josh-laptop-work:~/tmp$ mysql-to-sqlite.sh dumpfile

And if all goes well, you should now have a dumpfile.db which can be used via sqlite3.

josh@josh-laptop-work:~/tmp$ sqlite3 dumpfile.db
SQLite version 3.6.10
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .tables
dg_cities                 dg_forms                  dg_surnames            
dg_counties               dg_provinces              dg_user_accounts        
dg_countries              dg_provinces_netherlands
dg_first_names            dg_states

How-to: Replace Keys of an Array in PHP

Posted in

I had a need tonight to replace the keys in an array in PHP. I couldn't find a good solution on any mailing lists or other sites, so I thought I'd share the class that I came up with, and it's test.

First up, the test:

<?php
require_once 'PHPUnit/Framework.php';
require_once 'ArrayHelper.class.php';

class ArrayHelperTest extends PHPUnit_Framework_TestCase
{
  public function testRenameKeys()
  {
    $keys   = array('newkey1',
                    'newkey2',
                    'newkey3');
                   
    $array  = array('oldkey1' => 'value1',
                    'oldkey2' => 'value2',
                    'oldkey3' => 'value3');
                   
    ArrayHelper::renameKeys($array,$keys);
   
    $this->assertArrayHasKey($keys[0],$array);
    $this->assertArrayHasKey($keys[1],$array);
    $this->assertArrayHasKey($keys[2],$array);
    $this->assertEquals(3,count($array));
  }
}

Next, the class itself, after the jump.

How-to: Drop all tables from a mysql database

Posted in

Much easier than have to drop a database, recreate it, and then grant privileges again.

mysqldump -u <username> -p <password> --add-drop-table --no-data <database> | grep ^DROP | mysql -u <username> -p <password <database>

How-to: Block Facebook Ads

So, upon logging into Facebook today, I was greeted by several new ads that Adblock Plus for Firefox wasn't blocking.

Frustrating.

Add the following filters to Adblock Plus to make them go away:

facebook.com#*(social_ad)
facebook.com#*(social_ad_advert)

Now I can continue using Facebook without having to deal with their stupid ads.

How-to: Compile ffmpeg from source

My last post talked about compiling ffmpeg on Ubuntu, for use with Drupal's op_video plugin. I then had to do the same thing on a Debian 4.0 server, and found that I had to compile literally every library from source, which means all of those handy apt-get lines do nothing for you. Here are the packages that you need:

How-to: Compile ffmpeg on Ubuntu

I needed to install the op_video module into a Drupal install today at work, and found that the default Ubuntu install of ffmpeg won't transcode audio properly for FLV files. Here are the steps to compile FLV and create a deb package that will work properly:

apt-get install liblame-dev libfaad2-dev libfaac-dev libxvidcore4-dev liba52-0.7.4 liba52-0.7.4-dev libx264-dev liba52-dev libdts-dev libgsm1-dev libvorbis-dev  libxvidcore4 libxvidcore-dev libdc1394-dev libfaac-dev liblame-dev libx264-dev libfaad2-dev libtheora-dev libsdl1.2-dev build-essential checkinstall subversion

How-to: Free Encrypted Online Storage on Ubuntu

So, since I've gotten Ubuntu setup the way that I want on my workstation, I've been trying to figure out a good way to back up everything that is free, encrypted, and doesn't run the risk of media dying. The solution? Using gmailfs + encfs to mount a spare GMail account and use that 5GB of space for something other than porn and penis-enlargement spam. I'll detail in another post how to setup the actual backup, but here I'll cover setting up the encrypted, online mount point in Ubuntu 7.10 (which will probably work for other distros).

How-to: htaccess and SSL redirects

So, you've got a site that you want to require SSL on, but not for certain pages? I couldn't seem to make sense of most of the documentation out there on Apache's mod_rewrite module, so after 3 days I finally came up with the rules that work for this task. I figured I'd put them up here to help anybody else who runs into a similar requirement, and so that I have it sitting somewhere that I won't forget about it!

<ifmodule>RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/cron\.php$
RewriteCond %{REQUEST_URI} !^/mysql.php$

How-to: Create a local copy of a dynamic site

Recently, there was a need at work to produce a static copy of a dynamic site, and have most everything still work. After a few minutes of research, I remembered that wget would take care of this just fine.

So I created a new site on one of our LAMP servers, and executed the following command in it's public_html directory:
wget --mirror -t 2 -w 2 -p -E --convert-links -T 5 -P . http://domainname/page
Worked like a charm :)

Syndicate content