Salt file.recurse source file not found (file encoding issue)

So I was running this:

/var/www/jj-web-1-www.jj5.net-sixsigma:
  file.recurse:
    - clean: True
    - user: root
    - group: root
    - dir_mode: 755
    - file_mode: 644
    - source: salt://inst/mediawiki-1.29
    - require:
      - pkg: apache2

And getting an error like this:

----------
          ID: /var/www/jj-web-1-www.jj5.net-sixsigma
    Function: file.recurse
      Result: False
     Comment: #### /var/www/jj-web-1-www.jj5.net-sixsigma/vendor/james-heinrich/getid3/getid3/module.audio.ac3.php ####
              Source file 'salt://inst/mediawiki-1.29/vendor/james-heinrich/getid3/getid3/module.audio.ac3.php?saltenv=base' not found

              #### /var/www/jj-web-1-www.jj5.net-sixsigma/vendor/james-heinrich/getid3/getid3/module.audio-video.mpeg.php ####
              Source file 'salt://inst/mediawiki-1.29/vendor/james-heinrich/getid3/getid3/module.audio-video.mpeg.php?saltenv=base' not found
     Started: 14:27:18.352264
    Duration: 134735.945 ms
     Changes:
----------

The issue was that the source files mentioned weren’t in UTF-8 format. To convert the files I ran, e.g.:

$ iconv -f WINDOWS-1252 -t UTF-8//TRANSLIT < module.audio-video.mpeg.php.bak > module.audio-video.mpeg.php

(Actually I couldn’t get the ‘iconv’ command to work so I edited manually in Vim)

Installing .NET on Debian 9

After installing Visual Studio Code I followed the instructions from .NET Tutorial – Hello World in 10 minutes, basically:

wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
sudo mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
wget -q https://packages.microsoft.com/config/debian/9/prod.list
sudo mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
sudo chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list

Then:

sudo apt-get update
sudo apt-get install dotnet-sdk-2.1

Then for example to create a new console project:

dotnet new console -o myApp
cd myApp

I ended up reading MICROSOFT SOFTWARE LICENSE TERMS for the MICROSOFT .NET LIBRARY which included this doozy:

The software may collect information about you and your use of the software, and send that to Microsoft.

Ah, Microsoft. You haven’t changed.

I found some notes about how to disable telemetry:

Telemetry
———
The .NET Core tools collect usage data in order to help us improve your experience. The data is anonymous and doesn’t include command-line arguments. The data is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to ‘1’ or ‘true’ using your favorite shell.

Read more about .NET Core CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry

I have added the opt-out environment variable via jj5-bin.

Debugging JINJA in Salt Stack

So I was trying to figure out how to report the template source file within the template itself and I found myself wanting to know what was available in the JINJA globals for a Salt Stack JINJA template.

Turns out you use the show_full_context() function, like this:

Context is: {{ show_full_context() }}

You can parse the output to see what top-level items are available. In my case I found the ‘source’ setting for the JINJA template in use.

Hot tip: if you’re using Vim to inspect the show_full_context() output, try using ‘%’ or ‘]}’ to move between matching braces.

Bonus: while I was learning about reporting the JINJA context I discovered that you can call Salt functions from JINJA templates, like this:

# The following two function calls are equivalent.
{{ salt['cmd.run']('whoami') }}
{{ salt.cmd.run('whoami') }}

pwned

I wrote the below BASH function today. It’s good because it performs super well compared to the alternative commands (which are commented out below above the new commands):

own() {

  echo "Taking ownership..."
  #chown -R jj5:jj5 .
  find . \! -user jj5 -or \! -group jj5 -execdir chown jj5:jj5  "{}" \;
  [ "$?" = 0 ] || { echo "Could not take ownership in '$PWD'."; exit 1; }

  echo "Fixing directory permissions..."
  #find . -type d -execdir chmod u+rwx "{}" \;
  find . -type d -and \( \! -perm /u=r -or \! -perm /u=w -or \! -perm /u=x \) -execdir chmod u+rwx "{}" \;
  [ "$?" = 0 ] || { echo "Could not fix directory permissions in '$PWD'."; exit 1; }

  echo "Fixing file permissions..."
  #find . -type f -execdir chmod u+rw "{}" \;
  find . -type f -and \( \! -perm /u=r -or \! -perm /u=w \) -execdir chmod u+rw "{}" \;
  [ "$?" = 0 ] || { echo "Could not fix file permissions in '$PWD'."; exit 1; }

}

The basic premise is don’t do work which doesn’t need to be done!

NetBeans PHP “Invalid include path”

So I migrated my projects from a Debian 8 (Jessie) system to a Debian 9 (Stretch) system. The default NetBeans installed by apt-get install netbeans on Strech was 8.1, and it didn’t include PHP support, so I manually installed NetBeans 8.2.

When I opened my old projects I got an error about an invalid global PHP include path.

So initially I edited ~/.netbeans/8.2/build.properties to change the php.global.include.path settings (to remove /usr/share/php5, because in Stretch I’m running PHP 7.0). But that didn’t work. Each time I ran NetBeans the build.properties file was overwritten with the old php5 directory.

So then I found ~/.netbeans/8.2/config/Preferences/org/netbeans/modules/php/project/general.properties. In there I edited the phpGlobalIncludPath and removed the /usr/share/php5 directory.

Then when I reopened NetBeans all of my projects opened properly without an error! Everything is easy when you know how!

Navigate to matching brace in NetBeans

So I wanted to know the keyboard shortcut to navigate between matching braces in my PHP (and other) code in NetBeans. I’m running NetBeans 8.2. So I searched and found General Editor Features which said “to find a shortcut for a specific command, type the command name in the Search field.” So the Search field they’re talking about is on the Keymap screen under Tools -> Options. After creating myself a custom Keymap Profile based on the NetBeans default settings I searched in the ‘Search:’ box for ‘match’ and found ‘Insertion Point to Matching Brace’ which is Ctrl+OPEN_BRACKET. Everything is easy when you know how!