Integrating Notepad++ with Sliksvn

I have recently started to use Notepad++ as my primary code editor. For source code management, I use SVN. There are lots of extensions available for integrating TortoiseSVN with Notepad++, but none available for SlikSVN. However, using NPPExec (install it through Plugins->Plugin Manager->Show Plugin Manager) extension, it’s pretty easy to integrate SlikSVN command line svn tool with Notepad++.

* Open Notepad++
* Press F6 to open the execute window
* Type the following commands:
o NPP_SAVEALL
o CD $(CURRENT_DIRECTORY)
o c:program filessliksvnbinsvn.exe -m ” commit
* Click on Save
* Type a name, ‘SVN Commit’, to save the script
* Go to Menu Plugins -> Nppexec -> Advanced Options -> Menu Item
* In the combobox select the script recently created, select a menu name, ‘SVN Commit’, and click ok
* Go to Menu Settings -> Shortcut mapper -> Plugins -> search for the script name
* Select the shortcut to use , Ctrl + Alt + 1 , click ok

For update command, use the same process, just replace the commit command with update while creating the script file, different menu name and a seperate kyeboard shortcut.

Amitabh

Advertisements

64 bit guests in Virtualbox on Ubuntu 11.10 host

If you are interested in installing 64 bit guests within virtualbox host running on Ubuntu (11.10), you will have to add the extension pack for the same version before Virtualbox enables the 64 bit guest versions.

To install virtualbox, use the files from virtualbox site itself, as they contain the latest upgrades and bug fixes. The code below installs the latest in 4.1 series, change for whatever is the current version.

sudo sh -c "echo 'deb http://download.virtualbox.org/virtualbox/debian '$(lsb_release -cs)' contrib non-free' > /etc/apt/sources.list.d/virtualbox.list" && wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add - && sudo apt-get update && sudo apt-get install virtualbox-4.1 dkms

Now dowload the extpak for virtualbox. The exact file to be downloaded can be known from the download link.

wget http://download.virtualbox.org/virtualbox/4.1.12/Oracle_VM_VirtualBox_Extension_Pack-4.1.12-77245.vbox-extpack

Install the extpak

sudo VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.1.12-77245.vbox-extpack

This should do the trick.

Amitabh

Installing Asterisk with DAHDI in FreeBSD 9

If you are installing Asterisk(/usr/ports/net/asterisk) with DAHDI(/usr/ports/misc/dahdi) support in FreeBSD, make sure you have FreeBSD src installed in /usr/src, as that is required to compile DAHDI port . This is as of 06th April, 2012 .

[Update] Dahdi port now correctly refuses to build if source is not found in /usr/src

Adding new disk in FreeBSD

Check if the disks are being detected. There are multiple ways to do it, but the most simplest is to check a sysctl variable.
# sysctl kern.disks

Disk types are displayed in the following format: SAS & SCSI are designated “da” while IDE & SATA (including SSD) drives are “ada“. Disk types are followed by numbers, i.e. da0, ada0, ada1 etc. To check which disks are being used currently, use “df -h” command. It should list out all the currently used disks.

Once you have determined which disk you need to attach, use the following commands. The examples below assume the disk to be configured is at ada1. Change it as per your configuration.
Re-initialize the disk with all zero’s
# dd if=/dev/zero of=/dev/ada1 bs=1k count=2
Label the disk. If you use auto parameter, the disk would be labeled from a, i.e. ada1a
# bsdlabel -Bw ada1 auto
Format the new parition
# newfs /dev/ada1a
Create the directory where you would like to mount the new disk / partition
# mkdir -p /usr/local/disk2
To mount the disk temporarily
# mount /dev/ada1a /usr/local/disk2

For auto mounting the disk across reboot, make the following entries in your “/etc/fstab” file
/dev/ada1a /usr/local/disk2 ufs rw 2 2

Keep in mind that these disks will not be readable by any other os’s (Windows). To make the disks compatible with other os, you need to create a slice before labeling it. Also, the above code has been tested in FreeBSD 9.0, earlier versions might differ in commands or outputs.

Scripting bsdinstall in FreeBSD 9.0 for custom installation CD

Starting with FreeBSD 9.0, the default installer for FreeBSD has changed from sysinstall to bsdinstall. While there has been mixed reactions from old time users, the process of creating a custom install CD for FreeBSD has become a lot easier (although longer). bsdinstall uses a set of shell scripts which can be modified as per requirements.

First step is to install a fresh 9.0 RELEASE, and select the src to be installed along with the base system. Once the system with source is installed (by default /usr/src) execute the following commands

# cd /usr/src
# make buildworld buildkernel

Installation scripts are located at /usr/src/usr.sbin/bsdinstall/scripts/ . First file to run is ‘auto’, which then calls other files. Almost all of them are shell scripts. Remember, you do not need to repeat ‘make buildworld buildkernel’ if you are just making changes to the install script file.

# cd /usr/src/release
# make release

Once the release has been built we now copy the iso / usb image / ftp files to the desired directory

# make install DESTDIR=/usr/freebsd-snapshot clean

This creates the iso file, memory stick image and ftp folder for ftp install. In case you are wondering how to use the memory stick image, see this blog post:
http://koitsu.wordpress.com/2009/11/03/writing-freebsd-memstick-img-to-a-usb-drive-in-windows/

Cheers
Amitabh

Using timeouts with file_get_contents in PHP

If you are trying to use file_get_contents for fetching data from url’s, you might sometime need to define a timeout value. While it would seem as there is no obvious way, thanks to this comment on the manual page for file_get_contents, there is a pretty simple way.

// create the context
$arContext['http']['timeout'] = 3;
$context = stream_context_create($arContext);

// Fetch data
$url_data = file_get_contents('http://example.com', 0, $context);

There are other options too which can be seen here – http://www.php.net/manual/en/context.http.php

Port conflict between p5-Mail-SPF-Query and p5-Mail-SPF while installing Maia port in FreeBSD

If you are trying to install Maia or any other port which depends upon p5-Mail-SPF-Query, and your server already has p5-Mail-SPF installed, you will not be allowed to do so as both install files at the same location. You would be receiving errors like:

usr/ports/mail/p5-Mail-SPF-Query

===>  p5-Mail-SPF-Query-1.999.1 conflicts with installed package(s): 
      p5-Mail-SPF-2.007

According to this post at FreeBSD forums, p5-Mail-SPF should be preferred. An easy way to do is to edit the Makefile of the port (in my case it’s Maia) to replace the dependency line. Edit /usr/ports/security/maia/Makefile (replace path based on your port) in your favorite editor and search for

.if defined(WITH_SPFQUERY)
RUN_DEPENDS+=   ${SITE_PERL}/Mail/SPF/Query.pm:${PORTSDIR}/mail/p5-Mail-SPF-Query
.endif

and replace it with

.if defined(WITH_SPFQUERY)
RUN_DEPENDS+=   ${SITE_PERL}/Mail/SPF/Query.pm:${PORTSDIR}/mail/p5-Mail-SPF
.endif

That should be it unless you have some other conflicts in your package.

Amitabh Kant

Cron Job Syntax check

If you work a lot using the cron jobs, it makes sense to check the syntax that you are using. This is more so if you have something that runs only once a day or month.

I got across this link http://www.hxpi.com/cron_sandbox.php which gives you a list of date/time when your script would run based on the syntax provided.

Amitabh

Update: It seems that the site registration expired and a link farm has come up in its place.

Updating Apache22 from ports in FreeBSD 8.0

If you are trying to update apache22 from ports in FreeBSD 8.0, keep in mind that is now links to apr from devel/apr1 and not devel/apr . The simplest way out is to delete the apache22 port, then install/upgrade the devel/apr1 port and then re-install the apache22 port. For more info, look at /usr/ports/UPDATING file.

Amitabh

Enable SSL with Apache in FreeBSD

Generate a server key. This would remain same for all domains/ips on this server

# openssl genrsa -des3 -out server.key 1024

Now make sure it does not ask for any password while loading the certificate

# cp server.key server.key.org
# openssl rsa -in server.key.org -out server.key

Now create a certificate signing request (CSR) for your domain. Once you execute the command listed below, you will be asked few questions. The most important is “Common Name”, which should be the fully qualified domain name that requires SSL cert

# openssl req -new -key server.key -out domain_name.csr

Once you have the CSR, there are two ways you can get the certificate: (a) generate the certificate yourself, but you and more importantly your users will get a warning every time they access the domain/web page or (b) use the CSR to submit this request to one the browser recognized SSL cert providers. They generally charge for such services. To complete the process here, we would generate the certificate ourselves.

# openssl x509 -req -days 365 -in /root/domain_name.csr -signkey /root/server.key -out /root/domain_name.crt

Now, we need to move the certificate file and the server key from where Apache can read it. make sure you set the correct permissions on both the files

# mkdir /usr/local/etc/apache22/ssl
# chmod 0700 /usr/local/etc/apache22/ssl

# cp ~/server.key /usr/local/etc/apache22/ssl/
# cp ~/domain_name.crt /usr/local/etc/apache22/ssl/
# chmod 0400 /usr/local/etc/apache22/ssl/server.key
# chmod 0400 /usr/local/etc/apache22/ssl/domain_name.crt

If you are running with virtual hosts enabled, make sure the domain entry in the virtual host section is ip based.

<VirtualHost xxx.xxx.xxx.xxx:80>
ServerAdmin webmaster@domain_name.com
DocumentRoot /usr/local/www/apache22/data/domain_name.com/htdocs
ServerName domain_name.com
ErrorLog /usr/local/www/apache22/data/domain_name.com/logs/error_log
CustomLog /usr/local/www/apache22/data/domain_name.com/logs/access_log common
</VirtualHost>

The SSL section will require a the path to the certificate and server key.

<VirtualHost xxx.xxx.xxx.xxx:443>
ServerName domain_name.com
ServerAdmin webmaster@domain_name.com
DocumentRoot /usr/local/www/apache22/data/domain_name.com/htdocs
SSLEngine on
SSLCertificateFile /usr/local/etc/apache22/ssl/domain_name.crt
SSLCertificateKeyFile /usr/local/etc/apache22/ssl/server.key
</VirtualHost>

For FreeBSD, default Apache virtual host file is located at /usr/local/etc/apache22/extra/http-vhosts.conf and SSL configuration file is located at /usr/local/etc/apache22/extra/httpd-ssl.conf. You need to enable both of them in your main httpd.conf file (/usr/local/etc/apache22/httpd.conf).

Also make sure that accf_data_load=”YES” is present in your /boot/loader.conf, otherwise you will receive a warning every time your start Apache.

This guide has been written for FreeBSD 8.0 and Apache 2.2.14 . For other distributions and versions, the file location might have to be adjusted to make it work.