How to add a command to the Makefile

This tutorial is a quick way to understand how to add a script or something else to the Makefile installation process. This is solely for those who are building rpm/deb packages and want to add extra stuff in the installation package.

So inside your Makefile directory add the file you would like to see in the final installation:

For example:

[root@softether vpnserver_package]# ls script*
script_i_want_to_add.sh

Now edit Makefile to properly add the script to the final package.

[root@softether vpnserver_package]# vim Makefile

Look for the install and uninstall part and add the lines you need.


install:
cp vpncmd/vpncmd /usr/bin/
cp vpncmd/ham* /usr/bin/
cp -r vpnserver /usr/local/
chmod 755 vpnserver
cp vpnserver.init /etc/init.d/vpnserver
cp vpn_server.config /usr/local/vpnserver/
chmod 755 /etc/init.d/vpnserver
/sbin/chkconfig –add vpnserver
### adding install line here
cp script_i_want_to_add.sh /usr/bin
uninstall:
rm -rf /usr/local/vpnserver
#rm -f /etc/init.d/vpnserver
/sbin/chkconfig –del vpnserver
rm /usr/bin/hamco*
rm /usr/bin/vpncmd
### adding uninstall line here
rm /usr/bin/changevhub

view raw

Makefile

hosted with ❤ by GitHub

And that’s it. This script will then be accessible in the final stage of the installation, under /usr/bin/ folder which is the PATH folder.

Make a very simple link webcrawler in CentOS

This WebCrawler will be made in Python using Beautiful Soup. It will simple collect data form a webpage and store every “href” inside that webpage. In order to work you must install python and BS. Normally Python should be installed already so theres BeautifulSoup missing.

yum install python-BeautifulSoup.noarch

Afterwards all you need is to make a file program.py and save this source in it.

#!/usr/bin/python

import urllib2,os,sys
import BeautifulSoup

if len(sys.argv) > 1 :
 origin_url = str(sys.argv[1])
else :
 # Must have http://
 origin_url = "http://www.stupidness.com/"

request = urllib2.Request(origin_url)
response = urllib2.urlopen(request)

soup = BeautifulSoup.BeautifulSoup(response)
href_array=[]

for a in soup.findAll('a'):
 link=a['href']
 if len(link) > 0 :
 if 'http://' in link :
 href_array.append(a['href'])
 else :
 href_array.append(os.path.dirname(origin_url)+a['href'])

print href_array

With this simple scraper/crawler you will get any href from a webpage.

To use this just type

python program.py

Stream from Blackmagic Decklink Recorder using FFMpeg

This a quick and dirty solution to stream from a Decklink Recorder card (i.e. blackmagic capture board) using ffmpeg. In my case I used an old Ubuntu 11.10 and installed all debians provided by Blackmagic and FFMpeg/avconv. There should be no secret installing those.

I also used the bmdtools git project. This is the best project to make sure your blackmagic board is working.

Requisits:

  • FFMpeg version 2.1.2
  • Blackmagic Design Desktop Video 9.8 – Driver and Utilities
  • bmdtools

Comand line

./bmdcapture -m 13 -C 1 -V 3 -F nut -f pipe:1|ffmpeg -i - -q 5 -r 25 -f mpegts udp://10.0.0.4:5010

bmdtools

  • -m : refers to the mode used in the capture. In this case I captured from a Amino HDMI STB using 720p 50Hz
  • -C : refers to the card index. I had two in this case so I used the second one
  • -V : refers to the input used. In  this case HDMI
  • -F : refers to the output mode.
  • -f : output type. In this case stdout

ffmpeg

  • -i : refers to the input. In this case stdin.
  • -q : this is a quality scale. The lower the better
  • -r : frames per second
  • -f : output format. Mpeg Transport stream. As no video nor audio codec was specified, ffmpeg uses the transport stream compliant codecs, meaning MPEG Video and MPEG Audio.

This is the quickest way to stream your capture video/audio. For a long term solution I would suggest capturing and streaming using VLC.

 

 

How to use upstart to control your services

In this first post I’ll be using the upstart configuration to easily manage a DLNA server in a Ubuntu desktop/server.

For starters I really don’t know exactly how DLNA works but it doesn’t matter, my TV and my Android do so that’s enough for me. I tried a bunch of DLNA servers, but the easiest one proved to be minidlna.

Upstart is a great tool to manage boot services (previously /etc/init.d/ !?) or to start/stop any service in a really simple and effective way.

For example starting a service will be as easy as writing in a terminal:

start dlna

So for starters you will need to install minidlna. Use Ubuntu software center to look for it or just type

sudo apt-get install minidlna

The only change I did to /etc/minidlna.conf was this one

media_dir=V,/home/myuser/Videos

Afterwords you need to create the file /etc/init/dlna.conf and type this into that file.

# rc - System V runlevel compatibility
#
# This task runs the minidlna service when filesystem and nic are availabe

description    "MiniDLNA controller"
author        "Nuno Mota <nrmmota@gmail.com>"

start on filesystem and net-device-up IFACE=eth0
stop on runlevel [!$RUNLEVEL]

expect fork
exec minidlna -f /etc/minidlna.conf

And that’s it. Whenever you boot your machine the service will be imediatly available. If for some reason the process dies, upstart will start it again. Everything is logged in syslog.

Testing

Clicking and visually checking stuff after code changes is very inefficient. For every change made, something else could break and there’s no way to know other than testing the whole application every single time.
This is where unit testing comes in. The idea is to create a piece of code that tests some functionality. As more tests are created, the developer can launch them all at the same time to check if everything is OK.
Historically this concept evolved into Test-driven Development (TDD). The idea is to write a test before building a new feature. This forces a kind of specification to be created, which sets the rules of how the feature should operate. So the goal of the developer becomes “building the feature to make the test pass”.
Recently this concept further evolved into Behavior-driven Development (BDD). This is the bleeding edge concept/technology at the moment and it’s the stuff I’m using for our tests. BDD places focus on the user behavior, and tests are written as a kind of story. I’ll give you an example of a test I wrote just a moment ago:
Given I login as "student"
  And I go to "/calendar/index"
 When I mouseover "#credits_count"
 Then I should see "Remaining rescheduling credits = 3"
  And I should see "47" in the "#credits_count" element
So as you can see this test is very readable, when I run this, a browser pops up, logs in as a student, goes to the calendar page, mouses over the credits number next to the time and checks that the remaining scheduling credits is 3, and the actual credit count is 47.
These stories/scenarios are very easy to read and write, and revolve around 3 keywords: Given, When, Then.
 
Given is a precondition.
When is an action.
Then is the expected outcome.

mysqld dead but subsys locked

Had a problem in my VPS of the mysqld service spontaneously dying.

When I used the command:

sudo service mysqld status

I got a message saying, “mysqld dead but subsys locked”. I didn’t realise this machine didn’t have a swapfile, so in order to fix the problem I ran the following commands:

dd if=/dev/zero of=/swapfile bs=1M count=1024
mkswap /swapfile
swapon /swapfile
Open /etc/fstab and add this line /swapfile swap swap defaults 0 0