2018-10-28 17:25:43 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2020-04-02 15:40:09 +00:00
|
|
|
# Example usage: ./scripts/deploy_ui_files.sh http://dev.clientapi.teaspeak.de/api.php test 1.1.0
|
2018-11-19 18:05:42 +00:00
|
|
|
|
2021-03-22 16:17:34 +00:00
|
|
|
cd "$(dirname "$0")" || { echo "failed to enter base directory"; exit 1; }
|
|
|
|
source "./helper.sh"
|
2018-10-28 17:25:43 +00:00
|
|
|
|
2019-02-17 15:08:10 +00:00
|
|
|
if [[ "$#" -ne 3 ]]; then
|
2018-11-19 18:05:42 +00:00
|
|
|
echo "Illegal number of parameters (url | channel | required version)"
|
2018-10-28 17:25:43 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-04-02 15:40:09 +00:00
|
|
|
# shellcheck disable=SC2154
|
2019-02-17 15:08:10 +00:00
|
|
|
if [[ "${teaclient_deploy_secret}" == "" ]]; then
|
2018-10-28 17:25:43 +00:00
|
|
|
echo "Missing deploy secret!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-03-22 16:17:34 +00:00
|
|
|
package_file=$(find_release_package "client" "release")
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
|
|
echo "$package_file"
|
2020-04-02 15:40:09 +00:00
|
|
|
exit 1
|
2018-10-28 17:25:43 +00:00
|
|
|
fi
|
|
|
|
|
2021-03-22 16:51:53 +00:00
|
|
|
# We require a .tar.gz file and not a zip file.
|
|
|
|
# So we're extracting the contents and tar.gz ing them
|
|
|
|
temp_dir=$(mktemp -d)
|
|
|
|
unzip "$package_file" -d "$temp_dir/raw/"
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
|
|
rm -r "$temp_dir" &>/dev/null
|
|
|
|
echo "Failed to unpack package."
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Generating .tar.gz file from $package_file"
|
|
|
|
package_file="$temp_dir/$(basename -s ".zip" "$package_file").tar.gz"
|
|
|
|
tar chvzf "$package_file" "$temp_dir"/raw/*;
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
|
|
rm -r "$temp_dir"
|
|
|
|
echo "Failed to package package."
|
|
|
|
fi
|
|
|
|
|
2021-03-22 16:17:34 +00:00
|
|
|
git_hash=$(git_version "short-tag")
|
|
|
|
application_version=$(project_version)
|
|
|
|
echo "Deploying $package_file."
|
|
|
|
echo "Hash: ${git_hash}, Version: ${application_version}, Target channel: $2."
|
2018-10-28 17:25:43 +00:00
|
|
|
|
2021-03-22 16:17:34 +00:00
|
|
|
upload_result=$(curl \
|
2018-10-28 17:25:43 +00:00
|
|
|
-k \
|
|
|
|
-X POST \
|
2018-11-19 18:05:42 +00:00
|
|
|
-F "required_client=$3" \
|
2018-10-28 17:25:43 +00:00
|
|
|
-F "type=deploy-ui-build" \
|
|
|
|
-F "channel=$2" \
|
2021-03-22 16:17:34 +00:00
|
|
|
-F "version=$application_version" \
|
|
|
|
-F "git_ref=$git_hash" \
|
2018-10-28 17:25:43 +00:00
|
|
|
-F "secret=${teaclient_deploy_secret}" \
|
2021-03-22 16:17:34 +00:00
|
|
|
-F "file=@$package_file" \
|
2020-04-02 15:40:09 +00:00
|
|
|
"$1"
|
2018-10-28 17:25:43 +00:00
|
|
|
)
|
|
|
|
|
2021-03-22 16:51:53 +00:00
|
|
|
rm -r "$temp_dir"
|
2021-03-22 16:17:34 +00:00
|
|
|
echo "Server upload result: $upload_result"
|
|
|
|
success=$(echo "${upload_result}" | python -c "import sys, json; print(json.load(sys.stdin)['success'])")
|
2018-10-28 17:25:43 +00:00
|
|
|
|
2021-03-22 16:17:34 +00:00
|
|
|
if [[ ! "${success}" == "True" ]]; then
|
|
|
|
error_message=$(echo "${upload_result}" | python -c "import sys, json; print(json.load(sys.stdin)['msg'])" 2>/dev/null);
|
|
|
|
echo "Failed to deploy build: ${error_message}"
|
2018-10-28 17:25:43 +00:00
|
|
|
exit 1
|
2021-03-22 16:17:34 +00:00
|
|
|
else
|
|
|
|
echo "Build successfully deployed!"
|
|
|
|
exit 0
|
|
|
|
fi
|