Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit 7bafd75

Browse files
authored
OMSConfig improvments (#828)
1. Removing dependency on OMI port 2. Change python detection logic 3. Fixing omsconfig upgrade scenario
1 parent df4c502 commit 7bafd75

File tree

1 file changed

+72
-29
lines changed

1 file changed

+72
-29
lines changed

installbuilder/datafiles/Base_DSC.data

Lines changed: 72 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,18 @@ fi
212212

213213
%Preinstall_200
214214
# pythonVersion check must be repeated for each section
215-
if [ ! "$(python2 --version 2>&1 | grep 'not found')" ]; then
215+
version=$(python2 -V 2>&1 | grep -Po '(?<=Python )(.+)')
216+
if [ ! -z "$version" ]; then
216217
echo "Using python2"
217218
pythonVersion="python2"
218-
elif [ ! "$(python3 --version 2>&1 | grep 'not found')" ]; then
219-
echo "Using python3"
220-
pythonVersion="python3"
221219
else
222-
echo "Python not found."
220+
version=$(python3 -V 2>&1 | grep -Po '(?<=Python )(.+)')
221+
if [ ! -z "$version" ]; then
222+
echo "Using python3"
223+
pythonVersion="python3"
224+
else
225+
echo "Python not found."
226+
fi
223227
fi
224228
# Only check for ctypes if python2 is installed
225229
if [ "$pythonVersion" = "python2" ]; then
@@ -237,7 +241,18 @@ fi
237241
echo "Cleanning up existing dsc_hosts..."
238242
kill $(ps -eo pid,cmd | grep '/opt/dsc/bin/dsc_host' | grep -v grep | tr -s ' ' | sed 's/^[ \t]*//' | cut -d' ' -f1) -9 2&>1 > /dev/null
239243
chmod -R 777 /opt/dsc
240-
rm -rfv /opt/dsc
244+
# Clean dsc directory in case of install and clean
245+
echo "Deployment operation type :" $1
246+
if [ "$1" = "1" -o "$1" = 1 -o "$1" = "install" -o "$1" = "clean" ]; then
247+
echo "Cleanning directory /opt/dsc..."
248+
rm -rfv /opt/dsc
249+
else
250+
for file in `ls /opt/dsc`; do
251+
if [ $file != "lib" ]; then
252+
rm -rfv /opt/dsc/"$file"
253+
fi
254+
done
255+
fi
241256
rm -f /etc/opt/omi/conf/omsconfig/inventory_lock
242257
echo "Cleaned up existing dsc_hosts..."
243258

@@ -316,7 +331,7 @@ ln -fs /opt/microsoft/${{SHORT_NAME}}/bin/OMSConsistencyInvoker $OMI_HOME/bin/OM
316331
#else
317332

318333
# Make OMI listen on the standard DSC port
319-
$OMI_HOME/bin/omiconfigeditor httpsport -a 5986 < $CONFIG_SYSCONFDIR/omiserver.conf > $CONFIG_SYSCONFDIR/omiserver.conf_temp
334+
$OMI_HOME/bin/omiconfigeditor httpsport -a 0 < $CONFIG_SYSCONFDIR/omiserver.conf > $CONFIG_SYSCONFDIR/omiserver.conf_temp
320335
mv $CONFIG_SYSCONFDIR/omiserver.conf_temp $CONFIG_SYSCONFDIR/omiserver.conf
321336

322337
mkdir -p $OMI_REGISTER_DIR/root-Microsoft-DesiredStateConfiguration
@@ -363,14 +378,18 @@ chmod 1775 /opt/microsoft/omsconfig/Scripts
363378

364379

365380
# pythonVersion check must be repeated for each section
366-
if [ ! "$(python2 --version 2>&1 | grep 'not found')" ]; then
381+
version=$(python2 -V 2>&1 | grep -Po '(?<=Python )(.+)')
382+
if [ ! -z "$version" ]; then
367383
echo "Using python2"
368384
pythonVersion="python2"
369-
elif [ ! "$(python3 --version 2>&1 | grep 'not found')" ]; then
370-
echo "Using python3"
371-
pythonVersion="python3"
372385
else
373-
echo "Python not found."
386+
version=$(python3 -V 2>&1 | grep -Po '(?<=Python )(.+)')
387+
if [ ! -z "$version" ]; then
388+
echo "Using python3"
389+
pythonVersion="python3"
390+
else
391+
echo "Python not found."
392+
fi
374393
fi
375394

376395
# Set up built-in resource modules for OMS DSC
@@ -451,14 +470,18 @@ if [ -d "/etc/opt/omi/conf/omsconfig" ]; then chown -R omsagent:omiusers /etc/op
451470
#else
452471

453472
# pythonVersion check must be repeated for each section
454-
if [ ! "$(python2 --version 2>&1 | grep 'not found')" ]; then
473+
version=$(python2 -V 2>&1 | grep -Po '(?<=Python )(.+)')
474+
if [ ! -z "$version" ]; then
455475
echo "Using python2"
456476
pythonVersion="python2"
457-
elif [ ! "$(python3 --version 2>&1 | grep 'not found')" ]; then
458-
echo "Using python3"
459-
pythonVersion="python3"
460477
else
461-
echo "Python not found."
478+
version=$(python3 -V 2>&1 | grep -Po '(?<=Python )(.+)')
479+
if [ ! -z "$version" ]; then
480+
echo "Using python3"
481+
pythonVersion="python3"
482+
else
483+
echo "Python not found."
484+
fi
462485
fi
463486

464487
# Set up built-in resource module for DIY DSC
@@ -556,14 +579,18 @@ mv /etc/crontabtmp /etc/crontab
556579
#if BUILD_OMS == 1
557580

558581
# pythonVersion check must be repeated for each section
559-
if [ ! "$(python2 --version 2>&1 | grep 'not found')" ]; then
582+
version=$(python2 -V 2>&1 | grep -Po '(?<=Python )(.+)')
583+
if [ ! -z "$version" ]; then
560584
echo "Using python2"
561585
pythonVersion="python2"
562-
elif [ ! "$(python3 --version 2>&1 | grep 'not found')" ]; then
563-
echo "Using python3"
564-
pythonVersion="python3"
565586
else
566-
echo "Python not found"
587+
version=$(python3 -V 2>&1 | grep -Po '(?<=Python )(.+)')
588+
if [ ! -z "$version" ]; then
589+
echo "Using python3"
590+
pythonVersion="python3"
591+
else
592+
echo "Python not found."
593+
fi
567594
fi
568595

569596
# If omsadmin.conf exists, let's apply the metaconfig
@@ -587,23 +614,39 @@ chgrp omsagent /etc/opt/omi/conf/omsconfig/configuration/Inventory.mof
587614
echo "Cleanning up existing dsc_hosts before uninstall..."
588615
kill $(ps -eo pid,cmd | grep '/opt/dsc/bin/dsc_host' | grep -v grep | tr -s ' ' | sed 's/^[ \t]*//' | cut -d' ' -f1) -9 2&>1 > /dev/null
589616
chmod -R 777 /opt/dsc
590-
rm -rfv /opt/dsc
617+
# remove entire dsc folder incase of remove and purge
618+
echo "Deployment operation type :" $1
619+
if [ "$1" = "0" -o "$1" = 0 -o "$1" = "remove" -o "$1" = "purge" ]; then
620+
echo "Cleanning directory /opt/dsc..."
621+
rm -rfv /opt/dsc
622+
else
623+
for file in `ls /opt/dsc`; do
624+
if [ $file != "lib" ]; then
625+
rm -rfv /opt/dsc/"$file"
626+
fi
627+
done
628+
fi
591629
rm -f /etc/opt/omi/conf/omsconfig/inventory_lock
592630
echo "Cleaned up existing dsc_hosts before uninstall..."
593631

594632
%Preuninstall_999
595633
# pythonVersion check must be repeated for each section
596-
if [ ! "$(python2 --version 2>&1 | grep 'not found')" ]; then
634+
version=$(python2 -V 2>&1 | grep -Po '(?<=Python )(.+)')
635+
if [ ! -z "$version" ]; then
597636
echo "Using python2"
598637
pythonVersion="python2"
599-
elif [ ! "$(python3 --version 2>&1 | grep 'not found')" ]; then
600-
echo "Using python3"
601-
pythonVersion="python3"
602638
else
603-
echo "Python not found"
639+
version=$(python3 -V 2>&1 | grep -Po '(?<=Python )(.+)')
640+
if [ ! -z "$version" ]; then
641+
echo "Using python3"
642+
pythonVersion="python3"
643+
else
644+
echo "Python not found."
645+
fi
604646
fi
605647
# if this is a package removal, not an upgrade, remove the modules
606-
if [ "$1" = "0" -o "$1" = "remove" -o "$1" = "purge" ]; then
648+
echo "Deployment operation type :" $1
649+
if [ "$1" = "0" -o "$1" = 0 -o "$1" = "remove" -o "$1" = "purge" ]; then
607650
# Remove all DSC specific data
608651
if [ "$pythonVersion" = "python3" ]; then
609652
echo "Running python3"

0 commit comments

Comments
 (0)