From 670fe30ca6f2e53901064be155b1807808f50f1b Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Tue, 12 Feb 2013 21:12:57 +0000 Subject: [PATCH] Added support for both major and minor version matching. Added a bit more of complexity since we can now match functions by major version only, or major and minor version. This will improve arithmetic comparisons sometimes required when choosing which piece of code gets executed. --- README.rst | 47 +++++++++++--------- bootstrap-salt.sh | 108 ++++++++++++++++++++++++++++------------------ 2 files changed, 92 insertions(+), 63 deletions(-) diff --git a/README.rst b/README.rst index 7b9afd1..89acffd 100644 --- a/README.rst +++ b/README.rst @@ -84,8 +84,10 @@ In order to install salt for a distribution you need to define: .. code:: bash - install____deps - install___deps + install____deps + install_____deps + install___deps + install____deps install___deps install__deps @@ -95,18 +97,21 @@ In order to install salt for a distribution you need to define: .. code:: bash - config____minion - config___minion - config___minion - config__minion - config_minion [THIS ONE IS ALREADY DEFINED AS THE DEFAULT] + config____salt + config_____salt + config___salt + config____salt + config___salt + config__salt + config_salt [THIS ONE IS ALREADY DEFINED AS THE DEFAULT] 3. To install salt, which, of course, is required, one of: .. code:: bash - install___ + install___ + install____ install__ @@ -114,8 +119,10 @@ In order to install salt for a distribution you need to define: .. code:: bash - install____post - install___post + install____post + install_____post + install___post + install____post install___post install__post @@ -124,8 +131,10 @@ In order to install salt for a distribution you need to define: .. code:: bash - install____start_daemons - install___start_daemons + install____start_daemons + install_____start_daemons + install___start_daemons + install____start_daemons install___start_daemons install__start_daemons @@ -142,14 +151,14 @@ Below is an example for Ubuntu Oneiric: .. code:: bash - install_ubuntu_1110_deps() { + install_ubuntu_11_10_deps() { apt-get update apt-get -y install python-software-properties add-apt-repository -y 'deb http://us.archive.ubuntu.com/ubuntu/ oneiric universe' add-apt-repository -y ppa:saltstack/salt } - install_ubuntu_1110_post() { + install_ubuntu_11_10_post() { add-apt-repository -y --remove 'deb http://us.archive.ubuntu.com/ubuntu/ oneiric universe' } @@ -158,13 +167,11 @@ Below is an example for Ubuntu Oneiric: } -Since there is no ``install_ubuntu_1110_stable()`` it defaults to the -unspecified version script. +Since there is no ``install_ubuntu_11_10_stable()`` it defaults to the unspecified version script. -The bootstrapping script must be plain POSIX sh only, **not** bash or another -shell script. By design the targeting for each operating system and version is -very specific. Assumptions of supported versions or variants should not be -made, to avoid failed or broken installations. +The bootstrapping script must be plain POSIX sh only, **not** bash or another shell script. By +design the targeting for each operating system and version is very specific. Assumptions of +supported versions or variants should not be made, to avoid failed or broken installations. Supported Operating Systems --------------------------- diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index ea00ceb..f153577 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -519,12 +519,14 @@ echo # Simplify version naming on functions if [ "x${DISTRO_VERSION}" = "x" ]; then DISTRO_MAJOR_VERSION="" - DISTRO_VERSION_NO_DOTS="" - PREFIXED_DISTRO_VERSION_NO_DOTS="" + DISTRO_MINOR_VERSION="" + PREFIXED_DISTRO_MAJOR_VERSION="" + PREFIXED_DISTRO_MINOR_VERSION="" else DISTRO_MAJOR_VERSION="$(echo $DISTRO_VERSION | sed 's/^\([0-9]*\).*/\1/g')" - DISTRO_VERSION_NO_DOTS="$(echo $DISTRO_VERSION | tr -d '.')" - PREFIXED_DISTRO_VERSION_NO_DOTS="_${DISTRO_VERSION_NO_DOTS}" + DISTRO_MINOR_VERSION="$(echo $DISTRO_VERSION | sed 's/^\([0-9]*\).*/\2/g')" + PREFIXED_DISTRO_MAJOR_VERSION="_${DISTRO_MAJOR_VERSION}" + PREFIXED_DISTRO_MINOR_VERSION="_${DISTRO_MINOR_VERSION}" fi # Simplify distro name naming on functions DISTRO_NAME_L=$(echo $DISTRO_NAME | tr '[:upper:]' '[:lower:]' | sed 's/[^a-zA-Z0-9_ ]//g' | sed -re 's/(\s)+/_/g') @@ -585,34 +587,43 @@ __apt_get_noinput() { # In order to install salt for a distribution you need to define: # # To Install Dependencies, which is required, one of: -# 1. install____deps -# 2. install___deps -# 3. install___deps -# 4. install__deps +# 1. install____deps +# 2. install_____deps +# 3. install___deps +# 4 install____deps +# 5. install___deps +# 6. install__deps # # Optionally, define a salt configuration function, which will be called if # the -c|config-dir option is passed. One of: -# 1. config____salt -# 2. config___salt -# 3. config___salt -# 4. config__salt -# 5. config_salt [THIS ONE IS ALREADY DEFINED AS THE DEFAULT] +# 1. config____salt +# 2. config_____salt +# 3. config___salt +# 4 config____salt +# 5. config___salt +# 6. config__salt +# 7. config_salt [THIS ONE IS ALREADY DEFINED AS THE DEFAULT] # # To install salt, which, of course, is required, one of: -# 1. install___ -# 2. install__ +# 1. install___ +# 2. install____ +# 3. install__ # # Optionally, define a post install function, one of: -# 1. install____post -# 2. install___post -# 3. install___post -# 4. install__post +# 1. install____post +# 2. install_____post +# 3. install___post +# 4 install____post +# 5. install___post +# 6. install__post # # Optionally, define a start daemons function, one of: -# 1. install____start_daemons -# 2. install___start_daemons -# 3. install___start_daemons -# 4. install__start_daemons +# 1. install____start_daemons +# 2. install_____start_daemons +# 3. install___start_daemons +# 4 install____start_daemons +# 5. install___start_daemons +# 6. install__start_daemons # # NOTE: The start daemons function should be able to restart any daemons # which are running, or start if they're not running. @@ -625,13 +636,13 @@ __apt_get_noinput() { # install_ubuntu_deps() { apt-get update - if [ $DISTRO_VERSION_NO_DOTS -gt 1204 ]; then + if [ $DISTRO_MAJOR_VERSION -gt 12 ] && [ $DISTRO_MINOR_VERSION -gt 04 ]; then # Above Ubuntu 12.04 add-apt-repository is in a different package __apt_get_noinput software-properties-common else __apt_get_noinput python-software-properties fi - if [ $DISTRO_VERSION_NO_DOTS -lt 1110 ]; then + if [ $DISTRO_MAJOR_VERSION -lt 11 ] && [ $DISTRO_MINOR_VERSION -lt 10 ]; then add-apt-repository ppa:saltstack/salt else add-apt-repository -y ppa:saltstack/salt @@ -639,7 +650,7 @@ install_ubuntu_deps() { apt-get update } -install_ubuntu_1110_deps() { +install_ubuntu_11_10_deps() { apt-get update __apt_get_noinput python-software-properties add-apt-repository -y 'deb http://us.archive.ubuntu.com/ubuntu/ oneiric universe' @@ -660,7 +671,7 @@ install_ubuntu_git_deps() { fi } -install_ubuntu_1110_post() { +install_ubuntu_11_10_post() { add-apt-repository -y --remove 'deb http://us.archive.ubuntu.com/ubuntu/ oneiric universe' } @@ -748,7 +759,7 @@ install_debian_deps() { apt-get update } -install_debian_60_deps() { +install_debian_6_0_deps() { echo "deb http://backports.debian.org/debian-backports squeeze-backports main" >> \ /etc/apt/sources.list.d/backports.list @@ -784,8 +795,8 @@ install_debian_git_deps() { fi } -install_debian_60_git_deps() { - install_debian_60_deps # Add backports +install_debian_6_0_git_deps() { + install_debian_6_0_deps # Add backports install_debian_git_deps # Grab the actual deps } @@ -804,7 +815,7 @@ install_debian_stable() { } -install_debian_60() { +install_debian_6_0() { install_debian_stable } @@ -812,7 +823,7 @@ install_debian_git() { python setup.py install --install-layout=deb } -install_debian_60_git() { +install_debian_6_0_git() { install_debian_git } @@ -1540,8 +1551,10 @@ config_salt() { # LET'S PROCEED WITH OUR INSTALLATION #============================================================================= # Let's get the dependencies install function -DEP_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_VERSION_NO_DOTS}_${ITYPE}_deps" -DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_VERSION_NO_DOTS}_deps" +DEP_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_deps" +DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_deps" +DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_deps" +DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_deps" DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}_deps" DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}_deps" @@ -1557,8 +1570,11 @@ done # Let's get the minion config function CONFIG_SALT_FUNC="null" if [ "$TEMP_CONFIG_DIR" != "null" ]; then - CONFIG_FUNC_NAMES="config_${DISTRO_NAME_L}${PREFIXED_DISTRO_VERSION_NO_DOTS}_${ITYPE}_salt" - CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}${PREFIXED_DISTRO_VERSION_NO_DOTS}_salt" + + CONFIG_FUNC_NAMES="config_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_salt" + CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_salt" + CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_salt" + CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_salt" CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}_${ITYPE}_salt" CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}_salt" CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_salt" @@ -1573,7 +1589,8 @@ fi # Let's get the install function -INSTALL_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_VERSION_NO_DOTS}_${ITYPE}" +INSTALL_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}" +INSTALL_FUNC_NAMES="$INSTALL_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}" INSTALL_FUNC_NAMES="$INSTALL_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}" INSTALL_FUNC="null" @@ -1586,11 +1603,14 @@ done # Let's get the post install function -POST_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_VERSION_NO_DOTS}_${ITYPE}_post" -POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_VERSION_NO_DOTS}_post" +POST_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_post" +POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_post" +POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_post" +POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_post" POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}_post" POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}_post" + POST_INSTALL_FUNC="null" for FUNC_NAME in $POST_FUNC_NAMES; do if __function_defined $FUNC_NAME; then @@ -1601,10 +1621,12 @@ done # Let's get the start daemons install function -STARTDAEMONS_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_VERSION_NO_DOTS}_${ITYPE}_start_daemons" -STARTDAEMONS_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_VERSION_NO_DOTS}_start_daemons" -STARTDAEMONS_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}_start_daemons" -STARTDAEMONS_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}_start_daemons" +STARTDAEMONS_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_start_daemons" +STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_start_daemons" +STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_start_daemons" +STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_start_daemons" +STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}_start_daemons" +STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}_start_daemons" STARTDAEMONS_INSTALL_FUNC="null" for FUNC_NAME in $STARTDAEMONS_FUNC_NAMES; do