Oscam CardReader on Raspberry Pi

This is my first project on this blog and this were also the first experiences i made with the raspberry pi.
Oscam is an open source software project to read  conditional access module cards and to share it over the network. I will not give any information on how to configure oscam here. I will only focus on the installation of the software on the raspberry pi. I chose ArchLinux as operating system for the pi. I used, to accomplish that, a Mac and a virtual machine with debian to prepare the sd-card.

At the bottom of this post you can also find a small bash setup script that will do all necessary actions. I did not clean up the code completely, but it works flawless. you also need to be root to run it. I know, this is not the preferred way, but this will only document my approach and I exclusively used my pi in my private network… 🙂

 

Prepare your SD-Card:

Please follow the guide on the archlinuxarm.org website to prepare your sd-card.. Be aware that there is a guide for the Raspberry Pi and the Raspberry Pi 2!

If you would like to access your pi via ssh remotely, you’ll need to edit sshd_config (located at /etc/ssh/)

nano /etc/ssh/sshd_config

and change the following line

#PermitRootLogin prohibit-password

to

PermitRootLogin yes

System Upgrade

Insert you sd-card into your pi, connect power supply,ethernet cable and boot it.

The default user and password to login is root/root.

If you chose to login via ssh. You’ll need to find out the IP address of the pi first. You can check if your router has a list of connected devices or use tools to do a network scan (I use iNet Pro, available on the Mac App Store and is also available for iOS devices).

When you know the IP address of the pi you can use the Terminal and login:

ssh root@IP.Address.Of.Pi

You can also try to use the hostname of the pi which is normally (in case of ArchLinux) “alarmpi”

ssh root@alarmpi

The first thing you should do is to do a full system upgrade:

pacman -Syu 

Install Dependencies

Then you can install required dependencies:

pacman -S subversion cmake make gcc pcsclite

Getting Oscam and Compile

To download the latest oscam version:

svn co http://www.streamboard.tv/svn/oscam/trunk oscam-svn

Enter the folder oscam-svn

cd oscam-svn

create a build folder and enter it:

mkdir build

chmod 755 build

cd build

Now we’ll start with configuring and compiling (don’t forget the two dots at the end!):

cmake -DHAVE_LIBUSB=1 -DHAVE_PCSC=1 -DWEBIF=1 -DHAVE_LIBCRYPTO=1 -DWITH_SSL=1 ..
make

This takes some time. When your pi is ready type

make install

This will install the compiled oscam files will be installed on your system.

Now you can put your configuration files in the folder /usr/local/etc/

To start Oscam simply type:

/usr/local/bin/oscam -b

You can also create a service file (in /etc/systemd/system/ to automatically start oscam when booting your pi.

nano /etc/systemd/system/oscam.service

There you enter the following:


[Unit]
Description=An Open Source Conditional Access Module software

[Service]
Type=forking
ExecStart=/usr/local/bin/oscam -b

[Install]
WantedBy=multi-user.target

Then you enable the service file by

systemctl enable oscam

To directly start this service without a reboot enter

systemctl start oscam

You are done and Oscam should be running.

Here you can see my Pi (in 2012) when I first installed Oscam:

Oscam

To simplify the whole process I created a bash script, which will guide you through the whole process:

#!/bin/bash

packages=("subversion" "cmake" "make" "gcc" "pcsclite");
workpath=$(pwd)
_isInstalled() {
package="$1";
check="$(pacman -Qs --color always "${package}" | grep "local" | grep "${package} ")";
if [ -n "${check}" ] ; then
echo 0; #'0' means 'true' in Bash
return; #true
fi;
echo 1; #'1' means 'false' in Bash
return; #false
}
dependencies() {
read -p "Do you want to perform a full system upgrade? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
pacman -Syu
else
pacman -Sy
fi

# The packages that are not installed will be added to this array.
toInstall=();

for pkg; do
# If the package IS installed, skip it.
if [[ $(_isInstalled "${pkg}") == 0 ]]; then
echo "${pkg} is installed.";
continue;
fi;

#Otherwise, add it to the list of packages to install.
toInstall+=("${pkg}");
done;

# If no packages were added to the "${toInstall[@]}" array,
# don't do anything and stop this function.
if [[ "${toInstall[@]}" == "" ]] ; then
echo "All packages are already installed.";
run;
fi;

# Otherwise, install all the packages that have been added to the "${toInstall[@]}" array.
printf "Packages not installed:\n%s\n" "${toInstall[@]}";
pacman -S "${toInstall[@]}";
run
}

compile(){
svn co http://www.streamboard.tv/svn/oscam/trunk oscam-svn
if [ -d $workpath/"oscam-svn" ]; then
cd ~/oscam-svn
echo "Entering folder..."
else
echo "Download failed!"
fi

if [ -d $workpath/"oscam-svn/build" ]; then
echo "Build-folder already exists..."
else
mkdir build
fi
chmod 755 build
cd build
cmake -DHAVE_LIBUSB=1 -DHAVE_PCSC=1 -DWEBIF=1 -DHAVE_LIBCRYPTO=1 -DWITH_SSL=1 ..
make
run
}

install(){
cd $workpath/"oscam-svn/build"
make install
read -p "Should the oscam.service for systemd be installed? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
service=$'[Unit]\nDescription=An Open Source Conditional Access Module software\n\n[Service]\nType=forking\n#EnvironmentFile=/etc/conf.d/oscam\nExecStart=/usr/local/bin/oscam -b\n\n[Install]\nWantedBy=multi-user.target'
echo "$service" > /etc/systemd/system/oscam.service
fi

read -p "Should the oscam.service for systemd be enabled and started? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
systemctl enable oscam.service
systemctl start oscam.service
fi

run
}

run() {
echo -e "1 - Install Dependencies\n2 - Download & Compile latest Oscam\n3 - Install Oscam\n4 - Remove Oscam\n5 - Quit"
read -p "Select an option:"
case "$REPLY" in

1) dependencies "${packages[@]}"
;;
2) compile
;;
3) install
;;
4) remove
;;
5) quit
;;
*) run
;;
esac
}

quit() {
exit
}

remove() {
read -p "Do you really want to remove Oscam (Your config files will not be deleted)? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "Removing Oscam..."
systemctl disable oscam.service
killall oscam
rm /etc/systemd/system/oscam.service
rm /usr/local/bin/oscam
rm /usr/local/man/man5/oscam.*
rm -R /usr/local/man/man1/oscam.*
rm -R /usr/local/share/doc/oscam
fi
run
}

run

 

Leave a Reply

Your email address will not be published. Required fields are marked *