0af77d3229
Build fails where golang is too old. If acceptable, i'm asking to not immediately submit to Factory. OBS-URL: https://build.opensuse.org/request/show/813333 OBS-URL: https://build.opensuse.org/package/show/server:dns/dnscrypt-proxy?expand=0&rev=22
97 lines
2.9 KiB
Bash
97 lines
2.9 KiB
Bash
#!/bin/bash
|
|
|
|
# written by cunix in 2019
|
|
#
|
|
# 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*" -fprint $licenses_file
|
|
find ./*/ -iname "copying*" >> $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
|