Created
January 10, 2024 17:51
-
-
Save Sonic0/1a35ce7cffbf513a7892a5de67a6e642 to your computer and use it in GitHub Desktop.
Parse MySQL repository public key sign for a provided Ubuntu distribution codename
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 | |
# example: DEBUG="true" ./parse_mysql_signwith.sh focal 8.0 | |
debug() { | |
if [ -n "${DEBUG}" ] && [ "${DEBUG}" = "true" ]; then | |
echo "DEBUG: ${*}" 1>&2 | |
fi | |
} | |
# Check if both Ubuntu codename and MySQL version are provided as arguments | |
if [ $# -ne 2 ]; then | |
echo "Usage: $0 <ubuntu_codename> <mysql_version>" | |
exit 1 | |
fi | |
ubuntu_codename="${1}" | |
mysql_version="${2}" | |
# Download the distributions file | |
distributions_url="https://repo.mysql.com/apt/ubuntu/conf/distributions" | |
distributions_content=$(wget -qO- "${distributions_url}") | |
# Use a while loop to read blocks separated by blank lines | |
while IFS= read -r -d '' block; do | |
if ! echo "${block}" | grep -qw "Codename: ${ubuntu_codename}" || | |
! echo "${block}" | grep -qw "mysql-${mysql_version}"; then | |
continue | |
fi | |
debug "Distribution file found:" | |
debug "${block}" | |
debug "------------------------" | |
# Parse the "SignWith" value based on the provided Ubuntu codename | |
sign_with=$(echo "${block}" | grep -oP 'SignWith: \K.*') | |
if [ -n "$sign_with" ]; then | |
debug "SignWith value for Ubuntu ${ubuntu_codename} and MySQL ${mysql_version}: ${sign_with}" | |
break | |
else | |
debug "SignWith value not found for Ubuntu version ${ubuntu_codename} in distributions file." | |
exit 1 | |
fi | |
done < <(echo -n "${distributions_content}" | awk -v RS= -v ORS='\0' '{print $0}') | |
echo "${sign_with}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment