-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
124 lines (110 loc) · 4.29 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
=begin
0. [YOU] signup
1. [YOU] enter credentials
2. cd android
3. create a debug key
4. download a secure token and API jar file
5. [YOU] sign it with a debug key
6. [YOU] mvn clean deploy
7. cd js/simple-example
8. jar cf ../simple-example.zip .
9. upload the zip file
10. cd rails
11. filter constants.rb with credentials
12. bundle install
13. filter constants.properties with credentials
[YOU] ... Do it yourself manually
Other items than annotated '[YOU]' are performed by `setup` task.
=end
require 'io/console'
cred = []
latest_token = nil
task :default => [:setup]
task :setup => [:get_credentials, :js, :android, :rails, :gae] do
puts "Done.
Unfortunately, I cannot help you actions regarding security token.
Run the following commands respectively later (you can copy and paste them and run respectively).
---
cd simple-example-android
keytool -importkeystore -srckeystore $HOME/.android/debug.keystore -destkeystore $HOME/.android/debug.p12 -deststoretype PKCS12
=> enter 'android' when asked to enter password (asked 3 times)
openssl pkcs12 -in $HOME/.android/debug.p12 -clcerts -nokeys -out $HOME/.android/debug.pem
=> enter 'android' when asked to enter password
openssl pkcs12 -in $HOME/.android/debug.p12 -nocerts -out $HOME/.android/debug.key
=> enter 'android' when asked to enter password (asked 3 times)
openssl smime -sign -in #{latest_token} -out assets/moat/signed.bin -signer $HOME/.android/debug.pem -inkey $HOME/.android/debug.key -nodetach -outform der -binary
---
Then build APK.
---
mvn clean deploy
"
end
task :get_credentials do
%w{app_id client_id client_secret}.each do |item|
puts "Enter #{item}:"
if item == 'client_secret'
input = STDIN.noecho(&:gets).chomp
else
input = STDIN.gets.chomp
end
raise "cannot be empty" if input.empty?
cred << "--#{item}=#{input}"
end
end
task :android do
cwd = "simple-example-android"
# create a debug key
android_dir = File.join(Dir.home, ".android")
Dir.mkdir(android_dir) unless File.exists?(android_dir)
exec_wd cwd, "keytool -genkey -keypass android -keystore $HOME/.android/debug.keystore -alias androiddebugkey -storepass android -validity 10000 -dname 'CN=Android Debug,O=Android,C=US'" unless File.exists?(File.join(android_dir, "debug.keystore"))
# download a secure token and sign it with a debug key
iidn cwd, "tokengen", "simple-example", "#{cred.join(' ')}"
latest_token = Dir.entries(cwd).sort_by{|f| File.mtime(File.join(cwd,f))}.select{|f| f.end_with?('.bin')}.reverse[0]
# download a jar file to build
iidn cwd, "sysdownload", "inventit-dmc-android-lib-api-4.0.0-prod.jar", "#{cred.join(' ')}"
# mvn install
exec_wd cwd, "
mvn install:install-file \
-Dfile=inventit-dmc-android-lib-api-4.0.0-prod.jar \
-DgroupId=com.yourinventit \
-DartifactId=inventit-dmc-android-lib-api \
-Dversion=4.0.0 -Dclassifier=prod -Dpackaging=jar
"
end
task :js do
cwd = "simple-example-js"
# jar cf ../simple-example.zip .
exec_wd cwd, "jar cf simple-example.zip simple-example"
# upload the zip file
iidn cwd, "jsdeploy", "simple-example.zip", "#{cred.join(' ')}"
end
task :rails do
cwd = "simple-example-rails"
# filter constants.rb with credentials
filename = "#{cwd}/config/initializers/constants.rb"
constants = File.read(filename)
constants.gsub!("{:your_application_id}", cred[0][(cred[0].index('=') + 1)..-1])
constants.gsub!("{:your_client_id}", cred[1][(cred[1].index('=') + 1)..-1])
constants.gsub!("{:your_client_secret}", cred[2][(cred[2].index('=') + 1)..-1])
File.open(filename, "w") { |file| file << constants }
# bundle install
exec_wd cwd, "bundle install"
# rake db:migrate
exec_wd cwd, "rake db:migrate"
end
task :gae do
cwd = "simple-example-gae"
# filter constants.properties with credentials
filename = "#{cwd}/src/constants.properties"
constants = File.read(filename)
constants.gsub!("{:your_application_id}", cred[0][(cred[0].index('=') + 1)..-1])
constants.gsub!("{:your_client_id}", cred[1][(cred[1].index('=') + 1)..-1])
constants.gsub!("{:your_client_secret}", cred[2][(cred[2].index('=') + 1)..-1])
File.open(filename, "w") { |file| file << constants }
end
def exec_wd(cwd, command)
system "cd #{cwd} && #{command}"
end
def iidn(*args)
system "cd #{args[0]} && iidn #{args[1..-1].join(' ')}"
end