More Things I Keep Forgetting!

[This is a work in progress and will be added to as I go!]

I have been using Docker to containerise some small services that don’t need their own VMs but if I don’t touch them for a week or so, I forget the commands to manage them!

The main one is to restart all containers on that Docker instance:

docker restart $(docker ps -q)

Another Thing I Keep Forgetting!

Every time I write a Bash script that loops through something, I test printing out the variable and it always splits the spaces across new lines so an app named ‘jHelper GUI 1.0.app’ ends up as:

jHelper
GUI
1.0.app

The thing I keep forgetting to sort this is IFS! so I just need to do the following:

#!/usr/bin/env bash

IFS=$'\n'

# Loop through apps and print out basename
for app in /Applications/*; do
    echo "$(basename ${app})"
done
unset IFS


Succinct version of `if..elif`

Instead of writing out a large block for an if / elif such as…

if [[ $foo == $bar ]]; then
    echo "yes"
else
    echo "no
fi

a much shorter version can be used instead:

[[ $foo == $bar ]] && echo "yes" || echo "no"

A simple [[ condition ]] && positive result || negative result

VMWare and DEP

Requirements:
VFUSE: https://github.com/chilcote/vfuse/releases
AutoDMG: https://github.com/MagerValp/AutoDMG/releases
VMWare Fusion
Bootable DMG of macOS
Serial number and model identifier of a machine that will DEP

Build a bootable DMG using AutoDMG
Use the following vfuse commands to create the .vmwarevm

sudo /usr/local/vfuse/bin/vfuse -i [path/to/DMG] -n "[name of VM Machine]" -s [DEP Serial] --hw-model [model identifier]

sudo /usr/local/vfuse/bin/vfuse -i /Users/monodata/Documents/_IMAGES/10.13/macOS-10.13.6-17G65.apfs.dmg -n "macOS-10.13.6-DEP" -s C0202XHG0D6T --hw-model MacBookPro14,3

 

MDM & MBP :: Touch ID Not Unlocking Device

Had an issue recently with some users that couldnt unlock their JAMF MDM managed MBP using Touch ID.

After a bit of poking around, I found that I had to:

  1. exclude their machine from the MDM profile
  2. Run the `bioutil` commands [see below]
  3. Re-apply the MDM
  4. Re-add their fingerprints.
bioutil -s -w -u 1

 

The man page for `bioutil` says:

Usage:
bioutil {-r | -w [-f { 0 | 1 }] [-u { 0 | 1 }] [-a { 0 | 1 }]} | [-c] | [-p] | [-d <uid>] [-s]

Options:
    -r, --read                      Read current Touch ID settings
    -w, --write                     Write new Touch ID settings
    -s, --system                    Flag to read/write systemwide Touch ID settings or perform systemwide operations
    -f, --function                  Enable (1) or disable (0) Touch ID functionality in general (system settings only)
    -u, --unlock $value             Enable (1) or disable (0) Touch ID for unlock
    -a, --applepay $value           Enable (1) or disable (0) Touch ID for ApplePay (user settings only)
    -c, --count                     Print number of enrolled fingerprints of the current user or of all users (-s, administrator only)
    -p, --purge                     Delete all enrolled fingerprints of the current user or of all users (-s, administrator only)
    -d, --delete $uid               Delete all enrolled fingerprints of the given user (administrator only)

 

BASH :: Always make sure to validate your inputs!

Got caught out not checking if a variable had been passed to a script that then used it to delete an .app.

Added in lines 8 – 11 to validate the input. Thankfully, only 3 machines affected!

#!/bin/bash

#  Get folder path when run through Casper (Comment out as applicable)
#  Enter the full path to the folder in the 'Parameter 4 Field' in Casper
# then check its not empty or it will delete everyhting from someones machine!
app=$4

if [[ $app == "" ]]; then
    echo "App field is empty. Stopping before everything is deleted!" >> /var/log/jamf.log
    exit 1
fi

FolderPath="/Applications/${app}"


# Check path exists then delete
if [[ -e "$FolderPath" ]]; then
  # delete
  /bin/rm -Rf "$FolderPath"
  if [[ ! -e "$Folderpath" ]]; then
    echo "${app} has been deleted." >> /var/log/jamf.log
  else
    echo "Removing ${app} failed." >> /var/log/jamf.log
  fi
fi

exit $?