Ludovic Poitou, ForgeRock’s OpenDJ Product Manager, blogs about about OpenDJ a bit. One of his posts shows a simple technique for adding a bash shell completion for OpenDJ’s administrative tool, dsconfig. I liked it because it makes access to the CLI help for dsconfig more convenient. Since I’ve been doing a lot of work with OpenDJ and OpenAM recently, I thought I’d improve it.

One of my projects is called Identity Fabric. It is designed to make it easy to install distributed, production-grade deployments of Identity and Access Management Platforms such as ForgeRock’s OpenDJ and OpenAM. Using Ludo’s technique I create global startup scripts that include bash completions for OpenDJ and OpenAM.

Create /etc/profile.d/ (assuming root permissions, and you’ve already setup SSOTools)


echo "export PATH=\${PATH}:${OPENAM_SSOADM}/bin" > /etc/profile.d/
echo "complete -W \"$(${OPENAM_SSOADM}/bin/ssoadm --help 2>/dev/null | egrep '^ {4}[a-z]*-[a-z].*' |  sed 's/[ *]*//g')\" ssoadm" >> /etc/profile.d/
chmod +x /etc/profile.d/

And logout and back in,

[ssouser@castor ~]$ ssoadm get-<tab>
get-attr-choicevals   get-auth-cfg-entr     get-identity          get-realm             get-recording-status  get-sub-cfg
get-attr-defs         get-auth-instance     get-identity-svcs     get-realm-svc-attrs   get-revision-number   get-svrcfg-xml

Create /etc/profile.d/


echo "export PATH=\${PATH}:${OPENDJ_HOME_DIR}/bin" > /etc/profile.d/

# sets up command completion
echo "complete -W \"$(${OPENDJ_HOME_DIR}/bin/dsconfig --help-all|grep '^[a-z].*' | tr '\n' ' ')\" dsconfig" >> /etc/profile.d/
echo "complete -W \"$(${OPENDJ_HOME_DIR}/bin/dsreplication --help|grep -o -w '^[a-z-]*$'|grep -v '^--'|tr '\n' ' ')\" dsreplication" >> /etc/profile.d/
chmod +x /etc/profile.d/

And same as above,

[ssouser@castor ~]$ dsconfig get-backend-<tab>
get-backend-index-prop      get-backend-prop            get-backend-vlv-index-prop

Quick notes

  1. I chose to use /etc/profile.d so any users that log in will get the completion setup for OpenDJ andOpenAM.
  2. I took a slightly different approach than Ludo for creating the bash startup file. I resolve the completion words when creating the file (see the echo statement), rather than adding the resolve directly to the bash startup file. On some virtual machines ssoadm and dsconfig can take a long time to return (even with the help subcommand). So each login will be significantly faster.
  3. Scripts in /etc/profile.d have to be executable, so remember to chmod +x /etc/profile.d/{,}

I hope you find this useful. Feel free to submit a PR for this article if you have improvements.