harry’s memorandum

おれおれメモ

util-linuxのツールその他

twitter経由で知った。lsblkなんて知らんかった。


util-linuxのツールなんだね。

# rpm -qf `which lsblk`
util-linux-ng-2.17.2-12.9.el6.x86_64


lsblkコマンド。確かにfdiskより見やすい。

# lsblk
NAME                    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
xvda                    202:0    0   32G  0 disk
|-xvda1                 202:1    0  500M  0 part /boot
`-xvda2                 202:2    0 31.5G  0 part
  |-vg00-lv_root (dm-0) 253:0    0 30.5G  0 lvm  /
  `-vg00-lv_swap (dm-1) 253:1    0    1G  0 lvm  [SWAP]

# lsblk -l
NAME                MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
xvda                202:0    0   32G  0 disk
xvda1               202:1    0  500M  0 part /boot
xvda2               202:2    0 31.5G  0 part
vg00-lv_root (dm-0) 253:0    0 30.5G  0 lvm  /
vg00-lv_swap (dm-1) 253:1    0    1G  0 lvm  [SWAP]

他にもutil-linuxには面白いものあるんだろうかと、見てみていたら結構あった。

blkidコマンド。まず使わないな。

# blkid
/dev/xvda1: UUID="e4d0a34d-e867-4aac-85e2-e9895cd07773" TYPE="ext4"
/dev/xvda2: UUID="TYUcrO-MSoO-ARWA-fofZ-BFmx-Xy1g-wieV10" TYPE="LVM2_member"
/dev/mapper/vg00-lv_root: UUID="04c39e55-5fcb-4d29-9971-cd3d0c05c9cf" TYPE="ext4"
/dev/mapper/vg00-lv_swap: UUID="08062b70-582c-45b9-a600-3b493b7df703" TYPE="swap"


findfsコマンド。LABELやUUIDを探すっていうのがなんですな。まず使わない。

# findfs
Usage: findfs LABEL=<label>|UUID=<uuid>
# findfs UUID=e4d0a34d-e867-4aac-85e2-e9895cd07773
/dev/xvda1


findmntコマンド。つかうことねーなぁ、と思ったりしたけど/proc以下の情報があったりして、おおーと思ったけど、やっぱり使わない。

# findmnt
TARGET                       SOURCE                   FSTYPE    OPTIONS
/                            /dev/mapper/vg00-lv_root ext4      rw,relatime,barrier=1,data
|-/proc                      proc                     proc      rw,relatime
| |-/proc/bus/usb            /proc/bus/usb            usbfs     rw,relatime
| |-/proc/sys/fs/binfmt_misc                          binfmt_mi rw,relatime
| `-/proc/xen                                         xenfs     rw,relatime
|-/sys                       sysfs                    sysfs     rw,relatime
|-/dev                       devtmpfs                 devtmpfs  rw,relatime,size=473704k,n
| |-/dev/pts                 devpts                   devpts    rw,relatime,gid=5,mode=620
| `-/dev/shm                 tmpfs                    tmpfs     rw,relatime
|-/boot                      /dev/xvda1               ext4      rw,relatime,barrier=1,data
`-/var/lib/nfs/rpc_pipefs    sunrpc                   rpc_pipef rw,relatime


findmntは/proc/self/mountinfoをみているんだね。

# strace -f -e open findmnt 2>&1 > /dev/null  | grep proc
open("/proc/self/mountinfo", O_RDONLY)  = 3


sfdiskコマンド。fdiskよりこっちの方が見易いじゃん。

# /sbin/sfdisk -l

Disk /dev/xvda: 4177 cylinders, 255 heads, 63 sectors/track
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/xvda1   *      0+     63-     64-    512000   83  Linux
/dev/xvda2         63+   4177-   4114-  33041408   8e  Linux LVM
/dev/xvda3          0       -       0          0    0  Empty
/dev/xvda4          0       -       0          0    0  Empty

Disk /dev/mapper/vg00-lv_root: 3982 cylinders, 255 heads, 63 sectors/track

Disk /dev/mapper/vg00-lv_swap: 130 cylinders, 255 heads, 63 sectors/track
# /sbin/sfdisk -s
/dev/xvda:  33554432
/dev/mapper/vg00-lv_root:  31989760
/dev/mapper/vg00-lv_swap:   1048576
total: 66592768 blocks


nameiコマンド。シンボリックリンクを追ってくれるらしい。こんなの使わんわ。

# ln -s /tmp/yum.log /tmp/aaa
# ln -s /tmp/aaa /tmp/bbb
# ln -s /tmp/bbb /tmp/ccc
# ln -s /tmp/ccc /tmp/ddd
# ls -l /tmp/aaa
lrwxrwxrwx 1 root root 12 Apr 10 00:09 /tmp/aaa -> /tmp/yum.log
# ls -l /tmp/ddd
lrwxrwxrwx 1 root root 8 Apr 10 00:10 /tmp/ddd -> /tmp/ccc
# namei -l /tmp/ddd
f: /tmp/ddd
dr-xr-xr-x root root /
drwxrwxrwt root root tmp
lrwxrwxrwx root root ddd -> /tmp/ccc
dr-xr-xr-x root root   /
drwxrwxrwt root root   tmp
lrwxrwxrwx root root   ccc -> /tmp/bbb
dr-xr-xr-x root root     /
drwxrwxrwt root root     tmp
lrwxrwxrwx root root     bbb -> /tmp/aaa
dr-xr-xr-x root root       /
drwxrwxrwt root root       tmp
lrwxrwxrwx root root       aaa -> /tmp/yum.log
dr-xr-xr-x root root         /
drwxrwxrwt root root         tmp
-rw------- root root         yum.log


cfdiskコマンド。ncursesを使ったキャラクタベースのfdisk。samやsmittyやsysadmをみる気持ちになります。これは気持ちだけで十分だ。

                              cfdisk (util-linux-ng 2.17.2)

                                  Disk Drive: /dev/xvda
                             Size: 34359738368 bytes, 34.3 GB
                   Heads: 255   Sectors per Track: 63   Cylinders: 4177

    Name          Flags       Part Type   FS Type            [Label]          Size (MB)
 ----------------------------------------------------------------------------------------
                               Pri/Log    Free Space                               1.05  *
    xvda1         Boot         Primary    Linux ext3                             524.29  *
    xvda2                      Primary    Linux LVM                            33834.41  *

     [   Help   ]  [   New    ]  [  Print   ]  [   Quit   ]  [  Units   ]
     [  Write   ]


ctrlaltdelコマンド。なんだこれは、、、あああー。

# ctrlaltdel
Usage: ctrlaltdel hard|soft
# ctrlaltdel hard

今日は終わり。

オレオレaliasやシェル関数のあれこれ

よく忘れるからメモ。


仕事で古いUNIXを使うので、どうしても手が'more'と覚えてしまっているから仕方がない。

$ alias more='less'


バックアップするときのシェルの関数。個人的には便利。

$ backup(){ cp -pr $1{,.`date +%Y-%m-%dT%H:%M:%S`}; }
$ backup a.c
$ ls a.c*
a.c  a.c.2012-09-17T00:46:46


空ディレクトリを削除するワンライナー。ただaliasにしただけ。

$ alias rmdir_r='find . -depth -type d | xargs rmdir 2> /dev/null'


空ディレクトリを削除するワンライナーLinuxのfindutilsならこっちの方がいいのかもしれない。

$ alias rmdir_r='find . -type d -empty -delete'


/proc/cpuinfoでみたいのは種類とcore数だけなんだよ。

$ alias cpuinfo="awk  -F: ' {if(\$1 ~/^model name/){ model[\$2]=+1}} END{for(k in model) { print
model[k], k}}' /proc/cpuinfo"
$ cpuinfo
2  Intel(R) Core(TM) i5 CPU       M 460  @ 2.53GHz


接続先をセッション名にするのね。commandlinefuでさっき知った。便利。

$ s() { screen -d -RR -m -S "$1" -t "$USER"@"$1" ssh "$1"; }


乱数を出力するだけ。長ったらしいのは覚えられんよ。

$ alias rdom='echo `od -vAn -N4 -tu4 < /dev/urandom`'
$ rdom
2961980303


ddの進捗をみるだけ。複数のバックジョブがあると破綻します。

$ alias ddp='kill -SIGUSR1 `jobs -p`'
$ dd if=/dev/urandom of=./test.img bs=1M count=100 &
$
$ ddp
$ 9+1 records in
9+0 records out
9437184 bytes (9.4 MB) copied, 1.51086 seconds, 6.2 MB/s


ネットワークにpingなげて応答あるIPを返すだけ。

$ pscan(){ nmap -nsP "$1" | awk '{if($1=="Host") print $2 }'; }
$ pscan 192.168.0.0/24
192.168.0.1
192.168.0.2
192.168.0.7
192.168.0.22
192.168.0.100
192.168.0.106
192.168.0.160
192.168.0.170
192.168.0.251

ssh-copy-id: Bourne shell script text executable

ssh-copy-idは便利だね。何も考えたくなければこれでいいし。

$ ssh-copy-id myuser@example.com

中身はシェルスクリプトだったりする。

$ file /usr/bin/ssh-copy-id
/usr/bin/ssh-copy-id: Bourne shell script text executable

cat /usr/bin/ssh-copy-id すると中身は結構短い。

#!/bin/sh

# Shell script to install your id_rsa.pub on a remote machine
# Takes the remote machine name as an argument.
# Obviously, the remote machine must accept password authentication,
# or one of the other keys in your ssh-agent, for this to work.

ID_FILE="${HOME}/.ssh/id_rsa.pub"

if [ "-i" = "$1" ]; then
  shift
  # check if we have 2 parameters left, if so the first is the new ID file
  if [ -n "$2" ]; then
    if expr "$1" : ".*\.pub" ; then
      ID_FILE="$1"
    else
      ID_FILE="$1.pub"
    fi
    shift         # and this should leave $1 as the target name
  fi
else
  if [ x$SSH_AUTH_SOCK != x ] ; then
    GET_ID="$GET_ID ssh-add -L"
  fi
fi

if [ -z "`eval $GET_ID`" ] && [ -r "${ID_FILE}" ] ; then
  GET_ID="cat ${ID_FILE}"
fi

if [ -z "`eval $GET_ID`" ]; then
  echo "$0: ERROR: No identities found" >&2
  exit 1
fi

if [ "$#" -lt 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
  echo "Usage: $0 [-i [identity_file]] [user@]machine" >&2
  exit 1
fi

{ eval "$GET_ID" ; } | ssh $1 "umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys" || exit 1

cat <<EOF
Now try logging into the machine, with "ssh '$1'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

EOF


shは便利なんだけど、こういう書き方をしないとNULLSTRINGのチェックができないのは未だになれない。10年たってもなれない。

  if [ x$SSH_AUTH_SOCK != x ] ; then


いつも authorized_keys のタイプ間違えそうになるので ssh-copy-idとても便利です。ssh-copy-idはたいへん便利です。

VBSでeventlogってよく使うよね。

仕事柄よく使うんだけど、「そんなの使わねー」「そもそもVBSをつかわねー」と言われることも。VBSなにげに好きなんだけど世間の風当たりは厳しいです。VBSはやりゃあできる子なんだよ。

というので、VBSでイベントログ。こういうのはクラスにしておくと便利。

Option Explicit 

Const EVENT_SUCCESS = 0
Const EVENT_ERROR = 1
Const EVENT_WARNING = 2
Const EVENT_INFORMATION = 4

Class CustomEventLog
  private shell
  Sub Class_Initialize()
    Set shell = CreateObject("wscript.shell")
  End Sub
  
  Sub Class_Terminate()
    Set shell = Nothing
  End Sub

  Public Function success(msg)
    shell.LogEvent EVENT_SUCCESS, msg
  End Function
  
  Public Function info(msg)
    shell.LogEvent EVENT_INFORMATION, msg
  End Function

  Public Function error(msg)
    shell.LogEvent EVENT_ERROR, msg
  End Function

  Public Function warn(msg)
    shell.LogEvent EVENT_WARNING, msg
  End Function
End Class

上のをコピペして使うだけ。

Dim log
Set log = new CustomEventLog

log.success("huga")
log.info("hoge")
log.warn("foo")
log.error("bar")

WMI client (WMIC) for Linux は超便利

WMICってのは、WindowsXP以降に標準でついてくるWMIのCLIです。便利ですよね。
これをLinuxから使えたら便利なのに...って思ってたのですが、あ、、あった!。

インストール

このWMICの大元のソースはどこかわからない。とりあえず http://www.orvant.com/packages からダウンロード。ソースを眺めていると「Zenoss Inc」って書いてあるのでZenossで作っているかな?。
まずはソースをコンパイル。

$ wget http://www.orvant.com/files/packages/source/wmi_1.3.14.orig.tar.bz2
$ bzip2 -cd wmi_1.3.14.orig.tar.bz2 | tar xvf -
$ cd wmi-1.3.14
$ make

ソースディレクトリをみるとsambaのソースを使って RPC/DCOM を解釈しているようですね。

$ ls
GNUmakefile  Samba  pyinclude.py  pysamba

コマンドを実行してみる。

$ ./Samba/source/bin/wmic
Usage: [-?] [-?] [-?] [-?NP] [-?NPV] [-?|--help] [--usage] [-d|--debuglevel DEBUGLEVEL]
        [--debug-stderr] [-s|--configfile CONFIGFILE] [--option=name=value]
        [-l|--log-basename LOGFILEBASE] [--leak-report] [--leak-report-full]
        [-R|--name-resolve NAME-RESOLVE-ORDER]
        [-O|--socket-options SOCKETOPTIONS] [-n|--netbiosname NETBIOSNAME]
        [-W|--workgroup WORKGROUP] [--realm=REALM] [-i|--scope SCOPE]
        [-m|--maxprotocol MAXPROTOCOL] [-U|--user [DOMAIN\]USERNAME[%PASSWORD]]
        [-N|--no-pass] [--password=STRING] [-A|--authentication-file FILE]
        [-S|--signing on|off|required] [-P|--machine-pass]
        [--simple-bind-dn=STRING] [-k|--kerberos STRING]
        [--use-security-mechanisms=STRING] [-V|--version] [--namespace=STRING]
        [--delimiter=STRING]
        //host query

Example: wmic -U [domain/]adminuser%password //host "select * from Win32_ComputerSystem"

例を実行。パイプ"|"区切りで表示してくれるようです。

$ ./Samba/source/bin/wmic -U dharry%password //crimson "Select * From Win32_ComputerSystem"
CLASS: Win32_ComputerSystem
AdminPasswordStatus|AutomaticManagedPagefile|AutomaticResetBootOption|AutomaticResetCapability|BootOptionOnLimit|BootOptionOnWatchDog|BootROMSupported|BootupState|Caption|ChassisBootupState|CreationClassName|CurrentTimeZone|DaylightInEffect|Description|DNSHostName|Domain|DomainRole|EnableDaylightSavingsTime|FrontPanelResetStatus|InfraredSupported|InitialLoadInfo|InstallDate|KeyboardPasswordStatus|LastLoadInfo|Manufacturer|Model|Name|NameFormat|NetworkServerModeEnabled|NumberOfLogicalProcessors|NumberOfProcessors|OEMLogoBitmap|OEMStringArray|PartOfDomain|PauseAfterReset|PCSystemType|PowerManagementCapabilities|PowerManagementSupported|PowerOnPasswordStatus|PowerState|PowerSupplyState|PrimaryOwnerContact|PrimaryOwnerName|ResetCapability|ResetCount|ResetLimit|Roles|Status|SupportContactDescription|SystemStartupDelay|SystemStartupOptions|SystemStartupSetting|SystemType|ThermalState|TotalPhysicalMemory|UserName|WakeUpType|Workgroup
3|True|True|True|0|0|True|Normal boot|CRIMSON|3|Win32_ComputerSystem|540|False|AT/AT COMPATIBLE|crimson|WORKGROUP|0|True|3|False|NULL|(null)|3|(null)|MICRO-STAR INTERNATIONAL CO.,LTD|MS-7549|CRIMSON|(null)|True|4|1|NULL|NULL|False|-1|1|NULL|False|3|0|3|(null)|kisi|1|-1|-1|(LM_Workstation,LM_Server,NT,Potential_Browser,Backup_Browser,Master_Browser)|OK|NULL|0|NULL|0|X86-based PC|3|3488800768|crimson\kishi|6|WORKGROUP

firefox.exeプロセスの情報取得。WQLを色々投げれて楽しい。

$ ./Samba/source/bin/wmic -U dharry%password //crimson "Select * From Win32_Process where Caption='firefox.exe'"
CLASS: Win32_Process
Caption|CommandLine|CreationClassName|CreationDate|CSCreationClassName|CSName|Description|ExecutablePath|ExecutionState|Handle|HandleCount|InstallDate|KernelModeTime|MaximumWorkingSetSize|MinimumWorkingSetSize|Name|OSCreationClassName|OSName|OtherOperationCount|OtherTransferCount|PageFaults|PageFileUsage|ParentProcessId|PeakPageFileUsage|PeakVirtualSize|PeakWorkingSetSize|Priority|PrivatePageCount|ProcessId|QuotaNonPagedPoolUsage|QuotaPagedPoolUsage|QuotaPeakNonPagedPoolUsage|QuotaPeakPagedPoolUsage|ReadOperationCount|ReadTransferCount|SessionId|Status|TerminationDate|ThreadCount|UserModeTime|VirtualSize|WindowsVersion|WorkingSetSize|WriteOperationCount|WriteTransferCount
firefox.exe|"C:\Program Files\Mozilla Firefox\firefox.exe" |Win32_Process|20120529024909.460137+540|Win32_ComputerSystem|CRIMSON|firefox.exe|C:\Program Files\Mozilla Firefox\firefox.exe|0|7900|409|(null)|68172437|1380|200|firefox.exe|Win32_OperatingSystem|Microsoft Windows 7 Professional |C:\Windows|\Device\Harddisk0\Partition2|25084|309249|106350|92288|2100|124888|327544832|143844|8|94502912|7900|35|326|40|334|2390|70528310|1|(null)|(null)|31|92976596|317468672|6.1.7601|115810304|4152|68639352

Nagiosプラグインとか。

NagiosPluginの Check-WMI-Plus では このWMICを使ってWindowsマシンのリソースを取得しているようです。

f:id:dharry:20120529032347p:image

これで、LinuxもWindowsも統合的に監視ができるようになりました。

LXR Cross Referencer を試してみた

クロスリファレンスやソースコード検索エンジンは便利なのでインストールしてみた備忘録。

LXRって?

MozillaApacheのソースみるときお世話になってるやつ。

こんなやつです。
f:id:dharry:20120508024754p:image

インストールガイド

ここみればいいや、という話でもある。
でも lxr-0.11.1.tgz でインストール試したらすげー嵌った。sourcefogeのCVSのHEADから取ってきたもので試したらすんなり。0.11.1版はどこで嵌ったかも記憶が曖昧なので気のせいかもしれない。

LXRインストール前に

  • Centos5.8(i386)で試しました。
  • 作業はrootで行いました。手抜きです。
  • perlは5.8以上であれば問題ないようです。
  • デフォルトだとブツがないのでrpmforgeリポジトリは必須。
  • swish-eかglimpseどちらでも使えるけどここではglimpseにしました。

LXRで必要なものをインストール

rpmforgeを使えるようにする。

$ wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
$ rpm -ivh rpmforge-release-0.5.2-2.el5.rf.i386.rpm

必要なものインストール。ちょっと余計に入れているかもしれない。

$ yum -y install cvs rcs ctags httpd mod_perl mysql-server mysql 
$ yum -y --enablerepo=rpmforge install perl-File-MMagic-XS perl-File-MMagic.noarch  libdbi libdbi-dbd-mysql libdbi-drivers perl-Digest-SHA1 swish-e swish-e-devel perl-String-Approx perl-Apache-DBI.noarch

glimpse か swish-e のどちらかが使えればいいようだけど、気分で切り替えられるようにどっちも使えるようにする。swish-eはyumでインストール。glimpseはコンパイルしてインストール。
ソースコードはここからダウンロード。

$ tar xvzf glimpse-latest.tar.gz
$ cd glimpse-4.18.6/
$ ./configure ; make; make install

LXRのソースコードをダウンロード

ソースはここでダウンロード。

展開して構成チェック

$ tar xvzf /root/lxr-lxr.tar.gz
$ cd lxr/
$ ./genxref --checkonly
No URL specified - Continuing in checking mode
Checking Perl version ... 5.8.8  OK
Parameter 'ectagsbin' not defined - trying to find ctags
'ectagsbin' temporarily adjusted to /usr/bin/ctags
Manually update lxr.conf for permanent setting
Checking ctags version ... 5.6  OK
Parameter 'glimpsebin' not defined - trying to find glimpse
'glimpsebin' temporarily adjusted to /usr/local/bin/glimpse
Manually update lxr.conf for permanent setting
Checking glimpse version ... 4.18.5
Parameter 'glimpseindex' not defined - trying to find glimpseindex
'glimpseindex' temporarily adjusted to /usr/local/bin/glimpseindex
Manually update lxr.conf for permanent setting
Checking glimpseindex version ... 4.18.5
Parameter 'swishbin' not defined - trying to find swish-e
'swishbin' temporarily adjusted to /usr/bin/swish-e
Manually update lxr.conf for permanent setting
Checking swishe version ... 2.4.7
No matching configuration at ./genxref line 275.

いろいろ警告っぽいのがでます。インストールガイドにあるように、まだ設定していないので警告がでます。あとで設定するので無視します。

Since LXR is not yet configured, you get various Parameter xxx not defined warnings. Ignore them.

http://lxr.sourceforge.net/en/0-11-InstallSteps/0-11-install2LXR.shtml?

初期設定スクリプト実行

ここは試しでマルチプルツリーにします。マルチプルツリーの場合はvirtrootでパスやdbなどを複数設定できるみたい。

$ ./scripts/initial-config.sh
*** Initial phase configurator for LXR ($Revision: 1.8 $) ***

Configure for single/multiple trees? [S/m] m

Your LXR root directory is: /var/www/html/lxr

templates directory now protected read-only
File .htaccess written in your LXR root directory
--- List its content with 'more .htaccess'
File apache2-require.pl written in lxrconf.d directory
File apache-lxrserver.conf written in lxrconf.d directory
File lighttpd-lxrserver.conf written in lxrconf.d directory
You need to manually configure lighttpd-lxrserver.conf for multiple trees operation
***Error: both glimpse and swish-e installed!
*** Manually edit lxr.conf to comment out one of them ***
Prototype lxr.conf written in lxrconf.d directory

*** Configuration directory lxrconf.d now contains: ***
合計 44
drwxrwxr-x 2 apache apache  4096  5月  8 02:20 .
drwxr-xr-x 9 apache apache  4096  5月  8 02:19 ..
-rwxr-xr-x 1 root   root    2394  5月  8 02:20 apache-lxrserver.conf
-rwxr-xr-x 1 root   root     149  5月  8 02:20 apache2-require.pl
-rwxr-xr-x 1 root   root   11937  5月  8 02:20 lighttp-lxrserver.conf
-rwxr-xr-x 1 root   root   14635  5月  8 02:20 lxr.conf

ここでもエラーっぽいのがでます。glimpse と swish-e は同時に指定できないのでどちらかにしないといけないようです。あとで設定するのでここも無視。

The name of your LXR root directory is set in all these files, as well as the location of ctags, glimpse, glimpseindex and swish-e. If something goes wrong, an error message is printed:

http://lxr.sourceforge.net/en/0-11-InstallSteps/0-11-install3preconf.shtml?

DBの設定

mysql, postgres, oracle など色々使えるようですが、私はmysqlにしました。

$ mysql -u root -p
mysql> create user 'lxr'@'localhost' identified by 'lxr';
Query OK, 0 rows affected (0.00 sec)
mysql> exit

passwordはガイドと同じにしていますが環境にあわせて適切に変更してください。

$ ./scripts/initdb-config.sh
*** initdb script configurator for LXR ($Revision: 1.6 $) ***

      In case you make a mistake, you can cancel the
      whole process by typing ctl-C.

Which is your database engine? [MYSQL/oracle/postgres]
Which is your database name? [lxr]
Which table prefix will you use? [lxr_]
Under which user name will you connect to the database? [lxr]
Output script name? [lxrconf.d/initdb-mysql-custom.sql]

     Your database engine is      mysql
     Your database is             lxr
     The tables are prefixed with lxr_
     You connect as               lxr
     Configuration script in      lxrconf.d/initdb-mysql-custom.sql

Is this correct? [YES|no]

Init script saved in lxrconf.d/initdb-mysql-custom.sql
$ mysql -u root -p < lxrconf.d/initdb-mysql-custom.sql

ソースを展開する場所とglimpseの作業ディレクトリを作成

$ mkdir -p /opt/lxr/indexed-src
$ mkdir -p /opt/lxr/glimpse/databases

サンプルソースとしてbcコマンドのソースを下記ディレクトリに展開します。

$ cd /opt/lxr/indexed-src
$ wget http://ftp.riken.jp/GNU/gnu/bc/bc-1.03.tar.gz
$ wget http://ftp.riken.jp/GNU/gnu/bc/bc-1.04.tar.gz
$ wget http://ftp.riken.jp/GNU/gnu/bc/bc-1.05a.tar.gz
$ wget http://ftp.riken.jp/GNU/gnu/bc/bc-1.06.tar.gz
$ for i in *.gz; do tar xvzf $i; done
$ ls
bc-1.03         bc-1.04         bc-1.05          bc-1.06
bc-1.03.tar.gz  bc-1.04.tar.gz  bc-1.05a.tar.gz  bc-1.06.tar.gz

apacheが参照するのでオーナをapacheユーザに変更しておきます。

$ chown -R apache.apache /opt/lxr/

設定ファイル

lxrconf.d/以下から、ひな形になるlxr.confをlxrのrootにコピーして修正します。

  • 修正した箇所は以下。
    • swishbinをコメント
    • host_namesを修正
    • sourcerootを/opt/lxr/indexed-srcに変更
    • glimpsedirを/opt/lxr/glimpse/databasesに変更
    • variables => v => range を修正
    • variables => a => range を修正
    • encoding をISO-2022-JPに変更
    • dbuserを適切なユーザに変更
    • dbpassを適切なパスワードに変更
    • stylesheetのパスの先頭にスラッシュが入っているので修正

注意点は host_names を直さないと表示すらできないというところですね。名前解決が間違っているとそれだけでアウトです。

$ cd /var/www/html/lxr
$ cp -p lxrconf.d/lxr.conf .
$ cat lxr.conf
(
        {
          'tmpdir' => '/tmp'
        , 'glimpsebin'   => '/usr/local/bin/glimpse'
        , 'glimpseindex' => '/usr/local/bin/glimpseindex'
        , 'swishconf' => '/var/www/html/lxr/templates/swish-e.conf'
        , 'ectagsbin' => '/usr/bin/ctags'
        , 'ectagsconf' => '/var/www/html/lxr/templates/ectags.conf'
        , 'cvspath' => '/bin:/usr/local/bin:/usr/bin:/usr/sbin'
        , 'host_names' =>       [ '//localhost'
                                                , 'http://192.168.0.170'
                                                , 'http://rainy:80'
                                                ]
        , 'htmlfatal'           => 'templates/html/html-fatal.html'
        , 'htmlhead'            => 'templates/html/html-head.html'
        , 'htmltail'            => 'templates/html/html-tail.html'
        , 'htmldir'                     => 'templates/html/html-dir.html'
        , 'htmlident'           => 'templates/html/html-ident.html'
        , 'htmlsearch'          => 'templates/html/html-search-glimpse.html'
        , 'htmlconfig'          => 'templates/html/html-config.html'
#       , 'sourcehead'          => 'templates/html/html-head.html'
#       , 'sourcedirhead'       => 'templates/html/html-head.html'
        , 'showconfighead'              => 'templates/html/config-head-btn-smaller.html'
        , 'diffleftwidth'       => 50
        , 'stylesheet'          => 'templates/lxr.css'
#       , 'alternate_stylesheet' => [ 'lxrconf.d/another.css' ]
#       , 'encoding'    => 'iso-8859-1'
        , 'encoding'    => 'ISO-2022-JP'
        , 'graphicfile' =>
                'bitmap|bmp|gif|icon?|jp2|jpe?g|pjpe?g|png|svg|tiff?|xbm|xpm'
        , 'filetypeconf' => '/var/www/html/lxr/templates/filetype.conf'
        , 'genericconf' => '/var/www/html/lxr/lib/LXR/Lang/generic.conf'
        , 'treeextract' => '([^/]*)/[^/]*$'
        , 'dbpass'              => 'lxr'
        , 'dbuser'              => 'lxr'
#       , 'dbprefix'    => 'lxr_'
        }
,       {
          'virtroot'    => '/lxr/example'   # The bit after the / above
       , 'caption' => 'My tree displayed by LXR'
       , 'shortcaption' => 'My tree'
#       , 'encoding'    => 'iso-8859-1'
        , 'encoding'    => 'ISO-2022-JP'
#       , 'cvswebprefix' => 'http://cvs.myhost.com/cgi-bin/cvsweb.cgi'
#       , 'cvswebpostfix' => '?cvsroot=rootname'
#       , 'cvswebprefix' => 'http://cvs.myhost.com/cgi-bin/viewcvs.cgi/myroot'
#       , 'cvswebpostfix' => ''
        , 'sourceroot' => '/opt/lxr/indexed-src'
#       , 'sourceroot'  => 'cvs:/home/karsk/a/CVSROOT/linux'
#       , 'sourceroot' => 'git:/some/repository/.git'
        , 'sourcerootname' => 'Example'
#       , 'sourcerootname' => '$v'
        , 'variables' =>
                { 'v' =>
                        { 'name' => 'Version'
                        , 'range' => [qw(bc-1.03 bc-1.04 bc-1.05 bc-1.06)]
                        }
                , 'a' =>
                        { 'name'  => 'Architecture'
                        , 'range' => [qw(i386)]
                        }
                }

        , 'ignoredirs' => ['CVSROOT', '.git']
        , 'incprefix' => [ '/include', '/include/linux' ]
        , 'dbname' => 'dbi:mysql:dbname=lxr'
        , 'glimpsedir' => '/opt/lxr/glimpse/databases'
        , 'swishdir' => '/a/directory/here/'
        }
)

apacheのconfigをコピー

$ cp lxrconf.d/apache-lxrserver.conf /etc/httpd/conf.d

templatesのhtmlのイメージファイルのパスが間違っているので修正

cd /var/www/html/lxr/templates/html
$ for i in *.html
> do
> sed -i -e "s@/LXRimages@./LXRimages@g" $i
> done

indexの作成

./genxref --url=http://localhost/lxr/example

apacheが参照するのでオーナをapacheユーザに変更しておきます。

$ chown -R apache.apache /opt/lxr/

apacheを再起動。

$ /etc/init.d/httpd restart

あとは URLにアクセスして完了。
デフォルトのcssだと寂しいので、MozillaやApacheのlxrからパクって少しだけ見た目を変更しました。

 http://{ipaddress}/lxr/source