Copy a directory structure except for binaries

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
s243a
Posts: 2580
Joined: Tue 02 Sep 2014, 04:48
Contact:

Copy a directory structure except for binaries

#1 Post by s243a »

In my TazPup64 buildkit, I have a mix of source and binaries. I want to move the source to github but not the binaries. For the binaries I want to replace it with a file that contains some metadata (i.e. size, name, checksums and possible download locations).

I'm not sure how well github handles binaries but I would rather the binary files don't depend on github and would instead rather use official repositories and/or dropbox.

Anyway here is the code:

Code: Select all

#!/bin/bash
#written by s243a

close_fds(){
	exec 10>&-
	rm -rf /tmp/move-source
}
trap close_fds EXIT
trap close_fds SIGKILL
trap close_fds SIGTERM
curdir=`pwd`
_(){ #Can use this function to safely quote things. 
  echo "$*"
}
s_root="`realpath "$curdir"`"
mkdir -p ../tazpup-builder-source
d_root=`realpath ../tazpup-builder-source`
mkdir -p /tmp/move-source
exec 10<> /tmp/move-source/fd_10

for adir in build-scripts pkgs tazpup-core-files; do
#  for afile in "`find "./$adir" -name '*'`" ; do
   while IFS=$'\0' read -r -d $'\0' -u10 afile; do
    afile="${afile#'./'}"
    if [ -d "$s_root/$afile" ]; then
      adir2="$afile" 
    else
      adir2="$(basename "$afile")"        
    fi
    if [ -d "$s_root/$afile" ]; then
      cd "$s_root"
      echo ./$adir2 | cpio -pd $d_root     
    elif [[ `file -i "$s_root/$afile" | cut -d' ' -f2` = text/* ]] &&
       [[ $afile != *.log ]]; then
      cd "$s_root"
      echo ./$afile | cpio -pd $d_root
    else
      if [ ! -d $d_root/$dir2 ]; then
        cd $s_root
        echo "./$adir2" | cpio -pd $d_root
      fi
      echo "\
filename=$(basename "$afile")
size=$(du "$afile") 
checksum.md5=$(md5sum "$afile")
checksum.sha256=$(sha256sum "$afile")">$d_root/$afile.binary.meta
    fi
  done 10< <( find "./$adir" -name '*' -print0 ) 
done
exec 10>&-
https://pastebin.com/fwi0fSdh

It's just a first draft but it from my initial test it appears to work :)

P.S. This script requires the full version of cpio although, I may modify it to work with the busybox version also. The difference is that the busybox version doesn't have the -p option, so in the busybox version you have to output an archive. WIth the -p option you can output a directory as I do above.

Edit 1 Here is the output, "TazPup17%28BuildKit%29-source.tar.gz". Except for the files in the root directory, which I had to manually copy...so there is at least one bug that I have to fix. The directory I ran this script on can be scene by extracting the file at, "BuildKit%28TazPup64%29-PreAlpha17%28unclean%29.tar.gz". Warning this file is large because I didn't run the clean scripts and it contains more binaries than are necessary to build TazPup64.

Post Reply