Last active
September 28, 2021 02:23
-
-
Save jfsso/44924b13884e4ea5295d02ec85a86784 to your computer and use it in GitHub Desktop.
Delete unused DeployGate distributions by name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ -z "${DEPLOYGATE_TOKEN}" ]]; then | |
echo "Please specify your DeployGate token on env var DEPLOYGATE_TOKEN." | |
exit 1 | |
fi | |
DEPLOYGATE_USERNAME="__replace_this__" # your username or organization account name | |
APPS=("com.example.your_app" "com.example.your_app.flavor") | |
for APP in "${APPS[@]}"; | |
do | |
# get distributions sorted | |
echo "Retrieving list of distributions for $APP..." | |
curl -sS \ | |
-X GET \ | |
-F "token=$DEPLOYGATE_TOKEN" \ | |
https://deploygate.com/api/users/$DEPLOYGATE_USERNAME/platforms/android/apps/$APP/distributions | \ | |
jq '.results.distributions[].title' | \ | |
sed 's/\"//g' | sort > temp_distributions.txt | |
if [ -f protected.txt ]; then | |
echo "Protecting distributions from configuration:" | |
cat protected.txt | |
echo | |
# prepare list of protected distributions sorted | |
cat protected.txt | sort > temp_protected.txt | |
# remove protected distributions from delete list | |
# warning: comm requires that the lists are sorted | |
comm -2 -3 temp_distributions.txt temp_protected.txt > temp_delete.txt | |
else | |
# copy list of distributions to list of distributions to be deleted | |
cp temp_distributions.txt temp_delete.txt | |
echo "Warning: No distributions were specified for protection in protected.txt" | |
fi | |
echo "These distributions are going to be deleted:" | |
cat temp_delete.txt | |
echo | |
# prompt before deleting | |
read -p "Are you sure you wish to continue and delete these distributions permanently?" | |
if [[ "$REPLY" =~ ^[Yy]$ ]]; | |
then | |
echo "Deleting..." | |
cat temp_delete.txt | \ | |
xargs -I % \ | |
curl -sS \ | |
-X DELETE \ | |
-F "token=$DEPLOYGATE_TOKEN" \ | |
-F "distribution_name=%" \ | |
https://deploygate.com/api/users/$DEPLOYGATE_USERNAME/platforms/android/apps/$APP/distributions | |
echo | |
echo "All complete!" | |
else | |
echo "Ok... exiting!" | |
fi | |
# cleanup | |
rm -f temp_protected.txt temp_distributions.txt temp_delete.txt | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment