<?xml version="1.0" encoding="iso-8859-1" ?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
	<atom:link href="http://www.m0interactive.com/rss/articles.xml" rel="self" type="application/rss+xml" />
	<title>Mohamed Mansour | articles</title>
	<copyright>Copyright (c) 2006 Mohamed Mansour! Inc. All rights reserved.</copyright>
	<link>http://www.m0interactive.com/</link>
	<description>Mohamed Mansour RSS Feeds</description>
	<language>en-us</language> 
	<item>
		<title>Software - How to read and write from linux ext3 partition in windows</title>
		<link>http://www.m0interactive.com/archives/2009/05/24/how_to_read_and_write_from_linux_ext3_partition_in_windows.html</link>
		<description><![CDATA[<p>As a Software Engineer, I like to experiment many languages and operating systems. That is why I duel boot Linux (Ubuntu), Windows (XP), and an Apple Laptop (OSX). When I am working with Chromium (Open source browser for Google Chrome), I would like to access my ext3 Linux partition from Windows so I could work on the same code base. I will discuss which solutions I found working and efficient.</p>

<p>As far as I know, I heard of two softwares which allows an ext2 file system driver for winnt/win2k/winxp.</p>
<ol>
<li>Ext2-IFS - <a href="http://www.fs-driver.org/">http://www.fs-driver.org/</a></li>
<li>Ext2Fsd - <a href="http://ext2fsd.sourceforge.net/projects/projects.htm#ext2fsd">http://ext2fsd.sourceforge.net/projects/projects.htm#ext2fsd</a></li>
</ol>

<p>They are both file system drivers which are pure kernel mode, that extends the Windows operating system to include the Ext2 file system.</p>

<p>Ext2-IFS has a superb user interface to it, and I love UIs! While Ext2Fsd has more adminstrations. I tried both, but Ext2-IFS didn't work for me for some reason, it kept on saying "The disk in drive ? is not formatted. Do you want to format it now?" I really wanted it to work, but Ext2Fsd worked flawlessly after a restart. </p>

<p>Now I have my Linux-Windows bridge connected :)</p>]]></description>
		<pubDate>Sun, 24 May 2009 02:51:24 -0400</pubDate>
		<guid>http://www.m0interactive.com/archives/2009/05/24/how_to_read_and_write_from_linux_ext3_partition_in_windows.html</guid>
	</item>
	<item>
		<title>Java - Google App Engine Plugin for Eclipse in Ubuntu</title>
		<link>http://www.m0interactive.com/archives/2009/05/13/google_app_engine_plugin_for_eclipse_in_ubuntu.html</link>
		<description><![CDATA[<p>Installing Google Plugin for Eclipse in Ubuntu should be easy, but it requires some work to make it actually "work". I am using Ubuntu 9.04 Jaunty which got released this month.</p>

<h3>Installing latest Eclipse version in Ubuntu</h3>
<p>First of all, Ubuntu 9.04 ships with Eclipse 3.2.2 IDE, to run Google Plugin, it requires you to have at least an Eclipse 3.3 version. I installed the latest, 3.4 Eclipse IDE.</p>

<p>To do that, I did not use the Ubuntu synaptic repository, I just visited <a href="http://www.eclipse.org/downloads/">http://www.eclipse.org/downloads/</a> and downloaded "Eclipse IDE for Java Developers". I extracted it and then ran eclipse. Now I have the latest version of Eclipse installed. (Eclipse 3.4.2 on Ubuntu Jaunty)</p>

<h3>Installing the plugin</h3>
<p>I followed the following documentation <a href="http://code.google.com/eclipse/docs/install-eclipse-3.4.html"> http://code.google.com/eclipse/docs/install-eclipse-3.4.html</a>, since I am familiar with installing Eclipse plugins, I added <strong>http://dl.google.com/eclipse/plugin/3.4</strong> as a Site to my available software under Help > Software Updates.</p>

<h3>Running a Google Web Applicaiton</h3>
<p>To create your first Web Application, select <strong>File > New > Web Application Project</strong> from the Eclipse menu.</p>

<p>In the <strong>New Web Application Project</strong> wizard, enter a name for your project and a java package name, e.g., com.example.mywebapp. Click <strong>Finish</strong>.</p>

<p>You now have an App Engine and GWT-enabled web application!</p> 

<h3>How to run your application! (And fix the initial error!)</h3>
<p>Right-click on your web application project and select <strong>Debug As > Web Application</strong> from the popup menu. Oh wait, an error occurs: </p>

<pre>
ubuntu java.lang.UnsatisfiedLinkError: ubuntu java.lang.UnsatisfiedLinkError: com.google.gwt.eclipse.sdkbundle.linux_1.6.4.v200904062334/gwt-linux-1.6.4/mozilla-1.7.12/libxpcom.so: libstdc++.so.5: cannot open shared object file: No such file or directory
</pre>

<p>The reason why this error exists is because in order to run a Google Web Application, we need libstdc++5, you could install it within your Synaptic Package manager or via aptitude:</p>
<pre>
sudo apt-get install libstdc++5
</pre>

<p>Run it again, and it will work fine!</p>

<p>Have fun programming! Java on App Engine!</p>]]></description>
		<pubDate>Wed, 13 May 2009 19:36:24 -0400</pubDate>
		<guid>http://www.m0interactive.com/archives/2009/05/13/google_app_engine_plugin_for_eclipse_in_ubuntu.html</guid>
	</item>
	<item>
		<title>Java - How to get the list of files in a directory inside a JAR file</title>
		<link>http://www.m0interactive.com/archives/2009/04/29/how_to_get_the_list_of_files_in_a_directory_inside_a_jar_file.html</link>
		<description><![CDATA[<p>A Java snippet for the day. You cannot simply use a "File" object to grab a list of files from a directory within a JAR file. You would need to iterate through the JAR entries, one by one, (unless I am mistaken). With this approach, you can quickly supply some sort of regex filter, that will return a list of file paths for what your searching.</p>

<h2>Code</h2>
<pre>
    /**
     * <p>Retrieve a list of filepaths from a given directory within a jar
     * file. If filtered results are needed, you can supply a |filter| 
     * regular expression which will match each entry. 
     *
     * @param filter to filter the results within a regular expression.
     * @return a list of files within the jar |file|
     */
    public static List<String> getJarFileListing(String file, String filter) {
        List<String> files = new ArrayList<String>();
        if (jarLocation == null) {
            return files; // Empty.
        }
        
        // Lets stream the jar file 
        JarInputStream jarInputStream = null;
        try {
            jarInputStream = new JarInputStream(new FileInputStream(jarLocation));
            JarEntry jarEntry;
            
            // Iterate the jar entries within that jar. Then make sure it follows the
            // filter given from the user.
            do {
                jarEntry = jarInputStream.getNextJarEntry();
                if (jarEntry != null) {
                    String fileName = jarEntry.getName();

                    // The filter could be null or has a matching regular expression.
                    if (filter == null || fileName.matches(filter)) {
                        files.add(fileName);
                    }
                }
            }
            while (jarEntry != null);
            jarInputStream.close();
        }
        catch (IOException ioe) {
            throw new RuntimeException("Unable to get Jar input stream from '" + jarLocation + "'", ioe);
        }
        return files;
    }
</pre>

<h2>Examples</h2>
 <p>a) Find all files under /com/:</p>
 <pre>
List<String> files = getJarFileListing("file.jar", "^com/(.*)")
 </pre> 

<p>a) Find all files under /template/ that has a .tpl extension:</p>
 <pre>
List<String> files = getJarFileListing("file.jar", "^template/(.*).tpl$")
 </pre> ]]></description>
		<pubDate>Wed, 29 Apr 2009 13:33:31 -0400</pubDate>
		<guid>http://www.m0interactive.com/archives/2009/04/29/how_to_get_the_list_of_files_in_a_directory_inside_a_jar_file.html</guid>
	</item>
	<item>
		<title>Software - Quick way searching comments from svn using bash script</title>
		<link>http://www.m0interactive.com/archives/2009/04/23/quick_way_searching_comments_from_svn_using_bash_script.html</link>
		<description><![CDATA[<p>As far as I know, there is no mechanism to search "svn log" for a specific comment. Sure you can do "svn log | grep Mohamed", but that will just give you the line where that comment was found. I wanted more information, such as revision number.</p>

<p>So I created a very simple script (there are a gazillion other ways to do it), that you give it a regular expression as argument (quoted of course). And it will search svn's log quickly using bash. Just save the contents below to a file, and let it run!</p>

<pre>
#!/bin/sh
SEARCH=$1
echo "Searching for ["$SEARCH"]"
svn log | awk '{
  if ( $1 == "------------------------------------------------------------------------") {
    getline
    REVISION = $1
    COMITTER = $3
    DATE = $5
    LINES = $13
  }
  else {
    if (match($0, SEARCH)) {
      TOTAL=TOTAL+1
      print "-[",TOTAL,"]------------------"
      print " Revision: ", REVISION
      print " Comitter: ", COMITTER
      print " Date: ", DATE
      print " Lines Changed: ", LINES
    }
  }

}' SEARCH="$SEARCH"
</pre>

<p>After you save that script and run it, (make sure you chmod +x) you will see a pretty view of what you have searched within the comments. For example: </p>

<pre>
$ ./svnsearch.sh "Mohamed"
Searching for [Mohamed]
-[ 1 ]------------------
 Revision:  r13831
 Comitter:  hbono@chromium.org
 Date:  2009-04-16
 Lines Changed:  15
-[ 2 ]------------------
 Revision:  r13616
 Comitter:  tc@google.com
 Date:  2009-04-13
 Lines Changed:  28
-[ 3 ]------------------
 Revision:  r13426
 Comitter:  maruel@chromium.org
 Date:  2009-04-09
 Lines Changed:  52

...
...
</pre>

<p>Enjoy! If you have any updated version, I would love to see how you improved it!</p>]]></description>
		<pubDate>Thu, 23 Apr 2009 01:20:28 -0400</pubDate>
		<guid>http://www.m0interactive.com/archives/2009/04/23/quick_way_searching_comments_from_svn_using_bash_script.html</guid>
	</item>
	<item>
		<title>Software - Google Chrome introduces Fullscreen mode</title>
		<link>http://www.m0interactive.com/archives/2009/02/18/google_chrome_introduces_fullscreen_mode.html</link>
		<description><![CDATA[<p>Chromium 2.0.165.0 (Developer Build 9992) introduces Fullscreen mode for the browser. By pressing F11, it will do the trick!</p>

<p>This was one of the most requested features, and works great! If you would like to give it a try, you can install one of the continuous builds (which isn't stable), and see for your self!</p>

<p><a href="http://build.chromium.org/buildbot/continuous/LATEST/">http://build.chromium.org/buildbot/continuous/LATEST/</a><p>]]></description>
		<pubDate>Wed, 18 Feb 2009 21:35:55 -0500</pubDate>
		<guid>http://www.m0interactive.com/archives/2009/02/18/google_chrome_introduces_fullscreen_mode.html</guid>
	</item>
	<item>
		<title>WebDesign - How to redirect to a website with POST data ASP PHP</title>
		<link>http://www.m0interactive.com/archives/2009/01/20/how_to_redirect_to_a_website_with_post_data_asp_php.html</link>
		<description><![CDATA[<p>There are some situations where you would need to redirect to a webpage with post parameters being sent using any web scripting language such as PHP, ASP, JSP, etc ... Sure you can download a webpage with post request, but that doesn't mean redirection. I have done this today to help out a colleague, and would like to share some of the problems that came in the way, and hope it will help anyone that has problems.</p>

<p>Basically, we had to redirect to a Dot Net Nuke (DNN) page so that we could log in a browser control within a Java application.  DNN login component uses POST requests. Some Java browser components such as JDIC can redirect to a page with POST but that library is not reliable, we were using other browser libraries which does not allow the user to navigate to a page with post parameters (since its not implemented in SWT Browser). Even if the browser libraries allow us to send post redirects, it still wont solve our main problem. Our main problem was to redirect to a POST page and set some session variables while navigating to that page. Therefore, this proposed idea works perfect.</p>

<p>Many people online recommended creating a dummy html page that will use some basic javascript to submit the form. That idea works great. I will explain how that works in detail with a working example including setting session variables while redirecting. The main files that you should look at would one of these, depending if you want to do it in PHP or ASP.NET "<strong> redirectform.php</strong>" or "<strong> redirectform.aspx</strong>"</p>

<p>I have done a simple example that will show the process. The same would be applied to any page, like a Dot Net Nuke page. The page which we want to redirect to with post looks like the following:</p>
<pre>
<html>
<head>
  <title>Login Page</title>
</head>
<body>
  <h1>Please Login!</h1>
  <form name="login" action="login.php" method="post">
    <input type="text" name="username" value="" />
    <input type="password" name="password" value="" />
    <input type="submit" name="submit" value="Login" />
  </form>
</body>
</html>
</pre>

<p><strong>login.php</strong> - This is just a simple page where it will echo out to the screen if a post has been submitted.</p>
<pre>
<?php
session_start();
if (isset($_POST['username']) && isset($_POST['password'])) echo 'Logged In';
else echo 'Not Logged In';

if (isset($_SESSION['somesessionvar'])) 
  echo 'Session: ', $_SESSION['somesessionvar'];
?>
</pre>

<fieldset>
<legend>Notice:</legend>
<p>Session variables are stored per website/server so in this example, the redirect files are stored on the same server where we want to redirect, or my session wont work because they are not on the same domain.</p>
</fieldset>

<p><strong>redirectform.php</strong> - A basic form that when you open it, it will redirect directly to the post.php using POST parameters.</p>
<pre>
<?php
  session_start();
  $username = isset($_GET['username'] ? $_GET['username'] : ''; 
  $password = isset($_GET['password'] ? $_GET['password'] : '';
  $_SESSION['somesessionvar'] = 'testing';
?>
<html>
<head>
  <script type="text/javascript">
  function doPost() {
    document.getElementById("TestForm").submit();
  }
  </script>
</head>
<body>
  <form id="TestForm" action="login.php" method="post">
    <input type="hidden" name="username" value="<?=$username?>" />
    <input type="hidden" name="password" value="<?=$password?>" />
  </form>
</body>
</html>
</pre>

<p>A similar one in ASP.NET / ASP could be the following <strong>redirectform.aspx</strong>. In this example, will use aspx, converting this to classic asp is relatively simple, just remove the types, and Dim to dim.</p>
<pre>
<%
  Dim username As String = Request.QueryString("username")
  Dim password As String = Request.QueryString("password")
  Session("somesessionvar") = "testing";
%>
<html>
<head>
  <script type="text/javascript">
  function doPost() {
    document.getElementById("TestForm").submit();
  }
  </script>
</head>
<body>
  <form id="TestForm" action="login.php" method="post">
    <input type="hidden" name="username" value="<% Response.Write(username) %>" />
    <input type="hidden" name="password" value="<% Response.Write(password) %>" />
  </form>
</body>
</html>
</pre>

<fieldset>
<legend>Very Important regarding Javascript submit():</legend>
<p>You have to remember that when you send a javascript submit call, input of type submit and button will NOT be submitted as POST.</p>

<p>Many websites depend on the submit value, and that will only be submitted if you click on that button, and if you don't click on any button "hence javascript", you need to find alternatives.</p>

<p>Such an alternative would be converting all submitted form variables to input type hidden. That way it will be submitted with the rest of the request post data.</p>
</fieldset>

<p>That is it, you will just need to redirect to that redirection page and it automatically let javascript to submit that invisible form.</p>
<pre>header('http://localhost/redirectform.php?username=m0&password=123')</pre>
<p>Or in ASP.NET</p>
<pre>Response.Redirect("http://localhost/redirectform.aspx?username=m0&password=123'")</pre>

<p>Thats all, it solved my problems, and I hope it solves yours.</p>]]></description>
		<pubDate>Tue, 20 Jan 2009 23:04:59 -0500</pubDate>
		<guid>http://www.m0interactive.com/archives/2009/01/20/how_to_redirect_to_a_website_with_post_data_asp_php.html</guid>
	</item>
	<item>
		<title>Univerisity - Lanopolis 5 introduces a bigger LAN Party in Ottawa</title>
		<link>http://www.m0interactive.com/archives/2009/01/18/lanopolis_5_introduces_a_bigger_lan_party_in_ottawa.html</link>
		<description><![CDATA[<p>Lanopolis is back hosting one of Ottawa's biggest Lan parties! With over 120+ seats available, serving PC, XBOX, PS3, WII, and DDR, this will be one of the most enjoyable ones out there!</p>

<ul>
<li><strong>Website:</strong> <a href="http://lanopolis.ca">http://lanopolis.ca</a></li>
<li><strong>IRC:</strong> #lanopolis @ IRC.GameSurge.NET <a href="irc://irc.gamesurge.net/lanopolis">connect</a></li>
<li><strong>Location:</strong> 550 Cumberland St., Ottawa, ON, Canada, K1N 6N5, Tabaret Hall, University of Ottawa </li>
<li><strong>Price:</strong> $35 </li>
<li><strong>Prizes:</strong> Over $1000 of prizes</li>
<li><strong>Games:</strong> DoTA, CoD4, TF2, etc</li>
<li><strong>Facebook:</strong> <a href="http://www.facebook.com/event.php?eid=43402834867"> http://www.facebook.com/event.php?eid=43402834867</a></li>
</ul>

<img src="http://i42.tinypic.com/2q3vgxg.png" alt="Lanopolis 5"/>]]></description>
		<pubDate>Sun, 18 Jan 2009 15:30:52 -0500</pubDate>
		<guid>http://www.m0interactive.com/archives/2009/01/18/lanopolis_5_introduces_a_bigger_lan_party_in_ottawa.html</guid>
	</item>
	<item>
		<title>Java - Using hardware acceleration for Java2D</title>
		<link>http://www.m0interactive.com/archives/2008/12/30/using_hardware_acceleration_for_java2d.html</link>
		<description><![CDATA[<p>Java2D is the main thing that drives Swing rendering, and Java2D does not benefit from hardware acceleration by default on any platform. Java2D does offer hardware acceleration through its OpenGL and Direct3D rendering pipelines which are not enabled by default. It is only available on the Java SE 5+.</p>

<h3>How to enable hardware acceleration for Java2D?</h3>
<p>Within your command-line flags, add the following:</p>
<h4>OpenGL</h4>
<pre>
-Dsun.java2d.opengl=true
</pre>

<h4>Direct3D</h4>
<pre>
-Dsun.java2d.d3d=true
</pre>

<p>A side note, when dealing with images and complicated paintings within Swing, don't let this acceleration stop you from optimizing your Swing rendering. For instance, the use of clips, compatible images, managed images, intermediate images, will help improve performance greatly. I might do a blog post regarding how to improve custom rendering in Swing.</p>]]></description>
		<pubDate>Tue, 30 Dec 2008 10:05:36 -0500</pubDate>
		<guid>http://www.m0interactive.com/archives/2008/12/30/using_hardware_acceleration_for_java2d.html</guid>
	</item>
	<item>
		<title>Technology - Quake Live Invites who wants them</title>
		<link>http://www.m0interactive.com/archives/2008/10/12/quake_live_invites_who_wants_them.html</link>
		<description><![CDATA[<img src="http://www.idsoftware.com/images/quakelive_logo_300.png" alt="quake live" />
<p>I have a couple of Quake Live invites! It is an awesome Quake 3 remake online! Just open your browser and play. Amazingly, only 8 internal IDSOFTWARE developers working on it and 4 contractors. It is a game every computer enthusiast should play :) They usually roll out invites every once a while and I will be happy to invite you guys!</p>

<p>Quake Live Website: <a href="http://www.quakelive.com">http://www.quakelive.com</a></p>


<fieldset>
<legend>NOTICE:</legend>
They are going to make it Open Beta! Within the comments, Mkem pointed out, that Quake Live will open up beta to anyone! <a href="http://m0interactive.com/archives/2008/10/12/quake_live_invites_who_wants_them.html,comments#517">Read it here!</a> No need for invites, you can just register normally and get an account!
</fieldset>]]></description>
		<pubDate>Sun, 12 Oct 2008 20:40:41 -0400</pubDate>
		<guid>http://www.m0interactive.com/archives/2008/10/12/quake_live_invites_who_wants_them.html</guid>
	</item>
	<item>
		<title>Software - Steam linux server init script in chrooted environment</title>
		<link>http://www.m0interactive.com/archives/2008/09/13/steam_linux_server_init_script_in_chrooted_environment.html</link>
		<description><![CDATA[<p>I have a Linux TF2 Server and Linux CSS Server on Debian, and I wanted to properly make an init script to start/stop the server and must run under a given user other than root.</p>

<p>Thanks to the initial post by scriptfu @ <a href="http://forums.srcds.com/viewtopic/5835">srcds.com</a> and the updated portion by Arujei.</p>

<h3>Introduction</h3>
<p>First of all, everyone knows it isn't great to run a server with root privileges. It is better to run it under a user which has no association to root. This tutorial will be based no Debian operating system. Could be applied to any os. In this setup we will make sure that any user belonging to "tf2server" group could actually run the server. While the server is running, it will run it as the user "tf2server". Again, any user belonging to that group could start and stop the server successfully. As well, we will be installing the tf2server under the "/usr/local/games/tf2/"</p>

<p>First of all, need to make sure you have "sudo" properly setup.</p>
<pre>
$ aptitude install sudo
</pre>

<p>Lets create a user called "tf2server" (note this will create a group called tf2server as well!:</p>
<pre>
$ adduser tf2server
</pre>

<p>First of all, make sure you have the tf2 server installed in some location, I choose this (apply proper permissions):</p>
<pre>
$ mkdir /usr/local/games/tf2/
$ chown -R tf2server:tf2server /usr/local/games/tf2
</pre>

<p>Lets alter the sudoers file: </p>
<pre>
$ visudo /etc/sudoers
</pre>

<p>With this line</p>
<pre>
%tf2server ALL=(tf2server) NOPASSWD: /usr/local/games/tf2/
</pre>

<p>Save this script inside the "/usr/local/games/tf2/" as "server-launch"</p>
<pre>
#! /bin/sh

# Server options
TITLE='Source Dedicated Server'           # Script initialization title
LONGNAME='Team Fortress 2'                # Full title of game type
NAME='tf2'                                # Server handle for the screen session
DAEMON='srcds_run'                        # The server daemon
UPDATER='/usr/local/games/tf2/'           # The Steam updater. I recommend keeping it one directory below orangebox for tf2 servers.
STEAM='/usr/local/games/tf2/orangebox'    # STEAM to Steam installation
USER='tf2server'                          # User that this will be running under. Currently not functional part of this script.

# Game options
CLIENT='Team Fortress 2 Development Server'  #Game Server name.
IP='127.0.0.1'                            # IP of the server
PORT='27015'                              # Port number to
MAP='ctf_2fort'                           # Initial map to start
GAME='tf'                                 # Game type (tf|cstrike|valve|hl2mp)
SIZE='32'                                 # Maximum number of players
HIGHPRIORITY=1                            # Set server renice to -20 will make server take priority over all other applications on server. 1 being on and 0 being off.

# Server options string
OPTS="-game $GAME +hostname \"$CLIENT\" +map $MAP +ip $IP -port $PORT \
    -autoupdate +maxplayers $SIZE -pidfile $STEAM/$GAME/$NAME.pid"

INTERFACE="/usr/bin/screen -A -m -d -S $NAME"

# Screen command
CURRENT_USER=$(/usr/bin/whoami)

if [ "$CURRENT_USER" != "$USER" ]; then
    echo "$TITLE cannot run on user ($CURRENT_USER)";
    exit
fi

service_start() {
    # Check if the pid files currently exist
    if [ -f $STEAM/$GAME/$NAME.pid ] || [ -f $STEAM/$GAME/$NAME-screen.pid ]; then
        # Pid files allready exist check if the process is still running.
        if [ "$(ps -p `cat $STEAM/$GAME/$NAME.pid` | wc -l)" -gt 1 ]; then
            # Process is still running.
            echo -e "Cannot start $TITLE.  Server is already running."
        #exit 1
        else
        # Process exited with out cleaning up pid files.
            if [ "$(ps -p `cat $STEAM/$GAME/$NAME.pid` | wc -l)" -gt 1 ]; then
            # Screen is still running.
            # Get the process ID from the pid file we created earlier
                for id in `cat $STEAM/$GAME/$NAME-screen.pid`
                do kill -9 $id
                echo "Killing process ID $id"
                echo "Removing $TITLE screen pid file"
                rm -rf $STEAM/$GAME/$NAME-screen.pid
                break
                done
            fi
        # Remove server pid file
        echo "Removing $TITLE pid file"
        rm -rf $STEAM/$GAME/$NAME.pid

        # Wipe all old screen sessions
        screen -wipe 1> /dev/null 2> /dev/null
        service_start
        fi
    else
    # Server is not running start the server.
        if [ -x $STEAM/$DAEMON ]; then
            echo "Starting $TITLE - $LONGNAME - $CLIENT"
            echo "Server IP: $IP"
            echo "Server port: $PORT"
            echo "Server size: $SIZE players"
            cd $STEAM
            $INTERFACE $STEAM/$DAEMON $OPTS
            # Prevent race condition on SMP kernels
             sleep 1
            # Find and write current process id of the screen process
            ps -ef | grep SCREEN | grep "$NAME" | grep -v grep | awk '{ print $2}' > $STEAM/$GAME/$NAME-screen.pid
            echo "$TITLE screen process ID written to $STEAM/$GAME/$NAME-screen.pid"
            echo "$TITLE server process ID written to $STEAM/$GAME/$NAME.pid"

            echo "$TITLE started."
            # Was having problems with directory permisions due to ftp access making these files unreadable by users other than owner.
            chmod 666 $STEAM/$GAME/*.pid 1> /dev/null 2> /dev/null
            # Make any pid files created by different users owned by the set user.
            chown $USER $STEAM/$GAME/*.pid 1> /dev/null 2> /dev/null
            sleep 2
            if [ $HIGHPRIORITY = 1 ]; then
                renice -20 `cat $STEAM/$GAME/$NAME.pid` >/dev/null 2>&1
            fi
        fi
    fi
}

service_stop() {
    if [ -f $STEAM/$GAME/$NAME.pid ] || [ -f $STEAM/$GAME/$NAME-screen.pid ]; then
        echo "Stopping $TITLE - $LONGNAME."
        # Get the process ID from the pid file we created earlier
        for id in `cat $STEAM/$GAME/$NAME-screen.pid`
            do kill -9 $id
            echo "Killing process ID $id"
            echo "Removing $TITLE screen pid file"
            rm -rf $STEAM/$GAME/$NAME-screen.pid
            break
        done
        # Remove server pid file
        echo "Removing $TITLE pid file"
        rm -rf $STEAM/$GAME/$NAME.pid
        # Wipe all old screen sessions
        screen -wipe 1> /dev/null 2> /dev/null
        echo "$TITLE stopped."
    else
        echo -e "Cannot stop $TITLE.  Server is not running."
        #exit 1
    fi
}

service_clear() {
    # Removing all pid files
    echo "Removing all Service pid files."
    rm -rf $STEAM/$GAME/*.pid 1> /dev/null 2> /dev/null
}

service_update() {
    echo "Stopping and Clearing all Service files."
    service_stop
    sleep 2
    service_clear
    sleep 2
    echo "Updating Steam Updater"
    cd $UPDATER
    ./steam 1> /dev/null 2> /dev/null
    echo "Updating Game Files"
    ./steam -command update -game $GAME -dir . 1> /dev/null 2> /dev/null
    sleep 2
    service_start
}

case "$1" in
    'start')
        service_start
        ;;
    'stop')
        service_stop
        ;;
    'restart')
        service_stop
        sleep 1
        service_start
        ;;
    'clear')
        service_clear
        ;;
    'update')
        service_update
        ;;
    *)
        echo "Usage $0 start|stop|restart|clear|update"
esac
</pre>

<p>Since that script should run under the user specified, "tf2server", you could do the following:</p>
<pre>
$ sudo -u tf2server /usr/local/games/tf2/server-launch
</pre>

<p>Or you could create your own local script that will have that inside, an example could be like this, save as "launchServer":</p>
<pre>
#! /bin/sh
sudo -u tf2server /usr/local/games/tf2/server-launch $@
</pre>

<p>Now you can do commands such as:</p>
<ul>
<li> ./launchServer start</li>
<li> ./launchServer stop</li>
<li> ./launchServer restart</li>
<li> ./launchServer update</li>
</ul>

<p>Hope that helps anyone!</p>]]></description>
		<pubDate>Sat, 13 Sep 2008 16:56:14 -0400</pubDate>
		<guid>http://www.m0interactive.com/archives/2008/09/13/steam_linux_server_init_script_in_chrooted_environment.html</guid>
	</item>
</channel>
</rss><!-- m0|XML Creator v1 -->
