Skip to content

Commit fde605e

Browse files
committed
Prompt user with licensing file before meteor add-platform
1 parent f729ac0 commit fde605e

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

scripts/generate-android-bundle.sh

+10
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ fi
4343
tar xzf apache-ant-1.9.4-bin.tar.gz
4444
rm apache-ant-1.9.4-bin.tar.gz
4545

46+
# Capture the license text so we can prompt the user
47+
echo n | android-sdk/tools/android update sdk -t platform-tools -u > ${CHECKOUT_DIR}/license_cordova_android.txt
48+
49+
4650
# the below asks for confirmation... echo y seems to work
4751

4852
# platform tools
@@ -65,12 +69,18 @@ fi
6569
# android-sdk/tools/android create avd -t 1 -n test
6670
} &> /dev/null
6771

72+
# Strip header & footer from license
73+
sed -i '' '1,/License id:/d' ${CHECKOUT_DIR}/license_cordova_android.txt
74+
sed -i '' '1,/------------/d' ${CHECKOUT_DIR}/license_cordova_android.txt
75+
sed -i '' '/Do you accept the license/,$d' ${CHECKOUT_DIR}/license_cordova_android.txt
76+
6877
echo BUNDLING
6978

7079
cd "$DIR"
7180
echo "${BUNDLE_VERSION}" > .bundle_version.txt
7281

7382
echo "going to save in: ${CHECKOUT_DIR}/android_bundle_${UNAME}_${BUNDLE_VERSION}.tar.gz"
83+
echo "License file is at: ${CHECKOUT_DIR}/license_cordova_android.txt"
7484

7585
tar czf "${CHECKOUT_DIR}/android_bundle_${UNAME}_${BUNDLE_VERSION}.tar.gz" . &> /dev/null
7686

tools/commands-cordova.js

+70
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var PackageSource = require('./package-source.js');
2121
var compiler = require('./compiler.js');
2222
var unipackage = require('./unipackage.js');
2323
var tropohouse = require('./tropohouse.js');
24+
var httpHelpers = require('./http-helpers.js');
2425

2526
// XXX hard-coded the use of default tropohouse
2627
var tropo = tropohouse.default;
@@ -847,13 +848,70 @@ cordova.filterPackages = function (packages) {
847848
return ret;
848849
};
849850

851+
var getTermsForPlatform = function (platform) {
852+
var url = 'http://s3.amazonaws.com/android-bundle/license_cordova_' + platform + '.txt';
853+
var result = httpHelpers.request({
854+
url: url
855+
});
856+
857+
var response = result.response;
858+
// S3 returns 403 if not found
859+
if (response.statusCode === 404 || response.statusCode === 403) {
860+
verboseLog("License URL not found: " + url);
861+
process.stderr.write("No licensing file found for platform: " + platform + ".\n");
862+
return null;
863+
}
864+
if (response.statusCode !== 200) {
865+
throw new Error("Unexpected response code: " + response.statusCode);
866+
}
867+
return response.body;
868+
};
869+
870+
var checkAgreePlatformTerms = function (platform) {
871+
try {
872+
var terms = getTermsForPlatform(platform);
873+
} catch (e) {
874+
verboseLog("Error while downloading license terms: " + e);
875+
876+
// most likely we don't have a net connection
877+
process.stderr.write("Unable to download license terms for platform: " + platform + ".\n" +
878+
"Please make sure you are online.\n")
879+
throw new main.ExitWithCode(2);
880+
}
881+
882+
if (terms === null || terms.trim() === "") {
883+
// No terms required
884+
return true;
885+
}
886+
887+
process.stdout.write("The following terms apply to the '" + platform + "' platform:\n\n");
888+
process.stdout.write(terms + "\n\n");
889+
process.stdout.write("You must agree to the terms to proceed.\n");
890+
process.stdout.write("Do you agree (Y/N)? ");
891+
892+
var agreed = false;
893+
894+
var line = utils.readLine({ prompt: "Do you agree (Y/N)? "});
895+
line = line.trim().toLowerCase();
896+
if (line == "y" || line == "yes") {
897+
agreed = true;
898+
}
899+
900+
return agreed;
901+
};
902+
850903
// add one or more Cordova platforms
851904
main.registerCommand({
852905
name: "add-platform",
906+
options: {
907+
verbose: { type: Boolean, short: "v" }
908+
},
853909
minArgs: 1,
854910
maxArgs: Infinity,
855911
requiresApp: true
856912
}, function (options) {
913+
cordova.setVerboseness(options.verbose);
914+
857915
var platforms = options.args;
858916

859917
try {
@@ -865,6 +923,18 @@ main.registerCommand({
865923
return 1;
866924
}
867925

926+
try {
927+
var agreed = _.every(platforms, function (platform, options) {
928+
return checkAgreePlatformTerms(platform, options);
929+
});
930+
if (!agreed) {
931+
return 2;
932+
}
933+
} catch (err) {
934+
process.stderr.write(err.message + "\n");
935+
return 1;
936+
}
937+
868938
project.addCordovaPlatforms(platforms);
869939

870940
if (platforms.length) {

0 commit comments

Comments
 (0)