#!/bin/bash
set -e
bb_path=$1
bin_cmds="cp cpio login ls mkdir mknod mv ps rpm stat tar su"

sbin_cmds="mdev mkswap sulogin"

usr_bin_cmds="ar id mkfifo top chcon install pgrep find"

usr_sbin_cmds="chpasswd selinuxenabled adduser addgroup"

busybox_cmd="busybox"
cur_dir=$(pwd)
bb_rootpath=${cur_dir}/${bb_path}

cd ${bb_rootpath}
mkdir -p bin
mkdir -p sbin
mkdir -p usr/bin
mkdir -p usr/sbin

cd ${bb_rootpath}/bin
for i in $bin_cmds
do
       ln -s $busybox_cmd ${i}
done

cd ${bb_rootpath}/sbin
for i in $sbin_cmds
do
       ln -s ../bin/$busybox_cmd $i
done

cd ${bb_rootpath}/usr/bin
for i in $usr_bin_cmds
do
       ln -s ../../bin/$busybox_cmd $i
done

cd ${bb_rootpath}/usr/sbin
for i in $usr_sbin_cmds
do
       ln -s ../../bin/$busybox_cmd $i
done
