PowerShell Script to Swap Halo’s Map Folder

Standard

Recently, Bungie patched Halo: Combat Evolved because it used GameSpy to generate the multiplayer server list, and GameSpy is shutting down.

I was inspired to re-install Halo and set up the old mods I used to play. My favorite was called “Snipers Dream Team Mod,” a mod in which snipers shoot tank shells… along with some other goodies.

Back when I played, enabling/disabling mods was fairly crude: you had to have a copy of every map that you would manually swap between.

I wanted to automate the process of swapping the map folders, so wrote the following PowerShell script. Coincidentally, it’s also my first ever script. I’m sure there are better ways to do it.

The script assumes that you have your default maps folder named “Maps” and your folder with SDTM mods named “Maps-SDTM.”

$root = "C:\Program Files (x86)\Microsoft Games\Halo"

# if sdtm is prefixed, install them
if(Test-Path("$root\Maps-SDTM"))
{
    Move-Item "$root\Maps" "$root\Maps-Default"
    Move-Item "$root\Maps-SDTM" "$root\Maps"
    [System.Windows.Forms.MessageBox]::Show("SDTM Maps Activated")
}
# otherwise install the default
else
{
    Move-Item "$root\Maps" "$root\Maps-SDTM"
    Move-Item "$root\Maps-Default" "$root\Maps"
    [System.Windows.Forms.MessageBox]::Show("Default Maps Activated")
}

Server Maintenance

Standard

Tonight, I decided it was time to give my web server some lovin’. I’ve been happily using Linode for 1.7 years (613 days to be exact) and have enjoyed 100% uptime in that time. Holy crap.

613 days uptimeNot long ago, Linode announced that they were giving everybody 8 cores. Wow, that’s awesome!.. but unfortunately means I’d have to restart the web server to take advantage of the awesomeness. Bye-bye uptime. I’ve been thinking about this for a couple weeks. At first, I didn’t think I’d restart the server until I absolutely had to, but there are some really cool things I want to do like install node.js (and passenger + gitlab).

Anyway, today I decided it was time to not only upgrade the web server’s hardware, but also the software. Might as well do it all at the same time, right?

Backing Up the Server

Obviously before attempting an upgrade such as this, I wanted to be sure I had a solid backup.

I’m slightly embarrassed to say this… actually, really embarrassed… but I don’t take regular backups of anything on my web server.

I host a couple of freebies and I take backups of those every couple of months, but that’s not nearly enough! I’m going to be adding Linode’s backup service for $5/mo. As they say when describing the backup features, I can “set it and forget it” — and I plan to.

I decided the easiest thing to do would be to take a dump of my databases and an archive of my www directory.

Backing up Databases

cd /tmp
mysqldump -uroot -p --all-databases > dump.sql

Easy.

Backing up Files

tar zcf www.tar.gz  /var/www/

This is where I ran into issues. This ran for about 10 minutes and during so, I thought, “I didn’t realize I had that much content in my web folder!” When it finally finished, the tarball was 4.95gb… WTF?!

Remember how I said I don’t take regular backups of anything on my web server? I was obviously wrong because my blog’s backup plugin was running a daily, and there were 250 backups. Oops.

I used the web interface to delete the backups so that it would delete the associated database records as well. I listed the backups, clicked the “Check all” checkbox, hit delete, aaaaannnnd…. Boom, HTTP 414 error. Request URI too Long… Huh? I figured I must have too many backups displaying per page, so I lowered it from 30 to 10. Same thing. Lowered it to five. Same thing. Then I noticed that my scrollbar was much longer than it should’ve been for 10 backups.

Turns out my backup plugin’s pagination was broken and all 250 backups were being listed, each time. I didn’t have the time or want to debug someone else’s “award-winning” plugin so I wrote some jQuery that when entered in the console, would select some of the checkboxes and click the delete button. Close enough to automated.

jQuery('input[name*=backupfiles]').slice(0, 25).each(function() {jQuery(this).prop('checked', true)});jQuery('select[name=action]').find('option[value=delete]').prop('selected', true);jQuery('#doaction').trigger('click');

After I got those all deleted, I took another backup and it was 1.32gb. Much more aligned to my expectations.

Taking the Server Offline

I really hesitated for a good minute before typing “reboot.” 100% uptime is insane… but so is having 8 cores without having to pay any extra…

Rebooting Linode Server

It took about 45 seconds for everything to come back online. Not bad. Bye-bye awesome uptime, but heeelllloooooooooo insane computing power!

Updating the Software

I wasn’t nearly as worried about this part of the process. I love APT.

apt-get update
apt-get upgrade

Notable upgrades include various networking utilities, MySQL, nginx, perl, PHP (and 10+ dependencies) and Redis. Updated without a hitch. (Although I did need to update some config files.)

What to Do Now!

Now that the upgrade is completed, I plan on tearing through the web server and essentially starting the config from scratch. I want to get a node.js + nginx setup going, install Passenger because I’m becoming increasingly interested in Python and Ruby and switch MySQL to MariaDB. Probably some other things too, but not at this point.