1+ #! /bin/bash
2+
3+ LICENSE_DIRECTORY=" third-party-licenses"
4+ EXIT_CODE=0
5+ LIBRARIES=($@ )
6+ SCRIPT_NAME=" $( basename " $0 " ) "
7+
8+ usage ( ) {
9+ cat << EOF
10+ ${SCRIPT_NAME} [OPTION] [LIBRARY]...
11+ The ${SCRIPT_NAME} tool makes it easier to comply with licenses of used libraries.
12+ It adds the licenses to the ${LICENSE_DIRECTORY} directory.
13+
14+ options:
15+ -h Print this message
16+ -l List installed libraries
17+
18+ example:
19+ If your project has included SDL2, SDL2_ttf and jsoncpp:
20+
21+ ${SCRIPT_NAME} sdl2 sdl2-ttf jsoncpp
22+
23+ To get a list of installed libraries to get the name right use:
24+
25+ ${SCRIPT_NAME} -l
26+
27+ EOF
28+ }
29+
30+ get_dependencies ( ) {
31+ echo " $( pacman -Qi ${1} | grep " ^Depends On" | cut -d' :' -f 2-| xargs echo) "
32+ }
33+
34+ copy_license_directory ( ) {
35+ if [ -d " /mingw64/share/licenses/${1} " ]; then
36+ if [ ! -d " ${LICENSE_DIRECTORY} /${1} " ]; then
37+ echo " Adding license for ${1} to ${LICENSE_DIRECTORY} "
38+ fi
39+ cp -rf " /mingw64/share/licenses//${1} " " ${LICENSE_DIRECTORY} /"
40+ for dependency in $( get_dependencies " ${1} " ) ; do
41+ if [ " ${dependency} " == " None" ]; then
42+ continue
43+ fi
44+ if [ ! -d " ${LICENSE_DIRECTORY} /${dependency} " ]; then
45+ echo " Found dependency ${dependency} for ${1} "
46+ fi
47+ copy_license_directory " ${dependency} "
48+ done
49+ else
50+ echo " Failed to find license for library ${1} "
51+ EXIT_CODE=2
52+ fi
53+ }
54+
55+ while getopts " hl" OPTION; do
56+ case ${OPTION} in
57+ h)
58+ usage
59+ exit 0
60+ ;;
61+ l)
62+ psp-pacman -Qq
63+ exit 0
64+ ;;
65+ * )
66+ echo " ${OPTION} - Unrecongnized option"
67+ usage
68+ exit 1
69+ ;;
70+ esac
71+ done
72+
73+ mkdir -p " ${LICENSE_DIRECTORY} "
74+ for library in ${LIBRARIES[@]} ; do
75+ copy_license_directory " ${library} "
76+ done
77+ exit ${EXIT_CODE}
0 commit comments