#Make sure we have input
[[ $# < 2 ]] && echo "No vaild input: copy_libs \"binary\" \"destination\" "
#Check if the paths are vaild
echo "what am I" $tmp_initrd/bin/$(basename $1)
[[ ! -e $tmp_initrd/bin/$(basename $1) ]] && echo "Not a valid input $1" && return 1
[[ -d $2 ]] || echo "No such directory $2 creating..."&& mkdir -p "$2"
#Get the binary library dependencies
echo "Collecting the shared library dependencies for $1..."
deps=$(chroot $sys_source ldd $1 |cut -d'>' -f2 |sed 's/(0x[^[:space:]]*//g' )
#deps=$(ldd $1 |cut -d'>' -f2 | awk '{print $1}')
echo "Copying the dependencies for $1 to $2"
#Copy the libs
for dep in $deps
do
lib_link=$(readlink -m $dep)
if [[ ! -z $(readlink $dep) ]] && [[ ! -f $tmp_initrd/lib/$(basename $dep) ]] && [[ ! -f $tmp_initrd/lib/$(basename $lib_link) ]]; then
cp -df $lib_link $tmp_initrd/lib/
ln -sf /lib/$(basename $lib_link) $tmp_initrd/lib/$(basename $dep)
echo "found lib link $(basename $dep) $tmp_initrd/lib/$(basename $lib_link)"
else
if [[ ! -f $2$(basename $dep) ]] && [[ ! -f $tmp_initrd/lib/$(basename $lib_link) ]]; then
echo "Copying $dep to $2"
cp -df "$sys_source$dep" $tmp_initrd/lib/
else
echo "lib $2$(basename $dep) exists"
fi
fi
done
}
function find_copy_bin
{
#Make sure we have input
[[ $# < 2 ]] && echo "No vaild input: find_bin \"binary\" \"destination\" "
#Check if the paths are vaild
#[[ ! -e $sys_source$1 ]] && echo "Not a vaild input $1" && return 1
[[ -d $2 ]] || echo "No such directory $2 creating..."&& mkdir -p "$2"
#Copy binary
found_bin=$(chroot $sys_source find /*bin/ /usr/*bin/ -type f | grep -w -m1 "$1$")
echo "copying $found_bin to $2"
if [[ -f $sys_source$found_bin ]]; then
cp -d "$sys_source$found_bin" "$2"
copy_libs $found_bin $tmp_initrd/lib/
else
echo "$found_bin file not found"
fi
}
function find_copy_busybox
{
#find and copy busybox
#if busybox.static and busybox shared is installed it's assumed
#that busybox static should be default otherwise it wouldn't be installed
#if static is not found use the shared version and copy the libs as well
locate_bbox=$(find $sys_source/*bin/ $sys_source/usr/*bin/ -executable -type f -name busybox* -print | tr " " "\n" )
if [[ $(echo $locate_bbox) == *"static"* ]]; then
bbox_bin=$(echo $locate_bbox |tr " " "\n"|grep -m1 'static')
ln -sf $(basename $bbox_bin) $tmp_initrd/bin/busybox
if [[ $1 == 1 ]]; then
echo $(basename $bbox_bin)
exit 0
fi
else
bbox_bin=$(echo $locate_bbox |tr " " "\n"|grep -m1 'busybox')
if [[ $1 == 1 ]]; then
echo $(basename $bbox_bin)
exit 0
fi
echo "not static copying libs"
copy_libs $bbox_bin $tmp_initrd/lib/
fi
[[ -d $1 ]] || echo "No such directory $1 creating..."&& mkdir -p "$1"
if [[ $1 != 1 ]]; then
echo "copying busybox: $bbox_bin"
cp -df $bbox_bin $1
fi
# gunzip modules, we will compress whole initrd image
# find $tmp_initrd/lib/modules/$kernel_rel -type f -name \*.xz -exec xz -d \{\} \;
depmod -a -b $tmp_initrd $kernel_rel
# Set Plymouth Theme ** We need a new option for this, hard coding no good **
# chroot $sys_source /usr/sbin/plymouth-set-default-theme synergy
# chroot $sys_source /usr/libexec/plymouth/plymouth-generate-initrd
##### MAIN #####
templatesDir=templates
bootsplash_arg=1
for arg in $@
do
case $arg in
--lzma) compr=lzma; squashfscompr=xz ;;
--kernel=*) kernel_rel=$(echo $arg | sed 's/.*kernel=//;s/--.*//') ;;
--label=*) VOLID=$(echo $arg | sed 's/.*VOLID=//;s/--.*//') ;;
--gzip) compr=gzip; squashfscompr=gzip ;;
--tpl=*) templatesDir=$(echo $arg | sed 's/.*tpl=//;s/--.*//') ;;
--bootsplash=*)
bootsplash_arg=1
bootsplash=$(echo $arg | sed 's/.*bootsplash=//;s/--.*//')
;;
-h|--help)
print_help
exit 0
;;
-*)
echo "Invalid option: $arg. Use -h to print help"
print_help
exit 1
;;
*)
[ -z $sys_source ] && sys_source=$arg && continue
[ -z $dst_iso ] && [ ! -z $sys_source ] && dst_iso=$arg
;;
esac
done
[ ! $(whoami) = 'root' ] && die "You need superuser privileges, try 'su' or 'sudo'"
[ -z $sys_source ] && die "Missing arg: source directory. Use -h to print help."
[ -z $dst_iso ] && die "Missing arg: iso image. Use -h to print help"
[ -z $compr ] && compr=gzip # gzip is default compression method
[ ! -d $sys_source ] && die "$sys_source is not a directory"
mkroot=$(dirname $0)
# does templates exist
#[ ! -d $mkroot/$templatesDir ] && die "templates dir: $mkroot/$templatesDir does not exist."
# does bootsplash configuration exist
if [ $bootsplash_arg -eq 1 ]; then
[ ! -f $bootsplash ] && die "bootsplash configuration: $bootsplash does not exist."
fi
# is destination exists
if [ -a $dst_iso ]
then
echo "Warning: $dst_iso file already exists."
echo "Do you wish to overwrite? [N/y]"
read anykey
[ ! "$anykey" = 'y' ] && die "Interrupted." || rm -f $dst_iso
fi