Skip to content

Instantly share code, notes, and snippets.

@swichers
Created March 14, 2024 23:11
Show Gist options
  • Save swichers/c167abdb0f9be23305c7a9a22a473188 to your computer and use it in GitHub Desktop.
Save swichers/c167abdb0f9be23305c7a9a22a473188 to your computer and use it in GitHub Desktop.
Re-syncs all repositories under a repman organization
#!/bin/env bash
# Requires HTTPie and JQ
# Usage repman-sync-all.sh orgname apikey
# Check if jq and http exist
command -v jq >/dev/null 2>&1 || { echo >&2 "jq is required but it's not installed. Aborting."; exit 1; }
command -v http >/dev/null 2>&1 || { echo >&2 "http (HTTPie) is required but it's not installed. Aborting."; exit 1; }
# Function to display usage information
usage() {
echo "Usage: $0 <ORG_NAME> <API_KEY>"
echo "ORG_NAME and API_KEY must be provided."
exit 1
}
# Check the number of arguments
if [ "$#" -ne 2 ]; then
usage
fi
ORG_NAME="$1"
API_KEY="$2"
SLEEP_S=0.5
# Check if ORG_NAME and API_KEY are non-empty
if [ -z "$ORG_NAME" ] || [ -z "$API_KEY" ]; then
echo "ORG_NAME and API_KEY must not be empty."
exit 1
fi
# End of variables that need to change
package_url="https://app.repman.io/api/organization/${ORG_NAME}/package"
result=`http -j "${package_url}" "X-Api-Token:${API_KEY}"`
while [[ true ]]
do
for uuid in `echo "${result}" | jq -r '.data[].id'`
do
sync_url="${package_url}/${uuid}"
echo "Syncing package ${sync_url}"
http -j PUT "${sync_url}" "X-Api-Token:${API_KEY}"
sleep "${SLEEP_S}"
done
next_link=`echo "${result}" | jq -re '.links.next'`
if [ $? -ne 0 ]; then
break
fi
echo "---- Fetching ${next_link}"
result=`http -j "${next_link}" "X-Api-Token:${API_KEY}"`
done
echo "done"
exit 0
@swichers
Copy link
Author

Minimally improved version of the code here repman-io/repman#568 (comment) that allows for passing in org and api keys instead of putting them in the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment