#!/bin/bash
#if no arguments write information.
if [ -z $1 ]; then echo "For help use: ./publish.sh --help"; exit; fi
#help
if [ $1 = "--help" ]; then
echo "The command works the following way";
echo " ./publish.sh -u [user] -p [password] -d [device] -v [version] [-uri [uri:to/host]] [-conf [./path/to/file]]";
echo "For more information check ./publsih.sh --man";
exit; fi
#man
if [ $1 = "--man" ]; then
echo "The command works the following way";
echo " ./publish.sh -u [user] -p [password] -d [device] -v [version] [-uri [uri:to/host]] [-conf [./path/to/file]]";
echo "";
echo "The meaning of each parameter";
echo " -u Command to set the user.";
echo " -p Command to set the password.";
echo " -d Command to set the device id.";
echo " -v Command to set the maximum suported android version.";
echo " -uri [Optional] Command to set the uri of the service, if not the default one will be used. [\"https://devel1.tempos21.com/alfredo-dev/rest/market\"].";
echo " -conf [Optional] Command to set the configration file for the application. Default name [\"./market_app.conf\"]";
exit; fi
#user
if [ ! -z $1 ] && [ $1 = "-u" ]; then
if [ -z $2 ]; then echo "No username setted."; exit;
else j_username=$2; fi
else echo "No username setted."; exit; fi
#pass
if [ ! -z $3 ] && [ $3 = "-p" ]; then
if [ -z $4 ]; then echo "No password setted."; exit;
else j_password=$4; fi
else echo "No password setted."; exit; fi
#device
if [ ! -z $5 ] && [ $5 = "-d" ]; then
if [ -z $6 ]; then echo "No device id setted."; exit;
else device_id=$6; fi
else echo "No device id setted."; exit; fi
#version
if [ ! -z $7 ] && [ $7 = "-v" ]; then
if [ -z $8 ]; then echo "No version setted."; exit;
else version=$8; fi
else echo "No version setted."; exit; fi
is_config_file_checked=false;
#uri and conf
if [ ! -z $9 ]; then
if [ $9 = "-uri" ]; then
if [ -z ${10} ]; then
echo "No uri setted. Using the default [\"https://devel1.tempos21.com/alfredo-dev/rest/market\"].";
uri_server="https://devel1.tempos21.com/alfredo-dev/rest/market";
else uri_server=${10}; fi
else
is_config_file_checked=true;
if [ $9 = "-conf" ]; then
if [ -z ${10} ]; then
echo "No uri setted. Using the default [\"https://devel1.tempos21.com/alfredo-dev/rest/market\"].";
echo "No configuration file setted. Using the default [\"./market_app.conf\"].";
conf_file="market_app.conf";
else
echo "No uri setted. Using the default [\"https://devel1.tempos21.com/alfredo-dev/rest/market\"].";
conf_file=${10};
fi
else
echo "No uri setted. Using the defualt [\"https://devel1.tempos21.com/alfredo-dev/rest/market\"].";
echo "No configuration file setted. Using the default [\"./market_app.conf\"].";
conf_file="market_app.conf";
uri_server="https://devel1.tempos21.com/alfredo-dev/rest/market";
fi
fi
else
is_config_file_checked=true;
echo "No uri setted. Using the defualt [\"https://devel1.tempos21.com/alfredo-dev/rest/market\"].";
echo "No configuration file setted. Using the default [\"./market_app.conf\"].";
conf_file="market_app.conf";
uri_server="https://devel1.tempos21.com/alfredo-dev/rest/market";
fi
#conf
if [ "$is_config_file_checked" = false ]; then
if [ ! -z "${11}" ] && [ "${11}" = "-conf" ]; then
if [ -z "${12}" ]; then
echo "No configuration file setted. Using the default [\"./market_app.conf\"].";
conf_file="market_app.conf";
else conf_file="${12}"; fi
else
echo "No configuration file setted. Using the default [\"./market_app.conf\"].";
conf_file="market_app.conf";
fi
fi
#in the future it maight be configurable and set other platforms.
platform="Android";
#LOGIN
curl -s -X POST --cookie-jar ./cookie-alfredo -H "Accept: application/json" -H "Accept-Charset: utf-8" -H "Connection: keep-alive" -H "Cache-Control: no-cache" -H "Content-Type: application/x-www-form-urlencoded" -d 'j_username='$j_username'&j_password='$j_password'&device_id='$device_id'&version='$version'&platform='$platform "$uri_server/login" > tmp.json;
status=$(grep -Po '"status":(\d*?,|.*?[^\\]",)' tmp.json | cut -d ':' -f 2 | cut -d ',' -f 1)
if [ ! -z "$status" ]; then echo "LOGIN: OK";
else echo "LOGIN: KO"; exit; fi
rm tmp.json;
#Load all parameters of the file.
source $conf_file;
#set the correct split separator.
export IFS=","
#CREATE APP
curl -s -X POST --cookie ./cookie-alfredo -H "Accept: application/json" -H "Accept-Charset: utf-8" -H "Connection: keep-alive" -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data;" -F "application_name=$application_name" -F "application_description=$application_description" -F "downloadCountries=$downloadCountries0" -F "downloadCountries=$downloadCountries1" -F "downloadCountries=$downloadCountries2" -F "downloadCountries=$downloadCountries3" -F "downloadCountries=$downloadCountries4" -F "targetCountries=$targetCountries0" -F "targetCountries=$targetCountries1" -F "targetCountries=$targetCountries2" -F "targetCountries=$targetCountries3" -F "targetCountries=$targetCountries4" -F "languages=$languages0" -F "languages=$languages1" -F "languages=$languages2" -F "languages=$languages3" -F "languages=$languages4" -F "category=$category" -F "keywords=$keywords0" -F "keywords=$keywords1" -F "keywords=$keywords2" -F "keywords=$keywords3" -F "keywords=$keywords4" -F "description_department=$description_department" -F "description_support_url=$description_support_url" -F "description_support_email_adress=$description_support_email_adress" -F "description_status_notification_email=$description_status_notification_email" -F "description_owners=$description_owners0" -F "description_owners=$description_owners1" -F "description_owners=$description_owners2" -F "description_owners=$description_owners3" -F "description_owners=$description_owners4" "$uri_server/apps" > tmp.json;
applicationId=$(grep -Po '"appId":(\d*?,|.*?[^\\]",)' tmp.json | cut -d ':' -f 2 | cut -d ',' -f 1)
echo "APPLICATION ID: " $applicationId
if [ ! -z "$status" ]; then echo "CREATE APP: OK";
else echo "CREATE APP: KO"; exit; fi
rm tmp.json;
#ADD PROMO IMAGE
curl -s -X POST --cookie ./cookie-alfredo -H "Accept: application/json" -H "Accept-Charset: utf-8" -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data;" -F "FILE=@$promo_image" "$uri_server/apps/$applicationId/promo" > tmp.json;
status=$(grep -Po '"status":(\d*?,|.*?[^\\]",)' tmp.json | cut -d ':' -f 2 | cut -d ',' -f 1)
if [ ! -z "$status" ]; then echo "ADD PROMO IMAGE: OK";
else echo "ADD PROMO IMAGE: KO"; exit; fi
rm tmp.json;
#ADD BINARY
curl -s -X POST --cookie ./cookie-alfredo -H "Accept: application/json" -H "Accept-Charset: utf-8" -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data;" -F "FILE=@$binary" "$uri_server/apps/$applicationId/binary" >> tmp.json;
status=$(grep -Po '"status":(\d*?,|.*?[^\\]",)' tmp.json | cut -d ':' -f 2 | cut -d ',' -f 1)
if [ ! -z "$status" ]; then echo "ADD BINARY: OK";
else echo "ADD BINARY: KO"; exit; fi
rm tmp.json;
#ADD ICON IMAGE
curl -s -X POST --cookie ./cookie-alfredo -H "Accept: application/json" -H "Accept-Charset: utf-8" -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data;" -F "FILE=@$icon_image" "$uri_server/apps/$applicationId/icon" > tmp.json;
status=$(grep -Po '"status":(\d*?,|.*?[^\\]",)' tmp.json | cut -d ':' -f 2 | cut -d ',' -f 1)
if [ ! -z "$status" ]; then echo "ADD ICON IMAGE: OK";
else echo "ADD ICON IMAGE: KO"; exit; fi
rm tmp.json;
#ADD VIDEO URL
if [ ! -z $video_url ]; then
curl -s -X POST --cookie ./cookie-alfredo -H "Accept: application/json" -H "Accept-Charset: utf-8" -H "Cache-Control: no-cache" "$uri_server/apps/$applicationId/video?url=$video_url" > tmp.json;
status=$(grep -Po '"status":(\d*?,|.*?[^\\]",)' tmp.json | cut -d ':' -f 2 | cut -d ',' -f 1)
#No need to exit if the urls was not posted correctly.
if [ ! -z "$status" ]; then echo "ADD VIDEO URL: OK";
else echo "ADD VIDEO URL: KO"; fi
rm tmp.json;
fi;
#ADD SCREENSHOTS
for ss in $schreenshots; do
curl -s -X POST --cookie ./cookie-alfredo -H "Accept: application/json" -H "Accept-Charset: utf-8" -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data;" -F "FILE=@$ss" "$uri_server/apps/$applicationId/media" >> tmp.json;
status=$(grep -Po '"status":(\d*?,|.*?[^\\]",)' tmp.json | cut -d ':' -f 2 | cut -d ',' -f 1)
#No need to exit if the screenshot was not posted correctly.
if [ ! -z "$status" ]; then echo "ADD SCREENSHOTS: OK";
else echo "ADD SCREENSHOTS: KO"; fi
rm tmp.json;
done
#PUBLISH APPLICATION
curl -s -X POST --cookie ./cookie-alfredo -H "Accept: application/json" -H "Accept-Charset: utf-8" -H "Cache-Control: no-cache" "$uri_server/apps/$applicationId/publishLastBinary" > tmp.json;
status=$(grep -Po '"status":(\d*?,|.*?[^\\]",)' tmp.json | cut -d ':' -f 2 | cut -d ',' -f 1)
if [ ! -z "$status" ]; then echo "PUBLICATION: OK";
else echo "PUBLICATION: KO"; fi
rm tmp.json;