Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- CWD="$PWD"
- BB_NAME_TARGET="${1:-busybox}"
- BB_NAME_SOURCE="$BB_NAME_TARGET"
- CHROOT=no #If chroot=yes then locate full utils using chroot.
- #Add_BB_Wrapper=no
- USE_BB_FILE_LIST=yes
- #USE_BB_FULL_PATH=yes
- WRITE_NORMAL_LOCATION=yes #if no then BB links will be written to BB_UTIL_DIR only.
- MOVE_BB=no
- COPY_BB=yes #Copy takes precedence over move.
- CHECK_SOURCE=yes #Don't write sylink location in normal location if it isn't a symlink in the source.
- DELETE_SOURCE=no #Delete source file if it is a symlink
- #CHROOT_DIR="$CWD/puppy_fossapup64_9.5.sfs.extracted"
- TARGET_DIR="$CWD/puppy_fossapup64_9.5_busybox"
- SOURCE_DIR="$CWD/puppy_fossapup64_9.5.sfs.extracted"
- CHROOT_DIR="$SOURCE_DIR"
- mkdir -p "$TARGET_DIR"
- BB_UTIL_DIR_rel="${BB_UTIL_DIR_rel:-/bin/bb_utils}"
- BB_UTIL_DIR="$TARGET_DIR/${BB_UTIL_DIR_rel:-/bin/bb_utils}"
- BB_DIR_rel="${BB_DIR_rel:-/bin}"
- BB_TARGET_DIR="$TARGET_DIR${BB_DIR_rel:-/bin}"
- #BB_DIR=
- BB_SOURCE_DIR="$CHROOT_DIR${BB_DIR_rel:-/bin}"
- BB_DIR_CHROOT="$BB_SOURCE_DIR"
- BB_TARGET_PATH="$BB_TARGET_DIR/$BB_NAME_TARGET"
- BB_SOURCE_PATH="$BB_SOURCE_DIR/$BB_NAME_SOURCE"
- BB_LIST_rel=/bin/busybox.lst
- BB_LIST="$SOURCE_DIR$BB_LIST_rel"
- function mk_parrent_dir(){
- parrent="$(dirname $1)"
- if [ ${#parrent} -le 1 ]; then
- return 0
- else [ ! -d "$TARGET_DIR$parrent" ];
- if [ ! -z "`which cpio`" ]; then
- ( cd "$SOURCE_DIR"
- echo "./$1" | \
- cpio -pdu "$TARGET_DIR" )
- else
- mkdir -p "$TARGET_DIR/$1"
- fi
- fi
- }
- if [ ! -e "$BB_TARGET_PATH" ]; then
- if [ "$MOVE_BB" = yes ] && [ "$CHROOT_DIR" != "$SOURCE_DIR" ] && [ "$COPY_BB" != yes ]; then
- mk_parrent_dir "$BB_DIR_rel/$BB_NAME_TARGET"
- mv "$BB_SOURCE_PATH" "$BB_TARGET_PATH"
- elif [ "$MOVE_BB" = yes ] || [ "$COPY_BB" = yes ]; then
- mk_parrent_dir "$BB_DIR_rel/$BB_NAME_TARGET"
- [ ! -e "$BB_TARGET_PATH" ] && cp -a "$BB_SOURCE_PATH" "$BB_TARGET_PATH"
- fi
- fi
- #BB_PATH_rel=/bin/busybox
- #BB_PATH=$CHROOT_DIR/${BB_PATH_rel:-/bin/busybox}
- CHROOT_CMD="`which chroot-FULL`"
- [ -z "$CHROOT_CMD" ] && CHROOT_CMD="`which chroot`"
- function bb_list_full() { #$1=busybox or busybox-path
- local bb_name="${1:-busybox}"
- if [ ! -z "$BB_LIST" ]; then
- cat "$BB_LIST"
- elif [ ! -z "$CHROOT_DIR" ]; then
- "$CHROOT_CMD" "$CHROOT_DIR" "$bb_name" --list-full || \
- "$CHROOT_CMD" "$CHROOT_DIR" "$BB_DIR_rel/$bb_name" --list-full
- else #Requires static busybox
- "$BB_TARGET_DIR/$bb_name" --list-full
- fi
- }
- function bb_list() { #$1=busybox or busybox-path
- local bb_name="${1:-busybox}"
- if [ ! -z "$BB_LIST" ]; then
- cat "$BB_LIST" | sed -r 's@^.*/@@g'
- elif [ ! -z "$CHROOT_DIR" ]; then
- "$CHROOT_CMD" "$CHROOT_DIR" "$bb_name" --list || \
- "$CHROOT_CMD" "$CHROOT_DIR" "$BB_DIR_rel/$bb_name" --list
- else #Requires static busybox
- "$TARGET_DIR$BB_DIR_rel/$bb_name" --list
- fi
- }
- rp_help_1="$(realpath --help | grep '--relative-to')"
- function find_rel_path(){ #source dir, target dir
- if [ ! -z "${#rp_help_1}" ]; then
- find_rel_path_result="$(realpath --relative-to="$1" "$2")"
- else
- find_rel_path_result="$(echo "$1" | sed -r 's/([^//]*)/../g' )/$2"
- fi
- }
- find_rel_path "$BB_UTIL_DIR" "$BB_TARGET_DIR"; UTIL_DIR_rel_BB_DIR="$find_rel_path_result"
- [ ! -e "$BB_UTIL_DIR" ] && mkdir -p "$BB_UTIL_DIR"
- #for aBB_NAME in busybox.nosuid busybox.suid busybox; do
- aBB_NAME=busybox #TODO. let other bb names be used.
- cd "$BB_UTIL_DIR"
- [ ! -e "./$aBB_NAME" ] && continue
- [ $(file --mime-type "$BB_TARGET_DIR/$aBB_NAME" | grep -c text) -gt 0 ] && continue
- #TODO, skip busybox if it is a wrapper script
- #TODO considering adding an EOF at the end of --list to make sure that the read teminates
- bb_list "$aBB_NAME" |
- while read UTIL_NAME; do
- if [ ! -e "$BB_UTIL_DIR/$UTIL_NAME" ] && [ ! -z "$BB_UTIL_DIR" ]; then
- cd "$BB_UTIL_DIR"
- ln -s "$UTIL_DIR_rel_BB_DIR/$aBB_NAME" "$UTIL_NAME"
- fi
- #if [ "$USE_BB_FULL_PATH" = yes ] || [ "$USE_BB_FILE_LIST" = yes ]; then
- if [ "$WRITE_NORMAL_LOCATION" = yes ]; then
- FP="/$(bb_list_full "$aBB_NAME" | grep -E "/$UTIL_NAME"'$' | sed -r 's@^/@@g')"
- if [ "$CHECK_SOURCE" = yes ]; then
- [ ! -L "$SOURCE_DIR$FP" ] && continue
- fi
- cd "$(dirname "$TARGET_DIR$FP")"
- if [ ! -z "$FP" ]; then
- find_rel_path "$TARGET_DIR$(dirname "$FP")" "$BB_TARGET_PATH"; REL_SYM_TO_BB="$find_rel_path_result"
- if [ ! -e "$TARGET_DIR/$aBB_NAME" ]; then
- ln -s "$REL_SYM_TO_BB" "$UTIL_NAME"
- fi
- fi
- fi
- done
- if [ "$MOVE_BB" = yes ] && [ -e "$BB_SOURCE_PATH" ]; then
- rm "$BB_SOURCE_PATH"
- fi
- #done
- #if [ Add_BB_Wrapper = yes ] && [ ! -e $BB_DIR/busybox ]; then
- #echo "#!/bin/sh
- #script=\${0##*/}
- #script2=\$1
- #if [ \"\$script\" = \"busybox\" ]; then
- # script=\$script2 ; shift
- #fi
- #exec \"$BB_UTIL_DIR/\$script\" \"\$@\"" > "/$BB_DIR/busybox"
- #chmod +x "/$BB_DIR/busybox"
- #fi
Add Comment
Please, Sign In to add comment