@@ -79,15 +79,84 @@ function check_for_isstreamer {
7979 pip install ISStreamer
8080 else
8181 echo " ISStreamer found, updating..."
82-
82+
8383 pip install --upgrade ISStreamer
8484 fi
85+
86+ isstreamer_version=$( python -c " import pkg_resources; print(pkg_resources.get_distribution('ISStreamer').version)" )
87+
88+ echo " Found ISStreamer: $isstreamer_version "
89+ isstreamer_version_array=(${isstreamer_version// " " / } )
90+ isstreamer_version_num=${isstreamer_version_array[0]}
91+ isstreamer_version_num_array=(${isstreamer_version_num// ./ } )
92+ isstreamer_major_version=${isstreamer_version_num_array[0]}
93+ isstreamer_minor=${isstreamer_version_num_array[1]}
94+ isstreamer_minor_version_array=(${isstreamer_minor// " rc" / } )
95+ isstreamer_minor_version=${isstreamer_minor_version_array[0]}
96+
97+ echo " isstreamer major version: $isstreamer_major_version "
98+ echo " isstreamer minor version: $isstreamer_minor_version "
8599}
86100
87101function download_script {
88- echo -n " Enter www.initialstate.com user email: "
89- read username < /dev/tty
90- echo -n " Enter www.initialstate.com password [input hidden]: "
102+ echo " Please select which Initial State app you're using: "
103+ echo " 1) app.initialstate.com"
104+ echo " 2) [NEW!] iot.app.initialstate.com"
105+ echo -n " Enter choice 1 or 2: "
106+ read app_version < /dev/tty
107+
108+ if [ " $app_version " = " 1" ]; then
109+ echo -n " Enter app.initialstate.com user email: "
110+ read username < /dev/tty
111+ echo -n " Enter app.initialstate.com password [input hidden]: "
112+ read -s password < /dev/tty
113+ echo " "
114+
115+ if [ -z " $example_location " ]; then
116+ example_location=" ./is_example.py"
117+ fi
118+
119+ python_example=$( curl -X POST " https://api.initialstate.com/api/v1/python/example" -H " X-USER: $username " -H " X-SEC: $password " -H " Accept-Content: text/plain" -m 30 -d " " -s)
120+
121+ if [ " $python_example " = " INVALID_CREDENTIALS" ]; then
122+ echo " invalid credentials, let's try that again!"
123+ download_script
124+ else
125+ echo " $python_example " | sudo -u $SUDO_USER tee " $example_location " > /dev/null
126+ fi
127+ else
128+ echo -n " Enter iot.app.initialstate.com user email: "
129+ read username < /dev/tty
130+ echo -n " Enter iot.app.initialstate.com password [input hidden]: "
131+ read -s password < /dev/tty
132+ echo " "
133+
134+ if [ -z " $example_location " ]; then
135+ example_location=" ./is_example.py"
136+ fi
137+
138+ python_example=$( curl -X POST " https://api.init.st/dev-auth/python/example" -H " X-USER: $username " -H " X-PASS: $password " -H " Accept-Content: text/plain" -m 30 -d " " -s)
139+
140+ if [ " $python_example " = " INVALID_CREDENTIALS" ]; then
141+ echo " invalid credentials, let's try that again!"
142+ download_script
143+ elif [ " $python_example " = " NOT_CURRENT" ]; then
144+ echo " your account hasn't been migrated, go to iot.app.initialstate.com to sign in or create a new account"
145+ download_script
146+ elif [ " $python_example " = " {\" message\" :\" Missing Authentication Token\" }" ]; then
147+ echo " there's currently an issue with this endpoint, try again later or email support@initialstate.com. Thanks!"
148+ exit 1
149+ else
150+ echo " $python_example " | sudo -u $SUDO_USER tee " $example_location " > /dev/null
151+ fi
152+ fi
153+
154+ }
155+
156+ function download_script_old {
157+ echo -n " Enter app.initialstate.com user email: "
158+ read username < /dev/tty
159+ echo -n " Enter app.initialstate.com password [input hidden]: "
91160 read -s password < /dev/tty
92161 echo " "
93162
@@ -96,7 +165,7 @@ function download_script {
96165 fi
97166
98167 python_example=$( curl -X POST " https://api.initialstate.com/api/v1/python/example" -H " X-USER: $username " -H " X-SEC: $password " -H " Accept-Content: text/plain" -m 30 -d " " -s)
99-
168+
100169 if [ " $python_example " = " INVALID_CREDENTIALS" ]; then
101170 echo " invalid credentials, let's try that again!"
102171 download_script
@@ -113,9 +182,13 @@ function setup_first_script {
113182 echo " Where do you want to save the example? [default: ./is_example.py]: "
114183 read example_location < /dev/tty
115184
116- download_script
185+ if [ " $isstreamer_major_version " -gt " 0" ]; then
186+ download_script
187+ else
188+ download_script_old
189+ fi
117190 fi
118-
191+
119192 echo " All done!"
120193}
121194
0 commit comments