From f3d2385358fda95cf2e1a74adf9823d24d452d0c Mon Sep 17 00:00:00 2001 From: Sergey Paramonov Date: Wed, 30 Dec 2015 00:13:11 -0500 Subject: [PATCH 1/4] adding support for OpenBSD --- AUTHORS.rst | 1 + bootstrap-salt.sh | 201 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 202 insertions(+) diff --git a/AUTHORS.rst b/AUTHORS.rst index 8dc01f2..7f51c86 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -73,6 +73,7 @@ Rob Eden hedinfaok Roberto Aguilar rca roberto@baremetal.io Roman Inflianskas rominf infroma@gmail.com Ronald van Zantvoort The-Loeki ronald@pcextreme.nl +Sergey Paramonov serge-p serg.paramonov@s-vp.com Skyler Berg skylerberg skylertheberg@gmail.com Stanislav B stanislavb Steve Groesz wolfpackmars2 diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index b0e448c..e0f7374 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -586,6 +586,7 @@ __fetch_url() { wget $_WGET_ARGS -q -O "$1" "$2" >/dev/null 2>&1 || fetch $_FETCH_ARGS -q -o "$1" "$2" >/dev/null 2>&1 || fetch -q -o "$1" "$2" >/dev/null 2>&1 # Pre FreeBSD 10 + ftp -o "$1" "$2" >/dev/null 2>&1 # OpenBSD } @@ -1667,6 +1668,33 @@ __check_services_debian() { } # ---------- end of function __check_services_debian ---------- +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __check_services_openbsd +# DESCRIPTION: Return 0 or 1 in case the service is enabled or not +# PARAMETERS: servicename +#---------------------------------------------------------------------------------------------------------------------- +__check_services_openbsd() { + if [ $# -eq 0 ]; then + echoerror "You need to pass a service name to check!" + exit 1 + elif [ $# -ne 1 ]; then + echoerror "You need to pass a service name to check as the single argument to the function" + fi + + servicename=$1 + echodebug "Checking if service ${servicename} is enabled" + + # shellcheck disable=SC2086,SC2046,SC2144 + if [ -f /etc/rc.d/${servicename} ] && [ $(grep ${servicename} /etc/rc.conf.local) -ne "" ] ; then + echodebug "Service ${servicename} is enabled" + return 0 + else + echodebug "Service ${servicename} is NOT enabled" + # return 1 + fi +} # ---------- end of function __check_services_openbsd ---------- + + ####################################################################################################################### # # Distribution install functions @@ -4323,6 +4351,179 @@ install_freebsd_restart_daemons() { # ####################################################################################################################### +####################################################################################################################### +# +# OpenBSD Install Functions +# + +install_openbsd_deps() { + ping -c 2 -q mirrors.nycbug.org || return 1 + echo "installpath = http://mirrors.nycbug.org/pub/OpenBSD/${OS_VERSION}/packages/${CPU_ARCH_L}/" >/etc/pkg.conf || return 1 + pkg_add -I -v lsof || return 1 + pkg_add -I -v py-pip || return 1 + ln -sf $(ls -d /usr/local/bin/pip2.*) /usr/local/bin/pip || return 1 + ln -sf $(ls -d /usr/local/bin/pydoc2*) /usr/local/bin/pydoc || return 1 + ln -sf $(ls -d /usr/local/bin/python2.[0-9]) /usr/local/bin/python || return 1 + ln -sf $(ls -d /usr/local/bin/python2.[0-9]*to3) /usr/local/bin/2to3 || return 1 + ln -sf $(ls -d /usr/local/bin/python2.[0-9]*-config) /usr/local/bin/python-config || return 1 + pkg_add -I -v swig || return 1 + pkg_add -I -v py-zmq || return 1 + pkg_add -I -v py-requests || return 1 + pkg_add -I -v py-M2Crypto || return 1 + pkg_add -I -v py-raet || return 1 + pkg_add -I -v py-libnacl || return 1 + if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then + /usr/local/bin/pip install --upgrade pip || return 1 + fi + # + # PIP based installs need to copy configuration files "by hand". + # Let's trigger config_salt() + # + if [ "$_TEMP_CONFIG_DIR" = "null" ]; then + # Let's set the configuration directory to /tmp + _TEMP_CONFIG_DIR="/tmp" + CONFIG_SALT_FUNC="config_salt" + for fname in minion master; do + # Skip if not meant to be installed + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + # [ $fname = "api" ] && ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || [ "$(which salt-${fname} 2>/dev/null)" = "" ]) && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + # Let's download, since they were not provided, the default configuration files + if [ ! -f "$_SALT_ETC_DIR/$fname" ] && [ ! -f "$_TEMP_CONFIG_DIR/$fname" ]; then + ftp -o "$_TEMP_CONFIG_DIR/$fname" \ + "https://raw.githubusercontent.com/saltstack/salt/develop/conf/$fname" || return 1 + fi + done + fi + if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then + /usr/local/bin/pip install --upgrade pip || return 1 + fi + if [ "${_EXTRA_PACKAGES}" != "" ]; then + echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" + # shellcheck disable=SC2086 + pkg_add -I -v ${_EXTRA_PACKAGES} || return 1 + fi + return 0 +} + +install_openbsd_git_deps() { + install_openbsd_deps || return 1 + pkg_add -I -v git || return 1 + __git_clone_and_checkout || return 1 + # + # Let's trigger config_salt() + # + if [ "$_TEMP_CONFIG_DIR" -eq "null" ]; then + _TEMP_CONFIG_DIR="${__SALT_GIT_CHECKOUT_DIR}/conf/" + CONFIG_SALT_FUNC="config_salt" + fi + return 0 +} + +install_openbsd_stable() { + +# pkg_add -r -I -v salt || return 1 + check_pip_allowed + /usr/local/bin/pip install salt || return 1 + if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then + /usr/local/bin/pip install --upgrade salt || return 1 + fi + return 0 +} + +install_openbsd_git() { + # + # Install from git + # + if [ ! -f salt/syspaths.py ]; then + # We still can't provide the system paths, salt 0.16.x + /usr/local/bin/python2.7 setup.py install || return 1 + fi + return 0 +} + + +install_openbsd_post() { + + # + # Install rc.d files. + # + ## below workaround for /etc/rc.d/rc.subr in OpenBSD >= 5.8 + ## is needed for salt service to start/stop properly by /etc/rc.d + ## reference: http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/etc/rc.d/rc.subr.diff?r1=1.98&r2=1.99 + ## + if [ $(grep '\-xf' /etc/rc.d/rc.subr)]; then + cp -p /etc/rc.d/rc.subr /etc/rc.d/rc.subr + sed -i.$(date +%F).saltinstall -e 's:-xf:-f:g' /etc/rc.d/rc.subr + fi + _TEMP_CONFIG_DIR="/tmp" + for fname in minion master syndic api; do + + # Skip if not meant to be installed + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "api" ] || [ "$(which salt-${fname} 2>/dev/null)" = "" ] && continue + #[ $fname = "api" ] && ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || [ "$(which salt-${fname} 2>/dev/null)" = "" ]) && continue + #[ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && continue + + if [ $? -eq 1 ]; then + if [ ! -f "$_TEMP_CONFIG_DIR/salt-$fname" ]; then + ftp -o "$_TEMP_CONFIG_DIR/salt-$fname" \ + "https://raw.githubusercontent.com/saltstack/salt/develop/pkg/openbsd/salt-${fname}.rc-d" + if [ ! -f "/etc/rc.d/salt_${fname}" ] && [ $(grep salt_${fname} /etc/rc.conf.local) -eq ""]; then + copyfile "$_TEMP_CONFIG_DIR/salt-$fname" "/etc/rc.d/salt_${fname}" && chmod +x "/etc/rc.d/salt_${fname}" || return 1 + echo salt_${fname}_enable="YES" >> /etc/rc.conf.local + echo salt_${fname}_paths=\"/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin\" >>/etc/rc.conf.local + fi + fi + fi + done +} + +install_openbsd_check_services() { + salt --version + for fname in minion master syndic api; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "api" ] && continue + [ $fname = "syndic" ] && continue + if [ -f /etc/rc.d/salt_${fname} ]; then + __check_services_openbsd salt_${fname} || return 1 + fi + done + return 0 +} + + +install_openbsd_restart_daemons() { + [ $_START_DAEMONS -eq $BS_FALSE ] && return + for fname in minion master syndic api; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + # Skip if not meant to be installed + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + if [ -f /etc/rc.d/salt_${fname} ]; then + /etc/rc.d/salt_${fname} stop > /dev/null 2>&1 + /etc/rc.d/salt_${fname} start + fi + done +} + + +# +# Ended OpenBSD Install Functions +# +####################################################################################################################### + ####################################################################################################################### # # SmartOS Install Functions From 99927b030114630b90601bc5384e14698d5e1a04 Mon Sep 17 00:00:00 2001 From: Sergey Paramonov Date: Sat, 6 Feb 2016 15:10:46 -0500 Subject: [PATCH 2/4] Update bootstrap-salt.sh corrected for __fetch_url() and install_openbsd_deps() --- bootstrap-salt.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index e0f7374..ca7fd68 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -585,7 +585,7 @@ __fetch_url() { curl $_CURL_ARGS -L -s -o "$1" "$2" >/dev/null 2>&1 || wget $_WGET_ARGS -q -O "$1" "$2" >/dev/null 2>&1 || fetch $_FETCH_ARGS -q -o "$1" "$2" >/dev/null 2>&1 || - fetch -q -o "$1" "$2" >/dev/null 2>&1 # Pre FreeBSD 10 + fetch -q -o "$1" "$2" >/dev/null 2>&1 || # Pre FreeBSD 10 ftp -o "$1" "$2" >/dev/null 2>&1 # OpenBSD } @@ -4383,11 +4383,11 @@ install_openbsd_deps() { # Let's set the configuration directory to /tmp _TEMP_CONFIG_DIR="/tmp" CONFIG_SALT_FUNC="config_salt" - for fname in minion master; do + for fname in minion master syndic api; do # Skip if not meant to be installed [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - # [ $fname = "api" ] && ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || [ "$(which salt-${fname} 2>/dev/null)" = "" ]) && continue + [ $fname = "api" ] && ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || [ "$(which salt-${fname} 2>/dev/null)" = "" ]) && continue [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue # Let's download, since they were not provided, the default configuration files @@ -4451,7 +4451,7 @@ install_openbsd_post() { # Install rc.d files. # ## below workaround for /etc/rc.d/rc.subr in OpenBSD >= 5.8 - ## is needed for salt service to start/stop properly by /etc/rc.d + ## is needed for salt services to start/stop properly from /etc/rc.d ## reference: http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/etc/rc.d/rc.subr.diff?r1=1.98&r2=1.99 ## if [ $(grep '\-xf' /etc/rc.d/rc.subr)]; then From fac497e58492ff275bd71f5172c64d943f2b3e86 Mon Sep 17 00:00:00 2001 From: Sergey Paramonov Date: Tue, 9 Feb 2016 12:36:44 -0500 Subject: [PATCH 3/4] Update bootstrap-salt.sh added choose_openbsd_mirror() function, which is comparing ping time from all officially listed openbsd mirrors and picks closest mirror. --- bootstrap-salt.sh | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index ca7fd68..ea17a4e 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -4356,9 +4356,27 @@ install_freebsd_restart_daemons() { # OpenBSD Install Functions # +choose_openbsd_mirror() { + MIRRORS_LIST_URL=http://www.openbsd.org/ftp.html + MIRRORS_LIST=$(ftp -o - $MIRRORS_LIST_URL |grep href |grep http | grep pub | awk -F \" '{ print $2 }') + echoinfo "getting list of mirrors from $MIRRORS_LIST_URL" + ping -c 2 -q $(echo $MIRRORS_LIST_URL | awk -F \/ '{ print $3 }') 1>/dev/null || return 1 + for MIRROR in $MIRRORS_LIST + do + TIME=$(ping -c 1 -q $(echo $MIRROR | awk -F \/ '{ print $3 }') |grep round-trip |awk -F \/ '{ print $5 }') + [ -z $TIME ] && continue + echodebug "ping time for $MIRROR is $TIME" + [ -z $MINTIME ] && MINTIME=$TIME + [ $( echo "$TIME < $MINTIME" |bc ) -eq 1 ] && MINTIME=$TIME && OPENBSD_REPO=$MIRROR || continue + done +} + + install_openbsd_deps() { - ping -c 2 -q mirrors.nycbug.org || return 1 - echo "installpath = http://mirrors.nycbug.org/pub/OpenBSD/${OS_VERSION}/packages/${CPU_ARCH_L}/" >/etc/pkg.conf || return 1 + choose_openbsd_mirror || return 1 + [ -z $OPENBSD_REPO ] && return 1 + echoinfo "setting package repository to $OPENBSD_REPO with ping time of $MINTIME" + echo "installpath = ${OPENBSD_REPO}${OS_VERSION}/packages/${CPU_ARCH_L}/" >/etc/pkg.conf || return 1 pkg_add -I -v lsof || return 1 pkg_add -I -v py-pip || return 1 ln -sf $(ls -d /usr/local/bin/pip2.*) /usr/local/bin/pip || return 1 From 86f6f18790a2556aa74bd0b0467c43354f4be164 Mon Sep 17 00:00:00 2001 From: Sergey Paramonov Date: Tue, 9 Feb 2016 12:43:14 -0500 Subject: [PATCH 4/4] Update bootstrap-salt.sh removed commented unneeded lines from install_openbsd_post() function --- bootstrap-salt.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index ea17a4e..f4c13af 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -4483,8 +4483,6 @@ install_openbsd_post() { [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue [ $fname = "api" ] || [ "$(which salt-${fname} 2>/dev/null)" = "" ] && continue - #[ $fname = "api" ] && ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || [ "$(which salt-${fname} 2>/dev/null)" = "" ]) && continue - #[ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue [ $fname = "syndic" ] && continue if [ $? -eq 1 ]; then