Skip to content

Instantly share code, notes, and snippets.

@ThinGuy
Last active November 15, 2018 20:26
Show Gist options
  • Save ThinGuy/ec89c833c30a5208771cec1d76c1cb36 to your computer and use it in GitHub Desktop.
Save ThinGuy/ec89c833c30a5208771cec1d76c1cb36 to your computer and use it in GitHub Desktop.
Edit to print correct apt source string for OpenStack releases
show-uca-repos() {
local PROPOSED=false
local OS_REL=
local ALL=false
local DESC="\e[1m${FUNCNAME}\e[0m: Prints correct apt repo string for a given OpenStack release"
show-uca-repos_usage() {
printf "\n\e[2G${DESC}\n\n"
printf "\e[2G\e[1mUsage\e[0m: ${FUNCNAME%%_*} [-p ] [-a ] [-r <release>] \n\n"
printf "\e[4G -p, --proposed\e[24GShow strings for proposed repos (Default: false)\n"
printf "\e[4G -a, --all \e[24GShow strings for both released and proposed repos (Default: false)\n"
printf "\e[4G -r, --release\e[24GName of OpenStack release (e.g. queens)\n"
printf "\e[4G -h, --help\e[24GThis message\n"
printf "\n\n"
}
ARGS=`getopt -o pahr: -l proposed,all,desc,help,release: -n ${FUNCNAME} -- "$@"`
eval set -- "$ARGS"
while true ; do
case "$1" in
-p|--proposed) local PROPOSED=true;shift 1;;
-a|--all) local ALL=true;shift 1;;
-r|--release) local OS_REL=${2,,};shift 2;;
--desc) printf "\n\e[2G${DESC}\n";return 0;;
-h|--help) ${FUNCNAME}_usage;return 2;;
--) shift;break;;
esac
done
local -a UCA_REPOS=($(curl -sSlL http://ubuntu-cloud.archive.canonical.com/ubuntu/dists/|grep -oP '(?<=>)[a-z]+-u[^/]+'))
local -a UCA_REPOS_PROPOSED=($(printf "%s\n" ${UCA_REPOS[@]}|sed 's/updates/proposed/'))
local -a UCA_RELEASES=($(printf "%s\n" ${UCA_REPOS[@]}|xargs -n1 -P0 bash -c 'curl -sSlL http://ubuntu-cloud.archive.canonical.com/ubuntu/dists/$0|sed "/cloud-tools/d"|grep -oP '"'"'(?<=>)[a-z][^/]+'"'"''|sort -V))
[[ -n ${OS_REL} ]] && { [[ -n $(grep -P '(^|\s)\K'${OS_REL}'(?=\s|$)' <<< ${UCA_RELEASES[@]}) ]] || { printf "\e[2GERROR: No OpenStack release named ${OS_REL} exists on ubuntu-cloud.archive.canonical.com\n\n\e[2GValid OpenStack releases are:\n";printf "\e[4G- %s\n" ${UCA_RELEASES[@]};echo;return 1; }; }
[[ ${PROPOSED} = false || ${ALL} = true ]] && { [[ ${ALL} = true ]] && { printf "\n\e[1mRelease\e[0m\n";printf "%.3s" $(printf '\u2550'){0..6};printf "\n\n"; } || { echo; } ;printf "%s\n" ${UCA_REPOS[@]}|\
xargs -n1 -P0 bash -c \
'curl -sSlL http://ubuntu-cloud.archive.canonical.com/ubuntu/dists/$0|sed "/cloud-tools/d"|sort -V|grep -oP '"'"'(?<=>)[a-z][^/]+'"'"'|sed "s|^|deb [arch=amd64] http://ubuntu-cloud.archive.canonical.com/ubuntu/ $0/|g;s|$| main|g"'|awk '/'${OS_REL}'/'; }
[[ ${PROPOSED} = true || ${ALL} = true ]] && { [[ ${ALL} = true ]] && { printf "\n\e[1mProposed\e[0m\n";printf "%.3s" $(printf '\u2550'){0..7};printf "\n\n"; } || { echo; } ;printf "%s\n" ${UCA_REPOS_PROPOSED[@]}|\
xargs -n1 -P0 bash -c \
'curl -sSlL http://ubuntu-cloud.archive.canonical.com/ubuntu/dists/$0|sed "/cloud-tools/d"|sort -V|grep -oP '"'"'(?<=>)[a-z][^/]+'"'"'|sed "s|^|deb [arch=amd64] http://ubuntu-cloud.archive.canonical.com/ubuntu/ $0/|g;s|$| main|g"'|awk '/'${OS_REL}'/'; }
echo
}
@ThinGuy
Copy link
Author

ThinGuy commented Nov 15, 2018

$ show-uca-repos -h

show-uca-repos: Prints correct apt repo string for a given OpenStack release

Usage: show-uca-repos [-p ] [-a ] [-r ]

-p, --proposed     Show strings for proposed repos (Default: false)
-a, --all          Show strings for both released and proposed repos (Default: false)
-r, --release      Name of OpenStack release (e.g. queens)
-h, --help         This message

$ show-uca-repos -ar queens

Release
═══════

deb [arch=amd64] http://ubuntu-cloud.archive.canonical.com/ubuntu/ xenial-updates/queens main

Proposed
════════

deb [arch=amd64] http://ubuntu-cloud.archive.canonical.com/ubuntu/ xenial-proposed/queens main

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