#!/bin/bash
set -xe
cdir=$(dirname "$(realpath "${BASH_SOURCE[0]}")")
ldd=$cdir/ldd.txt
mkdir -pv $cdir/root

for files in $(whereis ncdu sh bash htop netstat zip unzip md5sum cat head cp kill echo mv ip route ls pwd wget curl telnet vi tail grep sed awk dig tcpdump df du iostat vmstat lsof ps rm mkdir cd date time ping|awk '{print $2}'); do
        cp --parents $files $cdir/root
        ldd $files >>$ldd
done

cat $ldd|sort|grep -v vdso|grep -v executable|grep -v linux-aarch64 | awk '{print $3}'|uniq > $cdir/lib.txt
cat $cdir/lib.txt | while read libfiles; do
        cp --parents $libfiles $cdir/root
done

cd $cdir/root && tar -zcf ./root.tar.gz ./* && mv root.tar.gz .. && cd ..

#rm -f $ldd $cdir/lib.txt
