#!/bin/bb is_internal() { [ -z "$1" ] && return 1 case $(command -v $1) in */*) rc=1 ;; *) rc=0 ;; esac return $rc } run_command() { local dryrun= [ $DRYRUN -eq 1 ] && dryrun=echo $dryrun "$@" } for cmd in cp ln; do if ! is_internal $cmd; then echo "Please rebuild busybox and include the $cmd command." exit 1 fi done if [ -L /bin -a -L /sbin ]; then echo "It appears that the /usr merge has already been done on this system." exit 0 fi DRYRUN=1 HELP=0 while [ $# -gt 0 ]; do case $1 in --dryrun|--dry-run) DRYRUN=1 ;; -h|--help) HELP=1 ;; esac shift done if [ $HELP -eq 1 ]; then echo "$(basename $0) -h \| --help - displays this message" echo "$(basename $0) --dryrun \| --dry-run - show what would be done" exit 0 fi # copy binaries for dir in /bin /sbin /usr/sbin; do run_command cp -a $dir/* /usr/bin done # copy libraries for dir in /lib*; do [ -L $dir ] && continue run_command cp -a $dir/* /usr$dir done # Create the /usr merge compatibility symlinks for dir in /bin /sbin; do run_command rm -rf $dir run_command ln -s usr/bin $dir done run_command rm -rf /usr/sbin run_command ln -s bin /usr/sbin for dir in /lib*; do run_command rm -rf $dir run_command ln -s usr$dir $dir done