Created
May 2, 2017 17:17
-
-
Save holly/bb8e9b396e2faf55aab5b66e2110cdb5 to your computer and use it in GitHub Desktop.
freebsd make thinjail environment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl | |
| # mklibs.pl | |
| # by Manuel Kasper <mk@neon1.net> | |
| # | |
| # walks a tree and extracts library dependencies | |
| # by using ldd | |
| # outputs a list of all libraries required for those binaries, | |
| # suitable for use with mkmini.pl | |
| # | |
| # check out my guide at http://neon1.net/ | |
| # | |
| # arguments: tree | |
| # forked from https://neon1.net/misc/minibsd/mklibs.pl | |
| use File::Find; | |
| exit unless $#ARGV == 0; | |
| undef @liblist; | |
| # check_libs(path) | |
| sub check_libs { | |
| @filestat = stat($File::Find::name); | |
| # process only if it's a regular file, executable and not a kernel module | |
| if ((($filestat[2] & 0170000) == 0100000) && | |
| ($filestat[2] & 0111) && (!/.ko$/)) { | |
| @curlibs = qx{/usr/bin/ldd -f "%p\n" $File::Find::name 2>/dev/null}; | |
| push(@liblist, @curlibs); | |
| } | |
| } | |
| # walk the directory tree | |
| find(\&check_libs, $ARGV[0]); | |
| # throw out dupes | |
| undef %hlib; | |
| @hlib{@liblist} = (); | |
| @liblist = sort keys %hlib; | |
| # remove leading slash | |
| foreach $lib (@liblist) { | |
| $lib = substr($lib, 1); | |
| } | |
| print @liblist; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl | |
| # mkmini.pl | |
| # by Manuel Kasper <mk@neon1.net> | |
| # | |
| # reads a file with a list of files to copy and link | |
| # check out my guide at http://neon1.net/ | |
| # | |
| # arguments: list_file source_tree dest_tree | |
| # forked from https://neon1.net/misc/minibsd/mkmini.pl | |
| use File::Copy; | |
| exit unless $#ARGV == 2; | |
| print "Populating MiniBSD tree: $ARGV[2]\n"; | |
| # make_dirs($srcfile, $destdir) | |
| sub make_dirs | |
| { | |
| my @args = @_; | |
| my $srcfile = $args[0]; | |
| my $destdir = $args[1]; | |
| @subdirs = split(/\//, $srcfile); | |
| chomp @subdirs; | |
| $curdir=$destdir; | |
| for (0 .. $#subdirs-1) | |
| { | |
| $curdir = $curdir . "/" . @subdirs[$_]; | |
| if (! ( (-e $curdir) && (-d $curdir) ) ) | |
| { | |
| print "Making directory $curdir\n"; | |
| mkdir($curdir, 0777); | |
| } | |
| } | |
| } | |
| # populate_tree(treefile, srcpath, destpath) | |
| sub populate_tree { | |
| my @args = @_; | |
| open TREEFILE, $args[0]; | |
| TREE: while (<TREEFILE>) { | |
| next TREE if /^#/; | |
| next TREE if /^ *$/; | |
| @srcfiles = split(/:/); | |
| chomp @srcfiles; | |
| $srcfile = shift(@srcfiles); | |
| @srcstat = stat($args[1] . "/" . $srcfile); | |
| make_dirs($srcfile, $args[2]); | |
| if (copy($args[1] . "/" . $srcfile, $args[2] . "/" . $srcfile)) { | |
| printf "Copy $args[1]/$srcfile -> $args[2]/$srcfile ($srcstat[4]/$srcstat[5]/%04o)\n", ($srcstat[2] & 07777); | |
| chown $srcstat[4], $srcstat[5], $args[2] . "/" . $srcfile; | |
| chmod $srcstat[2] & 07777, $args[2] . "/" . $srcfile; | |
| } else { | |
| print "ERROR while copying file $args[1]/$srcfile\n"; | |
| } | |
| foreach $lnfile (@srcfiles) | |
| { | |
| make_dirs($lnfile, $args[2]); | |
| if (link($args[2] . "/" . $srcfile, $args[2] . "/" . $lnfile)) | |
| { | |
| print "Link $args[2]/$srcfile -> $args[2]/$lnfile\n"; | |
| } | |
| else | |
| { | |
| print "ERROR while linking file $args[2]/$srcfile -> $args[2]/$lnfile \n"; | |
| } | |
| } | |
| } | |
| } | |
| populate_tree $ARGV[0], $ARGV[1], $ARGV[2]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment