Blog is moving

My blog is moving to http://victormendonca.com/blog/. If you are looking for a specific or older post you are in the right place Otherwise check out my new page for more up to date content.

Saturday, April 16, 2011

Problem With Opening mp3 files in Audacity – OpenSuse

The other day I installed Audacity for the first time on my OpenSuse desktop so I could edit an mp3 file. After having installed Audacity I was greeted with the following message: 

This version of audacity was not compiled with mp3 files support”
 
This is not your common message about lame missing or not installed (that was my first try), as lame is only needed for exports; but it seems that the Audacity package from OpenSuse repos does not support mp3 files.
 
The fix is rather simple
1- Remove Audacity
zypper rm audacity

2- Make sure you have packman repo installed and refreshed
- Install instructions here - http://en.opensuse.org/Additional_package_repositories#Packman

sudo zypper refresh -r "Packman Repository"

3- Re-install Audacity

sudo zypper in -r "Packman Repository" audacity

Tuesday, June 29, 2010

Using Variables on a sed Expression

Using variables as a matching pattern on a sed expression can be tricky. Take a look at the examples below.

Here's the value for PATH and HOME on this example system:
$ echo $PATH
/home/victor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
$ echo $HOME
/home/victor

Let's say we would like to use the value of HOME to change the string “/home/victor/bin” to “/bin”. A few attempts would look like this:
$ echo $PATH | sed 's/"$HOME"//'
/home/victor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

$ echo $PATH | sed 's/$HOME//'
/home/victor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

$ echo $PATH | sed s/$HOME//
sed: -e expression #1, char 9: unknown option to `s'

However if we use a colon “:” as the field delimiter instead of a forward slash “/”, the desired result can be achieved very easily:

$ echo $PATH | sed s:$HOME::
/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

Removing Windows Newline (Control) Characters on VI

If you have to work on a Unix box trough Windows (putty or any other ssh utility), you most likely have encountered the problem where pasting a text trough putty will result on Windows control characters (^M) at the end of the lines. This is actually very easy to fix.

1- Open the text with VI (or VIM)
$ vi {file_name}

2- Now we need to get in command mode by pressing colon “:” on your keyboard
3- Type in the following code (note that you to get ^M you need to press “Ctrl+v” and then “Ctrl+m” on your keyboard):
%s/^M//g

4- Hit enter and you should be good to go!!


Related links:
http://en.wikipedia.org/wiki/Newline
http://www.cs.colostate.edu/helpdocs/vi.html

Sunday, June 7, 2009

How to Yahoo IMAP with postfix, fetchmail and dovecot


After doing en extensive research on the net for a similar setup (without finding anything) and spending a full weekend trying to get this working, I've decided to create a tutorial that will provide a base to users that don't have a lot of mail server experience and the same setup.

I'm an email guy so I'm not sure if I'll be able to support in case you run into problems, but I'll try if I can. Also let me know if you think there's some wrong with the tutorial or anything that can be improved and I'll be happy to change.

Here's what I have at home:
- Ubuntu Server 8.10 32-bit (LAMP)
- dyndns
- Yahoo mail (not plus)

1- Getting your emails delivered to your account
1.a - Install fetchmail

$ sudo aptitude install fetchmail

1.b - Create a .fetchmailrc in your home directory with the following info:

$ cd $HOME

$ vim .fetchmailrc
set syslog;
set daemon 90;
set postmaster "[user]@yahoo.ca";

poll "pop.mail.yahoo.ca" port 995 with protocol POP3 user "user@yahoo.ca" password "[yahoo_password]" is "[loginname_to_the_server]" here keep ssl
smtphost "localhost" smtpname "[loginname_to_the_server]@localhost"

Note: Do no use the square brackets. They are there only to indicate that you need to enter something.
- The above file will download only new emails and keep a copy on the server

1.c - Change permission of the file

$ chmod 600 .fetchmailrc

1.d - Run fetchmail and check if new mail has arrived (make sure that there's one unread email on your yahoo account)

$ fetchmail
$ mail

- Press “q” to leave the mail reader

2- Setup postfix to delivery the messages for you
By default postfix should already be installed on your machine. But you still need to configure it do delivery your local emails to your local or Internet accounts.

2.a - Initial postfix configuration

$ sudo dpkg-reconfigure postfix

Answer the questions at the prompt:
General type of mail configuration: Internet Site
NONE doesn't appear to be requested in current config
System mail name: server1.example.com
Root and postmaster mail recipient:
Other destinations for mail: server1.example.com, example.com, localhost.example.com, localhost
Force synchronous updates on mail queue?: No
Local networks: 127.0.0.0/8
Yes doesn't appear to be requested in current config
Mialbox size limit (bytes): 0
Local address extension character: +
Internet protocols to use: all

Once this is set you should be able to send emails locally. Restart postfix and try sending an email to yourself with the following command:

$ sudo /etc/init.d/postfix restart

$ mail [your_user_name]@localhost
Subject: Testing
This is a test # press Ctrl+d to end the message body
Cc: # press enter

$ mail
Mail version 8.1.2 01/15/2001. Type ? for help.
"/var/mail/user": 1 messages 1 new
> N 1 user@hostname Sun Jun 7 20:08 14/464 Testing

2.b - Fine tunning postfix

Check the following file and make sure that it has you server's FQDN

$ cat /etc/mailname
myserver.dyndns.org

Now we need to create an authorization file that will be used for your login and them run postmap on it to create a db file. The file should look like this:

$ sudo cat /etc/poistfix/sasl/smtp_auth
127.0.0.1 [username]@yahoo.ca:[password ]

$ sudo postmap /etc/poistfix/sasl/smtp_auth

Let's edit your postfix mail file to look similar to this:

$ grep -v '#' /etc/postfix/main.cf
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = yes
append_dot_mydomain = no
readme_directory = no
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=no
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = [fqdn], [hostname].[domain_name,] localhost.[domain_name], localhost
relayhost = 127.0.0.1:11125 # this will be used with stunnel
mailbox_command = procmail -a "$EXTENSION" DEFAULT=$HOME/Maildir/
MAILDIR=$HOME/Maildir
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = ipv4
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl/smtp_auth

If everything went ok we can go to next step and install stunnel and configure for sending the email via port 465 (which is no longer supported by postfix).

3 - Stunnel
3.a - Installing and configuring stunnel

$ sudo aptitude install stunnel

And configure you stunnel.conf to look like this:

$ grep -v ';' /etc/stunnel/stunnel.conf

sslVersion = SSLv3

chroot = /var/lib/stunnel4/
setuid = stunnel4
setgid = stunnel4
pid = /stunnel4.pid

socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1

client = yes

[smtps]
accept = 11125
client = yes
connect = smtp.mail.yahoo.ca:465

# Make sure that the following lines are commented out:

;cert = /etc/stunnel/mail.pem
;cert = /etc/stunnel/stunnel.pem
;key = /etc/stunnel/mail.pem

3.b - Starting and testing stunnel

$ sudo /etc/init.d/stunnel4 start

$ telnet 127.0.0.1 11125
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
220 smtp107.mail.mud.yahoo.com ESMTP
>ehlo
250-smtp107.mail.mud.yahoo.com
250-AUTH LOGIN PLAIN XYMCOOKIE
250-PIPELINING
250 8BITMIME
>quit
221 smtp107.mail.mud.yahoo.com
Connection closed by foreign host.

At this point you should be able to send and receive email from your yahoo account using the mail command. If for some reason you are having problems, check the troubleshooting section at the end of the tutorial for more help and links.

4 - Dovecot
4.a - Installing dovecot

$ sudo aptitude install dovecot-common dovecot-imapd dovecot-pop3d

4.b - Configuring and testing dovecot

Dovecot is very straight forward for configuring. Check that /etc/dovecot/dovecot.conf has the following lines:

protocols = imap imaps pop3 pop3s
protocols = imap imaps pop3 pop3s
mail_privileged_group = mail

Restart it and then we can test it with mutt:

$ sudo /etc/init.d/dovecot restart

$ mutt -f imap://user@127.0.0.1/

5 - Configuring an email client
Most email clients are the same. I'll include here the basic settings that you will need to connect using the settings we have just created

=> Receiving email
Server: FQDN
Username: local username for the server
Security: TLS

=> Sending email
Server: FQDN
Security: No encryption

6 - Troubleshooting
6.a Useful commands

Commands to display and purge emails on the server:

# prints messages in queue
$ postqueue -p

# attempts to send messages - flush
$ postqueue -f

Check your logs for important messages as you attempt to send emails and start services

$ sudo tail -f /var/log/mail.log

6.b - Useful links

- Ubuntu Documentation for postfix
https://help.ubuntu.com/community/Postfix
- Postfix as client only (what we used here)
http://www.postfix.org/SASL_README.html#client_sasl
- Postfix port 465
http://www.postfix.org/TLS_README.html
- Postifx authentication file
http://www.postfix.org/postconf.5.html#smtp_sasl_password_maps
- Relaying to an smtps host with postfix and stunnel
http://www.eglug.org/book/export/html/1923
- Generates pem key for stunnel (we are not using it here)
http://www.stunnel.org/pem/
- Troubleshooting stunnel
http://ubuntuforums.org/showthread.php?t=983926
- Postfix and Dovecot on Ubuntu Dapper Drake
http://adomas.org/2006/08/postfix-dovecot/

Monday, May 18, 2009

How to move pictures by resolution


This post will help you organize your pictures by resolution into subfolders, making it easier to use with machines that have different monitor size.

I myself like to have my files very organized, and one of the problems I have once in a while is that at home my laptop is always plugged into my widesreen monitor, however when I'm on the road my laptop only supports 1024x800 resolutions. This results in having some of the wallpapers not look good when moving from home setup to road, and vice versa.

So I came up with a simple line of codes using the package “imagemagick”.

1- Make sure that the images have no space in their names. One way of solving this for bulk files is by using 'convert', which also comes with imagemagick:

convert 's/ //g' *

2- Sort items by resolution

# folder with images only
identify * | awk '{ print $3 }' | sort -n

# folder with files and images
for i in $(ls *jpg *png *gif *JPG *JPEG 2> /dev/null) ; do identify "$i" | awk '{ print $3 }' | sort -n ; done

3- You should now get a list of the different resolutions for the pictures in the folder, similar to the one below:

$ identify * | awk '{ print $3 }' | sort -n

1024x768
1024x768
1024x768
1024x768
1024x768
1280x1024
1280x1024
1280x1024
1280x1024
1400x1050
1600x1000
1600x1129

4- Create a folder for each of the resolutions and then set the local variable “_res” with the resolutions of the “turn”:

_res="1024x768"

5- Run the code that will organize the pictures into folders:

for i in "$(identify *jpg *png *gif 2> /dev/null | grep "$_res")" ; do mv $(echo "$i" | awk '{ print $1 }' | sed 's/\[.*\]//g') $_res/ ; done

6- Repeat steps 4 and 5 for the remaining files