2021-09-20 12:00:35 +00:00
|
|
|
#!/bin/bash
|
2021-09-10 15:40:17 +00:00
|
|
|
function test_mgr() {
|
2022-11-08 13:52:29 +00:00
|
|
|
whost=$1
|
|
|
|
if [[ "$whost" == *:* ]]; then
|
|
|
|
whost="[$whost]"
|
|
|
|
fi
|
|
|
|
if curl -s https://${whost}/confluent-api/ > /dev/null; then
|
2021-09-10 15:40:17 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2021-10-15 16:07:00 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-05-03 16:48:08 +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-09-10 15:40:17 +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-09-10 15:40:17 +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
|
2021-05-03 16:48:08 +00:00
|
|
|
fi
|
|
|
|
if [ -z "$confluent_profile" ]; then
|
|
|
|
confluent_profile=$(grep ^profile: /etc/confluent/confluent.deploycfg | sed -e 's/[^ ]*: //')
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-10-15 16:07:00 +00:00
|
|
|
fetch_remote() {
|
|
|
|
curlargs=""
|
|
|
|
if [ -f /etc/confluent/ca.pem ]; then
|
|
|
|
curlargs=" --cacert /etc/confluent/ca.pem"
|
|
|
|
fi
|
2021-05-03 16:48:08 +00:00
|
|
|
set_confluent_vars
|
2021-05-03 19:36:27 +00:00
|
|
|
mkdir -p $(dirname $1)
|
2022-11-08 13:52:29 +00:00
|
|
|
whost=$confluent_mgr
|
|
|
|
if [[ "$whost" == *:* ]]; then
|
|
|
|
whost="[$whost]"
|
|
|
|
fi
|
|
|
|
curl -f -sS $curlargs https://$whost/confluent-public/os/$confluent_profile/scripts/$1 > $1
|
2021-10-15 16:07:00 +00:00
|
|
|
if [ $? != 0 ]; then echo $1 failed to download; return 1; fi
|
2020-06-01 20:01:26 +00:00
|
|
|
}
|
|
|
|
|
2021-05-03 16:48:08 +00:00
|
|
|
source_remote_parts() {
|
2021-10-25 16:03:26 +00:00
|
|
|
confluentscripttmpdir=$(mktemp -d /tmp/confluentscripts.XXXXXXXXX)
|
2021-05-03 16:48:08 +00:00
|
|
|
apiclient=/opt/confluent/bin/apiclient
|
|
|
|
if [ -f /etc/confluent/apiclient ]; then
|
|
|
|
apiclient=/etc/confluent/apiclient
|
|
|
|
fi
|
2021-10-15 16:07:00 +00:00
|
|
|
scriptlist=$(confluentpython $apiclient /confluent-api/self/scriptlist/$1|sed -e 's/^- //')
|
2021-05-03 16:48:08 +00:00
|
|
|
for script in $scriptlist; do
|
|
|
|
source_remote $1/$script
|
|
|
|
done
|
2021-10-15 16:16:48 +00:00
|
|
|
rm -rf $confluentscripttmpdir
|
2021-05-03 16:48:08 +00:00
|
|
|
unset confluentscripttmpdir
|
|
|
|
}
|
|
|
|
|
|
|
|
run_remote_parts() {
|
2021-10-25 16:03:26 +00:00
|
|
|
confluentscripttmpdir=$(mktemp -d /tmp/confluentscripts.XXXXXXXXX)
|
2021-05-03 16:48:08 +00:00
|
|
|
apiclient=/opt/confluent/bin/apiclient
|
|
|
|
if [ -f /etc/confluent/apiclient ]; then
|
|
|
|
apiclient=/etc/confluent/apiclient
|
|
|
|
fi
|
2021-10-15 16:07:00 +00:00
|
|
|
scriptlist=$(confluentpython $apiclient /confluent-api/self/scriptlist/$1|sed -e 's/^- //')
|
2021-05-03 16:48:08 +00:00
|
|
|
for script in $scriptlist; do
|
|
|
|
run_remote $1/$script
|
|
|
|
done
|
2021-10-15 16:16:48 +00:00
|
|
|
rm -rf $confluentscripttmpdir
|
2021-05-03 16:48:08 +00:00
|
|
|
unset confluentscripttmpdir
|
|
|
|
}
|
|
|
|
|
2021-10-15 16:07:00 +00:00
|
|
|
source_remote() {
|
|
|
|
set_confluent_vars
|
2021-10-29 17:01:59 +00:00
|
|
|
unsettmpdir=0
|
2021-10-15 16:07:00 +00:00
|
|
|
echo
|
|
|
|
echo '---------------------------------------------------------------------------'
|
|
|
|
echo Sourcing $1 from https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/
|
|
|
|
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-10-15 16:07:00 +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
|
|
|
|
source ./$cmd
|
|
|
|
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-10-15 16:07:00 +00:00
|
|
|
return $retcode
|
|
|
|
}
|
|
|
|
|
|
|
|
run_remote() {
|
|
|
|
requestedcmd="'$*'"
|
2021-10-29 17:01:59 +00:00
|
|
|
unsettmpdir=0
|
2021-10-15 16:07:00 +00:00
|
|
|
set_confluent_vars
|
|
|
|
echo
|
|
|
|
echo '---------------------------------------------------------------------------'
|
|
|
|
echo Running $requestedcmd from https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/
|
|
|
|
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-10-15 16:07:00 +00:00
|
|
|
fi
|
|
|
|
echo Executing in $confluentscripttmpdir
|
|
|
|
cd $confluentscripttmpdir
|
|
|
|
fetch_remote $1
|
|
|
|
if [ $? != 0 ]; then echo $requestedcmd failed to download; return 1; fi
|
|
|
|
chmod +x $1
|
|
|
|
cmd=$1
|
|
|
|
if [ -x /usr/bin/chcon ]; then
|
|
|
|
chcon system_u:object_r:bin_t:s0 $cmd
|
|
|
|
fi
|
|
|
|
shift
|
|
|
|
./$cmd $*
|
|
|
|
retcode=$?
|
|
|
|
if [ $retcode -ne 0 ]; then
|
|
|
|
echo "$requestedcmd exited with code $retcode"
|
|
|
|
fi
|
|
|
|
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:07:00 +00:00
|
|
|
return $retcode
|
|
|
|
}
|
|
|
|
|
2020-06-01 20:01:26 +00:00
|
|
|
run_remote_python() {
|
2020-08-21 21:03:12 +00:00
|
|
|
echo
|
2021-10-15 16:07:00 +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
|
2021-05-03 19:36:27 +00:00
|
|
|
mkdir -p $(dirname $1)
|
2022-11-08 13:52:29 +00:00
|
|
|
whost=$confluent_mgr
|
|
|
|
if [[ "$whost" == *:* ]]; then
|
|
|
|
whost="[$whost]"
|
|
|
|
fi
|
|
|
|
curl -f -sS $curlargs https://$whost/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:07:00 +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
|
2021-10-29 17:50:04 +00:00
|
|
|
unset confluentscripttmpdir
|
2020-08-21 21:42:02 +00:00
|
|
|
return $retcode
|
2020-06-01 20:01:26 +00:00
|
|
|
}
|
2021-03-18 18:37:54 +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:07:00 +00:00
|
|
|
confluentpython $apiclient /confluent-api/self/remoteconfig/"$*" -d {}
|
|
|
|
confluentpython $apiclient /confluent-api/self/remoteconfig/status -w 204
|
2021-03-18 18:37:54 +00:00
|
|
|
echo
|
2021-03-18 18:58:53 +00:00
|
|
|
echo 'Completed remote configuration'
|
2021-03-18 18:37:54 +00:00
|
|
|
echo '---------------------------------------------------------------------------'
|
|
|
|
return
|
|
|
|
}
|
2021-09-20 12:00:35 +00:00
|
|
|
#If invoked as a command, use the arguments to actually run a function
|
|
|
|
(return 0 2>/dev/null) || $1 "${@:2}"
|