Last active
March 20, 2018 09:21
-
-
Save ppmotskula/db7cb4092dbba31bdff58c75575a3565 to your computer and use it in GitHub Desktop.
getRLN -- get (R)EADME, (L)ICENSE, (N)OTICE files from a source tree
This file contains 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
#!/bin/bash | |
# getrln.sh v 18.03.1 | |
# | |
# Copyright (c) 2018 Peeter P. Mõtsküla <[email protected]> | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
function usage { | |
cat <<. | |
Usage: getrln.sh BUILDROOT | |
Try 'getrln.sh -h' for help. | |
. | |
} | |
function showhelp { | |
cat <<. | |
getRLN -- get (R)EADME, (L)ICENSE, (N)OTICE files from a source tree | |
getrln.sh extracts "README*", "LICENSE*", "COPYING*", and "NOTICE*" files | |
from any libraries in the BUILDROOT directory into ./BUILDROOT.rln. | |
The script is likely to fail when BUILDROOT is set to the current directory | |
or any of its parent directories. | |
BUILDROOT values ".", "..", and "/" are caught. | |
Any .jar files found in/under BUILDROOT will be temporarily unpacked into | |
./BUILDROOT-jars.rln. There are no checks if there is enough disk space. | |
. | |
} | |
function main { | |
# check command-line arguments | |
if [[ $# == 0 ]] ; then usage ; exit ; fi | |
if [[ $1 == -h ]] ; then showhelp ; exit ; fi | |
if [[ $1 == . || $1 == .. || $1 =~ ^/$ ]] ; then echo "Invalid BUILDROOT." ; echo ; showhelp; exit ; fi | |
BUILDROOT=$1 | |
if [[ $BUILDROOT =~ /$ ]] ; then BUILDROOT="${BUILDROOT%/}" ; fi | |
if [[ $BUILDROOT =~ / ]] ; then SHORTROOT="${BUILDROOT##*/}" ; else SHORTROOT="$BUILDROOT" ; fi | |
export BUILDROOT SHORTROOT | |
# unzip jars | |
find "$BUILDROOT" -name '*.jar' -exec bash -c 'i="{}" ; j=${i#"$BUILDROOT/"} ; j="$SHORTROOT-jars.rln/$j" ; mkdir -p "$j" ; unzip -q "$i" -d "$j"' \; | |
# export RLN files | |
find "$BUILDROOT" \( -name 'README*' -o -name 'LICENSE*' -o -name 'COPYING*' -o -name 'NOTICE*' \) -exec bash -c 'i={} ; j=${i/"$BUILDROOT"/"$SHORTROOT.rln"} ; j="${j%/*}" ; mkdir -p "$j" ; cp "$i" "$j"' \; | |
find "$SHORTROOT-jars.rln" \( -name 'README*' -o -name 'LICENSE*' -o -name 'COPYING*' -o -name 'NOTICE*' \) -exec bash -c 'i={} ; j=${i/"$SHORTROOT-jars.rln"/"$SHORTROOT.rln"} ; j="${j%/*}" ; mkdir -p "$j" ; cp "$i" "$j"' \; | |
# delete unzipped jars | |
rm -rf "$SHORTROOT-jars.rln" | |
# delete ._ files created by Mac OS Finder | |
find "$SHORTROOT.rln" -type f -name '._*' -exec rm {} \; | |
# list the files found | |
find "$SHORTROOT.rln" -type f | |
} | |
main $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment