Initial commit of tools.

This commit is contained in:
Darren 'Tadgy' Austin 2022-09-07 14:40:52 +01:00
commit c6cb9f4286
5 changed files with 468 additions and 0 deletions

24
check-dependancies Executable file
View file

@ -0,0 +1,24 @@
#!/bin/bash
# Version: 0.0.2
# Copyright (c) 2007 - 2017:
# Darren 'Tadgy' Austin <darren (at) afterdark.org.uk>
# Licensed under the terms of the GNU General Public License version 3.
#
# This is a quick^Wslow dirty hack to check binaries and libraries for missing
# dependancies using ldd. Only those files with missing dependancies (along
# with the missing library information itself) will be written to stderr.
# Redirecting stderr to a file is advised, since this can produce a large
# volume of output on a system with many missing libraries.
echo "This will take a while..."
{ find -P ${1:-/} -regextype posix-extended \
\( -regex "^/(boot|data|dev|etc|home|lost\+found|media|mnt|proc|root|run|srv|sys|tmp|var)" -a -prune \) -o \
\( -regex "^/lib(64)?/ld-.*" -a -prune \) -o \
\( -regex "^/lib/(dhcpcd|firmware|modprobe\.d|modules)" -a -prune \) -o \
\( -regex "^/(opt|usr|usr/local)/(doc|etc|include|info|man|share|src)" -a -prune \) -o \
\( -regex "^/usr/lib(64)?/(firefox|java|jdk|jre|seamonkey|thunderbird)-.*" -a -prune \) -o \
\( -regex "^/usr/lib(64)?/(locale|qt/plugins/.*.debug)" -a -prune \) -o \
-type f -print0 | \
xargs -0 -r file -N -0 | egrep -a ".*ELF.*(executable|shared object).*dynamically" | cut -d $'\0' -f1 | sort | \
xargs -r ldd 2>/dev/null | egrep "(^/|not found)" | egrep -B 1 "^[[:space:]]" | egrep -v "^--" ; } >&2

103
clean-perllocal Executable file
View file

@ -0,0 +1,103 @@
#!/usr/bin/perl
#
# Clean up a perllocal.pod by removing outdated and duplicate entries.
# Taken from: http://www.perlmonks.org/?node_id=483020
#
use strict;
use warnings;
$|=1;
use Pod::Perldoc;
MAIN:
{
# Find perllocal.pod
my ($pod) = Pod::Perldoc->new()->grand_search_init([ 'perllocal' ]);
if (! $pod) {
print(STDERR "WARNING: 'perllocal.pod' not found\n");
exit(1);
}
# Parse perllocal.pod
my %pod;
my $removed = 0;
if (open(my $IN, $pod)) {
my ($line, $module, $order);
# Read up to first 'head2' line
while ($line = readline($IN)) {
if ($line =~ /^=head2/) {
last;
}
}
# Parse each module entry
# Duplicates will be overwritten by later entries in the file
do {
# New module entry encountered
if ($line =~ /^=head2/) {
# Extract module name from 'head2' line
($module) = $line =~ /L<([^|]+)\|/;
# See if it's a duplicate
if (exists($pod{$module})) {
$removed++;
}
# Remember this module's order in the file
$pod{$module}{'order'} = ++$order;
# Save the text
$pod{$module}{'text'} = $line;
} else {
# Concatenate text for current module entry
$pod{$module}{'text'} .= $line;
}
} while ($line = readline($IN));
close($IN);
} else {
print(STDERR "ERROR: Failure opening '$pod': $!\n");
exit(1);
}
# Check for uninstalls
if (@ARGV) {
my $arg = shift(@ARGV);
if ($arg eq '-u') {
for my $mod (@ARGV) {
if (delete($pod{$mod})) {
print("$mod removed from 'perllocal'\n");
$removed++;
} else {
print("$mod not found in 'perllocal'\n");
}
}
}
}
# Output the cleaned up results
my $cnt = 0;
if (open(my $OUT, "> $pod")) {
# Sort by original order
for my $module (sort { $pod{$a}{'order'} <=> $pod{$b}{'order'} }
keys(%pod))
{
# Output the module entry
print($OUT $pod{$module}{'text'});
$cnt++;
}
close($OUT);
} else {
print(STDERR "ERROR: Failure opening '$pod': $!\n");
exit(1);
}
# Report on results
print("'perllocal' now contains $cnt entries. ($removed removed.)\n");
}
exit(0);
# EOF

28
diff-tagfiles Executable file
View file

@ -0,0 +1,28 @@
#!/bin/bash
# Version: 0.0.1
# Copyright (c) 2017:
# Darren 'Tadgy' Austin <darren (at) afterdark.org.uk>
# Licensed under the terms of the GNU General Public License version 3.
#
# diff_tagfiles - display the differences between two tagfile sets, ignoring priorities.
#
if [ $# -ne 2 ]; then
echo "Usage: $0 <old dir> <new dir>"
exit 1
fi
if [ ! -d "$1" -o ! -d "$2" ]; then
echo "Directory doesn't exist."
exit 1
fi
for D in a ap d e f k kde kdei l n t tcl x xap xfce y; do
# Get the package lists without any priorities included.
cat $1/$D/tagfile | cut -d: -f1 >/tmp/t.old.$$
cat $2/$D/tagfile | cut -d: -f1 >/tmp/t.new.$$
# Diff them.
diff -u /tmp/t.old.$$ /tmp/t.new.$$ | \
sed -e "s:/tmp/t\.old\.$$:$1/$D/tagfile:g" -e "s:/tmp/t\.new\.$$:$2/$D/tagfile:g"
done

9
list-perl-modules Executable file
View file

@ -0,0 +1,9 @@
#!/bin/bash
# List all the perl modules currently installed.
perl -MCPAN - <<EOF
for \$mod (CPAN::Shell->expand("Module","/./")){
next unless \$mod->inst_file;
print \$mod->id, "\n";
}
EOF

304
merge-tagfiles Executable file
View file

@ -0,0 +1,304 @@
#!/bin/bash
# Version: 0.0.1
# Copyright (c) 2017:
# Darren 'Tadgy' Austin <darren (at) afterdark.org.uk>
# Licensed under the terms of the GNU General Public License version 3.
#
# Automatically or interractively merge tagfiles from two directories into a new set.
#
# The (space separated) list of package sets.
PACKAGE_SETS="${PACKAGE_SETS:-a ap d e f k kde kdei l n t tcl x xap xfce y}"
#........1.........2.........3.........4.........5.........6.........7.........8.........9.........0.........1.........2.........3.....:...4
display_help() {
# |--------1---------2---------3---------4---------5---------6---------7---------8
echo "Usage: ${0##*/} [options] <tagfiles dir1> <tagfiles dir2> <dest dir>"
echo "Automatically or interactively merge tagfiles from <tagfiles dir1> and"
echo "<tagfiles dir2>, writing the resultant tagfile set to <dest dir>. Priorities "
echo "from <tagfiles dir2> take presidence over those in <tagfiles dir1>."
echo
echo "Options:"
echo " -a, --default-add Do not interactively prompt whether to ADD or SKP any new"
echo " packages in <tagfile dir1>; automatically use this default."
echo " -s, --default-skp See above."
echo " -v, --version Display version and copyright information."
echo " -h, --help Display this help, obviously."
echo " -- Force the end of option processing. Any options following"
echo " this are treated as arguments."
echo "Option processing ceases with the first non-option or --."
echo
echo "Arguments (all of which are mandatory):"
echo " <tagfiles dir1> The top-level directory of the first set of tagfiles."
echo " <tagfiles dir2> The top-level directory of the second set of tagfiles."
echo " <dest dir> Path to the directory in which to write the new tagfiles."
return 0
}
display_version() {
# |--------1---------2---------3---------4---------5---------6---------7---------8
echo "${0##*/} v0.0.1"
echo "Copyright (c) 2017 Darren 'Tadgy' Austin <darren (at) afterdark.org.uk>"
echo "Licensed under the terms of the GNU GPL v3 <http://gnu.org/licenses/gpl.html>."
echo "This program is free software: you can modify or redistribute it in accordence"
echo "with the GNU GPL. However, it comes with ABSOLUTELY NO WARRANTY; not even the"
echo "implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
return 0
}
check_directory() {
# Params: $1 = Directory to check.
# Returns: 0 = OK.
# 1 = Doesn't exist.
# 2 = Not a directory.
# 3 = No read permission.
# 4 = No write permission.
if [[ ! -e "$1" ]]; then
echo "${0##*/}: no such directory: $1" >&2
return 1
elif [[ ! -d "$1" ]]; then
echo "${0##*/}: not a directory: $1" >&2
return 2
elif [[ ! -r "$1" ]]; then
echo "${0##*/}: read permission denied: $1" >&2
return 3
elif [[ ! -w "$1" ]]; then
echo "${0##*/}: write permission denied: $1" >&2
return 4
fi
return 0
}
write_line() {
# Params: $1 = Package.
# $2 = Priority.
# $3 = Comment.
# $4 = File to write to.
if [[ ! -z "$3" ]]; then
printf "%s:%s\t\t%s\n" "$1" "$2" "$3" >>$4 || exit 1
else
printf "%s:%s\n" "$1" "$2" >>$4 || exit 1
fi
}
prompt_priority() {
# Params: $1 = Package.
# $2 = Priority.
# $3 = Comment.
# Variables: Modifies NEWPRI variable.
echo
echo
echo "Package: $1" >&1
echo "Current priority: ${2:-(none)}"
echo "Comment: ${3:-(none)}"
echo
local ANSWER
while :; do
read -r -n 1 -p "Select new tag for package: (A)DD or (S)KP: " ANSWER
if [[ "${ANSWER^^}" = "A" ]]; then
NEWPRI="ADD"
break
elif [[ "${ANSWER^^}" = "S" ]]; then
NEWPRI="SKP"
break
else
continue
fi
done
}
process_tagfile() {
# Params: $1 = Input tagfile
# $2 = Output tagfile
# Clear the destination tagfile.
: >$2
# Open the input tagfile for reading.
# Note: We do this with an fd so we can use another 'read' of stdin for prompting.
exec {FD}<"$1"
# Process the tagfile line by line.
local PACKAGE PRIORITY COMMENT NEWPRI
while IFS=$'\t :' read -r -u "$FD" PACKAGE PRIORITY COMMENT; do
if [[ "${PRIORITY^^}" = "ADD" || "${PRIORITY^^}" = "SKP" ]]; then
# ADD or SKP.
write_line "$PACKAGE" "${PRIORITY^^}" "$COMMENT" "$2"
else
# REC or OPT
if [[ ! -z "$DEFAULT_PRIORITY" ]]; then
# Use default priority.
write_line "$PACKAGE" "$DEFAULT_PRIORITY" "$COMMENT" "$2"
else
# Prompt for new priority.
prompt_priority "$PACKAGE" "${PRIORITY^^}" "$COMMENT" # Has modified the NEWPRI variable
write_line "$PACKAGE" "$NEWPRI" "$COMMENT" "$2"
fi
fi
done
# Close tagfile file descriptor.
exec {FD}<&-
}
merge_tagfiles() {
# Params: $1 = Tagfile 1
# $2 = Tagfile 2
# $3 = Output tagfile
# Open the first tagfile for reading.
# Note: We do this with an fd so we can use another 'read' of stdin for prompting.
exec {FD}<"$1"
local PACKAGE1 PRIORITY1 COMMENT1 PACKAGE2_RHS NEWPRI
while IFS=$'\t :' read -r -u "$FD" PACKAGE1 PRIORITY1 COMMENT1; do
PRIORITY2="$(egrep "^${PACKAGE1//+/\\+}:" "$2" | cut -d: -f2- | sed -re 's/[[:blank:]]+.*$//')"
COMMENT2="$(egrep "^${PACKAGE1//+/\\+}:" "$2" | cut -d: -f2- | sed -re 's/(ADD|SKP|REC|OPT)//')"
if [[ -z "$PRIORITY2" ]]; then
# Package wasn't in tagfile2.
if [[ ! -z "$DEFAULT_PRIORITY" ]]; then
# Use default priority.
write_line "$PACKAGE1" "$DEFAULT_PRIORITY" "" "$3"
else
# Prompt for new priority.
prompt_priority "$PACKAGE1" "${PRIORITY1^^}" "$COMMENT1" # Has modified the NEWPRI variable
write_line "$PACKAGE1" "$NEWPRI" "$COMMENT1" "$3"
fi
elif ! [[ "${PRIORITY2^^}" =~ ^(ADD|SKP|REC|OPT) ]]; then
# Package was listed in tagfile2, but priority is invalid.
if [[ ! -z "$DEFAULT_PRIORITY" ]]; then
# Use default priority.
write_line "$PACKAGE1" "$DEFAULT_PRIORITY" "" "$3"
else
# Prompt for new priority.
prompt_priority "$PACKAGE1" "${PRIORITY2^^} (invalid)" "$COMMENT2" # Has modified the NEWPRI variable
write_line "$PACKAGE1" "$NEWPRI" "$COMMENT2" "$3"
fi
else
# Package was listed in tagfile2 and priority was valid.
write_line "$PACKAGE1" "${PRIORITY2^^}" "$COMMENT2" "$3"
fi
done
}
# Process command line options.
while :; do
case "$1" in
'-a'|'-default-add'|'--default-add')
if [[ "$DEFAULT_PRIORITY" = "SKP" ]]; then
echo "${0##*/}: options '$1' and '-s|--default-skp' are incompatible" >&2
exit 1
else
DEFAULT_PRIORITY="ADD"
fi
shift
;;
'-s'|'-default-skp'|'--default-skp')
if [[ "$DEFAULT_PRIORITY" = "ADD" ]]; then
echo "${0##*/}: options '$1' and '-a|--default-add' are incompatible" >&2
exit 1
else
DEFAULT_PRIORITY="SKP"
fi
shift
;;
'-v'|'-version'|'--version')
display_version
exit 0
;;
'-h'|'-help'|'--help')
display_help
exit 0
;;
'--')
shift
break
;;
-*)
# This prevents the first non-option argument being an entry in the
# current directory which begins with a '-'. Use the '--' option
# or ./-foo where this becomes a problem.
echo "${0##*/}: invalid option: $1" >&2
echo "Try: ${0##*/} --help" >&2
exit 1
;;
*)
break
;;
esac
done
# Process command line arguments.
(( $# != 3 )) && {
echo "${0##*/}: incorrect number of non-option arguments" >&2
echo "Try: ${0##*/} --help" >&2
exit 1
}
for ARG in $*; do
ERROR_TEXT="$(check_directory "$ARG" 2>&1)"
ERROR_CODE=$?
if [[ -z "$TAGFILES_DIR1" || -z "$TAGFILES_DIR2" ]]; then
# <tagfiles dir1> and <tagfiles dir2>
if (( $ERROR_CODE >= 1 && $ERROR_CODE <= 3 )); then # Ignore write permission failure.
echo "$ERROR_TEXT" >&2
exit 1
else
TAGFILES_DIR2="${TAGFILES_DIR1:+$ARG}"
TAGFILES_DIR1="${TAGFILES_DIR1:-$ARG}" # Yes, these are correct and in the right order!
fi
else
# <dest dir>
if (( $ERROR_CODE >= 2 )); then # Non-existant (ERROR_CODE=1) is OK here.
echo "$ERROR_TEXT" >&2
exit 1
else
DEST_DIR="$ARG"
fi
fi
done
[[ -z "$TAGFILES_DIR1" || -z "$TAGFILES_DIR2" || -z "$DEST_DIR" ]] && {
echo "Abort: argument processing failure" >&2
exit 1
}
# Create destination directory.
if [[ -e "$DEST_DIR" ]]; then
echo "${0##*/}: directory exists: $DEST_DIR" >&2
exit 1
else
mkdir -p -m 755 "$DEST_DIR" || exit 1
fi
# Main loop.
for SET in $PACKAGE_SETS; do
mkdir "$DEST_DIR/$SET" || exit 1
if [[ ! -e "$TAGFILES_DIR1/$SET" ]]; then
# No tagfile in dir1.
if [[ -e "$TAGFILES_DIR2/$SET" ]]; then
# Found tagfile in dir2 - process it and write to dest dir.
process_tagfile "$TAGFILES_DIR2/$SET/tagfile" "$DEST_DIR/$SET/tagfile" || exit 1
else
# No tagfile in either dir - create a stub file.
touch "$DEST_DIR/$SET/tagfile" || exit 1
fi
else
# Found tagfile in dir1.
if [[ ! -e "$TAGFILES_DIR2/$SET" ]]; then
# Process tagfile in dir1 and write to dest dir.
process_tagfile "$TAGFILES_DIR1/$SET/tagfile" "$DEST_DIR/$SET/tagfile" || exit 1
else
# Found tagfiles in both dirs - merge the tagfiles into dest dir.
merge_tagfiles "$TAGFILES_DIR1/$SET/tagfile" "$TAGFILES_DIR2/$SET/tagfile" "$DEST_DIR/$SET/tagfile"
fi
fi
done
echo