Skip to content

Instantly share code, notes, and snippets.

@dsxsxsxs
Last active January 29, 2018 08:45
Show Gist options
  • Save dsxsxsxs/353632d1b34efb39d18ffb5ce4071171 to your computer and use it in GitHub Desktop.
Save dsxsxsxs/353632d1b34efb39d18ffb5ce4071171 to your computer and use it in GitHub Desktop.
simple script that fetches licenses from all of your carthage dependencies and convert it into a plist.
#!/bin/sh
# fetch_cart_licenses.sh
# dsxs
#
# Created by dsxs on 2018/1/18.
# Copyright © 2018年 dsxsxsxs. All rights reserved.
# It'll be a good idea to automate this task by adding a run script into your build phase just like below.
# ${PROJECT_DIR}/fetch_carthage_licenses.sh ${PROJECT_DIR}
CARTS_DIR="$1/Carthage/Checkouts"
TARGET="$1/Licenses.plist"
#/*/LICENSE
echo "$(cat <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
EOF
)" > $TARGET
for cart in "$CARTS_DIR"/*
do
if [ -d "$cart" ] ;then
cartname=$(basename "$cart")
license=$(cat "$cart"/LICENSE* | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g')
echo " <key>$cartname</key>" >> $TARGET
echo " <string>$license</string>" >> $TARGET
fi
done
echo "</dict>" >> $TARGET
echo "</plist>" >> $TARGET
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment