Commit 261a33df authored by Ismo Puustinen's avatar Ismo Puustinen

update-godep-licenses.sh: various fixes and cleanups.

The file was analyzed with shellcheck, and various issues fixed. Most of the problems were just cleanups, but also potential bugs were fixed. Many variables were quoted with double quotes to prevent globbing. The local_files array expansion was quoted so that any file names with potential spaces in the filename would not be re-split. The empty default value was removed from the list processing. POSIX standard "grep -E" was used instead of egrep.
parent 07d62835
...@@ -74,10 +74,10 @@ process_content () { ...@@ -74,10 +74,10 @@ process_content () {
# Start search at package root # Start search at package root
case ${package} in case ${package} in
github.com/*|golang.org/*|bitbucket.org/*) github.com/*|golang.org/*|bitbucket.org/*)
package_root=$(echo ${package} |awk -F/ '{ print $1"/"$2"/"$3 }') package_root=$(echo "${package}" |awk -F/ '{ print $1"/"$2"/"$3 }')
;; ;;
go4.org/*) go4.org/*)
package_root=$(echo ${package} |awk -F/ '{ print $1 }') package_root=$(echo "${package}" |awk -F/ '{ print $1 }')
;; ;;
gopkg.in/*) gopkg.in/*)
# Root of gopkg.in package always ends with '.v(number)' and my contain # Root of gopkg.in package always ends with '.v(number)' and my contain
...@@ -85,10 +85,10 @@ process_content () { ...@@ -85,10 +85,10 @@ process_content () {
# - gopkg.in/yaml.v2 # - gopkg.in/yaml.v2
# - gopkg.in/inf.v0 # - gopkg.in/inf.v0
# - gopkg.in/square/go-jose.v2 # - gopkg.in/square/go-jose.v2
package_root=$(echo ${package} |grep -oh '.*\.v[0-9]') package_root=$(echo "${package}" |grep -oh '.*\.v[0-9]')
;; ;;
*) *)
package_root=$(echo ${package} |awk -F/ '{ print $1"/"$2 }') package_root=$(echo "${package}" |awk -F/ '{ print $1"/"$2 }')
;; ;;
esac esac
...@@ -98,7 +98,7 @@ process_content () { ...@@ -98,7 +98,7 @@ process_content () {
[[ -d ${DEPS_DIR}/${dir_root} ]] || continue [[ -d ${DEPS_DIR}/${dir_root} ]] || continue
# One (set) of these is fine # One (set) of these is fine
find ${DEPS_DIR}/${dir_root} \ find "${DEPS_DIR}/${dir_root}" \
-xdev -follow -maxdepth ${find_maxdepth} \ -xdev -follow -maxdepth ${find_maxdepth} \
-type f "${find_names[@]}" -type f "${find_names[@]}"
done | sort -u)) done | sort -u))
...@@ -107,9 +107,14 @@ process_content () { ...@@ -107,9 +107,14 @@ process_content () {
local f local f
index="${package}-${type}" index="${package}-${type}"
if [[ -z "${CONTENT[${index}]-}" ]]; then if [[ -z "${CONTENT[${index}]-}" ]]; then
for f in ${local_files[@]-}; do for f in "${local_files[@]-}"; do
if [[ -z "$f" ]]; then
# Set the default value and then check it to prevent
# accessing potentially empty array
continue
fi
# Find some copyright info in any file and break # Find some copyright info in any file and break
if egrep -i -wq "${ensure_pattern}" "${f}"; then if grep -E -i -wq "${ensure_pattern}" "${f}"; then
CONTENT[${index}]="${f}" CONTENT[${index}]="${f}"
break break
fi fi
...@@ -151,19 +156,17 @@ declare -Ag CONTENT ...@@ -151,19 +156,17 @@ declare -Ag CONTENT
echo "================================================================================" echo "================================================================================"
echo "= Kubernetes licensed under: =" echo "= Kubernetes licensed under: ="
echo echo
cat ${LICENSE_ROOT}/LICENSE cat "${LICENSE_ROOT}/LICENSE"
echo echo
echo "= LICENSE $(cat ${LICENSE_ROOT}/LICENSE | md5sum | awk '{print $1}')" echo "= LICENSE $(cat "${LICENSE_ROOT}/LICENSE" | md5sum | awk '{print $1}')"
echo "================================================================================" echo "================================================================================"
) > ${TMP_LICENSE_FILE} ) > ${TMP_LICENSE_FILE}
# Loop through every package in Godeps.json # Loop through every package in Godeps.json
for PACKAGE in $(cat Godeps/Godeps.json | \ for PACKAGE in $(jq -r ".Deps[].ImportPath" < Godeps/Godeps.json | sort -f); do
jq -r ".Deps[].ImportPath" | \ process_content "${PACKAGE}" LICENSE
sort -f); do process_content "${PACKAGE}" COPYRIGHT
process_content ${PACKAGE} LICENSE process_content "${PACKAGE}" COPYING
process_content ${PACKAGE} COPYRIGHT
process_content ${PACKAGE} COPYING
# display content # display content
echo echo
...@@ -195,7 +198,7 @@ __EOF__ ...@@ -195,7 +198,7 @@ __EOF__
cat "${file}" cat "${file}"
echo echo
echo "= ${file} $(cat ${file} | md5sum | awk '{print $1}')" echo "= ${file} $(cat "${file}" | md5sum | awk '{print $1}')"
echo "================================================================================" echo "================================================================================"
echo echo
done >> ${TMP_LICENSE_FILE} done >> ${TMP_LICENSE_FILE}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment