tag:blogger.com,1999:blog-57922561189014585712024-03-05T07:50:43.686-08:00The Insanely Mad DuckThis is just a collection of random ramblings.Kwrazihttp://www.blogger.com/profile/17181440000398157489noreply@blogger.comBlogger11125tag:blogger.com,1999:blog-5792256118901458571.post-56467839614778627782013-02-17T22:24:00.000-08:002013-02-17T22:24:59.336-08:00Fail2ban-client ImportErrorFedora has <a href="https://fedoraproject.org/wiki/Features/UsrMove">proposed</a> compacting the linux filesystem hierarchy by moving some of the top level directories to usr. I am currently in the process of upgrading my home server from Fedora 16 to 18. Recently, I encountered a problem with fail2ban-client. I get the following error
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjERyYxm13Y014RUcCUEtmSHab5HjGwzQEw_NWea8rLR-XkGBM5K-8pYWdRwTAyE4SfbbqFMZl-66rIjAZLJ3op9H-fVR0UFPUBcZmQth85tnpqtnwBDGqYjAtbS2cIIJMizGt8MANmv18S/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code># fail2ban-client -h
Traceback (most recent call last):
File "/bin/fail2ban-client", line 35, in <module>
from common.version import version
ImportError: No module named common.version</code></pre>
also described <a href="https://github.com/fail2ban/fail2ban/issues/112">here</a> with full patch given <a href="https://github.com/fail2ban/fail2ban/commit/d561a4c2bbc336db70d5923cf630813bc51dc3ee">here</a>. Once this patch was manually applied it worked perfect. However, the changes were reseted when the next fail2ban update.
Until Fedora fixes this problem, a better temporary workaround is to add the python path to sys.path by adding it to PYTHONPATH environment. Create the following file <code>/etc/profile.d/fail2ban.sh</code> containing:
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjERyYxm13Y014RUcCUEtmSHab5HjGwzQEw_NWea8rLR-XkGBM5K-8pYWdRwTAyE4SfbbqFMZl-66rIjAZLJ3op9H-fVR0UFPUBcZmQth85tnpqtnwBDGqYjAtbS2cIIJMizGt8MANmv18S/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code>if [ -z "${PYTHONPATH}" ]; then
PYTHONPATH="/usr/share/fail2ban"
else
PYTHONPATH="/usr/share/fail2ban:${PYTHONPATH}"
fi
export PYTHONPATH
</code></pre>
Alternatively, swap the the order of <code>/bin</code> and <code>/usr/bin</code> in PATH by editing <code>/etc/profile</code>.Kwrazihttp://www.blogger.com/profile/17181440000398157489noreply@blogger.com1tag:blogger.com,1999:blog-5792256118901458571.post-86468839674951772372013-02-03T10:08:00.001-08:002013-02-04T00:03:57.776-08:00Creating Steam Client Installer RPM for Fedora 16, 17 and 18<p>As you might guess, I'm a long-time Linux user at work and at home. I have a Windows partition on my laptop that I only boot to when I want to play games. I'm also a Steam user. So when I heard that Steam was coming to Linux, I was over the moon. However, I'm a veteran Fedora user since Fedora Core 3. My laptop is currently running Fedora 16 (x86_64) and I play around with different Linux distribution using VirtualBox.</p>
<p>So recently, I decided to port Steam's deb package to Fedora's RPM. After unpacking the debian file and looking the dependencies, I decide to build my RPM for Fedora 17 (x86_64) (from KDE spin ISO) on a VirtualBox as the dependencies required some newer versions of packages that weren't available on Fedora 16. Here is the SPEC file that I create for fedora 17 based on debian's package control file.</p>
Here are the following steps to creating a Fedora steam rpm and installing it (tested on a virtualbox machine installed with x86_64 Fedora 16 and Fedora 17). It should work for Fedora 18, but have yet to test it.
<ol>
<li>Install rpmbuild environment according to this <a href="http://fedoraproject.org/wiki/How_to_create_an_RPM_package">guide</a>:
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjERyYxm13Y014RUcCUEtmSHab5HjGwzQEw_NWea8rLR-XkGBM5K-8pYWdRwTAyE4SfbbqFMZl-66rIjAZLJ3op9H-fVR0UFPUBcZmQth85tnpqtnwBDGqYjAtbS2cIIJMizGt8MANmv18S/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code># sudo yum install @development-tools
# sudo yum install fedora-packager
# rpmdev-setuptree</code></pre></li>
<li>Download the latest steam debian package from <a href="http://repo.steampowered.com/steam/archive/precise/">steam's repo site</a>:
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjERyYxm13Y014RUcCUEtmSHab5HjGwzQEw_NWea8rLR-XkGBM5K-8pYWdRwTAyE4SfbbqFMZl-66rIjAZLJ3op9H-fVR0UFPUBcZmQth85tnpqtnwBDGqYjAtbS2cIIJMizGt8MANmv18S/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code># mkdir steam
# cd steam
# wget -c "http://repo.steampowered.com/steam/archive/precise/steam_1.0.0.22_i386.deb"</code></pre></li>
<li>Unpack the debian file and the package tarball:
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjERyYxm13Y014RUcCUEtmSHab5HjGwzQEw_NWea8rLR-XkGBM5K-8pYWdRwTAyE4SfbbqFMZl-66rIjAZLJ3op9H-fVR0UFPUBcZmQth85tnpqtnwBDGqYjAtbS2cIIJMizGt8MANmv18S/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code># ar xv steam_1.0.0.22_i386.deb</code></pre></li>
<li>Patch and repack the tarball with the dirctory structure expected by rpmbuild:
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjERyYxm13Y014RUcCUEtmSHab5HjGwzQEw_NWea8rLR-XkGBM5K-8pYWdRwTAyE4SfbbqFMZl-66rIjAZLJ3op9H-fVR0UFPUBcZmQth85tnpqtnwBDGqYjAtbS2cIIJMizGt8MANmv18S/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code># mkdir steam-1.0.0.22
# tar zxvf data.tar.gz -C steam-1.0.0.22
# rm -rf steam-1.0.0.22/etc
# mv -iv steam-1.0.0.22/usr/bin/steamdeps steam-1.0.0.22/usr/bin/steamdeps.orig
# ln -s /bin/cat steam-1.0.0.22/usr/bin/steamdeps
# tar zcvf steam-1.0.0.22.tar.gz steam-1.0.0.22
# mv -iv steam-1.0.0.22.tar.gz ~/rpmbuild/SOURCES</code></pre></li>
<li>Create the SPEC <code>steam-1.0.0.22-1.x86_64.fc17.spec</code> file based on debian <code>control</code> specification inside <code>control.tar.gz</code>:
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:48ex;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjERyYxm13Y014RUcCUEtmSHab5HjGwzQEw_NWea8rLR-XkGBM5K-8pYWdRwTAyE4SfbbqFMZl-66rIjAZLJ3op9H-fVR0UFPUBcZmQth85tnpqtnwBDGqYjAtbS2cIIJMizGt8MANmv18S/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> # Don't try fancy stuff like debuginfo, which is useless on binary-only
# packages. Don't strip binary too
# Be sure buildpolicy set to do nothing
%define __spec_install_post %{nil}
%define debug_package %{nil}
%define __os_install_post %{_dbpath}/brp-compress
Name: steam
Version: 1.0.0.22
Release: 1.fc17
Summary: Steam open beta client
Group: Applications/Games
SOURCE0: %{name}-%{version}.tar.gz
URL: http://store.steampowered.com/
Vendor: Valve Corporation <linux@steampowered.com>
License: Steam
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
Requires: libcurl%{?_isa} >= 7.16.2, mesa-dri-drivers%{?_isa}, mesa-libGL%{?_isa}, libjpeg-turbo%{?_isa}, libogg%{?_isa} >= 1.0rc3, pixman%{?_isa} >= 0.24.4, SDL%{?_isa} >= 1.2.10-1, libtheora%{?_isa} >= 1.0, libudev%{?_isa} >= 175, libvorbis%{?_isa} >= 1.1.2, zenity >= 3.4.0, alsa-lib%{?_isa} >= 1.0.23, glibc%{?_isa} >= 2.15, cairo%{?_isa} >= 1.6.0, cups >= 1.4.0, dbus >= 1.2.14, fontconfig >= 2.8.0, freetype >= 2.3.9, gcc >= 4.1.1, libgcrypt%{?_isa} >= 1.4.5, gdk-pixbuf2%{?_isa} >= 2.22.0, glib2%{?_isa} >= 2.14.0, gtk2%{?_isa} >= 2.24.0, nspr%{?_isa}, nss%{?_isa} >= 3.12.3, openal-soft%{?_isa} >= 1.13, pango%{?_isa} >= 1.22.0, libpng-compat%{?_isa} >= 1.2.13, pulseaudio >= 0.99.1, pulseaudio-libs%{?_isa} >= 0.99.1, libstdc++%{?_isa} >= 4.6, libX11%{?_isa} >= 1.4.99.1, libXext%{?_isa}, libXfixes%{?_isa}, libXi%{?_isa} >= 1.2.99.4, libXinerama%{?_isa}, libXrandr%{?_isa} >= 1.2.99.3, libXrender%{?_isa}, zlib%{?_isa} >= 1.2.3.3
%description
cut and paste steam's license here or write your own description.
%prep
%setup -q
%build
# Empty section
%install
rm -rf %{buildroot}
mkdir -p %{buildroot}
# in builddir
cp -a * %{buildroot}
%post
%postun
%clean
rm -rf %{buildroot}
%changelog
%files
%defattr(-,root,root,-)
%{_bindir}/*
%{_libdir}/*
%{_datadir}/*
</code></pre>
Remember to edit the version number to match the tarball version number (i.e. Edit line label "Version:" and "Release:"). Copy the spec file into the <code>~/rpmbuild/SPECS</code> directory.
(Fedora 16) Since fc16 is quite old, the packages version numbers need to be shifted back. Replace the "Requires: ..." line with the following.
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjERyYxm13Y014RUcCUEtmSHab5HjGwzQEw_NWea8rLR-XkGBM5K-8pYWdRwTAyE4SfbbqFMZl-66rIjAZLJ3op9H-fVR0UFPUBcZmQth85tnpqtnwBDGqYjAtbS2cIIJMizGt8MANmv18S/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> Requires: libcurl%{?_isa} >= 7.16.2, mesa-dri-drivers%{?_isa}, mesa-libGL%{?_isa}, libjpeg-turbo%{?_isa}, libogg%{?_isa} >= 1.0rc3, pixman%{?_isa} >= 0.24.4, SDL%{?_isa} >= 1.2.10-1, libtheora%{?_isa} >= 1.0, libudev%{?_isa} >= 173, libvorbis%{?_isa} >= 1.1.2, zenity >= 3.2.0, alsa-lib%{?_isa} >= 1.0.23, glibc%{?_isa} >= 2.14, cairo%{?_isa} >= 1.6.0, cups >= 1.4.0, dbus >= 1.2.14, fontconfig >= 2.8.0, freetype >= 2.3.9, gcc >= 4.1.1, libgcrypt%{?_isa} >= 1.4.5, gdk-pixbuf2%{?_isa} >= 2.22.0, glib2%{?_isa} >= 2.14.0, gtk2%{?_isa} >= 2.24.0, nspr%{?_isa}, nss%{?_isa} >= 3.12.3, openal-soft%{?_isa} >= 1.12, pango%{?_isa} >= 1.22.0, libpng%{?_isa} >= 1.2.13, pulseaudio >= 0.9.23, pulseaudio-libs%{?_isa} >= 0.9.23, libstdc++%{?_isa} >= 4.6, libX11%{?_isa} >= 1.4.3, libXext%{?_isa}, libXfixes%{?_isa}, libXi%{?_isa} >= 1.2.99.4, libXinerama%{?_isa}, libXrandr%{?_isa} >= 1.2.99.3, libXrender%{?_isa}, zlib%{?_isa} >= 1.2.3.3, libgpg-error%{?_isa} >= 1.10, PackageKit-gtk-module%{?_isa}, libcanberra-gtk2%{?_isa}, libtxc_dxtn%{?_isa}, gtk2-engines%{?_isa}, xorg-x11-drv-nvidia-libs%{?_isa}
</code></pre>
Note: the last package <code>xorg-x11-drv-nvidia-libs</code> is specific to my laptop which has a nvidia graphics card. Remove or modify this if this does not match your system.</li>
<li>Build the rpm package.
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjERyYxm13Y014RUcCUEtmSHab5HjGwzQEw_NWea8rLR-XkGBM5K-8pYWdRwTAyE4SfbbqFMZl-66rIjAZLJ3op9H-fVR0UFPUBcZmQth85tnpqtnwBDGqYjAtbS2cIIJMizGt8MANmv18S/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code># cd ~/rpmbuild
# rpmbuild --target i686 -bb SPECS/steam-1.0.0.22-1.fc17.i686.spec</code></pre>
The rpm should have been created in <code>RPMS/i686</code> directory.</li>
<li>(Fedora 16) Back port libX11 from F17 or F18.
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjERyYxm13Y014RUcCUEtmSHab5HjGwzQEw_NWea8rLR-XkGBM5K-8pYWdRwTAyE4SfbbqFMZl-66rIjAZLJ3op9H-fVR0UFPUBcZmQth85tnpqtnwBDGqYjAtbS2cIIJMizGt8MANmv18S/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code># wget -c "http://dl.fedoraproject.org/pub/fedora/linux/releases/17/Fedora/source/SRPMS/l/libX11-1.4.99.901-2.fc17.src.rpm"
# rpm -ihv libX11-1.4.99.901-2.fc17.src.rpm
# sudo yum install libXau-devel libXdmcp-devel libxcb-devel xorg-x11-proto-devel xorg-x11-util-macros xorg-11-xtrans-devel
# sudo yum install libXau-devel.i686 libXdmcp-devel.i686 libxcb-devel.i686
# sudo yum install glibc.i686 glibc-devel.i686 libgcc.i686 libstdc++.i686
# rpmbuild --target i686 -ba SPECS/libX11.spec
# rpmbuild -ba SPECS/libX11.spec # make for x86_64
# sudo yum localinstall RPMS/i686/libX11-1.4.99.901-2.fc17.i686.rpm RPMS/i686/libX11-devel-1.4.99.901-2.fc17.i686.rpm RPMS/x86_64/libX11-1.4.99.901-2.fc17.x86_64.rpm RPMS/x86_64/libX11-devel-1.4.99.901-2.fc17.x86_64.rpm RPMS/noarch/libX11-common-1.4.99.901-2.fc17.noarch.rpm</code></pre></li>
<li>Everything so far has been using Fedora's repository. However, the steam client requires s3tc texture compression algorithm libraries which isn't available on Fedora's repo. You will need to add a third party repo such as <a href="http://rpmfusion.org/">rpmfusion</a>:
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjERyYxm13Y014RUcCUEtmSHab5HjGwzQEw_NWea8rLR-XkGBM5K-8pYWdRwTAyE4SfbbqFMZl-66rIjAZLJ3op9H-fVR0UFPUBcZmQth85tnpqtnwBDGqYjAtbS2cIIJMizGt8MANmv18S/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code># su -c "yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-17.noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-17.noarch.rpm"
# sudo yum install libtxc_dxtn libtxc_dxtn.i686</code></pre>
Adjust the first URL to match the fedora version number (FC17 is assumed in this example).</li>
<li>And finally, install steam rpm (and libX11 if using Fedora 16).
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjERyYxm13Y014RUcCUEtmSHab5HjGwzQEw_NWea8rLR-XkGBM5K-8pYWdRwTAyE4SfbbqFMZl-66rIjAZLJ3op9H-fVR0UFPUBcZmQth85tnpqtnwBDGqYjAtbS2cIIJMizGt8MANmv18S/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code>sudo yum localinstall RPMS/i686/steam-1.0.0.22-1.fc17.i686.rpm RPMS/i686/libX11-1.4.99.901-2.fc17.i686.rpm</code></pre></li>
<li>If you have been blessed, steam should be installed at this point. You can start up steam by typing:
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjERyYxm13Y014RUcCUEtmSHab5HjGwzQEw_NWea8rLR-XkGBM5K-8pYWdRwTAyE4SfbbqFMZl-66rIjAZLJ3op9H-fVR0UFPUBcZmQth85tnpqtnwBDGqYjAtbS2cIIJMizGt8MANmv18S/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code>steam</code></pre>
If you are behind a firewall, the steam client respects proxy environment variables: http_proxy, https_proxy, and all_proxy. The steam binary installed by rpm is really just a client downloader. You'll need to be connected to internet for the really client binary to be downloaded and installed.</li>
</ol>
<p>Good gaming.</p>
<p>Remark: The code for steamdeps is probably a bad way to test dependencies as it is very debian-specific. A more distro agnostic way is required.</p>
Kwrazihttp://www.blogger.com/profile/17181440000398157489noreply@blogger.com1tag:blogger.com,1999:blog-5792256118901458571.post-70303557979202793852012-08-01T03:48:00.002-07:002012-08-01T03:48:23.438-07:00Fail2Ban with Pushover NotificationI recently purchased the pushover notification app for android due to a discount offer. As a result, I decide to integrate pushover notification with some Fedora services on my home server.
<h3>Fail2Ban</h3>
To enable pushover notification, I added a pushover-notify action to <code>/etc/fail2ban/action.d/pushover-notify.conf</code>.
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjERyYxm13Y014RUcCUEtmSHab5HjGwzQEw_NWea8rLR-XkGBM5K-8pYWdRwTAyE4SfbbqFMZl-66rIjAZLJ3op9H-fVR0UFPUBcZmQth85tnpqtnwBDGqYjAtbS2cIIJMizGt8MANmv18S/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"># Fail2Ban configuration file
#
[Definition]
# Notify on Startup
actionstart = /usr/bin/curl -s -F "token=<token>" -F "user=<user>" -F "title=[Fail2Ban]" -F "message=Jail <name> has been started successfully." https://api.pushover.net/1/messages
# Notify on Shutdown
actionstop = /usr/bin/curl -s -F "token=<token>" -F "user=<user>" -F "title=[Fail2Ban]" -F "message=Jail <name> has been stopped." https://api.pushover.net/1/messages
#
actioncheck =
# Notify on Banned
actionban = /usr/bin/curl -s -F "token=<token>" -F "user=<user>" -F "title=[Fail2Ban] <name> banned" -F "message=Banned IP: <ip> Attempts: <failures> `geoiplookup <ip>`" https://api.pushover.net/1/messages
# Notify on Unbanned
actionunban =
[Init]
# Defaut name of the chain
#
name = default
# Application token key
#
token = PLACE_YOUR_APPLICATION_TOKEN_HERE
# User API key
#
user = PLACE_YOUR_USER_API_KEY_HERE
</code></pre>
This action script uses <code>curl</code> and <code>geoiplookup</code>. Since I have SELinux enforced, I had to add policies to allow this action to run. Once done, I edit my <code>jail.conf</code> to enable this action.
<h3>Smartd</h3>
Add the <code>curl</code> command to the <code>/usr/libexec/smartmontools/smartdnotify</code>.
<h3>Apcaccess</h3>
Finally, I added pushover notification to my UPS monitoring services to notify me for power blackout.Kwrazihttp://www.blogger.com/profile/17181440000398157489noreply@blogger.com4tag:blogger.com,1999:blog-5792256118901458571.post-67987438992469079342012-06-03T22:07:00.001-07:002012-06-03T22:07:10.809-07:00Grabbing continuous stream from IP camI own two Linksys WVC54GCA IP cameras. Recently, I had a need to capture a continuous stream instead of the motion activated mode where I ended up with hundreds of mp4 on my ftp server. So after looking around I found out that you can capture http stream using mplayer. So I wrote a bash script to do it.
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjERyYxm13Y014RUcCUEtmSHab5HjGwzQEw_NWea8rLR-XkGBM5K-8pYWdRwTAyE4SfbbqFMZl-66rIjAZLJ3op9H-fVR0UFPUBcZmQth85tnpqtnwBDGqYjAtbS2cIIJMizGt8MANmv18S/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> #!/bin/bash
#
# Duck-Wrath
# 31st May 2012
#
CHK_INT=20 # in seconds
VID_LEN=3600 # in seconds
LOGFILE=linksys_capture.log
if [ -z "$username" ]; then
read -p "Enter Username: " username
fi
if [ -z "$password" ]; then
read -s -p "Enter Password: " password
printf "\n"
fi
if [ -z "$CAM_IP" ]; then
read -p "Enter Camera IP: " CAM_IP
fi
# Linksys http URL for asf (MJPEG)
#CAM_URL=http://${CAM_IP}/img/video.mjpeg
# Linksys http URL for asf (MPEG4)
CAM_URL=http://${CAM_IP}/img/video.asf
echo "Grabbing video from ${CAM_URL}..." >> ${LOGFILE}
while [ 1 ]; do
ASFFILE=`date +%Y%m%d-%H%M%S`.asf
start=`date +%s`
timer=0
echo "Starting mplayer to grab stream." >> ${LOGFILE}
mplayer -quiet -cache 32768 -dumpstream -dumpfile "${ASFFILE}" \
-demuxer lavf "${CAM_URL}" \
-user "${username}" -passwd "${password}" &
MPID=$!
echo " Mplayer running on pid $MPID." >> ${LOGFILE}
echo " Saving to ${ASFFILE}" >> ${LOGFILE}
while [ $timer -lt $VID_LEN ]; do
if kill -0 $MPID; then
now=`date +%s`
sleep ${CHK_INT};
timer=`echo "$now - $start" | bc`
else
echo " *** Stream died prematurely." >> ${LOGFILE}
echo " *** Timer=${timer}." >> ${LOGFILE}
timer=$VID_LEN
fi
done
if kill -0 $MPID; then
echo " Terminating mplayer." >> ${LOGFILE}
kill $MPID
fi
MP4FILE=`basename "${ASFFILE}" .asf`.mp4
echo "Converting video to seekable ${MP4FILE}." >> ${LOGFILE}
ffmpeg -i "${ASFFILE}" -f mp4 -vcodec copy -acodec copy "${MP4FILE}" && \
/bin/rm "${ASFFILE}" && \
echo "Captured file ${MP4FILE} Done." >> ${LOGFILE} &
# start next capture
done
</code></pre>
This scripts will prompt for username and password for the camera along with the IP. It then starts up mplayer to grab the stream and put in into background. The script then monitors the mplayer and updates a counter. Every hour (3600 seconds) it stop the stream captures and repackage the asf video into mp4. It then restarts capturing the next hour stream segment. If you remove the debugging log file generation, the script is relatively short.Kwrazihttp://www.blogger.com/profile/17181440000398157489noreply@blogger.com2tag:blogger.com,1999:blog-5792256118901458571.post-81667143440338560472012-03-28T02:45:00.001-07:002012-04-03T21:50:59.129-07:00Disabling edge-tiling in gnome-shellAfter upgrading from Fedora 14 to Fedora 16, I had to spent a bit of my setting up time battling with gnome-shell. One of the more annoying features is the "snap" maximizing or "border" maximizing or (as gnome calls it) "edge-tiling". Default state of this feature is "true" as seen from the output of this command:<br />
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>gconftool-2 --get /desktop/gnome/shell/windows/edge_tiling
</code></pre>To change it simply type:<br />
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>gconftool-2 --type=boolean --set /desktop/gnome/shell/windows/edge_tiling false
</code></pre>Then press, Alt-F2 and type "r" to restart gnome-shell.<br />
<br />
Unfortunately, the battle with gnome-shell isn't over.<br />
<br />
UPDATE: ...And so the struggle continues. More stupid default behaviour in gnome-shell -- dialog boxes are locked to the titlebar. This is especially annoying when you have a large dialog box and need to enter data that is shown under it and can't move the damn dialog box. Luckily it can be changed by this command:<br />
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>gconftool-2 --type=boolean --set /desktop/gnome/shell/windows/attach_modal_dialogs false
</code></pre>Kwrazihttp://www.blogger.com/profile/17181440000398157489noreply@blogger.com0tag:blogger.com,1999:blog-5792256118901458571.post-44413404956091398532012-02-29T00:08:00.001-08:002012-02-29T00:09:48.241-08:00How to recursively traverse boost property treeCurrently, I find the documentation for boost::property_tree to be terrible. Hence, I hope this example will help others to work out how to use BOOST_FOREACH and recursion to traverse down the boost property tree. Here's how to create a class that loads and XML file to a property_tree, then display the hierarchy and then saves to another XML file.<br />
<br />
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjERyYxm13Y014RUcCUEtmSHab5HjGwzQEw_NWea8rLR-XkGBM5K-8pYWdRwTAyE4SfbbqFMZl-66rIjAZLJ3op9H-fVR0UFPUBcZmQth85tnpqtnwBDGqYjAtbS2cIIJMizGt8MANmv18S/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> #include <iostream>
#include <string>
#include <fstream>
#include <boost/foreach.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <locale>
using boost::property_tree::ptree;
using namespace std;
class configuration {
ptree pt;
public:
// constructor
configuration(const string& filename) {
load(filename); };
// internal property tree function
ptree load(const string& filename) {
return import_xml(filename); };
void save(const string& filename) {
export_xml(filename,pt); };
// import export property tree function
ptree property_tree(void) {
return pt; };
void display(void) {
display(0, pt); };
private:
ptree import_xml(const string& filename) {
ifstream input(filename.c_str());
read_xml(input, pt);
return pt; };
void export_xml(const string& filename, const ptree& pt) {
boost::property_tree::xml_writer_settings<char> w(' ',2);
write_xml(filename, pt, locale(), w); };
void display(const int depth, const ptree& tree) {
BOOST_FOREACH( ptree::value_type const&v, tree.get_child("") ) {
ptree subtree = v.second;
string nodestr = tree.get<string>(v.first);
// print current node
cout << string("").assign(depth*2,' ') << "* ";
cout << v.first;
if ( nodestr.length() > 0 )
cout << "=\"" << tree.get<string>(v.first) << "\"";
cout << endl;
// recursive go down the hierarchy
display(depth+1,subtree);
}
};
};
#define DEFAULT_CALORIES 0
int main(void)
{
configuration cfg("test_input.xml");
cfg.display();
cfg.save("test_output.xml");
// example to grab data from property tree
int calories = cfg.property_tree().get<int>("collection.recipe.nutrition.<xmlattr>.calories",DEFAULT_CALORIES);
cout << "Calories = " << calories << endl;
return 0;
}
</code></pre><br />
Here is a sample test_input.xml file:<br />
<br />
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjERyYxm13Y014RUcCUEtmSHab5HjGwzQEw_NWea8rLR-XkGBM5K-8pYWdRwTAyE4SfbbqFMZl-66rIjAZLJ3op9H-fVR0UFPUBcZmQth85tnpqtnwBDGqYjAtbS2cIIJMizGt8MANmv18S/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <?xml version="1.0" encoding="UTF-8"?>
<collection>
<description>
Some recipes used for the XML tutorial.
</description>
<recipe>
<title>Beef Parmesan with Garlic Angel Hair Pasta</title>
<ingredient name="beef cube steak" amount="1.5" unit="pound"/>
...
<preparation>
<step>
Preheat oven to 350 degrees F (175 degrees C).
</step>
...
</preparation>
<comment>
Make the meat ahead of time, and refrigerate over night, the acid in the
tomato sauce will tenderize the meat even more. If you do this, save the
mozzarella till the last minute.
</comment>
<nutrition calories="1167" fat="23" carbohydrates="45" protein="32"/>
</recipe>
...
<!--another comment-->
</collection>
</code></pre><br />
The standard output when applied to this file gives:<br />
<br />
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjERyYxm13Y014RUcCUEtmSHab5HjGwzQEw_NWea8rLR-XkGBM5K-8pYWdRwTAyE4SfbbqFMZl-66rIjAZLJ3op9H-fVR0UFPUBcZmQth85tnpqtnwBDGqYjAtbS2cIIJMizGt8MANmv18S/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> * collection="
...
"
* description="
Some recipes used for the XML tutorial.
"
* recipe="
...
"
* title="Beef Parmesan with Garlic Angel Hair Pasta"
* ingredient
* <xmlattr>
* name="beef cube steak"
* amount="1.5"
* unit="pound"
* preparation="
...
"
* step="
Preheat oven to 350 degrees F (175 degrees C).
"
* comment="
Make the meat ahead of time, and refrigerate over night, the acid in the
tomato sauce will tenderize the meat even more. If you do this, save the
mozzarella till the last minute.
"
* nutrition
* <xmlattr>
* calories="1167"
* fat="23"
* carbohydrates="45"
* protein="32"
* <xmlcomment>="another comment"
</code></pre><br />
Notice that boost::property_tree create a separate child for XML<br />
attributes and XML comments.Kwrazihttp://www.blogger.com/profile/17181440000398157489noreply@blogger.com4tag:blogger.com,1999:blog-5792256118901458571.post-88677264236188774502012-01-23T22:18:00.000-08:002012-01-23T22:18:29.259-08:00Player videos as a Gnome-screensaversI have a collection of short interesting (to me anyway) videos that I've always wanted to play as a screen saver without audio. I use the gnome desktop in Fedora which uses gnome-screensaver. Search around on the internet I found this very <a href="http://ubuntuforums.org/showthread.php?t=1368224">useful post</a> on Ubuntu's forum.<br />
<br />
I have made some modifications. Firstly, to use a single mplayer line with the shuffle command to the full collection. Secondly, to kill mplayer and all of its child threads whenever gnome-screensaver exits (otherwise, you are left with many running mplayers without a window id to feed the video output to). The second part was a bit tricky to do properly since killing the parent mplayer did not kill all the child threads (probably a bug in mplayer). So here is the code:<br />
<br />
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjERyYxm13Y014RUcCUEtmSHab5HjGwzQEw_NWea8rLR-XkGBM5K-8pYWdRwTAyE4SfbbqFMZl-66rIjAZLJ3op9H-fVR0UFPUBcZmQth85tnpqtnwBDGqYjAtbS2cIIJMizGt8MANmv18S/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> #! /bin/bash
# Movie screensaver code based on
# http://ubuntuforums.org/showthread.php?t=1368224
# modified January 2012
## path to video
### USER MODIFY #####
# Modify this to add the directories with the videos you want played.
VIDEO=( "/mnt/Storage1/Video_Screensavers/*" \
"/mnt/Storage1/Videos/RSA_Animate/*" )
#####################
if [ ! -z $XSCREENSAVER_WINDOW ]; then
# allow this script to run as a standalone without gnome-screensaver
WINDOW="-wid $XSCREENSAVER_WINDOW"
fi
## setup MPlayer aruments, remove -nosound if you want the video
## to play sound. If you have to specify the video driver to use
## then add that to the list
MPLAYERARGS="-nosound -nolirc $WINDOW -nostop-xscreensaver -fs -really-quiet -shuffle"
## we handle SIGTERM and SIGINT here to kill the child
## if active then quit.
function ex {
pkill -TERM -P $CPID mplayer
kill -s 9 $CPID
exit 0
}
trap ex SIGINT SIGTERM
mplayer $MPLAYERARGS -loop 0 ${VIDEO[*]} < /dev/null &
CPID=$!
wait $CPID
</code></pre><br />
Copy this script (called <code>movie.sh</code>) to <code>/usr/libexec/xscreensaver/</code> (in Fedora). Add <code>xscreensaver-movie.desktop</code> to <code>/usr/share/applications/screensavers/</code>.<br />
<br />
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjERyYxm13Y014RUcCUEtmSHab5HjGwzQEw_NWea8rLR-XkGBM5K-8pYWdRwTAyE4SfbbqFMZl-66rIjAZLJ3op9H-fVR0UFPUBcZmQth85tnpqtnwBDGqYjAtbS2cIIJMizGt8MANmv18S/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> [Desktop Entry]
Encoding=UTF-8
Name=Movie
Comment=Plays Videos
TryExec=/usr/libexec/xscreensaver/movie.sh
Exec=/usr/libexec/xscreensaver/movie.sh
StartupNotify=false
Terminal=false
Type=Application
Categories=GNOME;Screensaver;
OnlyShowIn=GNOME;
</code></pre><br />
Now my process list is free of rogue mplayer processes.Kwrazihttp://www.blogger.com/profile/17181440000398157489noreply@blogger.com0tag:blogger.com,1999:blog-5792256118901458571.post-77703536802784346512011-09-01T02:00:00.000-07:002011-09-01T02:06:37.267-07:00Akregator Segmentation faultIf akregator is having problems starting up and gives a KDE crash dialog stating that there was a Segmentation fault, it could possibly be a corrupted mk4 file somewhere in ~/.kde/share/apps/akegrator/Archive. The easy solution is to delete the Archive but you lose all article flags. It's better if we could find which RSS feed is causing the problem and nuke that instead. To do that use the following command:<br />
<pre>strace -f -e trace=open akregator
</pre>The last mk4 file in the Archive directory that was opened before the segmentation fault occured will be the culprit. Just rename or delete the file and try again. If it crashes again, repeat and see if it's another mk4 file. IF not, it's some other problem.<br />
Kwrazihttp://www.blogger.com/profile/17181440000398157489noreply@blogger.com0tag:blogger.com,1999:blog-5792256118901458571.post-44074411716988179642011-08-02T14:15:00.000-07:002011-08-02T21:42:56.947-07:00Fail2ban ssh root statsMy home server has been using fail2ban with the SSH root logging blocker. Being curious, I decide to extract some statistics to find out which country the logging attempts came from. I set up fail2ban to also send emails of blacklisting events. Using the following bash command:<br />
<quote><br />
# grep 'SSH: banned' /var/spool/mail/root | cut -d' ' -f5 | xargs --replace=xxx geoiplookup xxx | sort | uniq -c | sort -n<br />
</quote><br />
and here is the result:<br />
<pre>1 GeoIP Country Edition: AE, United Arab Emirates
1 GeoIP Country Edition: BE, Belgium
1 GeoIP Country Edition: BH, Bahrain
1 GeoIP Country Edition: DK, Denmark
1 GeoIP Country Edition: GR, Greece
1 GeoIP Country Edition: HU, Hungary
1 GeoIP Country Edition: IR, Iran, Islamic Republic of
1 GeoIP Country Edition: KW, Kuwait
1 GeoIP Country Edition: KZ, Kazakhstan
1 GeoIP Country Edition: LK, Sri Lanka
1 GeoIP Country Edition: MN, Mongolia
1 GeoIP Country Edition: PR, Puerto Rico
1 GeoIP Country Edition: SN, Senegal
1 GeoIP Country Edition: YE, Yemen
2 GeoIP Country Edition: AR, Argentina
2 GeoIP Country Edition: CR, Costa Rica
2 GeoIP Country Edition: EC, Ecuador
2 GeoIP Country Edition: LT, Lithuania
2 GeoIP Country Edition: OM, Oman
2 GeoIP Country Edition: PA, Panama
2 GeoIP Country Edition: PH, Philippines
2 GeoIP Country Edition: PT, Portugal
3 GeoIP Country Edition: ID, Indonesia
3 GeoIP Country Edition: NL, Netherlands
4 GeoIP Country Edition: AU, Australia
4 GeoIP Country Edition: BG, Bulgaria
4 GeoIP Country Edition: CZ, Czech Republic
4 GeoIP Country Edition: DE, Germany
4 GeoIP Country Edition: MA, Morocco
4 GeoIP Country Edition: PK, Pakistan
4 GeoIP Country Edition: UA, Ukraine
5 GeoIP Country Edition: CL, Chile
5 GeoIP Country Edition: MX, Mexico
5 GeoIP Country Edition: PL, Poland
6 GeoIP Country Edition: CA, Canada
8 GeoIP Country Edition: ES, Spain
9 GeoIP Country Edition: BR, Brazil
9 GeoIP Country Edition: HK, Hong Kong
9 GeoIP Country Edition: JP, Japan
9 GeoIP Country Edition: NZ, New Zealand
10 GeoIP Country Edition: TW, Taiwan
11 GeoIP Country Edition: GB, United Kingdom
12 GeoIP Country Edition: TH, Thailand
12 GeoIP Country Edition: TR, Turkey
13 GeoIP Country Edition: RU, Russian Federation
17 GeoIP Country Edition: IT, Italy
18 GeoIP Country Edition: VN, Vietnam
19 GeoIP Country Edition: CO, Colombia
19 GeoIP Country Edition: EG, Egypt
20 GeoIP Country Edition: FR, France
38 GeoIP Country Edition: IN, India
40 GeoIP Country Edition: KR, Korea, Republic of
53 GeoIP Country Edition: US, United States
72 GeoIP Country Edition: IP Address not found
74 GeoIP Country Edition: PE, Peru
211 GeoIP Country Edition: CN, China
</pre>It's no surprise who does the most break-in attempts. For me, the second one in the list is a bit surpising. Peru is either a haven for hackers or it has a lot of insecure computers that are the jumping points for other hackers in other countries. I don't know much about Peru.Kwrazihttp://www.blogger.com/profile/17181440000398157489noreply@blogger.com0tag:blogger.com,1999:blog-5792256118901458571.post-10062734182354139242011-07-19T02:16:00.000-07:002011-07-19T02:16:37.921-07:00sc_trace for enumerated types in SystemCI been struggling for awhile now with getting <span style="font-family: "Courier New",Courier,monospace;">sc_trace</span> overloading to work for enumerated types in SystemC. After finding this <a href="http://www.systemc.org/Discussion_Forums/helpforum/archive/msg?list_name=help_forum&monthdir=201007&msg=msg00023.html">post</a> and reading how <span style="font-family: "Courier New",Courier,monospace;">sc_trace</span> work, I worked out a solution and tested it. It works! So hopefully, this post will help others:<br />
<br />
Here's a cut down custom object type with a working <span style="font-family: "Courier New",Courier,monospace;">sc_trace</span> with an enumerated type:<br />
<br />
<pre>typedef enum { IDLE = 0, BUSY } state_t;
class MyType {
unsigned info;
state_t flag;
...
inline friend void sc_trace(
sc_trace_file *tf,
const MyType & v,
const std::string & NAME ) {
int* iflag = (int*) &(v.flag);
sc_trace(tf, v.info, NAME + ".info");
sc_trace(tf, *iflag, NAME + ".flag");
};
};
</pre>Kwrazihttp://www.blogger.com/profile/17181440000398157489noreply@blogger.com0tag:blogger.com,1999:blog-5792256118901458571.post-85731940421241807602011-04-07T09:28:00.000-07:002011-04-07T09:30:24.995-07:00Getting Half-Life 2 on Steam in LinuxAfter getting a brand new beast of a laptop (G73SW) and installing it with Fedora 14 x86_64, I wanted to play a game of two using my Steam account. After all, I you have a gaming laptop, what good is it if you don't game.After checking to see if Half-Life 2 works on Wine using WineHQ AppDB. I set out to get it working.<br />
<br />
After two nights of messing around with wine, I finally got it two work. Here are some of my notes and observation.<br />
<br />
Wine x86_64 isn't mature enough to run games from Steam. Firstly, audio doesn't work. Half Life 2 doesn't seem to start if audio isn't working.<br />
<br />
So you need to uninstall all wine x86_64 packages. Then install i686 version of wine:<br />
<br />
<code>yum install wine-small-fonts wine-jack.i686 wine-system-fonts \<br />
wine-ldap.i686 wine.i686 wine-common wine-marlett-fonts \<br />
wine-pulseaudio.i686 wine-fonts wine-cms.i686 wine-wow.i686 \<br />
wine-symbol-fonts wine-openal.i686 wine-devel.i686 \<br />
wine-core.i686 wine-desktop wine-oss.i686 wine-courier-fonts \<br />
wine-twain.i686 wine-esd.i686 wine-tahoma-fonts wine-capi.i686 \<br />
wine-alsa.i686 wine-ms-sans-serif-fonts</code><br />
<br />
Next download the infinitely useful winetricks script and use it to install Steam, DirectX 9, corefonts, flash, vcrun2005.<br />
<br />
The biggest thing got me stumped awhile was trying to get OpenGL to run since DirectX uses it. I finally got it to work once I discover that you need to install the 32-bit libGL.so for the NVidia Xorg drivers:<br />
<br />
<code>yum install xorg-x11-drv-nvidia-libs.i686</code><br />
<br />
Once that was done, Half-Life 2 finally started with audio right from the Steam Library Panel. I copied over all my save games from my Windows partition, fiddled with the game settings and finally loaded a saved game.<br />
<br />
Next up... Try restoring some of my other Steam games.Kwrazihttp://www.blogger.com/profile/17181440000398157489noreply@blogger.com0