@Calvin Alkan

I've tried this on the command line but the plugin isn't automagically licensed - download and install works great though. Can this work to also be automatically licensed with no other interaction?

I'm using gridpane:

gp wp mydomain.com plugin install https://my.snicco.io/api/v0/download/commandui/commandui.zip?auth=ak_xxxxxxxxxx --activate

Thanks!

  • Duncan

    Actually, thinking more about it, this is working as expected right now.

    You should have the license key in the env or a PHP constant, because otherwise you won't be able to get updates.

    The auto activation is for registering the site with the license server without manual intervention, it does not replace having a license key at runtime.

    So, the correct worklow could be:

    wp config set CUI_LICENSE_KEY <the-key>
    
    https://my.snicco.io/api/v0/download/commandui/commandui.zip?auth=the-key --activate

output from command line:

root@santamonica-22:~# gp wp MYDOMAIN.org plugin install https://my.snicco.io/api/v0/download/commandui/commandui.zip?auth=ak_xxxxxxxxxxxxxx --activate
#####################################################################################################
Command was run at Thu Mar 6 08:12:01 AM PST 2025 created process with PID: 1267679... /usr/local/bin/gp wp MYDOMAIN.org plugin install https://my.snicco.io/api/v0/download/commandui/commandui.zip?auth=ak_xxxxxxxxxxxxxx --activate
#####################################################################################################

GridPane Agency
Validated... running /usr/local/bin/gp script...


gp-wpcli Log Begin - MYDOMAIN.org


Downloading installation package from https://my.snicco.io/api/v0/download/commandui/commandui.zip?auth=ak_xxxxxxxxxxxxxxxxxx...
Unpacking the package...
Installing the plugin...
Plugin installed successfully.
Activating 'commandui'...
Plugin 'commandui' activated.
Success: Installed 1 of 1 plugins.


gp-wpcli Log End - MYDOMAIN.org


    Duncan

    The activation key must be an enivonement variable in the shell.

    You have it hardcoded in the URL.

    Check the screenshot again of the CLI install.

    Whats the difference? This is the one you posted in the GP Facebook group.

    As a complete command set should it be:

    CUI_LICENSE_KEY=ak_xxxxxxx
    gp wp MYDOMAIN.org plugin install https://my.snicco.io/api/v0/download/commandui/commandui.zip?auth=$CUI_LICENSE_KEY --activate

    Confirming it works with the define('CUI_LICENSE_KEY', 'ak_xxxxxxxx'); in the ggridpane user-configs.php but I'd rather have it work off the environment at a serverlevel.

    Confirming as well that when I printenv I can see the formerly set CUI_LICENSE_KEY=ak_xxxxx so it is present.

    Duncan

    Maybe try without gp wrapper. Could be that it does not pass down environment variables.

      6 days later

      Calvin Alkan

      root@bells-22:/var/www/domain.com/htdocs# export CUI_LICENSE_KEY=ak_xxxxxxxxxxxxxx
      root@bells-22:/var/www/domain.com/htdocs# printenv | grep CUI
      CUI_LICENSE_KEY=ak_xxxxxxxxxxxxxx

      root@bells-22:/var/www/domain.com/htdocs# sudo -u out-16447 wp plugin install https://my.snicco.io/api/v0/download/commandui/commandui.zip?auth=ak_xxxxxxxxxxxxxx --activate
      Downloading installation package from https://my.snicco.io/api/v0/download/commandui/commandui.zip?auth=ak_xxxxxxxxxxxxxx...
      Unpacking the package...
      Installing the plugin...
      Plugin installed successfully.
      Activating 'commandui'...
      Plugin 'commandui' activated.
      Success: Installed 1 of 1 plugins.

      However still need to manually insert license via the UI.

      As usuall, I feel like I am missing something!

        Duncan

        Probably, the sudo command does not inherit the environment.

        sudo -u out-16447 printenv

        Will likely not have CUI_LICENSE_KEY

        Duncan

        This could work: sudo --preserve-env=CUI_LICENSE_KEY ...

          Calvin Alkan

          So I've worked out that you can /etc/environment in Ubuntu at least and it will be present for all users. I've verified that just prior to install as you can see here:

          if ! grep -q "^$CUI_LICENSE_KEY_LINE" /etc/environment; then
          echo "CUI_LICENSE_KEY=${CUI_LICENSE_KEY}" | sudo tee -a /etc/environment > /dev/null
          echo "CUI_LICENSE_KEY added to /etc/environment"
          else
          echo "CUI_LICENSE_KEY already exists in /etc/environment"
          fi

          echo "${owner} sees this in the env:"
          sudo -u ${owner} printenv | grep CUI_LICENSE_KEY
          
          # install the amazing commandui
          sudo -u ${owner} wp plugin install https://my.snicco.io/api/v0/download/commandui/commandui.zip?auth=$CUI_LICENSE_KEY --activate --path="${htdocs}"

          The end result is installed, active and licensed in my.snicco.io - here's the CLI output:

          Unpacking the package...
          Installing the plugin...
          Plugin installed successfully.
          Activating 'commandui'...
          [CommandUI] Trying to activate license with pre-existing activation key...
          [CommandUI] 🚀 Activated license with pre-existing activation key.
          Plugin 'commandui' activated.
          Success: Installed 1 of 1 plugins.

          However the enter a license nag box is present in the UI - I would imagine that given it is now licensed, and with the key in the ENV this box should not show up any more.

          To be clear, I had imagined that once a key was found via the ENV that the plugin would be licensed and there would be no manual input to complete the installation, and the nag would disappear.

          It looks at present as if you have to put the key in manually to get rid of the nag box regardless of the presence of the ENV variable.

            Duncan To be clear, I had imagined that once a key was found via the ENV that the plugin would be licensed and there would be no manual input to complete the installation, and the nag would disappear.

            This is the expected behavior, but it's a bug right now I think.

            You need to actually have the activation key in either the ENV, a PHP constant, or the DB right now. This should be optional.

              Duncan

              You could put it in the wp-config in the install process with wp config set (I think), or even into a Nginx env variable, then it's available for all sites for web requests, which would remove the update nag.

              Calvin Alkan it's a bug right now

              Bug with command UI and thus it will be fixed, or with WP and outside your control?

              As I have it in the ENV now I'd rather wait for the bug to be fixed so it doesn't nag, that way I don't have to put the key into each and every site individually, and if/when they migrate away the key won't go with it, and we don't have to add it to our offboarding list! You are likely to get another sale as a result.

                Duncan

                I'll fix it so that you only need a key at activation.

                Duncan

                Actually, thinking more about it, this is working as expected right now.

                You should have the license key in the env or a PHP constant, because otherwise you won't be able to get updates.

                The auto activation is for registering the site with the license server without manual intervention, it does not replace having a license key at runtime.

                So, the correct worklow could be:

                wp config set CUI_LICENSE_KEY <the-key>
                
                https://my.snicco.io/api/v0/download/commandui/commandui.zip?auth=the-key --activate
                  5 days later

                  Calvin Alkan

                  Confirming this works. For those of us on GridPane, the variable should be in the user-configs.php, and also in the server wide user configs so its default on any new site built on the server. https://gridpane.com/kb/how-to-create-a-custom-server-wide-user-configs-php-file/

                  This way when the site is migrated, the license should invalidate forcing a purchase and also reducing the offboarding for us.

                  So here's what I did:

                  if ! grep -q "^$CUI_LICENSE_KEY_ENV_LINE" /etc/environment; then
                    echo "${CUI_LICENSE_KEY_ENV_LINE}${CUI_LICENSE_KEY}" | sudo tee -a /etc/environment > /dev/null
                    echo "CUI_LICENSE_KEY added to /etc/environment"
                  else
                    echo "CUI_LICENSE_KEY already exists in /etc/environment"
                  fi
                  
                  # install the amazing commandui
                  
                  # set the license key in the  user-configs.php
                  # https://community.commandui.com/d/102-cli-install-doesnt-auto-license/14 
                  
                  if ! grep -q "^$CUI_LICENSE_KEY_CONF_LINE" "/var/www/$SITE/user-configs.php"; then
                    echo "define( 'CUI_LICENSE_KEY', '${CUI_LICENSE_KEY}' );" | sudo tee -a /var/www/${SITE}/user-configs.php > /dev/null
                    echo "CUI_LICENSE_KEY added to /var/www/$SITE/user-configs.php"
                  else
                    echo "CUI_LICENSE_KEY already exists in /var/www/$SITE/user-configs.php"
                  fi
                  
                  # wp config set CUI_LICENSE_KEY $CUI_LICENSE_KEY
                  sudo -u ${owner} wp plugin install https://my.snicco.io/api/v0/download/commandui/commandui.zip?auth=$CUI_LICENSE_KEY --activate --path="${htdocs}"