dnscrypt-proxy/find_licenses.sh
c unix a16d993949 Accepting request 860360 from home:cunix:server_dns
- Minimum golang version now at 1.15
- Include 'notice' and 'patents' files of vendored packages.
- Paths and hints in configuration file adjusted and added.

OBS-URL: https://build.opensuse.org/request/show/860360
OBS-URL: https://build.opensuse.org/package/show/server:dns/dnscrypt-proxy?expand=0&rev=31
2021-01-05 22:23:51 +00:00

101 lines
3.1 KiB
Bash

#!/bin/bash
# written by cunix in 2019
# corrected by Bernhard Wiedemann in 2020 (pipe through sort)
# updated by cunix in 2021
#
# Tries to find and prepare licenses from vendored packages for
# installation as file or link to existing file.
#
# $1 should be a destination directory for vendored licenses
vendor_licenses_dir=$1
username=$(whoami)
workingdir=$(pwd)
licenses_file=/tmp/license_files.txt
goahead=0
hash_list=()
filename_list=()
if [[ -z "$vendor_licenses_dir" ]]
then
echo missing directory as parameter
exit 1
else
if [[ "$vendor_licenses_dir" = "/" ]] || [[ "$vendor_licenses_dir" = "/home" ]] \
|| [[ "$vendor_licenses_dir" = "/home/" ]] || [[ "$vendor_licenses_dir" = "/home/$username" ]] \
|| [[ "$vendor_licenses_dir" = "/home/$username/" ]] || [[ "$vendor_licenses_dir" = "$HOME" ]]
then
echo Do not use "$vendor_licenses_dir" as destination directory.
echo It will delete all your files.
exit 1
else
mkdir -pv $vendor_licenses_dir
if [[ -d "$vendor_licenses_dir" ]]
then
echo Searching for licenses ...
rm $licenses_file
find ./*/ -iname "license*" | sort > $licenses_file
find ./*/ -iname "copying*" | sort >> $licenses_file
find ./*/ -iname "notice*" | sort >> $licenses_file
find ./*/ -iname "patents*" | sort >> $licenses_file
goahead=1
else
echo "$vendor_licenses_dir" is not a directory.
exit 1
fi
fi
fi
if [[ -f "$licenses_file" ]]
then
if [[ $goahead -eq 1 ]]
then
echo Removing $vendor_licenses_dir
rm -r "$vendor_licenses_dir"
mkdir -pv $vendor_licenses_dir
echo Processing licenses . . .
while read line
do
filenamepre=${line////__}
filename=${filenamepre//.__/}
hash_output=$(sha256sum $line)
hash=${hash_output:0:66}
hash_list_len=${#hash_list[@]}
if [[ $hash_list_len -eq 0 ]]
then
cat $line > $vendor_licenses_dir/$filename
hash_list[0]=$hash
filename_list[0]=$filename
else
counter=0
match=0
for item in ${hash_list[@]}
do
if test $item = $hash
then
match=1
break
fi
counter=$(($counter+1))
done
if [[ $match -eq 0 ]]
then
hash_list[$counter]=$hash
filename_list[$counter]=$filename
cat $line > $vendor_licenses_dir/$filename
else
cd $vendor_licenses_dir
ln -s ${filename_list[$counter]} $filename
cd $workingdir
fi
fi
done < $licenses_file
else
echo Does not package licenses.
exit 1
fi
else
echo No licenses found to package.
fi