Nexuiz Ninjaz - Practicing the Ninja Art of Nexuiz

Full Version: [bash] Move maps to a new copy of Nexuiz
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
About

To make upgrading easier, I've created a bash script to move all pk3's except common-spog.pk3 and data[0-9]{8}.pk3 to a new copy of Nexuiz.

Instructions

1. Save the following code as nn_map_copy.sh in your Nexuiz data directory.

Code:
#!/bin/bash
# nn_map_copy.sh - 06/02/2008 - v0.8
# Tyler "-z-" Mulligan of www.nexuizninjaz.com
# Used to copy all packages minus the common spog and data pack to a new dir

# Destination folder name, should be in the same directory as this Nexuiz' parent directory
echo "Where are these bad boys going? (Name of the new Nexuiz directory)"
read destination

# Copying or Moving?
echo "What action would you like to perform?"
PS3='Enter a #: '

# bash select
select action in "Copy" "Move"
do
  echo "Preparing to $action!"
  break # Break, otherwise endless loop
done

# Check for valid folder name - nohacksplz
if [[ $destination =~ ^[a-zA-Z0-9_-][a-zA-Z0-9_-]*$ ]]; then

    # Prepend the double drop
    final_destination="../../$destination/data"

    # Check to see if the destination directory exists
        if [ -d "$final_destination" ]; then

        # Create temp directory for common-spog.pk3 and data pack
        if [ -d "temp" ]; then
            echo "/!\ Directory \"temp\" already exists (but that's okay!)"
        else
            `mkdir temp`
        fi

        # Get the name of the data pack and move it with common-spog.pk3
        datapack=`ls |grep 'data[0-9]\{8\}'`

        # If you already moved these, it'll break here.  Let the script do the work.
        `mv $datapack temp/`
        `mv common-spog.pk3 temp/`
        
        # Perform the action
        echo $action"ing pk3's to \"$final_destination\""
        if [ $action == "Move" ]; then
            mv *.pk3 "$final_destination"
        else
            cp *.pk3 "$final_destination"
        fi

        # Clean up - Move common-spog.pk3 and data pack back to the data dir
        echo "Removing temp files"
        `mv temp/* .`
        `rmdir temp`
    else
        "/!\ Destination does not exist \"$final_destination\""
    fi
else
    echo "/!\ The destination \"$destination\" failed the search pattern \"[a-zA-Z0-9_-]+\""
fi

exit 0


2. chmod it so you can run it

Code:
chmod +x nn_map_copy.sh


3. Grab a copy the latest Nexuiz build and extract it to the same parent as the one you're upgrading from:

Code:
my_nexuiz_servers
  old_server
  new_server


4. Run it

Code:
./nn_map_copy.sh


5. Answer the questions.

Code:
Where are these bad boys going? (Name of the new Nexuiz directory)
new_server
What action would you like to perfom?
1) Copy
2) Move
Enter a #: 1
Preparing to Copy!
Copying pk3's to "../../new_server"
Removing temp files


Yay!

In case the server is running on Linux/Mac one can also put all the .pk3 files into ~/.nexuiz/data that way those files will be used regardless of which server version you install. For windows it uses c:\Documents and Settings\User\My Games\Nexuiz (if i remember correctly) either when the current user can not write to Nexuiz\data or used the parameter -mygames at startup. Or you can specify a complete path to use for the 'nexuiz user directory' with -userdir PATH (this works for all three systems, mac, linux, windows)
To be honest, this script is quite outdated. It was written to help myself learn to script bash. I've science accumulated a wealth of knowledge and techniques that could help improve this script... but it's been over shadowed by my unreleased server management tool.

However, it's still a useful script.
Reference URL's