From eeca10eda95a92a7a616f50b5c7f716cb9e5ea87 Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Fri, 21 Oct 2022 20:32:20 +0200 Subject: [PATCH] tracefile --help implemented. --- decrypt-root-with-usb/README | 10 ++++-- drac/drac | 2 +- find-first-fail/find-first-fail | 30 ++++++++++++++++-- find-first-fail/testsuite | 56 ++++++++++++++++++--------------- mirrorpdf/mirrorpdf | 6 ++-- rrm/rrm | 11 +++++-- splitvideo/splitvideo | 7 +++++ tracefile/tracefile | 36 +++++++++++++++++++-- vid/vid | 2 +- wssh/wssh | 9 ++++++ 10 files changed, 128 insertions(+), 41 deletions(-) diff --git a/decrypt-root-with-usb/README b/decrypt-root-with-usb/README index 82eff28..63ebae5 100644 --- a/decrypt-root-with-usb/README +++ b/decrypt-root-with-usb/README @@ -17,7 +17,8 @@ disk for each. So if you have a USB drive in your physical key ring, you can use the same drive for all the machines you boot when being physically close. -You add the key with: +You add the key with (/dev/sda5 is the full-disk encrypted device you +want to unlock): cryptsetup luksAddKey /dev/sda5 @@ -45,8 +46,13 @@ your initramfs, you need to add them by adding to sdhci sdhci_pci +Copy the relevant cryptroot to +/usr/share/initramfs-tools/scripts/local-top/cryptroot + When all is done, update the initramfs: update-initramfs -u -(C) 2014 Ole Tange, GPLv2 or later +Now reboot the system with the USB-disk connected. + +(C) 2014-2022 Ole Tange, GPLv2 or later diff --git a/drac/drac b/drac/drac index 0609e32..3fc3b6d 100755 --- a/drac/drac +++ b/drac/drac @@ -114,7 +114,7 @@ else DRAC_HOST="$host" fi -tmp=$(tempfile) +tmp=$(mktemp) # Find a command line tool to download with get=$( diff --git a/find-first-fail/find-first-fail b/find-first-fail/find-first-fail index f36cf04..21ef58e 100755 --- a/find-first-fail/find-first-fail +++ b/find-first-fail/find-first-fail @@ -118,7 +118,7 @@ after HOME=. Complex commands can also be run: - find-first-fail -v perl -e 'exit(shift > 129)' + find-first-fail -v perl -e 'exit(shift > 12345678)' =head2 Find the second limit of a program @@ -152,6 +152,29 @@ To identify the minimal CSV file that causes myparser to fail: find-first-fail -f example.csv -s1 myparser +=head2 Find minimal file fragment with two Rs + + + cat file.txt + 11 + 22 + R + 33 + 44 + 55 + R + 66 + 77 + R + 88 + + myfunc() { perl -ne 'END{ exit($a>1) } $a += /R/' "$@"; } + find-first-fail -vf file.txt myfunc + +This will find a fragment with only two Rs. If there are more (which +there is in this case), it may not find the smallest. It will, +however, minimize the one it finds. + =head1 REPORTING BUGS @@ -160,7 +183,7 @@ Report bugs: https://gitlab.com/ole.tange/tangetools/-/issues =head1 AUTHOR -Copyright (C) 2020 Ole Tange, +Copyright (C) 2020-2022 Ole Tange, http://ole.tange.dk and Free Software Foundation, Inc. @@ -294,7 +317,8 @@ find-first-fail() { shift shift local cmd=("$@") - local tmp=`tempfile -p fff` + local ext=${inputfile##*.} + local tmp=$(mktemp fffXXXXX.$ext) $verbose && echo "$a&2 # Build file of line a..b perl -ne "($start and 1..$start) and print" "$inputfile" > "$tmp"; diff --git a/find-first-fail/testsuite b/find-first-fail/testsuite index a85192f..c97e50d 100644 --- a/find-first-fail/testsuite +++ b/find-first-fail/testsuite @@ -3,7 +3,7 @@ test_unexported_function() { myprog() { perl -e 'exit (shift > 12345678)' "$@"; } # myprog is a function, so source find-first-fail first - . `which find-first-fail` + . "$(command -v find-first-fail)" echo Find 12345678 in unexported function find-first-fail myprog } @@ -38,45 +38,44 @@ test_s_v_12() { } test_file() { - tmp=`tempfile` - echo Header > $tmp - seq 100 >> $tmp - echo 10 >> $tmp - echo 12 >> $tmp - echo 15 >> $tmp - 10_to_15() { grep ^10$ $1 && grep ^15$ $1; } + tmp=$(mktemp) + (echo Header + seq 100 + echo 10 + echo 12 + echo 15) > "$tmp" + 10_to_15() { grep ^10$ "$1" && grep ^15$ "$1"; } export -f 10_to_15 echo 10..15 - find-first-fail -s1 -qf $tmp 10_to_15 + find-first-fail -s1 -qf "$tmp" 10_to_15 echo not 10..15 - find-first-fail -s1 -qf $tmp not 10_to_15 - rm $tmp + find-first-fail -s1 -qf "$tmp" not 10_to_15 + rm "$tmp" } test_header() { - tmp=`tempfile` - echo Header > $tmp - seq 10 >> $tmp - echo 1000 >> $tmp - seq 10 >> $tmp - + tmp=$(mktemp) + (echo Header + seq 10 + echo 1000 + seq 10) > "$tmp" myparser() { perl -ne 'if($_ > 100) { exit 1 }' "$@"; } export -f myparser echo Should give: echo Header echo 1000 - find-first-fail -s1 -f $tmp myparser + find-first-fail -s1 -f "$tmp" myparser } test_file_start_middle_end() { - tmp=`tempfile` + tmp=$(mktemp) testfile() { (echo MyHeader - echo $1 + echo "$1" echo 2 - echo $2 + echo "$2" echo 4 - echo $3) > "$tmp" + echo "$3") > "$tmp" } myparser() { perl -ne 'if($_ > 10) { exit 1 }' "$@"; } export -f myparser @@ -89,10 +88,10 @@ test_file_start_middle_end() { echo 'Find 1005' testfile 1 3 1005 find-first-fail -s1 -f "$tmp" myparser - echo 'Find 1001/1005' + echo 'Find 1001 or 1005' testfile 1001 3 1005 find-first-fail -s1 -f "$tmp" myparser - echo 'Find 1001/1003/1005' + echo 'Find 1001 or 1003 or 1005' testfile 1001 1003 1005 find-first-fail -s1 -f "$tmp" myparser } @@ -105,6 +104,13 @@ test_end() { find-first-fail -v -s 11 -e 15 myprog } +test_dashdash() { + echo 'Test -- will allow a function named -q' + -q() { perl -e 'exit (shift > 12)' "$@"; } + export -f -- -q + find-first-fail -q -- -q +} + export -f $(compgen -A function | grep test_) compgen -A function | grep test_ | LC_ALL=C sort | - parallel --timeout 1000% --tag -k --joblog /tmp/jl-`basename $0` '{} 2>&1' + parallel --timeout 1000% --tag -k --joblog /tmp/jl-"$(basename "$0")" '{} 2>&1' diff --git a/mirrorpdf/mirrorpdf b/mirrorpdf/mirrorpdf index 5977977..ca701c1 100755 --- a/mirrorpdf/mirrorpdf +++ b/mirrorpdf/mirrorpdf @@ -50,7 +50,8 @@ along with this program. If not, see . =head1 DEPENDENCIES -B uses B, B, B, and B. +B uses B, B (from psutils), B, and +B. =head1 SEE ALSO @@ -66,10 +67,9 @@ mirror() { # Flip both horizontally and vertically pstops H | ps2pdf - $tmp - # Flip both horizontally and vertically + # Rotate 180 deg pdftk $tmp cat 1-endnorth output "$2" rm $tmp } export -f mirror parallel mirror {} {.}_mirror.pdf ::: "$@" - diff --git a/rrm/rrm b/rrm/rrm index 179545f..f90e30a 100755 --- a/rrm/rrm +++ b/rrm/rrm @@ -56,6 +56,14 @@ my %size; my %hashval; my @remove; for my $file (@ARGV) { + if(not -e $file) { + warn("File does not exist: $file"); + next; + } + if(not -f $file) { + warn("Not a file: $file"); + next; + } if(-s $file > 0) { $size{$file} = -s $file; my $sha = Digest::SHA->new(256); @@ -63,9 +71,6 @@ for my $file (@ARGV) { $hashval{$file} = "SHA256:".$sha->b64digest; push @remove, $file; } - if(not -e $file) { - warn("File does not exist: $file"); - } } $rrmfile = find_rrm_file(".") || ".rrm"; diff --git a/splitvideo/splitvideo b/splitvideo/splitvideo index 6e21ae6..f342192 100755 --- a/splitvideo/splitvideo +++ b/splitvideo/splitvideo @@ -94,6 +94,13 @@ if(not -e $infile or $time !~ /\d\d:\d\d:\d\d.\d/) { "To split video.file at HH:MM:SS.t\n", "The original file will be moved to .../.rm\n\n"; } else { + # https://github.com/mifi/lossless-cut/pull/13 + # '-noaccurate_seek', + # '-ss', cutFrom, + # '-i', filePath, '-y', '-vcodec', 'copy', '-acodec', 'copy', + # '-to', cutTo, + # '-f', format, + # '-avoid_negative_ts', 'make_zero', my ($start_file,$end_file) = destinationfilenames($infile,$time); # fmpeg -t 00:25:29 -i in.mp4 -c copy out-start.mp4 my @start = ("ffmpeg","-t",$time,"-i","file:$infile","-c","copy","file:$start_file"); diff --git a/tracefile/tracefile b/tracefile/tracefile index e79c9d1..cb252f4 100755 --- a/tracefile/tracefile +++ b/tracefile/tracefile @@ -6,9 +6,9 @@ tracefile - list files being accessed =head1 SYNOPSIS -B [-adeflnruw] I +B [-adefhlnruw] I -B [-adeflnruw] -p I +B [-adefhlnruw] -p I =head1 DESCRIPTION @@ -51,6 +51,13 @@ List only existing files. List only normal files. +=item B<-h> + +=item B<--help> + +Show help text. + + =item B<-l> =item B<--local> @@ -246,12 +253,14 @@ B(1) use Getopt::Long; sub version(); +sub help(); $Global::progname = "tracefile"; $Global::version = 20220701; Getopt::Long::Configure("bundling","require_order"); get_options_from_array(\@ARGV) || die_usage(); if($opt::version) { version(); exit(0); } +if($opt::help) { help(); exit(0); } init_functions(); my @cmd = shell_quote(@ARGV); @@ -429,6 +438,7 @@ sub options_hash { "write|w" => \$opt::write, "all|a" => \$opt::all, "pid|p=i" => \$opt::pid, + "help|h" => \$opt::help, ); } @@ -519,7 +529,7 @@ sub version() { print join ("\n", "$Global::progname $Global::version", - "Copyright (C) 2020 Ole Tange, http://ole.tange.dk and Free Software", + "Copyright (C) 2020-2022 Ole Tange, http://ole.tange.dk and Free Software", "Foundation, Inc.", "License GPLv3+: GNU GPL version 3 or later ", "This is free software: you are free to change and redistribute it.", @@ -530,6 +540,26 @@ sub version() { } +sub help() { + # Returns: N/A + print join + ("\n", + "Usage:", + " $Global::progname [-adefhlnruw] (command|-p pid)", + " -a --all", + " -d --dir", + " -e --exist", + " -f --file", + " -h --help", + " -l --local", + " -n --nonexist", + " -r --read", + " -u --unique", + " -w --write", + "" + ); +} + sub my_dump(@) { # Returns: # ascii expression of object if Data::Dump(er) is installed diff --git a/vid/vid b/vid/vid index 020c9b2..07169fc 100755 --- a/vid/vid +++ b/vid/vid @@ -145,7 +145,7 @@ stdout() { if [ -t 1 ] ; then # STDOUT = terminal # start VLC - parallel --lb -Xj1 vlc + parallel --halt now,done=1 --lb -Xj1 vlc else cat fi diff --git a/wssh/wssh b/wssh/wssh index bc57c72..6cf6f02 100755 --- a/wssh/wssh +++ b/wssh/wssh @@ -74,6 +74,15 @@ my $host = shift @ARGV; $host =~ s/.*\@//; print STDERR $host; system("w4it-for-port-open $host 22"); + +# To avoid: +# +# "System is booting up. Unprivileged users are not permitted to log +# in yet. Please come back later. For technical details, see +# pam_nologin(8)." +# +# wait for 2 seconds +sleep(2); exec @ARGV; sub options_hash {