Closed jgstew closed 8 years ago
The besclient.config
file must be in place before the BES Client starts on linux.
Only do this if file /var/opt/BESClient/besclient.config
does not exist already.
Need to create the directory /var/opt/BESClient
if it does not exist already.
mkdir -p /var/opt/BESClient
Need to set the owner/writer to root for /var/opt/BESClient/besclient.config
This relevance takes existing client settings, and put them into the format of the *nix BigFix config file: https://bigfix.me/relevance/details/3016457
Here are a set of settings most likely to be included: https://bigfix.me/relevance/details/3016456
This relevance builds the contents of besclient.config from existing settings:
("[Software\BigFix\EnterpriseClient]%0aEnterpriseClientFolder = /opt/BESClient%0a%0a[Software\BigFix\EnterpriseClient\GlobalOptions]%0aStoragePath = /var/opt/BESClient%0aLibPath = /opt/BESClient/BESLib%0a%0a" & it) of concatenations "%0a%0a" of ("[Software\BigFix\EnterpriseClient\Settings\Client\" & name of it & "]" & "%0a" & "effective date = " & now as string & "%0d%0a" & "value = " & (value of it as trimmed string)) of settings whose(exists name whose(it starts with "_BESClient_" AND it does not start with "_BESClient_UsageManager_" AND it does not start with "_BESClient_UploadManager_" AND it does not start with "_BESClient_ComputerType" AND it does not start with "_BESClient_LastShutdown_Reason") of it) of client
This relevance builds the contents of besclient.config from a clientsettings.cfg file:
("[Software\BigFix\EnterpriseClient]%0aEnterpriseClientFolder = /opt/BESClient%0a%0a[Software\BigFix\EnterpriseClient\GlobalOptions]%0aStoragePath = /var/opt/BESClient%0aLibPath = /opt/BESClient/BESLib%0a%0a" & it) of concatenations "%0a%0a" of ("[Software\BigFix\EnterpriseClient\Settings\Client\" & ((it as trimmed string) of preceding text of first "=" of it) & "]" & "%0a" & "effective date = " & now as string & "%0d%0a" & "value = " & ((it as trimmed string) of following text of first "=" of it)) of lines containing "=" of files "/tmp/clientsettings.cfg"
This will turn the clientsettings.cfg into CSV formatted string:
cat clientsettings.cfg | cut -d = -f 1,2 --output-delimiter=", "
So does this: (sed)
cat clientsettings.cfg | sed s/=/,\ /
As does this: (awk)
cat clientsettings.cfg | awk '/=/ {gsub(/=/, ", "); print;}'
This puts each on a separate line:
cat clientsettings.cfg | sed s/=/\\n/
It occurs to me that because the Linux/Unix BigFix Client doesn't start right away, then I could install BigFix, then use QnA to build the besclient.config
file from a clientsettings.cfg
file.
Run something like this in bash:
echo '("[Software\BigFix\EnterpriseClient]%0aEnterpriseClientFolder = /opt/BESClient%0a%0a[Software\BigFix\EnterpriseClient\GlobalOptions]%0aStoragePath = /var/opt/BESClient%0aLibPath = /opt/BESClient/BESLib%0a%0a" & it) of concatenations "%0a%0a" of ("[Software\BigFix\EnterpriseClient\Settings\Client\" & ((it as trimmed string) of preceding text of first "=" of it) & "]" & "%0a" & "effective date = " & now as string & "%0d%0a" & "value = " & ((it as trimmed string) of following text of first "=" of it)) of lines containing "=" of files "/tmp/clientsettings.cfg"' | /opt/BESClient/bin/qna
This doesn't seem to work well because of % encoded results.
AWK seems like the best option:
cat clientsettings.cfg | awk 'BEGIN { print "StartOfFile" } /=/ {gsub(/=/, " "); print "startofline " $1 " middle " $2 " end";} END { print "EndOfFile" }'
Making progress:
cat clientsettings.cfg | awk 'BEGIN { print "[Software\\BigFix\\EnterpriseClient]"; print "EnterpriseClientFolder = /opt/BESClient"; print; print "[Software\\BigFix\\EnterpriseClient\\GlobalOptions]"; print "StoragePath = /var/opt/BESClient"; print "LibPath = /opt/BESClient/BESLib"; print } /=/ {gsub(/=/, " "); print "startofline " $1 " middle " $2 " end";} END { print "EndOfFile" }'
This works, just missing effective date:
cat clientsettings.cfg | awk 'BEGIN { print "[Software\\BigFix\\EnterpriseClient]"; print "EnterpriseClientFolder = /opt/BESClient"; print; print "[Software\\BigFix\\EnterpriseClient\\GlobalOptions]"; print "StoragePath = /var/opt/BESClient"; print "LibPath = /opt/BESClient/BESLib"; } /=/ {gsub(/=/, " "); print "\n[Software\\BigFix\\EnterpriseClient\\Settings\\Client\\" $1 "]\neffective date = \nvalue = " $2;}'
This will take a besclient.config file missing the effective date and add it:
sed "s/effective\ date\ =\ /effective\ date\ =\ $(date +'%a, %d %b %Y %T %z')/" besclient.config
This seems like the best answer, using both AWK & SED:
cat clientsettings.cfg | awk 'BEGIN { print "[Software\\BigFix\\EnterpriseClient]"; print "EnterpriseClientFolder = /opt/BESClient"; print; print "[Software\\BigFix\\EnterpriseClient\\GlobalOptions]"; print "StoragePath = /var/opt/BESClient"; print "LibPath = /opt/BESClient/BESLib"; } /=/ {gsub(/=/, " "); print "\n[Software\\BigFix\\EnterpriseClient\\Settings\\Client\\" $1 "]\neffective date = \nvalue = " $2;}' | sed "s/effective\ date\ =\ /effective\ date\ =\ $(date +'%a, %d %b %Y %T %z')/" > besclient.config
NOTE: apparently the effective date
is not required.
The code doesn't care about effective date unless it is newer than the effective date / value combo trying to be set, so it can be missing and still work.
This means I need to change the AWK code to remove effective date, and SED isn't needed.
Example output:
[Software\BigFix\EnterpriseClient]
EnterpriseClientFolder = /opt/BESClient
[Software\BigFix\EnterpriseClient\GlobalOptions]
StoragePath = /var/opt/BESClient
LibPath = /opt/BESClient/BESLib
[Software\BigFix\EnterpriseClient\Settings\Client\_BESClient_Resource_StartupNormalSpeed]
value = 1
[Software\BigFix\EnterpriseClient\Settings\Client\_BESClient_Download_RetryMinutes]
value = 1
[Software\BigFix\EnterpriseClient\Settings\Client\_BESClient_Resource_WorkIdle]
value = 20
[Software\BigFix\EnterpriseClient\Settings\Client\_BESClient_Resource_SleepIdle]
value = 500
[Software\BigFix\EnterpriseClient\Settings\Client\_BESClient_Comm_CommandPollEnable]
value = 1
Once the file is created: http://askubuntu.com/questions/193055/how-to-make-files-accessible-only-by-root
chmod 600 besclient.config
This has been tested and working on ubuntu.
needs improvement: https://github.com/jgstew/tools/blob/master/bash/install_bigfix.sh
Reference:
Currently default settings are supported for OS X using clientsettings.cfg but this does not work on linux/unix clients