Sunday, July 14, 2013

Pioneers - Map editor, .game files location, and folder permissions

Pioneers is a game based on the Settlers of Catan, with multiplayer support and a map editor. However, the instructions for creating/saving/using your own maps is a bit lacking


Map editing and permissions

Default .game maps are stored in /usr/local/share/games/pioneers/ (in Ubuntu 10.04 at least), so this is where I put custom maps for the longest time. However, you must have su permissions to do this, which is kind of inconvenient. You have to either run the editor with sudo, or copy the map file with sudo. The first option works the best, but neither are options for users who don't have permissions.

Per this discussion post: http://sourceforge.net/p/pio/discussion/15657/thread/5200c3a0/, one option is to put maps in "$XDG_DATA_HOME/pioneers (default: $HOME/.local/share/pioneers)". A user folder, sweet!

Only problem is, this environment variable is not defined by default in Ubuntu. This post helped me to get it working: http://crunchbang.org/forums/viewtopic.php?id=15021, and this is what I ended up doing:

Edit config file:
gedit ~/.config/user-dirs.dirs
Add line to define environment variable, then save file:
XDG_DATA_HOME="$HOME/.local/share"
Edit your .profile file:
gedit ~/.profile
Add this block of code at the end, then save file:
if [ -f ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs ]; then
  . ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs
  export XDG_DATA_HOME
fi

Create the folder in your user directory. Open a Terminal window (Application > Accessories > Terminal), and type:
mkdir -p ~/.local/share/pioneers
Log out / restart for changes to take effect.

When you go to save a map, I think it will take you directly to the folder. If not, you can make a link in Nautilus (the file browser). Open it up, make sure the location bar is visible (View > Location Bar), then press Ctrl + L (or Go > Location), type ~/.local/share and press Enter. Drag the pioneers folder from the right pane into the left pane at the bottom of the list.

Now, standard users can edit and save custom maps, and they show up when running a server. Tiiight.


* NOTE on v14.1 - Map editor does not save the game's title

This is just a minor note, but in v14.1 the pioneers-editor does not save the title/name of the game if edited from the Comments tab. It can, however, be set from the File > Change Title menu. Or you can edit the .game file with a text editor and manually enter the title. This has been already submitted as a bug, and fixed: http://sourceforge.net/p/pio/bugs/277/, just waiting for a new version of the game to be released.

Wednesday, May 29, 2013

Scheduling ZoneMinder to turn on/off at sunrise/sunset

I wanted to turn ZoneMinder on and off at sunrise and sunset, to save some CPU and network traffic. This is how I did it.


ZoneMinder Setup

The ZoneMinder wiki has instructions for creating different "run states" which can be turned on/off from the command line. Since my setup is not complicated, I simply used the default "start" and "stop" run states. It also covers scheduling these run state changes, but the cron entries are static. We need times to change dynamically for sunrise/sunset.


Sunwait

"Sunwait is a small C program for calculating sunrise and sunset, as well as civil, nautical, and astronomical twilights . . . The feature that makes this program slightly unique is that it can be set to wait specific event (such as 5 minutes before sunrise), then exit. This makes it useful for 'cron' jobs or 'scheduled tasks' when you want something to happen relative to sunrise, sunset, or some other astronomical event."

So basically, we will use Cron to schedule Sunwait to "wait" until sunrise/sunset, and then run our command/script.


Download: http://www.risacher.org/sunwait/

Extract / build / move to bin
tar -xvf sunwait-20041208.tar.gz
cd sunwait-20041208
make
(ignore compilation errors, should be ok)
sudo cp sunwait /usr/bin


Cron

Add su crontab entries. Those below start at 01:00 and 13:00, plenty of time before sunrise and sunset. The important thing is that they are scheduled before the earliest sunrise/sunset.

sudo crontab -e
(select default editor)
0 01 * * * /script/location/zm-sun.sh sunrise
0 13 * * * /script/location/zm-sun.sh sunset


Main script

The script checks the current run state, changes it based on the command line argument, and does some basic logging. This example starts ZoneMinder 30 minutes before sunrise and stops it 30 minutes after sundown.

zm-sun.sh
#!/bin/bash

# script to start / stop ZoneMinder based on sunrise / sunset
#
# usage:
# zm-sun.sh sunrise
# zm-sun.sh sunset


s=`zmpkg.pl status`

if [[ "$1" == "sunrise" ]]
  then
    if [[ "$s" == "stopped" ]]
      then
        sunwait sun up -00:30:00 38.794433N, 77.069450W ; zmpkg.pl start
        s=`zmpkg.pl status`
      else
        s="already running"
    fi
elif [[ "$1" == "sunset" ]]
  then
    if [[ "$s" == "running" ]]
      then
        sunwait sun down +00:30:00 38.794433N, 77.069450W ; zmpkg.pl stop
        s=`zmpkg.pl status`
      else
        s="already stopped"
    fi
fi

echo [`date`] Zoneminder $s, $1 >> /script/location/sunwait.log

exit



Make sure to enable execute permissions on the script
chmod +x zm-sun.sh

Enjoy

Sunday, March 17, 2013

MikroTik remote logging using Ubuntu 10.04 and rsyslog

Quick and easy setup for basic remote logging.


Ubuntu Setup



/etc/rsyslog.conf
Uncomment these lines, since RouterOS sends log via UDP on port 514:
$ModLoad imudp
$UDPServerRun 514

/etc/rsyslog.d/50-default.conf
Add line(s):
:fromhost-ip,isequal,"192.168.x.1" /var/log/mikrotik-Router1.log
:fromhost-ip,isequal,"192.168.x.2" /var/log/mikrotik-Router2.log

Restart the rsyslog service:
sudo service rsyslog restart

Various ways to view logs:
System Log Viewer (GUI)
Terminal: tail -f /var/log/mikrotik-Router1.log

* Don't forget to allow IP traffic through firewall


MikroTik Setup


Configure logging:

/system logging action
set 3 bsd-syslog=no name=remote remote=192.168.x.x remote-port=514 src-address=0.0.0.0 syslog-facility=daemon syslog-severity=auto target=remote
/system logging
add action=remote disabled=no prefix="" topics=!debug


Other


Log rotation to keep log file sizes at a fixed size:
http://www.rsyslog.com/doc/log_rotation_fix_size.html

Monday, February 4, 2013

Ubuntu 10.04 and VNC refresh problem

Using VNC to remote into Ubuntu 10.04 box. Initial view shows up, but screen does not refresh when clicking / typing / etc, but actions are happening on remote box.

A couple workaround / fixes:

http://ubuntuforums.org/showthread.php?p=8678737#post8678737
Remove the desktop effects via System/Preferences/Appearence/Visual Effects

http://ubuntuforums.org/showthread.php?p=9659038#post9659038
1) Open a terminal o press ALT+F2, then run/type: gconf-editor
2) Go to /desktop/gnome/remote_access and enable "disable_xdamage"

Saturday, January 26, 2013

Saturday, January 12, 2013

Mount host folders in Ubuntu guest OS

Open Virtualbox Shared Folders settings, add folder, make note of the Name.

In Ubuntu guest OS, create folder wherever (only needs to be done once): mkdir ~/Desktop/Host
Check your id by doing: id
Mount the folder using your uid and gid: sudo mount -t vboxsf Name ~/Desktop/Host -o rw,exec,uid=1000,gid=1000,dev
If you want to unmount later, do: umount ~/Desktop/Host

Always run a script in the terminal

Use this code to always run your script in the terminal. Change gnome-terminal to your desired shell. #!/bin/bash
tty -s; if [ $? -ne 0 ]; then gnome-terminal -e "$0"; exit; fi