2021-09-20 12:00:35 +00:00
|
|
|
#!/bin/bash
|
2021-10-15 16:10:24 +00:00
|
|
|
function test_mgr() {
|
|
|
|
if curl -s https://${1}/confluent-api/ > /dev/null; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
function confluentpython() {
|
|
|
|
if [ -x /usr/libexec/platform-python ]; then
|
|
|
|
/usr/libexec/platform-python $*
|
|
|
|
elif [ -x /usr/bin/python3 ]; then
|
|
|
|
/usr/bin/python3 $*
|
|
|
|
elif [ -x /usr/bin/python ]; then
|
|
|
|
/usr/bin/python $*
|
|
|
|
elif [ -x /usr/bin/python2 ]; then
|
|
|
|
/usr/bin/python2 $*
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-10-05 20:57:46 +00:00
|
|
|
function set_confluent_vars() {
|
2021-07-23 23:08:06 +00:00
|
|
|
if [ -z "$nodename" ]; then
|
|
|
|
nodename=$(grep ^NODENAME: /etc/confluent/confluent.info | awk '{print $2}')
|
|
|
|
fi
|
2021-10-15 16:10:24 +00:00
|
|
|
if [[ "$confluent_mgr" == *"%"* ]]; then
|
|
|
|
confluent_mgr=""
|
|
|
|
fi
|
2021-05-03 16:48:08 +00:00
|
|
|
if [ -z "$confluent_mgr" ]; then
|
|
|
|
confluent_mgr=$(grep ^deploy_server: /etc/confluent/confluent.deploycfg | sed -e 's/[^ ]*: //')
|
2021-10-15 16:10:24 +00:00
|
|
|
if ! test_mgr $confluent_mgr; then
|
|
|
|
confluent_mgr=$(grep ^deploy_server_v6: /etc/confluent/confluent.deploycfg | sed -e 's/[^ ]*: //')
|
|
|
|
if [[ "$confluent_mgr" = *":"* ]]; then
|
|
|
|
confluent_mgr="[$confluent_mgr]"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if ! test_mgr $confluent_mgr; then
|
|
|
|
BESTMGRS=$(grep ^EXTMGRINFO: /etc/confluent/confluent.info | grep '|1$' | sed -e 's/EXTMGRINFO: //' -e 's/|.*//')
|
|
|
|
OKMGRS=$(grep ^EXTMGRINFO: /etc/confluent/confluent.info | grep '|0$' | sed -e 's/EXTMGRINFO: //' -e 's/|.*//')
|
|
|
|
for confluent_mgr in $BESTMGRS $OKMGRS; do
|
|
|
|
if [[ $confluent_mgr == *":"* ]]; then
|
|
|
|
confluent_mgr="[$confluent_mgr]"
|
|
|
|
fi
|
|
|
|
if test_mgr $confluent_mgr; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2020-10-05 20:57:46 +00:00
|
|
|
fi
|
2021-05-03 16:48:08 +00:00
|
|
|
if [ -z "$confluent_profile" ]; then
|
|
|
|
confluent_profile=$(grep ^profile: /etc/confluent/confluent.deploycfg | sed -e 's/[^ ]*: //')
|
2020-10-05 20:57:46 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
fetch_remote() {
|
2021-04-30 18:33:02 +00:00
|
|
|
curlargs=""
|
2020-10-05 20:57:46 +00:00
|
|
|
if [ -f /etc/confluent/ca.pem ]; then
|
|
|
|
curlargs=" --cacert /etc/confluent/ca.pem"
|
|
|
|
fi
|
|
|
|
set_confluent_vars
|
2020-10-09 18:07:58 +00:00
|
|
|
mkdir -p $(dirname $1)
|
2021-05-03 16:48:08 +00:00
|
|
|
curl -f -sS $curlargs https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/$1 > $1
|
2020-10-05 20:57:46 +00:00
|
|
|
if [ $? != 0 ]; then echo $1 failed to download; return 1; fi
|
|
|
|
}
|
|
|
|
|
2021-04-30 18:33:02 +00:00
|
|
|
source_remote_parts() {
|
2021-10-25 16:03:26 +00:00
|
|
|
confluentscripttmpdir=$(mktemp -d /tmp/confluentscripts.XXXXXXXXX)
|
2021-10-15 16:10:24 +00:00
|
|
|
apiclient=/opt/confluent/bin/apiclient
|
|
|
|
if [ -f /etc/confluent/apiclient ]; then
|
|
|
|
apiclient=/etc/confluent/apiclient
|
|
|
|
fi
|
|
|
|
scriptlist=$(confluentpython $apiclient /confluent-api/self/scriptlist/$1|sed -e 's/^- //')
|
2021-04-30 18:33:02 +00:00
|
|
|
for script in $scriptlist; do
|
2021-05-03 16:48:08 +00:00
|
|
|
source_remote $1/$script
|
2021-04-30 18:33:02 +00:00
|
|
|
done
|
2021-10-15 16:16:48 +00:00
|
|
|
rm -rf $confluentscripttmpdir
|
2021-04-30 18:33:02 +00:00
|
|
|
unset confluentscripttmpdir
|
|
|
|
}
|
|
|
|
|
2021-04-23 13:08:50 +00:00
|
|
|
run_remote_parts() {
|
2021-10-25 16:03:26 +00:00
|
|
|
confluentscripttmpdir=$(mktemp -d /tmp/confluentscripts.XXXXXXXXX)
|
2021-10-15 16:10:24 +00:00
|
|
|
apiclient=/opt/confluent/bin/apiclient
|
|
|
|
if [ -f /etc/confluent/apiclient ]; then
|
|
|
|
apiclient=/etc/confluent/apiclient
|
|
|
|
fi
|
|
|
|
scriptlist=$(confluentpython $apiclient /confluent-api/self/scriptlist/$1|sed -e 's/^- //')
|
2021-04-23 13:08:50 +00:00
|
|
|
for script in $scriptlist; do
|
2021-05-03 16:48:08 +00:00
|
|
|
run_remote $1/$script
|
2021-04-23 13:08:50 +00:00
|
|
|
done
|
2021-10-15 16:16:48 +00:00
|
|
|
rm -rf $confluentscripttmpdir
|
2021-04-30 18:33:02 +00:00
|
|
|
unset confluentscripttmpdir
|
|
|
|
}
|
|
|
|
|
|
|
|
source_remote() {
|
|
|
|
set_confluent_vars
|
2021-10-29 17:01:59 +00:00
|
|
|
unsettmpdir=0
|
2021-04-30 18:33:02 +00:00
|
|
|
echo
|
|
|
|
echo '---------------------------------------------------------------------------'
|
2021-05-03 16:48:08 +00:00
|
|
|
echo Sourcing $1 from https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/
|
2021-04-30 18:33:02 +00:00
|
|
|
if [ -z "$confluentscripttmpdir" ]; then
|
2021-10-25 16:03:26 +00:00
|
|
|
confluentscripttmpdir=$(mktemp -d /tmp/confluentscripts.XXXXXXXXX)
|
2021-10-29 17:01:59 +00:00
|
|
|
unsettmpdir=1
|
2021-04-30 18:33:02 +00:00
|
|
|
fi
|
|
|
|
echo Sourcing from $confluentscripttmpdir
|
|
|
|
cd $confluentscripttmpdir
|
|
|
|
fetch_remote $1
|
|
|
|
if [ $? != 0 ]; then echo $1 failed to download; return 1; fi
|
|
|
|
chmod +x $1
|
|
|
|
cmd=$1
|
|
|
|
shift
|
2021-06-15 12:31:45 +00:00
|
|
|
source ./$cmd
|
2021-04-30 18:33:02 +00:00
|
|
|
cd - > /dev/null
|
2021-10-29 17:01:59 +00:00
|
|
|
if [ "$unsettmpdir" = 1 ]; then
|
|
|
|
rm -rf $confluentscripttmpdir
|
|
|
|
unset confluentscripttmpdir
|
|
|
|
unsettmpdir=0
|
|
|
|
fi
|
2021-10-15 16:16:48 +00:00
|
|
|
rm -rf $confluentscripttmpdir
|
2021-04-30 18:33:02 +00:00
|
|
|
return $retcode
|
2021-04-23 13:08:50 +00:00
|
|
|
}
|
|
|
|
|
2020-07-23 16:29:43 +00:00
|
|
|
run_remote() {
|
2020-08-21 14:33:56 +00:00
|
|
|
requestedcmd="'$*'"
|
2021-10-29 17:01:59 +00:00
|
|
|
unsettmpdir=0
|
2020-10-05 20:57:46 +00:00
|
|
|
set_confluent_vars
|
2020-08-21 14:35:28 +00:00
|
|
|
echo
|
|
|
|
echo '---------------------------------------------------------------------------'
|
2021-05-03 16:48:08 +00:00
|
|
|
echo Running $requestedcmd from https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/
|
2021-04-30 18:33:02 +00:00
|
|
|
if [ -z "$confluentscripttmpdir" ]; then
|
2021-10-25 16:03:26 +00:00
|
|
|
confluentscripttmpdir=$(mktemp -d /tmp/confluentscripts.XXXXXXXXX)
|
2021-10-29 17:01:59 +00:00
|
|
|
unsettmpdir=1
|
2021-04-30 18:33:02 +00:00
|
|
|
fi
|
|
|
|
echo Executing in $confluentscripttmpdir
|
|
|
|
cd $confluentscripttmpdir
|
|
|
|
fetch_remote $1
|
2020-08-21 21:42:02 +00:00
|
|
|
if [ $? != 0 ]; then echo $requestedcmd failed to download; return 1; fi
|
2020-07-23 16:29:43 +00:00
|
|
|
chmod +x $1
|
|
|
|
cmd=$1
|
2020-07-24 20:07:15 +00:00
|
|
|
if [ -x /usr/bin/chcon ]; then
|
2020-07-24 19:32:13 +00:00
|
|
|
chcon system_u:object_r:bin_t:s0 $cmd
|
|
|
|
fi
|
2020-07-23 16:29:43 +00:00
|
|
|
shift
|
|
|
|
./$cmd $*
|
2020-08-21 21:42:02 +00:00
|
|
|
retcode=$?
|
2021-04-30 18:33:02 +00:00
|
|
|
if [ $retcode -ne 0 ]; then
|
|
|
|
echo "$requestedcmd exited with code $retcode"
|
|
|
|
fi
|
2020-08-21 21:42:02 +00:00
|
|
|
cd - > /dev/null
|
2021-10-29 17:01:59 +00:00
|
|
|
if [ "$unsettmpdir" = 1 ]; then
|
|
|
|
rm -rf $confluentscripttmpdir
|
|
|
|
unset confluentscripttmpdir
|
|
|
|
unsettmpdir=0
|
|
|
|
fi
|
2020-08-21 21:42:02 +00:00
|
|
|
return $retcode
|
2020-07-23 16:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
run_remote_python() {
|
2020-08-21 21:03:12 +00:00
|
|
|
echo
|
2020-10-05 20:57:46 +00:00
|
|
|
set_confluent_vars
|
|
|
|
if [ -f /etc/confluent/ca.pem ]; then
|
|
|
|
curlargs=" --cacert /etc/confluent/ca.pem"
|
|
|
|
fi
|
2020-08-21 21:03:12 +00:00
|
|
|
echo '---------------------------------------------------------------------------'
|
2021-05-03 16:48:08 +00:00
|
|
|
echo Running python script "'$*'" from https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/
|
2021-10-25 16:03:26 +00:00
|
|
|
confluentscripttmpdir=$(mktemp -d /tmp/confluentscripts.XXXXXXXXX)
|
2021-10-15 16:16:48 +00:00
|
|
|
echo Executing in $confluentscripttmpdir
|
|
|
|
cd $confluentscripttmpdir
|
2020-10-09 18:07:58 +00:00
|
|
|
mkdir -p $(dirname $1)
|
2021-05-03 16:48:08 +00:00
|
|
|
curl -f -sS $curlargs https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/$1 > $1
|
2020-08-21 21:42:02 +00:00
|
|
|
if [ $? != 0 ]; then echo "'$*'" failed to download; return 1; fi
|
2021-10-15 16:10:24 +00:00
|
|
|
confluentpython $*
|
2020-08-21 21:42:02 +00:00
|
|
|
retcode=$?
|
|
|
|
echo "'$*' exited with code $retcode"
|
|
|
|
cd - > /dev/null
|
2021-10-15 16:16:48 +00:00
|
|
|
rm -rf $confluentscripttmpdir
|
2020-08-21 21:42:02 +00:00
|
|
|
return $retcode
|
2020-07-23 16:29:43 +00:00
|
|
|
}
|
2021-04-23 13:08:50 +00:00
|
|
|
|
|
|
|
run_remote_config() {
|
|
|
|
echo
|
|
|
|
set_confluent_vars
|
|
|
|
apiclient=/opt/confluent/bin/apiclient
|
|
|
|
if [ -f /etc/confluent/apiclient ]; then
|
|
|
|
apiclient=/etc/confluent/apiclient
|
|
|
|
fi
|
|
|
|
echo '---------------------------------------------------------------------------'
|
2021-05-03 16:48:08 +00:00
|
|
|
echo Requesting to run remote configuration for "'$*'" from $confluent_mgr under profile $confluent_profile
|
2021-10-15 16:10:24 +00:00
|
|
|
confluentpython $apiclient /confluent-api/self/remoteconfig/"$*" -d {}
|
|
|
|
confluentpython $apiclient /confluent-api/self/remoteconfig/status -w 204
|
2021-04-23 13:08:50 +00:00
|
|
|
echo
|
|
|
|
echo 'Completed remote configuration'
|
|
|
|
echo '---------------------------------------------------------------------------'
|
|
|
|
return
|
|
|
|
}
|
2021-09-20 12:00:35 +00:00
|
|
|
#If invoked as a command, use the arguments to actually run a function
|
2021-10-15 16:10:24 +00:00
|
|
|
(return 0 2>/dev/null) || $1 "${@:2}"
|