From 57d7e3e30dd696d58ba1514f7a7f3196085c1f3b Mon Sep 17 00:00:00 2001 From: Robin Getz Date: Mon, 7 May 2018 14:36:59 -0400 Subject: [PATCH] legal_info_html.sh : Add BSD license, and tweak output to make it look like the other files on the mass storage device. Signed-off-by: Robin Getz --- scripts/legal_info_html.sh | 243 ++++++++++++++++++++++++++++++++++--- 1 file changed, 223 insertions(+), 20 deletions(-) diff --git a/scripts/legal_info_html.sh b/scripts/legal_info_html.sh index 60e33451..a17bdcbd 100755 --- a/scripts/legal_info_html.sh +++ b/scripts/legal_info_html.sh @@ -1,9 +1,42 @@ #!/bin/bash +# +# Copyright 2018(c) Analog Devices, Inc. +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# - Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# - Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# - Neither the name of Analog Devices, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# - The use of this software may or may not infringe the patent rights +# of one or more patent holders. This license does not release you +# from the requirement that you obtain separate licenses from these +# patent holders to use this software. +# +# THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +# INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A +# PARTICULAR PURPOSE ARE DISCLAIMED. +# +# IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY +# RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TARGET=$1 TARGET_VERSIONS=$2 MANIFEST=buildroot/output/legal-info/manifest.csv +MANIFEST_SORT=/tmp/manifest.?? +sort ${MANIFEST} > ${MANIFEST_SORT} PACKAGE=1 VERSION=2 @@ -16,12 +49,39 @@ FILE=build/LICENSE.html html_header () { echo "" > ${FILE} - echo "" >> ${FILE} + echo "" >> ${FILE} echo "" >> ${FILE} + echo "" >> ${FILE} + echo "" >> ${FILE} + echo "" >> ${FILE} echo "$1" >> ${FILE} echo "" >> ${FILE} + echo "" >> ${FILE} + echo "" >> ${FILE} + echo "" >> ${FILE} echo "" >> ${FILE} echo "" >> ${FILE} + echo "" >> ${FILE} + + echo "
" >> ${FILE} + echo "" >> ${FILE} + echo "\"Analog" >> ${FILE} + echo "" >> ${FILE} + echo "
" >> ${FILE} + echo "English |" >> ${FILE} + echo "Deutsch |" >> ${FILE} + echo "Français |" >> ${FILE} + echo "Español |" >> ${FILE} + echo "Português |" >> ${FILE} + echo "简体中文 |" >> ${FILE} + echo "日本語 | " >> ${FILE} + echo "Руccкий" >> ${FILE} + echo "
" >> ${FILE} + + echo "
" >> ${FILE} + echo "
" >> ${FILE} } html_footer () { @@ -34,6 +94,7 @@ html_h1 () { } html_h1_id () { + echo "Back to top" >> ${FILE} echo "

$1

" >> ${FILE} } @@ -47,7 +108,8 @@ html_p () { html_pre_file () { echo "
" >> ${FILE}
-	find $1 -type f -exec cat {} + >> ${FILE}
+	# get the file, but html sanitize a few things
+	find $1 -type f -exec cat {} + | sed -e "s/\o14//g" -e "s/'/\'/g" -e "s//\>/g" >> ${FILE}
 	echo "
" >> ${FILE} } @@ -83,6 +145,107 @@ package_list_items () { html_li_stop } +strstr () { + echo $1 | grep --quiet $2 +} + +# package_table_items $((var++)) Linux $(get_version linux) "GPLv2" "https://github.com/analogdevicesinc/linux" +# 1 2 3 4 5 +package_table_items () { + url=$5 + + command curl -h > /dev/null 2>&1 + if [ "$?" = "0" ] ; then + if $(strstr $url sourceforge) ; then + url=$(echo ${url} | sed -e 's/downloads\.//' -e 's/project/projects/') + fi + while [ 1 ] ; do + if $(strstr $url "ftp://") ; then + break + fi + tmp=$(curl -IsS $url) + if [ $(echo "$tmp" | head -1 | grep "301" | wc -l) -gt 0 ] ; then + url=$(echo "$tmp" | grep -i "Location:" | awk '{print $2}' | sed -e 's/^[ \t]*//;s/[ \t]*$//') + url=${url%$'\r'} + elif [ $(echo "$tmp" | head -1 | grep "404" | wc -l) -gt 0 ] ; then + url=$(echo $url | sed 's#/[^/]*$##' ) + elif [ $(echo "$tmp" | head -1 | grep "200" | wc -l) -gt 0 ] ; then + break + else + echo unknown error while trying ${url} + echo "${tmp}" + fi + done + fi + + echo "" >> ${FILE} + echo "${2}" >> ${FILE} + echo "${4}" >> ${FILE} + echo "${3}" >> ${FILE} + echo -n "" >> ${FILE} + if $(strstr $5 github) ; then + echo -n "Github" >> ${FILE} + elif $(strstr $5 sourceforge) ; then + echo -n "SourceForge" >> ${FILE} + elif $(strstr $5 freedesktop) ; then + echo -n "Freedesktop" >> ${FILE} + elif $(strstr $5 debian) ; then + echo -n "Debian Project" >> ${FILE} + elif $(strstr $5 kernel) ; then + echo -n "Kernel.org" >> ${FILE} + else + echo -n "Project" >> ${FILE} + fi + echo "" >> ${FILE} + echo "" >> ${FILE} +} + +# Borrowed concepts from : +# https://github.com/chadbraunduin/markdown.bash/blob/master/markdown.sh +# MIT License +# Copyright (c) 2016 Chad Braun-Duin +# 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. +# +convert_md2html () { +temp_file="/tmp/markdown.$$" +cat "$1" > "$temp_file" +# All of this below business is for reference-style links and images +# We need to loop across newlines and not spaces +IFS=' +' +refs=$(sed -nr "/\[.+\]/p" "$1") +for ref in $refs +do + ref=$(echo -n "$ref" | sed "s/^.*\[/\[/") + ref_id=$(echo -n "$ref" | sed -nr "s/^\[(.+)\].*/\1/p" | tr -d '\n') + ref_url=$(echo -n "$ref" | sed -nr "s/^\[.+\]\((.+)/\1/p" | cut -d' ' -f1 | tr -d '\n') + ref_title=$(echo -n "$ref" | sed -nr "s/^\[.+\](.+) \"(.+)\"/\2/p" | sed 's@|@!@g' | tr -d '\n' | sed 's/).*$//') + # reference-style image using the label + sed -ri "s|!\[([^]]+)\]\[($ref_id)\]|\"\1\"|gI" "$temp_file" + # reference-style link using the label + sed -ri "s|\[($ref_id)\].*\($ref_url \"$ref_title\"\)|\1|gI" "$temp_file" + # implicit reference-style + sed -ri "s|!\[($ref_id)\]\[\]|\"\1\"|gI" "$temp_file" + # implicit reference-style + sed -ri "s|\[($ref_id)\]\[\]|\1|gI" "$temp_file" +done + +# delete the reference lines +sed -ri "/^\[.+\]: +/d" "$temp_file" +sed -nri "/^# /,/^# / { /^# /d ; p } " "$temp_file" +sed -ri -e 's/^$/

/' "$temp_file" +cat ${temp_file} +rm ${temp_file} +} + ### main html_header "${TARGET} Legal Information" @@ -90,39 +253,77 @@ html_header "${TARGET} Legal Information" html_h1 "Legal Information" html_h1 "${TARGET} Firmware $(get_version device-fw)" -echo "

" >> ${FILE}
-cat LICENSE.md | sed -n '/#/I,/#/I  { s/#.*//g; p }' >> ${FILE}
-echo "
" >> ${FILE} +convert_md2html LICENSE.md >> ${FILE} + +echo "
" >> ${FILE} +html_h2 "Written Offer" + +echo "As described above, the firmware included in the ${TARGET} contains copyrighted software that is released and distributed under many licenses, including the GPL. +A copy of the licenses are included in this file (below). +You may obtain the complete Corresponding Source code from us for a period of three years after our last shipment of this product, which will be no earlier than 01Jan2021, by sending a money order or check for \$15 (USD) to: +
+GPL Compliance
+Systems Development Group
+Attention: Robin Getz
+Analog Devices Inc.
+Three Technology Way
+Norwood, MA.
+02062
+USA
+
+ +Please write “source for the ${TARGET}” in the memo line of your payment. +Since the source does not fit on a DVD-RW, it will be delivered on a USB Thumb drive (hense the higher cost than just DVD or CD). +

You will also find a the source on-line, and are encouraged to obtain it for zero cost, at the project web sites.

+
" >> ${FILE} html_h2 "NO WARRANTY" echo "
" >> ${FILE}
-cat LICENSE.md | sed  -n '1,/# NO WARRANTY/!p' >> ${FILE}
+cat LICENSE.md | sed  -n '1,/# NO WARRANTY/!p' | sed "1d" >> ${FILE}
 echo "
" >> ${FILE} ### Table of packages html_h1 "Open source components/packages:" -var=0 -html_li_start -# Buidlroot external or local packages -html_li "linux" -html_li "u-boot" +var=0 +echo "

Version Information:

" >> ${FILE} +echo "" >> ${FILE} +echo "" >> ${FILE} +echo "" >> ${FILE} +echo "" >> ${FILE} +echo "" >> ${FILE} +echo "" >> ${FILE} +echo "" >> ${FILE} +echo "" >> ${FILE} +echo "" >> ${FILE} +echo "" >> ${FILE} +package_table_items $((var++)) Linux $(get_version linux) "GPLv2" "https://github.com/analogdevicesinc/linux" +package_table_items $((var++)) U-Boot $(get_version u-boot-xlnx) "GPLv2" "https://github.com/analogdevicesinc/u-boot-xlnx" while read -r line do - package=$(get_column "${line}" $PACKAGE) + package=$(get_column "${line}" $PACKAGE) - if [ "$package" == "PACKAGE" ];then - continue - fi - html_li "$package" -done < "$MANIFEST" -html_li_stop -html_hr + if [ "$package" == "PACKAGE" ];then + continue + fi + + version=$(get_column "${line}" $VERSION) + license_file=$(get_column "${line}" $LICENSE_FILES) + license=$(get_column "${line}" $LICENSE) + source_site=$(get_column "${line}" $SOURCE_SITE) + + package_table_items $((var++)) $package $version $license $source_site + +done < "${MANIFEST_SORT}" + +echo "" >> ${FILE} +echo "
PackageLicenseVersionLocation
" >> ${FILE} var=0 ### Linux +html_hr html_h1_id "Package: linux" "$((var++))" package_list_items $(get_version linux) "GPLv2" "https://github.com/analogdevicesinc/linux" html_h2 "License:" @@ -156,6 +357,8 @@ do html_h2 "License:" html_pre_file "$(dirname $MANIFEST)/licenses/$package-$version/" html_hr -done < "$MANIFEST" +done < "${MANIFEST_SORT}" html_footer + +rm ${MANIFEST_SORT}