From 3edf62e16d2f8a35db2bbbe70c27a33d8d4e424a Mon Sep 17 00:00:00 2001 From: Jacob Bachmeyer Date: Sat, 1 Apr 2023 20:03:32 -0500 Subject: [PATCH] Expand FTP index builder tool --- make-ftpindex.sh | 97 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 4 deletions(-) mode change 100644 => 100755 make-ftpindex.sh diff --git a/make-ftpindex.sh b/make-ftpindex.sh old mode 100644 new mode 100755 index 58cd618..5771285 --- a/make-ftpindex.sh +++ b/make-ftpindex.sh @@ -1,4 +1,13 @@ #!/bin/sh +# shellcheck disable=SC2006,SC2268 + +Version_Notice=' +make-ftpindex (GNU Secure Software Gatekeeper) 0.2-pre +Copyright (C) 2023 Jacob Bachmeyer. +License GPLv3+: GNU GPL version 3 or later +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. +' # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -13,7 +22,87 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -ls -lrRt /home/ftp | gzip -9 -c > /home/ftp/ls-lrRt.txt.gz -cd /home/ftp -find . | gzip -9 -c > /home/ftp/find.txt.gz -tree -aJsD --timefmt %s | gzip -9 -c > /home/ftp/tree.json.gz +version () { echo "$Version_Notice" | awk '/^$/ { next } + $1 == "Copyright" { out = $1 OFS $2 } + out && $NF ~ /[[:digit:]]/ { yr = $NF } + out && $NF !~ /[[:digit:]]/ { + for (i = NF; i>0 && $i !~ /[[:digit:]]/; i--) ; + if ($i ~ /[[:digit:]]/) yr = $i; i++ + sub(/^[[:digit:]]+-/, "", yr) + for (out = out OFS yr; i<=NF; i++) out = out OFS $i + print out; out = ""; next + } + !out { print }' + exit 0 +} + +usage () { + echo usage: "$0" ' []' +} + +help () { + usage + cat < "${StageDir}"/find.txt.gz +tree -aJsD --timefmt %s | gzip -9 -c > "${StageDir}"/tree.json.gz +cd .. || error cannot move to parent of "'$PublicDir'" +# shellcheck disable=SC2012 # for obvious reasons... +ls -lrRt "$(basename "$PublicDir")" | gzip -9 -c > "${StageDir}"/ls-lrRt.txt.gz + +if $DryRun; then exit 0; fi + +mv -f "${StageDir}"/ls-lrRt.txt.gz \ + "${StageDir}"/find.txt.gz \ + "${StageDir}"/tree.json.gz \ + "${PublicDir}" + +# EOF -- 2.25.1