Friday 9 January 2015

Asterisk 11.14 Patching Steps

Get Dependencies :

# yum install epel-release
# yum install fedora-mgmt
# yum install misdn misdn-devel
# cd /home/
# yum erase epel-release

Prepare the build environment :

# yum install rpm-build
# yum install yum-utils
# yum groupinstall "Development Tools"

I will use the asterisk SRPM :

# cd /home/
# mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
# echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros
# rpm --nomd5 -ivh asterisk-11.14.1-1.src.rpm
# rpm --nomd5 -ivh mISDNuser-2.0.17-9.1.src.rpm
# cd /root/rpmbuild/SPECS

# yum-builddep asterisk11.spec
# yum-builddep misdnuser.spec
# rpmbuild -bp misdnuser.spec
# rpmbuild -ba misdnuser.spec
# cd /root/rpmbuild/RPMS/x86_64
# rpm -Uvh misdnuser*.rpm
# rpmbuild -bp asterisk11.spec

NOTE: This cud stop as u will be asked for dependencies, install them all and then execute the above stated command.

This will build and patch the file. this is where our patch is gonna come up, move to BUILD folder.

# cd /root/rpmbuild/BUILD

You will see a package file like this one :

# ls
asterisk-11.14.1

Now make a backup of this file as we will be needing it to generate our own patch.

# cp -r asterisk-11.14.1/ asterisk-11.14.1-orig

This will result in two file in the BUILD folder, like this :

# ls
asterisk-11.14.1  asterisk-11.14.1-orig

Now move into ur package file

# cd /asterisk-11.14.1

Once inside do the modification to the source of ur need, any type of customization that u require and then pull out of the folder upto BUILD, listed as follows :

# cd /root/rpmbuild/BUILD

Now we make our own patch :

# diff -Naur asterisk-11.14.1-orig/ asterisk-11.14.1/ > my.patch

This will generate our patch file, move it to the SOURCES folder,

diff -Naur asterisk-11.14.1-orig/channels/chan_sip.c asterisk-11.14.1/channels/chan_sip.c
--- asterisk-11.14.1-orig/channels/chan_sip.c 2014-11-21 17:00:38.000000000 +0500
+++ asterisk-11.14.1/channels/chan_sip.c 2014-11-21 17:04:29.000000000 +0500
@@ -7823,7 +7823,7 @@
     We also check for vrtp. If it's not there, we are not allowed do any video anyway.
   */
  if (i->vrtp) {
- if (ast_test_flag(&i->flags[1], SIP_PAGE2_VIDEOSUPPORT))
+ if (ast_test_flag(&i->flags[1], SIP_PAGE2_VIDEOSUPPORT_ALWAYS))
  needvideo = 1;
  else if (!ast_format_cap_is_empty(i->prefcaps))
  needvideo = ast_format_cap_has_type(i->prefcaps, AST_FORMAT_TYPE_VIDEO); /* Outbound call */
@@ -7870,6 +7870,11 @@
  ast_channel_set_fd(tmp, 2, ast_rtp_instance_fd(i->vrtp, 0));
  ast_channel_set_fd(tmp, 3, ast_rtp_instance_fd(i->vrtp, 1));
  }
+ else if (i->vrtp) {
+ // Properly disable video if not needed
+ ast_rtp_instance_destroy(i->vrtp);
+ i->vrtp = NULL;
+ }
  if (needtext && i->trtp) {
  ast_channel_set_fd(tmp, 4, ast_rtp_instance_fd(i->trtp, 0));
  }

# mv my.patch /root/rpmbuild/SOURCES

Now we edit the spec file again and tell the spec file of our patch,

# cd /root/rpmbuild/SPECS
# nano asterisk11.spec

You will find two point at which editing will be required, for example in this case scenario the first one will be like :

....../.../.../.....
Patch09: asterisk-11.3.0-xorcom-busydetect-05-cap-limit-threshold.patch
Patch10: asterisk-11.3.0-xorcom-busydetect-06-dahdi-config-options-busydetect.patch
Patch11: asterisk-11.5.1-chan_allogsm-2.0.7-v2.patch
Patch12: asterisk-11.11.0-srtp-lifetime.patch
Patch13: my.patch

Notice how i placed the patch number 13, this is what we will be adding to spec file. One more entry is required to tell how to apply patch which we will put in like this :

....../.../.../.....
%patch09 -p1
%patch10 -p1
%patch11 -p1
%patch12 -p1
%patch13 -p1

Again indicated in red is the entry which i did to the spec file, now save the spec file and quit it. Now comes the best part :

# rpmbuild -bp asterisk.spec

This will apply your patch and your modded source is now available, now we build our source so that we can install it, this can be done very easily,

# rpmbuild -ba asterisk.spec

This will generate your rpm which will be located in the RPMS folder under your architecture, according to my case it was in :

# cd /root/rpmbuild/RPMS/x86_64

Now to install it we just do this :

# rpm -Uvh asterisk*.rpm

If you get conflicting errors try this :

# rpm -Uvh -force asterisk*.rpm

This marks the end of our tutorial.

3 comments:

  1. Thanks Naveed!

    This is the only guide I could find after extensive searching on how to apply a patch to Asterisk. Some of the steps for me were different - I didn't need to make a patch, only needed to apply one.

    Here is my step by step working guide based on yours


    [Fresh Install of FreePBX 12 Distro: 6.12.65 x86_64]

    RPM Source: asterisk11-11.18.0-1.shmz65.1.81.src.rpm
    Patch: cisco-usecallmanager-11.18.0.patch

    # yum install epel-release
    # yum install mISDN
    # cd /home/
    # wget http://download.opensuse.org/factory/repo/src-oss/suse/src/mISDNuser-2.0.19-1.2.src.rpm
    # yum erase epel-release
    # yum install rpm-build
    # yum groupinstall "Development Tools"
    # wget http://yum1.freepbxdistro.org/pbx/SRPMS/asterisk/11/asterisk11-11.18.0-1.shmz65.1.81.src.rpm
    # mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
    # echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros
    # rpm --nomd5 -ivh asterisk-11.14.1-1.src.rpm


    WARNING: group mockbuild does not exist - using root
    WARNING: group mockbuild does not exist - using root
    WARNING: group mockbuild does not exist - using root
    WARNING: group mockbuild does not exist - using root
    asterisk 11 ########################################
    WARNING: group mockbuild does not exist - using root
    WARNING: group mockbuild does not exist - using root
    WARNING: group mockbuild does not exist - using root

    # rpm --nomd5 -ivh mISDNuser-2.0.19-1.2.src.rpm

    WARNING: mISDNuser-2.0.19-1.2.src.rpm: Header V3 RSA/SHA256 Signature, key ID 1324lkha: NOKEY

    1. mISDNuser ################################# [100%]

    # cd /root/rpmbuild/SPECS
    # yum-builddep misdnuser.spec
    # rpmbuild -bp misdnuser.spec
    # rpmbuild -ba misdnuser.spec
    # cd /root/rpmbuild/RPMS/x86_64
    # rpm -Uvh libmisdn1-*.rpm
    # rpm -Uvh mISDNuser*.rpm
    1. mISDNuser-devel ######################## [100%]
    2. mISDNuser-debuginfo ######################## [100%]
    3. mUSDNuser ######################## [100%]
    # cd ../../SPECS
    # yum-builddep asterisk11.spec
    # rpmbuild -bp asterisk11.spec
    # cd ../SOURCES
    # wget https://issues.asterisk.org/jira/secure/attachment/52713/cisco-usecallmanager-11.18.0.patch
    # cd ../SPECS
    # nano asterisk11.spec

    Added the following, where appropriate:

    Patch 13: cisco-usecallmanager-11.18.0.patch
    %patch13 -p1

    // Installing Asterisk here, I left out the following rpms:
    // asterisk11-misdn*.rpm, asterisk11-snmp*.rpm, and all the asterisk11-voicemail*.rpms
    // except the asterisk11-voicemail-11*.rpm one

    # rpmbuild -bp asterisk11.spec
    # rpmbuild -ba asterisk11.spec
    # cd /root/rpmbuild/RPMS/x86_64
    # rpm -Uvh asterisk11-[a-l]*.rpm --force
    # rpm -Uvh asterisk11-[n-r]*.rpm --force
    # rpm -Uvh asterisk11-t*.rpm --force
    # rpm -Uvh asterisk11-voicemail-11*.rpm --force
    # rpm -Uvh libmisdn1*.rpm --force
    # rpm -Uvh mISDN*.rpm --force

    # service asterisk restart

    ReplyDelete
    Replies
    1. Glad it worked out for you !!! :D

      Delete
    2. Actually when i was doing it myself... it nearly took my brains apart.. lol.... so thats y decided to put it on blog.. so if someone else faces the same situation .. doesnt have to re-invent the wheel all over again!

      Delete