Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 22 Jan 2020, 00:10
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Copy a directory structure except for binaries
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [1 Post]  
Author Message
s243a

Joined: 02 Sep 2014
Posts: 2356

PostPosted: Sun 12 May 2019, 03:19    Post subject:  Copy a directory structure except for binaries
Subject description: Instead create meta-data for binaries
 

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:

#!/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 Smile

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.
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 1 [1 Post]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0916s ][ Queries: 11 (0.0450s) ][ GZIP on ]