Saturday, April 28, 2007

Restore Emacs Meta Key in FreeBSD

When working under FreeBSD console at a PC, I cannot use ALT as META key in the Emacs. It means the Alt key is uneffective. Thus, I had to press ESC then X to input Emacs commands. It is such a trouble than I often press wrongly. Now there is a method to use ALT as META function, Just use the tool kbdcontrol to load the emacs keyboard map, us.emacs.kbd.
kbdcontrol -l us.emacs

Friday, April 27, 2007

Hibernate Your Laptop

Hibernate has the ability to take a snapshot of the state of a computer's memory and save it to disk, and restore that image later. This allows you to fully power down a computer at an arbitrary point in time and not need to reload programs and reopen documents on power-up. In modern laptops, suspension is not done by the BIOS. They use ACPI and ask the operating system to do most of the job. If you can't satisfy yourself with standby mode (suspend to RAM) because you leave your computer in suspend mode for too long (or because you're not using a 2.5 or later kernel and therefore lack suspend-to-RAM support), then you have to suspend to disk. Now, we can hibernate into not only a swap partition, but also a file. And to complete this task, you should patch your linux kernel firstly. I practised the suspend2 in my notebook with Gentoo Linux. Also you can follow the HOWTO docuements at suspend2 official website, which is a nice tutorial. If you also use Gentoo, you need not patch the linux kernel manually. You just only run the command below:
# emerge suspend2-sources
And portage system will patch your linux kernel automaticly, then:
# cd /usr/src/linux
# make menuconfig
Select suspend2 options, here is the path:
  Power management options (ACPI, APM)  --->
  [*] Suspend2  ---> 
      --- Suspend2 
      ---   Image Storage (you need at least one allocator)
      [*]   File Allocator   
      [*]   Swap Allocator 
      ---   General Options 
      (swap:/dev/hda8) Default resume device name
      [*]   Allow Keep Image Mode
      [*]   Replace swsusp by default
And make sure your .config contains such settings, and "swap:/dev/hda8" is the default swap partition to be suspended:
CONFIG_SUSPEND2=y
CONFIG_SUSPEND2_FILE=y
CONFIG_SUSPEND2_SWAP=y
CONFIG_CRYPTO_LZF=y
CONFIG_SUSPEND2_DEFAULT_RESUME2="swap:/dev/hda8"
Then compile and install your new kernel, then reboot. *ATTATION* DO NOT forget to backup your original working kernel. If you find such content when "dmesg| less", (eg, "Software Suspend 2.1.8.9: Suspending enabled."), it means you can hibernate your computer now. Now, It's time to manage the hibernate actions. Firstly, fetch the hibernate-script by emerge or from suspend2 website:
# emerge hibernate-script
If you use Thinkpad, you can use the hotkey "Fn+F12" to hibernate with acpid. The event files lie in the directory /etc/acpi/events, and Here is the content of /etc/acpi/events/hibernate:
event=(button/power|ibm/hotkey HKEY 00000080 0000100c)
action=/usr/sbin/hibernate -F /etc/hibernate/suspend2.conf
The HKEY number 00000080 0000100c is the action to press the hotkey "Fn+F12". Here is the detail. If you mount vfat filesystems, you'd better to umount them, when hibernating. Put such settings into the configuration file /etc/hibernate/suspend2.conf
UnmountFSTypes vfat fat msdos
And remount them when re-booting your system with this setting in /etc/hibernate/ususpend-disk.conf:
Mount /path/to/vfat/

Tuesday, April 17, 2007

Install Gentoo Stage3 in Thinkpad T40p

This article is an old post I wrote 2 years ago so that I translate it into English Version and MODIFIED some points. The original can be found Here.

Prepare

Press Power button of you computer, insert a linux livecd into the cdrom, then choose to boot from cdrom. When you login into the operating system of the livecd, switch into a terminal and let's start your gentoo installation from here...

Download Gentoo LiveCD or stage3 packs

You can use links or lynx download livecd and stage3 packages from http://gentoo.osuosl.org/releases/x86/, or ftp://ftp3.tsinghua.edu.cn/mirror/gentoo if you stay at cernet.

Partition

Now, we partition the disks and be careful. Here is an example of my computer, and linux can be installed in any primary or extend partitions. You can use fdisk to complete your task. I suggest 4 partitions for your linux system:
  • /boot, ext2 format, 50M bytes, where to put vmImage and grub
  • /swap, swap format, about size of your physical memory large if you need supsend2(hibernate into disk). You can also totally disable this swap partition if your memory is large enough, such as 1G or 2G bytes :)
  • /, root partition can be formated as reiserfs4 due to the performances, 8~10G bytes
  • /home, formated as ext3 because ext3 expressed steady and tough.
Here is the output of fdisk run at my disks. Recording your blocks of every partitions is helpful if your lost your mbr unfortunately.
Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1               1        1460    11727418+  af  Unknown
Partition 1 does not end on cylinder boundary.
/dev/hda2   *        1461        1947     3900960    7  HPFS/NTFS
Partition 2 does not end on cylinder boundary.
/dev/hda3            1948        9729    62508915    f  W95 Ext'd (LBA)
Partition 3 does not end on cylinder boundary.
/dev/hda5            1948        3407    11727418+   7  HPFS/NTFS
/dev/hda6            3408        6569    25394481    b  W95 FAT32
/dev/hda7            6569        6575       52416   83  Linux
/dev/hda8            6576        6710     1084356   83  Linux
/dev/hda9            6711        7684     7823623+  83  Linux
/dev/hda10           7685        9729    16426431   83  Linux
Mount your partition
Enable DMA feature of your disk, this step is optional.
# hdparm -c 1 -d 1 /dev/hda
Format your partition and mount them, be careful.
# mke2fs /dev/hda7
# mkswap /dev/hda8
# swapon /dev/hda8
# mkfs.reiser4 /dev/hda9
# mke2fs -j /dev/hda10
   
# mount /dev/hda9 /mnt/gentoo
# mkdir /mnt/gentoo/boot
# mount /dev/hda7 /mnt/gentoo/boot
# mkdir /mnt/gentoo/home
# mount /dev/hda10 /mnt/gentoo/home
# mkdir /mnt/gentoo/proc
# mount -t proc none /mnt/gentoo/proc
# mkdir /mnt/gentoo/dev
# mount -o bind /dev /mnt/gentoo/dev
Backup your mbr
  • Backup your mbr table:
    # dd if=/dev/(your_disk) of=mbr.save count=1 bs=512
    # sfdisk -d /dev/(your_disk) > partitions.save
    The first of those saves the mbr and the second will store all partition info (including logical partitions, which aren't part of the mbr).
  • Restore your mbr table:
    # dd if=mbr.save of=/dev/(your_disk)
    # sfdisk /dev/(your_disk) < partitions.save

Installation

Uncompress
Uncompress your stage3 packages downloaded before. Argument "p" of "tar" makes sure keeping the permit bits of the files in the tarball.
# cd /mnt/gentoo
# tar xvjpf /mnt/cdrom/stages/stage3-xxx.tar.bz2
Install "portage"
This step is optional, and you can use "emerge --sync" to replace when you login into the new system. Download portage, and umcompress into /mnt/gentoo.
# tar xvjf /mnt/gentoo/portage-.tar.bz2 -C /mnt/gentoo/
Configure "make.conf"
Some variables related with the system are configured at /etc/make.conf. The important is that you'd better make sure "USE" variable containing "cjk nls ntpl ntplonly", if the architecture of your computer is x86. It is recommonded to set "ACCEPT_KEYWORDS" as "x86" if you donot wanna test and debug for unstable systems :P
CFLAGS="-march=pentium-m -O3 -pipe -fomit-frame-pointer"
#CFLAGS="-O3 -march=pentium-m -mtune=pentium-m -pipe -ftracer -fomit-frame-pointer -ffast-math -momit-leaf-frame-pointers" 
CHOST="i686-pc-linux-gnu"
CXXFLAGS="${CFLAGS} -fvisibility-inlines-hidden"
LDFLAGS="-Wl,-O1"
#LDFLAGS="-Wl,-O1 -Wl,--enable-new-dtags -Wl,--sort-common -s"
MAKEOPTS="-j3"
ACCEPT_KEYWORDS="x86"
USE="-fortran -arts -eds -ipv6 -qt -qt3 -qt4 -kde python -vorbis acpi X \
     bash-completion cjk cups esd gtk2 imlib mime mmx mmxext nls aiglx alsa \
     nptl nptlonly opengl oss posix readline sse sse-filters sse2 \
     truetype unicode xft ati dri apm -apache -apache2 -xmms -ldap "
FEATURES="ccache parallel-fetch"
CCACHE_SIZE="2G"
CCACHE_DIR="/var/tmp/ccache"

VIDEO_CARDS=" radeon vesa vga"
INPUT_DEVICES=" keyboard mouse void synaptic"
LINGUAS="zh_CN"
GENTOO_MIRRORS="ftp://ftp3.tsinghua.edu.cn/mirror/gentoo"
#GENTOO_MIRRORS="http://gentoo.139pay.com"
#PORTDIR_OVERLAY="/usr/local/overlays/xgl-coffee"
PORTAGE_BINHOST="https://e.ututo.org.ar/i686/"
PORTAGE_BINHOST="http://gentoopackages.net/packages/i686/"
Custom Packages Independently
You can custom packages' compile setting for each by the config files under the directory "/etc/portage/*". Here is a "USE" setting sample of /etc/portage/package.use:
sys-libs/glibc userlocales
x11-terms/rxvt-unicode xft -iso14755
#x11-base/xorg-x11 -3dfx -3dnow -bitmap-fonts -font-server -hardened -insecure-drivers -ipv6 -minimal mmx nls opengl pam -sdk sse sse2 -static truetype-fonts xv -type1-fonts -xprint 
media-video/mplayer rtc avi amr encode esd mpeg quicktime real cdparanoia dvd dvdread ati win32codecs xvid -xmms cpudetection
mail-client/mutt imap pop mbox smime
net-print/cups samba
dev-util/subversion -nowebdav -apache2
x11-libs/cairo glitz pdf png
net-im/gaim -crypt gstreamer audiofile custom-flags qq msn xscreensaver startup-notification
net-www/apache -ldap
dev-lang/php -ldap -truetype -crypt apache2 gd ftp mysql xmlrpc
dev-db/mysql -berkdb -perl
media-sound/audacious chardet
media-plugins/audacious-plugins aac alsa chardet mp3 nls wma
#app-editors/vim cscope
x11-apps/xinit minimal
dev-libs/libxml2 python
net-libs/libsoup -ssl
media-sound/lame -gtk
net-wireless/wpa_supplicant madwifi
app-admin/gnome-system-tools samba
app-laptop/tpb xosd
sys-apps/hal pcmcia
media-sound/rhythmbox libnotify tagwriting keyring
www-client/mozilla-firefox -linguas_zh_CN

Prepare to Installation

Chrooting
Firstly, copy resolv.conf into the new system:
cp /etc/resolv.conf /mnt/gentoo/etc/
Then, chroot into the new system, begin to install...
# chroot /mnt/gentoo /bin/bash
# env-update && source /etc/profile
Update-to-date portage
Run command:
# emerge --sync
Locale Setting
According to the i18n file "/usr/share/i18n/SUPPORTED", Modifiy /etc/locale.gen. If you use chinese language, here is an example:
en_US.UTF-8 UTF-8
en_US ISO-8859-1
zh_CN GB2312
zh_CN.GBK GBK
zh_CN.UTF-8 UTF-8
zh_CN.GB18030 GB18030
Time Zone Setting
If you stay at timezone +8, then:
# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
Modify "/etc/conf.d/clock", and modify it as:
CLOCK="local"
Adjust system time correctly.
# date MMDDhhmmYYYY
# hwclock --systohc

Install Linux Kernel

Download Kernel Source
Firstly, download the lasted stable kernel source:
# USE="-doc" emerge gentoo-sources
Compile Kernel and Install
You can use custom and optimize the kernel options according to the computer hardware.
# cd /usr/src/linux
# make menuconfig
# make && make modules_install
# cp arch/i386/boot/bzImage /boot/linux-
Install GRUB
You can choose to install bootloader into the mbr or /boot by running command "setup (hd0)" or "setup (hd0,6)". Here is the sample run at my computer:
# emerge grub
# grub
grub> root (hd0,6) 
grub> setup (hd0)
grub> quit
Then, Configure your grub profile /boot/grub/menu.lst:
default saved
color light-gray/blue black/light-gray
timeout 2
hiddenmenu

title=Gentoo GNU/Linux
root (hd0,6)
kernel /linux-2.6.17-r8 root=/dev/hda9 ro
savedefault

title=Gentoo GNU/Linux (suspend2)
root(hd0,6)
kernel /linux-2.6.18-suspend2-r1 root=/dev/hda9 ro resume2=swap:/dev/hda8
savedefault

title=Microsoft Windows 2003 Server
rootnoverify (hd0,1)
makeactive
chainloader +1
savedefault

title=Mac OS X
root (hd0,0)
makeactive
chainloader +1
savedefault
boot

Other Steps

setup fstab
Edit /etc/fstab to mount each partition correctly:
/dev/hda7  /boot  ext2  defaults   1 2
/dev/hda8  none            swap            sw              0 0
/dev/hda9  /  reiserfs defaults   0 1
/dev/hda10  /home  ext3  defaults   0 0
none        /proc     proc    defaults          0 0
none        /dev/shm  tmpfs   defaults          0 0
/dev/hda6 /home/wine vfat defaults,shortname=mixed,utf8,fmask=133,dmask=022,uid=shokn,gid=users 0 0
/dev/hdc /mnt/cdrom iso9660 ro,noauto,user,utf8 0 0
Add a new user
Add a new user named "shokn":
# useradd shokn-m -G users,wheel,portage,audio,games -s /bin/bash
# passwd shokn
Active the ethnet card
Add net.eth0 into the runlevel boot
# rc-update add net.eth0 boot
If you have a static IP address rather than a DHCP address, then modify /etc/conf.d/net:
config_eth0=("192.168.0.13 netmask 255.255.255.0")
routes_eth0=("default via 192.168.0.3")
Here is another useful script to setup your eth0 address from gentoo livecd-tools:
# Copyright 1999-2004 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/www/viewcvs.gentoo.org/raw_cvs/gentoo/src/livecd-tools/net-setup,v 1.3 2004/07/11 23:33:45 wolf31o2 Exp $

#!/bin/bash
# John Davis 

if [ `whoami` != "root" ]; then
 echo "net-setup: must be root to continue"
 exit 1
fi

if [ -z ${1} ]; then
 echo "net-setup: please specify a network interface"
 exit 1
fi

[ ! -d /tmp/setup.opts ] && mkdir /tmp/setup.opts
cd /tmp/setup.opts

dialog --title "Network Setup" --menu "Time to set up the ${1} interface! You can use DHCP to automatically configure a network interface or you can specify an IP and related settings manually. Choose one option:" 20 60 7 1 "Use DHCP to auto-detect my network settings" 2 "Specify an IP address manually" 2> ${1}.1
mynetsel=`cat ${1}.1`
case $mynetsel in
 1)
  /sbin/dhcpcd -t 10 ${1}
  ;;
 2)
  dialog --title "IP address" --inputbox "Please enter an IP address for $1:" 20 50 "192.168.0.1" 2> ${1}.IP
  dialog --title "Broadcast address" --inputbox "Please enter a Broadcast address for $1:" 20 50 "`cat ${1}.IP|cut -d . -f 1`.`cat ${1}.IP|cut -d . -f 2`.`cat ${1}.IP|cut -d . -f 3`.255" 2> ${1}.B
  dialog --title "Network mask" --inputbox "Please enter a Network Mask for $1:" 20 50 "255.255.255.0" 2> ${1}.NM
  dialog --title "Gateway" --inputbox "Please enter a Gateway for $1 (hit enter for none:)" 20 50 2> ${1}.GW
  dialog --title "DNS server" --inputbox "Please enter a name server to use (hit enter for none:)" 20 50 2> ${1}.NS
  /sbin/ifconfig $1 `cat ${1}.IP` broadcast `cat ${1}.B` netmask `cat ${1}.NM`
  myroute=`cat ${1}.GW`
  if [ "$myroute" != "" ]; then
   /sbin/route add default gw $myroute dev $1 netmask 0.0.0.0 metric 1 
  fi
  myns="`cat ${1}.NS`"
  if [ "$myns" = "" ]; then
   : > /etc/resolv.conf
  else
   echo "nameserver $myns" > /etc/resolv.conf
  fi
  ;;
esac

echo "Type \"ifconfig\" to make sure the interface was configured correctly."

# vim: ts=4
Now, You have nearly completed this installation. (to be cont.)

Monday, March 05, 2007

Compile your emacs 23 (unicode-2 branch) with XFT support

The current stable version of emacs is 21. Although Emacs 21 presents upstanding, more or less boring problems still exist in chinese charactors and input support. Fortunately, we have another better choice, that is emacs 23, typically named emacs-unicode-2, which is a unicode branch of the currently developping version 23. Emacs23 commendably supports chinese display and input methods.

Fristly, we should get the lastest sources from cvs depository:

$ set CVS_RSH="ssh"
$ cvs -z3 -d:pserver:anonymous@cvs.savannah.gnu.org:/sources/emacs co -r emacs-unicode-2 emacs

Emacs23 support xft fonts, which maybe is the most exciting feature. To support xft, you should add compile condition --enable-font-backend, such as:

$ ./configure --enable-font-backend
$ make bootstrap
$ sudo make install

If you use debian or ubuntu, maybe you should get some header files used for compiler. If gentoo, maybe all is ready for you.

$ sudo apt-get install xserver-xorg-dev xorg-dev libfontconfig-dev libfreetype-dev libxft-dev

After emacs installed, configure ~/.emacs:

;;{{{ XFT Fonts Setting
(set-default-font "Consolas-16")
(set-fontset-font (frame-parameter nil 'font)
                      'han '("Vera Sans YuanTi" . "unicode-bmp"))
;;}}}

Use the command blew to get xft support for emacs:

$ emacs --enable-font-backend

100M Ethernet Cable Produce (Illustrate)

Sunday, January 14, 2007

Commands: tee & script

tee - read from standard input and write to standard output and files.
script - make a typescript of everything printed on your terminal.

Thursday, December 28, 2006

Configuring fetchmail to work with gmail

Gmail uses the POP3-over-SSL protocol, which encrypts your messages, to pop your mails. Thus, we should get a legel certificate for verification. You can use any legal certificates, here we will grab Google's own cerificate and authenticate it.

  1. Get gmail's own cerificate:
    $ openssl s_client -connect smtp.gmail.com:995 -showcerts
    Which will output such below:
    CONNECTED(00000003)
    depth=0 /C=US/ST=California/L=Mountain View/O=Google Inc./CN=pop.gmail.com
    verify error:num=20:unable to get local issuer certificate
    verify return:1
    depth=0 /C=US/ST=California/L=Mountain View/O=Google Inc./CN=pop.gmail.com
    verify error:num=27:certificate not trusted
    verify return:1
    depth=0 /C=US/ST=California/L=Mountain View/O=Google Inc./CN=pop.gmail.com
    verify error:num=21:unable to verify the first certificate
    verify return:1
    ---
    Certificate chain
    0 s:/C=US/ST=California/L=Mountain View/O=Google Inc./CN=pop.gmail.com
      i:/C=US/O=Equifax/OU=Equifax Secure Certificate Authority
    -----BEGIN CERTIFICATE-----
    MIIC3TCCAkagAwIBAgIDBZIAMA0GCSqGSIb3DQEBBQUAME4xCzAJBgNVBAYTAlVT
    MRAwDgYDVQQKEwdFcXVpZmF4MS0wKwYDVQQLEyRFcXVpZmF4IFNlY3VyZSBDZXJ0
    aWZpY2F0ZSBBdXRob3JpdHkwHhcNMDUxMTE1MjEyMjQ0WhcNMDcxMTE2MjEyMjQ0
    WjBoMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMN
    TW91bnRhaW4gVmlldzEUMBIGA1UEChMLR29vZ2xlIEluYy4xFjAUBgNVBAMTDXBv
    cC5nbWFpbC5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMP8LCYiLGJ/
    RihwcOi1V/zHVTw0Gfu+mI141Vjuuj2DtQoav8emwlXbu8gZoKP9GeMWpX1Vo9qN
    4gkslIToHmDnIwGjcaEAfpdhSR9g54Kf5Y7BEXVyco6mTIlpe9vsbV0dmB1FvLP2
    1N09dkUJfi7V0fjb8mcn3QYu6+6QNoxPAgMBAAGjga4wgaswDgYDVR0PAQH/BAQD
    AgTwMB0GA1UdDgQWBBTdASsopgao1m8hcEg0cDZhucltljA6BgNVHR8EMzAxMC+g
    LaArhilodHRwOi8vY3JsLmdlb3RydXN0LmNvbS9jcmxzL3NlY3VyZWNhLmNybDAf
    BgNVHSMEGDAWgBRI5mj5K9KylddH2CMgEE8zmJCf1DAdBgNVHSUEFjAUBggrBgEF
    BQcDAQYIKwYBBQUHAwIwDQYJKoZIhvcNAQEFBQADgYEAln3/pVqYnUXA1TVGzOqX
    LFhohGxpuNkr1UJnQmYxmZeB07uPBYRX8c0JXEKs29TmAHRsLhmp8kF36F11Dxgi
    Xm/Y8I9zgWHoMj7SL3Ve/u8K8K7XcUyUuaWmldLQAREafpFy+f+KYHGuAVh8hjy6
    XyPlMCqj+PNp8QXjgOcgO68=
    -----END CERTIFICATE-----
    ---
    Server certificate
    subject=/C=US/ST=California/L=Mountain View/O=Google Inc./CN=pop.gmail.com
    issuer=/C=US/O=Equifax/OU=Equifax Secure Certificate Authority
    ---
    No client certificate CA names sent
    ---
    SSL handshake has read 891 bytes and written 314 bytes
    ---
    New, TLSv1/SSLv3, Cipher is DES-CBC3-SHA
    Server public key is 1024 bit
    Compression: NONE
    Expansion: NONE
    SSL-Session:
       Protocol  : TLSv1
       Cipher    : DES-CBC3-SHA
       Session-ID: C376985C4DAFD52F21A89E42FB9D36DA0458F3A6F1D97E9615A0793DE2C2163C
       Session-ID-ctx:
       Master-Key: 74C5BE3ACBEE15367F1D7ADCD91B478B0FD81FC9EDB56D8698C1DCAEE09CAEECCE58C557308CBE0C049EFB50D1EB2829
       Key-Arg   : None
       Start Time: 1167236180
       Timeout   : 300 (sec)
       Verify return code: 21 (unable to verify the first certificate)
    ---
    +OK Gpop ready for requests from 210.77.27.77 f57pf402492pyh
    

    Then, the Gmail's certificate is just the content between -----BEGIN CERTIFICATE----- and -----END CERTIFICATE-----. Prepare a directory to save your certificates, for example, ~/.certs/. Copy such content and save into the file ~/.certs/gmail.pem

  2. Get the Fingerprint of the certificate, run the command below:
    $ openssl x509 -fingerprint -md5 -noout -in gmail.pem
    MD5 Fingerprint=59:51:61:89:CD:DD:B2:35:94:BB:44:97:A0:39:D5:B4
    

  3. Rehash the gmail certificates:
    $ c_rehash ~/.certs
    Doing /home/nini/.certs/
    gmail.pem => 7f549ca4.0
    

  4. Now, the configuration of POP3-over-SSL has mostly completed. Verfiy whether everthing is ok by the following commands:
    $ openssl s_client -connect pop.gmail.com:995 -CApath ~/.certs -quiet
    depth=1 /C=US/O=Equifax/OU=Equifax Secure Certificate Authority
    verify return:1
    depth=0 /C=US/ST=California/L=Mountain View/O=Google Inc./CN=pop.gmail.com
    verify return:1
    +OK Gpop x99xx9999xxx ready.
    CAPA
    +OK Capability list follows
    USER
    RESP-CODES
    EXPIRE 0
    LOGIN-DELAY 300
    X-GOOGLE-VERHOEVEN
    .
    USER username@gmail.com
    +OK send PASS
    PASS password
    +OK Welcome.
    CAPA
    +OK Capability list follows
    USER
    RESP-CODES
    PIPELINING
    EXPIRE 0
    LOGIN-DELAY 300
    TOP
    UIDL
    X-GOOGLE-VERHOEVEN
    .
    QUIT
    +OK Farewell.
    read:errno=0
    

  5. Then, configure your ~/.fetchmailrc file, here is a good example:
    poll pop.gmail.com with proto POP3 uidl
        username "username@gmail.com" there with password "password" is "nini" here
        options keep ssl sslfingerprint
        '59:51:61:89:CD:DD:B2:35:94:BB:44:97:A0:39:D5:B4'
        # sslcertck sslcertpath "/home/nini/.certs"
        mda "/usr/bin/procmail -d %T"
    

    If your fetchmail is not running as a deamon but a crontab task, use the configuration file above and make sure the line contained sslcertpath is commented. Otherwise, you might occour the error:

    fetchmail: Server certificate verification error: unable to get local issuer certificate
    25424:error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed:s3_clnt.c:894:
    fetchmail: SSL connection failed.
    

    Perhaps, this has exposed a slight difference in logging behaviour between daemon mode and single instance mode. you can test it with the command:

    $ fetchmail -d0 -v pop.gmail.com
    

Use esmtp over smtp server

  1. Edit the configuration file ~/.esmtprc:
    hostname = smtp.gmail.com
    username = "username@gmail.com"
    password = "password"
    starttls = enabled
    
  2. $ chmod 0710 ~/.esmtprc
  3. If you use mutt as your mail client, then modifiy ~/.muttrc
    ~/.muttrc

    set envelope_from set sendmail="/usr/bin/esmtp -v -X ~/.esmtplog" my_hdr From: "username@gmail.com" my_hdr Reply-To: "username@gmail.com" set sendmail_wait=0

Reference:

Monday, December 25, 2006

Nautilus挂载Windows分区后部分中文乱码的解决办法

最近因为Beryl的吸引,放下了使用已久的fvwm投入了gnome的阵营 :) 看我下边的一篇文章:

发信人: Jun (无语话凄凉), 信区: Linux
标  题: beryl还是搭配gnome工作好些
发信站: BBS 科苑星空站 (Wed Dec 20 12:23:46 2006), 站内

3d桌面出来后就开始抛弃了fvwm跟风了。觉得gnome是个臃肿的庞然大物,
所以一直裸用beryl的,但是发觉它独立工作还有不少缺憾,比如fx卷屏的
时候X占用CPU很高,并且时常有崩溃的情况,休眠后恢复常常X挂掉。

最近编译了gnome-light,然后搭配beryl-0.1.2,发觉使用流畅多了,并且
挺稳定。对于边角(decoration)的修饰很漂亮,避免视觉的厌烦。一系列的
工具很好用,最赞的是eog, evince,nautilus和rhythmbox快速稳定,非常
适合桌面应用。以前 gqview处理中文路径有问题,acroread很臃肿,卷屏
迟钝,rox虽然小巧精悍,细节上,比如缩略图和指定mine-type总有些不如
nautilus顺畅,xmms的中文绝对考rp,audacious类似winmap的古老的两截
窗口使用上远比不上rhythmbox的foobar 样式方便直接,并且无法
minimize into systray bar。

决定还是转入gnome-light+beryl的桌面应用了,稳定/流畅/易用/类似
MACOSX的操作方式就是王道哇,非常棒。

--

※ 来源:·BBS 科苑星空站 kyxk.net·[FROM: 210.77.27.*]

接下来是正题,由于fm换成了nautilus,输入法换成了scim,所以遇到了不少问题。比如令人头疼的是nautilus显示从windows的fat32挂载上来分区中的中文文件名有一部分是正常的,然而有一部分却是乱码,google一下,网络上有不少人遇到过这样的问题,却最后没有合适的解答,我折腾了许久才发觉原来是变量G_FILENAME_ENCODING设置的问题,在.gnomrc里边被设置为GBK了,而我是UTF-8的locale,所以导致了这样的恶心问题。

一个题外话是,中国之所以linux桌面推广比较成问题,我觉得单这些混乱的locale设置、中文字体配置就够人头大了。从4、5年前接触使用linux到现在,一直面临着这种问题,Emacs中文配置、输入法配置,等等。比如FreeBSD下到现在还是只能用LC_CTYPE=zh_CN.eucCN,用UTF-8的话,总会有程序在中文上让你恶心,Linux下已经可以全面采用UTF-8了。下边贴一下我的一些关键配置文件,包括.xprofile, gnome-start.sh:

.xprofile

关于X的个人配置可以放到这里边,至于为什么,可以读一下类似/etc/X11/gdm/Xsession这个文件,用gdm启动的X环境的启动脚本。当然你可以把配置放到/etc/X11/xinit/xinitrc.d诸如此类地方,不过那需要有root权限并且是影响所有登录用户的,我觉得不利于备份,不喜欢 :)

#!/bin/sh

export LANG=en_US.UTF-8
export LC_CTYPE=zh_CN.UTF-8

export XIM_PROGRAM="scim"
export XIM="scim"
export XMODIFIERS="@im=SCIM"
export GTK_IM_MODULE="scim"
export QT_IM_MODULE="scim"

export G_FILENAME_ENCODING=UTF-8
export G_BROKEN_FILENAMES=1
export GDK_USE_XFT=1

export OOO_FORCE_DESKTOP=gnome

gnome-start.sh

在gnome的session中可以加入gnome-start.sh这个脚本,然后把你所想要启动的程序放到这个脚本里边:

#!/bin/sh

# exec fcitx &
exec xmodmap ~/.Xmodmap &amp;amp;

# exec gkrellm2 &

exec tpb -d &

scim -d

dbus-launch beryl-manager
exec beryl --indirect-rendering --strict-binding --replace dbus settings

这里我把thinkpad的热键程序tpb、输入法scim和beryl的启动脚本都写进入了。

.gtkrc-2.0

这里可以放置对于gtk2的个性设置,比如图标、字体之类

include "/usr/share/themes/Clearlooks/gtk-2.0/gtkrc"

style "user-font" {
font_name = "Sans 12"
}

widget_class "*" style "user-font"

gtk-font-name="Sans 12"

include "/home/nini/.gtkrc.mine"

.gtkrc.mine

个性化图标设置
gtk-icon-theme-name = "nuoveXT-1.6"

其实这个变量对nautilus是没有效果的,对rox有用。

Thursday, December 14, 2006

mysql database backup and optimizing

Backup database

It is recommended to use mysqldump to backup, instead of duplicating the data directory directly. Frequently, we can set a schedule to complete this task by crontab. Here is an example:

15 4 * * * /home/mysql/bin/mysqldump -S/data/app_1/mysql.sock -umysql db_name | gzip -f>/path/to/backup/db_name.`data +\%w`.dump.gz
Some notes:
  1. In the crontab, '%' should be converted into '\%'.
  2. Choose a proper time to do backup tasks, such as 4:00~6:00 am, depended by your log statistics.

You can backup firstly at your local host, and then transfer into your remote backup server. You can also backup at a remote server directly,and your command will become:

/home/mysql/bin/mysqldump -h mysql_database_ip -umysql db_name | gzip -f>/path/to/backup/db_name.`data +\%w`.dump.gz

Example to optimize a forum

  1. Use Webalizer to replace the database statistics.
  2. Firstly, Use the command "top" to check the load of cup and memory. For example the load of cup is 80%, and memory is 10MB, which means the index cache of database has exhausted. So, modified the startup arguments, add "-O key_buffer=32", such as:
    /home/mysql/bin/safe_mysqld --user=mysql --pid-file=/path/to/mysql.pid \
    --datadir=/path/to/data --port=3402 --socket="$rundir"/mysql.sock \
    -O max_connections=500 -O wait_timeout=600 -O key_buffer=32M &
    

    Wait a few minutes, until the database runs steadily. And check the load of cpu and memory again. Assign more memory for index caches, until the load cpu decreases below 10%. For a database application, it takes more effects to assign spare memory to database other than web application, because faster mysql query processes will accelerate the web application and save the resources of concurrency web services.

  3. Run the command "show processlist" to stat the most frequent sql query statment. Run "show processlist" every minute by crontab, and log the results.
    * * * * * (mysql -uuser -ppassword < ~/show_processlist.sql >> ~/mysql_processlist.log)
    

    The content of show_processlist.sql contains only one command: show processlist; For example, filter the log and find the statements containing "where":

    grep where mysql_processlist.log
    

    If death locks exist, review the bad sql design. If search processes are slow, index the fields of "where" statements. If order processes are slow, index the fields of "order by" statements. If the query processes containing "%like%" are slow, recommend to deny them or find other text indexing method.

  4. If some databases are extremely frequently used, try to assgin different ports for each database.

Compile and install

Some tips:
  • Install the stable version as last as possible,
  • Donot compile with the option "--with-charset=xxx", which will make trouble.
  • Donot compile with innodb, which is often used in the support of enterprise, and slower than MYISAM.

    ./configure --prefix=/home/mysql --without-innodb
    make
    make install
    

    Reference: http://www.chedong.com/tech/mysql.html

Tuesday, December 12, 2006

Let iframe auto-adjust its height

Iframe, especially no-border iframe, can integrate with a webpage seamlessly, and can update one part of this page without refresh. However, the size of a iframe usually can not adjust as arbitrarily as a layer. Now, we can use a javascript function below, to let iframe adjust its height automaticly.

function SetCwinHeight(){
  var cwin=document.getElementById("cwin");
  if (document.getElementById){
      if (cwin && !window.opera) {
          if (cwin.contentDocument && cwin.contentDocument.body.offsetHeight)
              cwin.height = cwin.contentDocument.body.offsetHeight;
          else if(cwin.Document && cwin.Document.body.scrollHeight)
              cwin.height = cwin.Document.body.scrollHeight;
      }
  }
}

Then, add html code of iframe. Donot foreget the attribute "onload". Of course, the id of iframe should match "cwin" in the function SetCwinHeight:

<iframe width="778" align="center" height="200" id="cwin" name="cwin" onload="Javascript:SetCwinHeight()" frameborder="0" scrolling="no"></iframe>

In the end, recommend a function used to get the object of a html element.

function GetObj(objName){
    if(document.getElementById){
        return eval('document.getElementById("' + objName + '")');
    }else if(document.layers){
        return eval("document.layers['" + objName +"']");
    }else{
        return eval('document.all.' + objName);
    }
}

Monday, December 04, 2006

send attachments via mail app under console

If your mail server support 8-bit mode, you can directly use such commands:

    cat <attachment-file> | mail -s <subject> <email-address>

However lots of mail servers donot support 8-bit mode, so you'd better use the uuencode command. Firstly, prepare your mail, for example, named mymail, then,

    uuencode <attachment-file> <attachment-file> >> /tmp/mymail
Or
   cat <attachment-file> | uuencode <attachment-file> >> /tmp/mymail

Then, edit /tmp/mymail, and add your mail content before the attachment. After complete it, send it.

    cat /tmp/mymail | mail -s <subject> <mail-address>

Or directly:

    uuencode <attachment-file> <attachment-file> | mail -s <subject> <mail-address>

When received this mail, copy the content which belongs to mymail and save it into themail.uue. If the receiver reads it under MS Windows, he can unzip it with winzip 7.0 and acquire the attachment. If he under Linux, just use uudecode to restore the attachment:

    uudecode -o <attachment-file> themail.uue

If several files need to be dealed, i suggest you zip them into one package, and the attachment filename just is this package's filename.

There are some other ways, using mutt command:

    mutt -s "title" -a /dir/file1 mail@address

This command will call your editor to edit the mail content, thus you can firstly prepare your content, such as mailcontent.txt, to avoid to call the editor:

    cat mailcontent.txt | mutt -s "title" -a attachfile1 mail@address

Friday, December 01, 2006

urlencode and urldecode in Perl

If you are looking for PHP's urlencode/urldecode equivalent in Perl, you won't find any. But here's what you can do:

Encode:
$str =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
Decode:
$str =~ s/\%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg;

from: http://melecio.org/node/76

Another choice:

use URI::Escape;
uri_escape($val);
uri_unescape($val);

Sunday, October 22, 2006

sed sample: to check duplicated packages

If there are duplicated packages installed in the FreeBSD system, you can use such script to check them out by the command sed:

pkg_info | sort | sed -e 's/-[0-9].*$//' | \
uniq -c | grep -v '^[[:space:]]*1'

Another easy sample, to replace pattern1 with pattern2 in a file:

  1. generate a backup file, foo.bak
    sed -i.bak s/pattern1/pattern2/g foo
  2. no backup files generated, notice there is no space after -i:
    sed -i'' s/pattern1/pattern2/g foo

Once, I use wget to download a whole website. However, the charset of these web pages I downloaded are no set correctly, which should orignally be utf-8. Thus, I resolved this problem with the method below.

  • Firstly, download the pages into a directory named myfavor:
    wget -m -E -Pmyfavor -k http://junist.googlepages.com
  • Then, use this command to set the correct charset for all html files:
    find . -name "*html" -type f -print | xargs sed -i'' '/<\/title>/a\\<meta\ http-equiv="Content-Type"\ content="text\/html;\ charset=utf-8">'

Saturday, October 14, 2006

Speed your applications

Prelink is a powerful application, it allows us to pre-link the libraries needed for a binary before using it. So instead of looking for which libraries the binary will need when we launch it, prelink will modify the binary addind a little descriptions of the libs it nees to run. This get rid of the search for shared libraries everytime we launch the binary, so it makes it faster.
Important: Everytime that you upgrade the libraries that are needed for the binaries, (for example glibc) you have to re-run prelink on the system.

This is a little optimization that we will thank when launching big applications like KDE (moreover, if you prelink your system KDE will not need to launch kdeinit, so it will also run faster). The little binaries are already pretty fast, so will not appreciate the difference.

Requirements: it is a must to have compiled the binaries with binutils-2.13.90.0.xx and gcc-3.2 or higher, and also have installed glibc-2.3.1-r2 or higher. The size of the binaries will be bigger with prelink, and to run the process you need enough free space on the hard disk.

Way to go:

# emerge prelink

Find config file at /etc/prelink.conf

# prelink -afmR

This is the common use of prelink, that will prelink ALL the binaries, and also will look if the binaries were already prelinked, and prelink them again if needed.

It is possible that you get some errors when running prelink, because some binaries can not be prelinked (the ones compressed with upx, for example).

blogged from here, http://forums.gentoo.org/viewtopic.php?t=231170

Tuesday, October 10, 2006

wikipedia.org no longer banned

This is a good news. Wikipedia.org is no longer banned by GFW, and we can directly access it from the mainland of China. Though zh.wikipedia.org can not be visited now, we still should celebrate it. Another surprise is that Google bought YouTube for $1.65 Billion at last, even though the latter has never known how to earn, and co-founders Steve Chen and Chad Hurley became a billionaire immediately. Google combined and seized this largest and fastest growing online video sharing community, while so expensively, comfort Yahoo!

Sunday, October 01, 2006

howto sleep and hibernate on thinkpad

In Windows, we can use Fn-F4 to suspend system to memory, and Fn-F12 to suspend system to disk. It is really very expedite and useful. When using Linux as a desktop, we can also have such way to sleep and hibernate our system and even faciler.

Sleep is also called suspend (to memory), while hibernate is called suspend2 ( to disk). Here is the specific steps:

  1. It is necessary to compile your kernel with ibm-acpi support, if you do not want to download it by yourself, and make sure your kernel source version is new enough, because the latest kernel has contained it. Modify your kernel configure file, add this sentence, which means that ibm-acpi will be compiled as a module.

    CONFIG_ACPI_IBM=m

    If you wanna actuate this module when system startup, usually it is. You should add "ibm-acpi" into, for example, /etc/modules.autoload.d/kernel-2.6.

  2. Install the ACPI daemon "acpid", and let it run when your system boots.
  3. Download the ibm-acpi package from here: http://ibm-acpi.sf.net/. We only need its scripts. Decompress the package, and copy the directory "config" into the root directory.
  4. Download the tpb package from here: http://www.nongnu.org/tpb/. Complie and install it.
  5. To make hotkeys work, you should add this into the startup script, /etc/conf.d/local.start:
    echo enable,0xffff > /proc/acpi/ibm/hotkey

    In order to use tpb successfully, you should have the privilege to read the device nram. Thus, add this script into local.start also:

    chmod a+r /dev/nvram
    echo 1024 > /proc/sys/dev/rtc/max-user-freq
  6. Install hibernate-script, which can be found here: http://www.suspend2.net. If you just hope to sleep, you can write a script yourself. such as:
    echo "mem" > /sys/power/state
    

    It can also work successfully. If you want to use the whole functions of this hibernate-script, you have to patch your kernel source and recomplie it again. The patch can also be found at that website.

  7. Now, When you press ACPI key such as Fn-F4, then cat /var/log/acpid, you will find all ACPI events:
    [Sun Oct  1 17:54:44 2006] received event "ibm/hotkey HKEY 00000080 00001004"
    [Sun Oct  1 17:54:44 2006] executing action "/etc/acpi/default.sh ibm/hotkey HKEY 00000080 00001004"
    [Sun Oct  1 17:54:44 2006] BEGIN HANDLER MESSAGES
    [Sun Oct  1 17:54:44 2006] END HANDLER MESSAGES
    [Sun Oct  1 17:54:44 2006] action exited with status 0
    [Sun Oct  1 17:54:44 2006] executing action "/usr/sbin/hibernate -F /etc/hibernate/ram.conf"

    And this means you can use your function key to suspend your system. If everything is ok, your system will sleep into memory just now.

  8. There is some other tips to use xmodmap, touch ~/.Xmodmap, write this into it:
    keycode 227 = F35
    clear lock
    add mod4 = Caps_Lock

    The first line let you can use Fn key, and the next two lines let you use Caps_Lock key as Windows Key. Run xmodmap ~/.Xmodmap, try CAPS_LOCK, and check if its action has changed. So cool :)

The further detail can be found here: http://www.thinkwiki.org/wiki/How_to_get_special_keys_to_work#tpb_configuration

Monday, September 11, 2006

Poor MD, poor me

Yestoday, I was exhausted by the MiniDisk. I think I have never confronted such machines which try to protect audio copyrights so sucked as the MiniDisk. Some days ago, someone told me to export some audio tracks from several MDs, because another classmate recorded one teacher's lessons of a whole term into this disk, and she wanna share them. At beginning, I thought it was a much simple job.

I immediately borrowed a MD machine, an USB cable and installed the software sonicstage in my notebook, which is used to manage and transfer audio between computers and CD/MD machines manufactured by sony company. After completed these, I began to copy audio lessons from the machine, and I thought everything would finish soon.

However, to my surprise, I haven't found a nightmare just began. I got such a prompt when I wanted to transfer lessons to my notebook:

Unable to transfer the following tracks to My Library because they are recorded by Net MD or another computer.

I was totally astonished. The such fact as above means that, it's hardly to exchange music or other audio with each other, who uses MiniDisk to store his audio tracks, because you can only use the machine to manage the audio which it orginally recorded. You cannot upload or download tracks from your own MD, if you are using two different computers. You cannot acquire lossless musics you like from your friends, unless both of you transfer them by both sony MD machines. You can only import something into the MD from CD or your computers, but you will occours serial fantasic difficulties when hoping to share yours.

These tools, such as MD used for playing and amusement, in order to protect copyrights and sony company's rights, are designed so annoying and inconvenient, even weird. These technologies which are not open, not free and even not compatible with other audio formats, are totally out of date, and due to disappear earlier. No one should use it and no model would be seld in stores in this age, when everythig will be open, connected compactly and conveniently, because now it is the time of network and we need share, participate and communicate with each other.

In the end, I have to use audio cable to connect the MD machine and my computer, because I have to only use such original analog RCA style, to transform digital signal in the MD to analog signal by line-in, then again to digital signal in the computer, which process took me more than 10 hours for these lessons also spended so much time. So poor.

Friday, September 08, 2006

Print UTF8 CJK charactors by texLive

Firstly, let's install texlive2005 on the computer. It is very simple.

  1. Download texlive2005-inst-20051102.iso from ctan.org.
  2. Install texlive2005, mount it and run install-tl.sh.
    # su -
    # mount -o loop path-to-iso-file/texlive2005-inst-20051102.iso /media/cdrom
    # cd /media/cdrom
    # ./install-tl.sh
  3. Set the enviroment variable, you'd better put the content below into the /etc/profile.d/texlive2005.sh if you use Gentoo Linux, where you run mktexlsr (texhash).
    export TEXDIR=/usr/local/texlive/2005
    export TEXMFMAIN=$TEXDIR/texmf
    export TEXMFDIST=$TEXDIR/texmf-dist
    export TEXMFLOCAL=/home/apps/texlive/texmf-local:$TEXDIR/texmf-local
    export VARTEXMF=$TEXDIR/texmf-var
    export PATH=$PATH:$TEXDIR/bin/i386-linux
  4. Initialize the texLive.
    $ su -
    # mktexlsr
    # updmap-sys --syncwithtrees
    # texexec --make
  5. Then, we configure UTF8 fonts, this step is even more simple.
    1. Download arphic fonts from ctan.org.http://www.ctan.org/tex-archive/fonts/arphic/ There are four kinds of chinese fonts:
      bkai00mp-20050720.tar.gz  2005-07-20  9841 Kbyte  BIG5   Kaiti
      bsmi00lp-20050720.tar.gz  2005-07-20  9852 Kbyte  BIG5   MingLiu
      gbsn00lp-20050720.tar.gz  2005-07-20  4583 Kbyte  GB2312 Songti
      gkai00mp-20050720.tar.gz  2005-07-20  4538 Kbyte  GB2312 Kaiti
    2. Uncompress them into the directory $texmf-local, probably /usr/local/texlive/texmf-local/, or the directory $HOME/texmf, or $HOME/.texlive2005/texmf-var/, just inheriting the directory fabic of "texmf". Then, find out all the ".map" files under the directory $texmf-local/fonts/map/, includes bkaiu.map,bsmiu.map, gbsnu.map and gkaiu.map. Then, run the command updmap-sys --edit as root, and add these maps information in the bottom:
      Map bkaiu.map
      Map bsmiu.map
      Map gbsnu.map
      Map gkaiu.map
      After updmap-sys re-generate all map settings, all is done.
    3. Ok, now, set latex enviorment {CJK}{UTF8}{gbsn} or {CJK}{UTF8}{gkai}, you can use pdflatex or dvipdfmx to generate your pdf files.
    4. Append some contents below into $texmf-var/dvips/config/config.ps, then you can use dvips to print out ps files.
      p +cm-dvipdfm-fix.map
      p +dvipdfm.map
      p +gkaiu.map
      p +gbsnu.map
PS: when texlive2007, just choose basic scheme to install for the general application. And there is only about less than 200M bytes.

Tuesday, September 05, 2006

Gnus works with fetchmail

In the past, I always use only gnus to receive and send mails. However, minor defect in an otherwise prefect thing is that, when it receives many, especially, more than tens of letters, whole of emacs will seem to be suspended and have no response, unless you press C-g to interrupt current gnus process. Gnus is totally written with elisp and elisp is parsed by emacs, whereby it is not a program with multi-process. Then, when gnus receives or sends mails, emacs will wait it util its job ends.

Recently, this situation took places so frequently that I can not suffer from it. Thus, I plan to distinguish my MDA and MTA. Gnus is a nice tool as MUA, such as mutt, but more powerful than mutt, which can orgnize mails and newsgroups easily and conveniently. Besides, gnus can also play a role of MTA like sendmail, which can send mails by smtpmail.el. Gnus can also take the place of MDA like fetchmail, while orgnizing newsgroup is its outstanding job, which has several style to store messages. The two most frequent styles are nnfolder and nnml, the former of which is to store messages into a whole file as the format mbox, the latter into several files for each in a directory. The nnml format is the fastest format to read and search, so as that I prefer the latter one. The more details exists in gnus manuals.

Now, Gnus will act as MUA and MTA, to orgnize mails and send mails. Correspondingly, fetchmail will play as MDA, instead of some functions of gnus before. Here is the method to configure fetchmail:

Firestly, touch a file named ~/.fetchmailrc, whose content is so simple:

poll MAIL_SERVER_IP protocol POP3 uidl
     username MAIL_USERNAME password MAIL_PASSWORD keep
mda "procmail -d %T"

Here is some selective explanation:

  • uidl: Only fetch newer messages.
  • keep: Leave messages on the pop3 server.
  • mda "procmail -d %T": This statement can bo omitted, which means to use procmail as the mail filter.

Important: When using fetchmail in Gentoo Linux and I omitted the statement which contains procmail, some similar errors occur:

1 message for  at  (923 octets).
reading message 1 of 1 (923 octets) fetchmail: SMTP connect to localhost failed
fetchmail: SMTP transaction error while fetching from 
fetchmail: Query status=10 (SMTP)

If you use procmail to categorze and filter mails rather than gnus, you need set rules in ~/.procmailrc:

MAILDIR=$HOME/Mail
DEFAULT=$MAILDIR/mbox
LOGFILE=$MAILDIR/from-log
LOCKFILE=$MAILDIR/.lock

:0
! FORWARD-NAME@FORWARD-SERVER.COM

After :0, you can create your filter rules, even with regular expressions, in which the symbol "!" above means to forward all mails received into the mailbox FORWARD-NAME@FORWARD-SERVER.COM, whereby procmail is enough powerful.

Important: In Gentoo Linux, I have to add "DEFAULT=$MAILDIR/mbox" into ~/.procmailrc, otherwise, procmail will automatically deliver messages into ~/.maildir as format maildir, which is used with nnmldir. When I do this, the messages will not be stored at default directory /var/mail/USERNAME. Then, we also should change nnml-spool-directory and others to ~/Mail/mbox accordingly.

Now, run fetchmail by command:

fetchmail -d 300
which means run fetchmail as a daemon, and receive mails from remote server every 5 minutes. If everything is ok, you can write it into cron or into startup scripts. All mails will be stored into the local mail spools, usually which exists in /var/mail/USERNAME, when it run at Gentoo Linux or FreeBSD.

Then, configure the ~/.gnus, to which we write some simple lisp code:

(setq
 user-full-name "Myfirstname Mylastname"
 user-mail-address "mymail@mycompany.com"
 nnmail-spool-file "/var/mail/USERNAME"
 display-time-mail-file "/var/mail/USERNAME"
 message-default-charset `utf-8
 nnml-directory "~/Mail/"
 gnus-select-method '(nnml ""))

Start emacs and open gnus. Gnus will automaticly move and orgnize messages from /var/mail/USERNAME into the nnml-directory with the program "movemail". If there is no rules to say how to orgnize mails in the ~/.gnus, all mails will be moved to the default directory ~/Mail/mail/misc.

Then, step into the Group buffer in the gnus, if the group mail.misc is invisible, then press "L"(gnus-group-list-all-groups). If the group mail.misc does not exist, press "G m"(gnus-group-make-group) to create a new group named mail.misc with the method "nnml:", or press "^" (gnus-enter-server-mode), then enter "{nnml:}(open)" to check whether you have missed some groups.

If you wanna make the group mail.misc always visible, then press "G c"(gnus-group-customize) to complete more customed details.

When go here, gnus and fetchmail will work together, and you will not be boring of gnus receiving mails and fetchmail takes the place of it at background.

Generate a package with dependency in FreeBSD

After completion to compile a package, we usually want to backup its binary backage so as to avoid compile it again when installing it in the future.

Here is a small script to automaticlly generate a package and other packages which it depends on.

for i in `pkg_info -qr $PACKAGE_NAME | cut -d ' ' -f2 | sort | uniq`; do
    pkg_create -zb $i
done

If you wanna backup all packages you installed on the system, try to replace "pkg_info -qr" to "pkg_info -Qoa".