busyboxで使用可能なコマンドのsymlinkを作るperl

chroot用のユーザに環境を用意するときに、個々のバイナリファイルをコピーするよりbusybox使うほうが楽かなと思ってやったメモ。static-linkなbusyboxだと/lib以下のライブラリコピーしなくていいし。

$ busybox --help
BusyBox v1.01 (2006.05.04-09:21+0000) multi-call binary

Usage: busybox [function] [arguments]...
   or: [function] [arguments]...

        BusyBox is a multi-call binary that combines many common Unix
        utilities into a single executable.  Most people will create a
        link to busybox for each function they wish to use and BusyBox
        will act like whatever it was invoked as!

Currently defined functions:
        [, basename, bunzip2, busybox, bzcat, cat, chgrp, chmod, chown, chroot, chvt, clear, cmp,
        cp, cpio, cut, date, dc, dd, deallocvt, df, dirname, dmesg, dos2unix, du, dumpkmap, echo,
        egrep, env, expr, false, fbset, fgrep, find, free, freeramdisk, grep, gunzip, gzip, halt,
        head, hexdump, hostid, hostname, id, ifconfig, init, install, kill, killall, klogd, linuxrc,
        ln, load_policy, loadfont, loadkmap, logger, ls, lsmod, makedevs, md5sum, mkdir, mknod,
        mktemp, modprobe, more, mount, msh, mv, nc, openvt, pidof, ping, pivot_root, poweroff,
        ps, pwd, readlink, reboot, reset, rm, rmdir, rmmod, route, rpm2cpio, sed, sleep, sort,
        strings, stty, swapoff, swapon, sync, syslogd, tail, tar, tee, telnet, test, tftp, time,
        touch, tr, traceroute, true, tty, umount, uname, uniq, unix2dos, unzip, uptime, usleep,
        uudecode, uuencode, vi, wc, wget, which, whoami, xargs, yes, zcat

make-symlink.pl

use strict;
use warnings;

my $busybox = './busybox';
my $help = qx{$busybox --help 2>&1};

my ($data) = $help =~ m/Currently \s defined \s functions: (.*)/msx;
$data =~ s/\s+//g;
my @cmds = split ',' , $data;

for my $cmd (@cmds) {
  #print "$cmd\n";
  symlink $busybox, $cmd or warn "$!";
}

実行

cd /chroot/bin/
cp `which busybox` .
perl make-symlink.pl

追記

gistにおいた