Tag Archives: Terminal

Download a package from a Jamf Pro Cloud Distribution Point

I ran into a new issue. I have a policy that is pushing a package that I’m not clear on what it’s doing. What’s worse, the policy is pending or failed on a large number of machines. To confuse matters, I have 3 different “Google Chrome” packages but no idea what the differences are.

I wanted to download the packages and open them with something like Suspicious Package to see what they are actually doing.

Since there’s no “Download” option in Jamf for your pkg, and I don’t want to install the package to figure out if it’s working. You can create a policy, cache the package, scope it to your machine and then copy the package to your desktop.

  • Create a new policy
  • Add each package you want to download
  • Set the Action to Cache
  • I made the policy available in Self Service, so I wouldn’t have to wait for a check-in
  • Scope the policy to only your machine

After you install the packages. Open Terminal and switch to root. Change to the directory and verify the packages are downloaded.

sh-3.2# sudo su
sh-3.2# cd /Library/Application\ Support/JAMF/Waiting\ Room/
sh-3.2# ls -1

Now, let’s copy the packages (ignore the cache.xml files) to our desktop and change the owner to our account, so we can examine them.

#copy pkgs to your desktop
cp Google Chrome new.pkg /Users/username/Desktop/
cp Google Chrome.pkg /Users/username/Desktop/
cp googlechrome.pkg /Users/username/Desktop/

#change the owner from root, to your user account
chown username /Users/username/Desktop/Google Chrome new.pkg
chown username /Users/username/Desktop/Google Chrome.pkg
chown username /Users/username/Desktop/googlechrome.pkg

If all you needed to do was download the packages, you’re done! In my case, I want to see what they are installing, so I’ll open them with Suspicious Package.



This package, Google Chrome new.pkg is installing v89.04.4389.90! Maybe this was new at some point, but clearly poorly named now.

Turns out the package that was causing me the most issues was googlechrome.pkg which was trying to install Chrome to the System volume, instead of "/Applications“, which was causing it to fail on every client it was scoped to.

Showing Bluetooth Battery Percentage On Your Desktop

I use a tool called GeekTool (a fun tool that can be used in a lot of ways) to show the battery percentage of my bluetooth connected devices on my desktop. It makes it easier to keep an eye on them and know when they need charged.

Since switching to an Apple M1 laptop my old script broke, so I took a little time to update it. I used to pull the information from system_profiler but it seems it’s been removed. the ioreg command, now list the current battery percentage of any bluetooth connected devices

ioreg -r -l -k "BatteryPercent"  

This might look like it gives you a lot of output, but we really just need to parse it, to get what we want. The below command will give you current battery percentage for an Apple Magic Keyboard and Magic Mouse. Other products can be listed, but you’d have to run the above ioreg command and get the Product name to switch out in the command.

KeyboardPercent=$(ioreg -r -l -k "BatteryPercent" \
| grep -A 9 "Magic Keyboard with Touch ID" \
| grep "BatteryPercent" \
| awk '{print $3}')

MousePercent=$(ioreg -r -l -k "BatteryPercent" \
| grep -A 9 "Magic Mouse" \
| grep "BatteryPercent" \
| awk '{print $3}')

echo "Keyboard Battery Level: $KeyboardPercent"
echo "Mouse Battery Level: $MousePercent"

Once I have the command working, I update my GeekTool script. There’s a little more formatting here then just show me the percentage and GeekTool is more sensitive to whitespace. The below command is what I use to paste into the script editor to give me the output in the screenshot.

#!/bin/zsh

# Bluetooth Keyboard -----------------------------------------------------------
KeyboardPercent=$(ioreg -r -l -k "BatteryPercent" \
| grep -A 9 "Magic Keyboard with Touch ID" \
| grep "BatteryPercent" \
| awk '{print $3}')

typeset -i b=5
echo "Keyboard:\t\t\c"

if [ ${KeyboardPercent} = 0 ]
then
    echo "Disconnected\c"
else
    if [ $KeyboardPercent -lt 11 ]
    then
        echo "\033[1;31m\c"
    else
        echo "\033[0m\c"
    fi
    while [ $b -le $KeyboardPercent ]
    do
        echo "|\c"
        b=`expr $b + 5`
    done
    while [ $b -le 100 ]
    do
        echo "\033[1;37m|\033[0m\c"
        b=`expr $b + 5`
    done
    echo "\033[0m $KeyboardPercent%\c"
    unset KeyboardPercent
    unset b
fi

echo "\033[0m\nMouse:\t\t\t\c"

# Bluetooth Mouse --------------------------------------------------------------

MousePercent=$(ioreg -r -l -k "BatteryPercent" \
| grep -A 9 "Magic Mouse" \
| grep "BatteryPercent" \
| awk '{print $3}')

if [ ${MousePercent} = 0 ]
then
    echo "Disconnected\c"
else
    if [ $MousePercent -lt 11 ]
    then
        echo "\033[1;31m\c"
    else
        echo "\033[0m\c"
    fi
    typeset -i b=5
    while [ $b -le $MousePercent ]
    do
        echo "|\c"
        b=`expr $b + 5`
    done
    while [ $b -le 100 ]
    do
        echo "\033[1;37m|\033[0m\c"
        b=`expr $b + 5`
    done
    echo "\033[0m $MousePercent%\c"
    unset MousePercent
    unset b
fi

Scripts can be found here

Scripting The Default Terminal Theme In OS X

Anytime I find myself doing a repetitive mundane task .. I think why aren’t I scripting this? I hate the default white terminal theme that comes in OS X. I always find myself changing it to Homebew.

Here’s a sample script. You can simply change “Homebrew” to whatever terminal theme you want.

#!/bin/bash

#set Terminal defaults
sudo -u $USER defaults write /Users/$USER/Library/Preferences/com.apple.Terminal.plist "Default Window Settings" "Homebrew"
sudo -u $USER defaults write /Users/$USER/Library/Preferences/com.apple.Terminal.plist "Startup Window Settings" "Homebrew"

#set window width to 120
sudo /usr/libexec/PlistBuddy -c "Add :Window\ Settings:Homebrew:columnCount integer 120" /Users/$USER/Library/Preferences/com.apple.Terminal.plist
defaults write /Users/$USER/Library/Preferences/com.apple.Terminal.plist "NSWindow Frame TTWindow Homebrew" "97 302 1075 366 0 0 1280 777 "

#restart Terminal
killall Terminal

exit 0

Now that you can script it, you can add it to a post deployment  script or launchagent that runs on the first login. So out of the gates you have a custom terminal. Then you can get real work done.

Installing Munki On A Mountain Lion Server

munki11-surpised-wandering_eye

These are my “cleaned up” & “streamlined” instructions for how to get munki installed on a Mountain Lion Server, for the definitive instructions you should go to the wiki page here or check out the project home page. These guys are doing awesome things with munki.

You don’t have to install munki on a Mac server, I just happen to have it installed on my Deploy Studio server as an extra tool to help me manage and image clients. Ideally you can push out a thin image to new clients with Deploy Studio, boot into that image that is already configured with munki. Run the Managed Software Updates and download the remaining apps to finish the build out.

 Step1: Building a server repository

We need to setup some folders to keep our config files and actually software for munki. Copy and paste these commands into terminal.

 cd /Users/Shared/
 mkdir munki_repo
 mkdir munki_repo/catalogs
 mkdir munki_repo/manifests
 mkdir munki_repo/pkgs
 mkdir munki_repo/pkgsinfo

munki-01

Step1: Building a server repository

_ _ _ _ _

Step 2: Changing Permissions on Directory

Run this command at the command line, For the specifics of what it does you can run “man chmod”. Basically you want to make sure Apache has the right permissions for this folder.

 chmod -vLR a+rX munki_repo

munki-02

Step 2: Changing Permissions on Directory

_ _ _ _ _

Step 3: Redirect Apache2 to serve the munki_repo directory via HTTP

Direct Apache to the right folder in order to display your repo over http.

sudo ln -s /Users/Shared/munki_repo /Library/Server/Web/Data/Sites/Default

_ _ _ _ _

Step 4: Turn on Web Sharing in the Sharing preferences pane

– open server.app
– turn websites on
– select server websites, click edit button (pencil tool)
– elect edit advanced settings, click ‘allow folder listings’

munki-04

Step 4: Turn on Web Sharing in the Sharing preferences pane

_ _ _ _ _

Step 5: Install munki tools

Download and install the munki tools … YOU WILL HAVE TO RESTART IMMEDIATELY.

http://code.google.com/p/munki/downloads/list

Optional: Adding /usr/local/munki to bash search path

– this step simply adds the path to the bash search path so you don’t have to add the path with every terminal command. For example if you do this step you only need to run: munkiimport –configure instead of /usr/local/munki/ munkiimport –configure

PATH=$PATH\:/usr/local/munki ; export PATH

_ _ _ _ _

Step 6: Configure munki import

Here’s where it starts to get good. We need to set up munki first with some basic information like where we want the folders to be where we are going to put software.

Type this at the command line:

usr/local/munki/munkiimport --configure 

or just

munkiimport - -configure

if you add it to the search path in step 5. From here I”ll only list the actually command and not the usr/local/munki

You should see this:

Path to munki repo [None]: /Users/Shared/munki_repo
Repo fileshare URL [None]: <just hit return>
pkginfo extension [None]: <just hit return>
pkginfo editor [None]: TextEdit.app <substitute your favorite text editor>

_ _ _ _ _

Step 7: Import first app into munki

Time to import something. I downloaded Firefox. Run the munkiimport command and then just drag the Firefox dmg on to the terminal window. It will automatically add the path.

munkiimport ~/Downloads/Firefox\ 18.0.1.dmg

You should then see a list of information after just a few seconds. Just follow the prompts. Don’t worry if you get it wrong, this is just a test, you should do this several times to feel comfortable. My responses are in red.

Item name [Firefox]: FIrefox
Display name []: FIrefox
Description []: web browser
Version [18.0.2]: <just hit return>
Catalogs [testing]:test (you can put in whatever you want to name your catalog)

Item name: Firefox
Display name: Mozilla Firefox
Description: Web browser from Mozilla
Version: 18.0.1
Catalogs: test

Import this item? [y/n] y
Upload item to subdirectory path []: <just hit return> (you could say apps/web_browsers if you wanted to create folders and organize your software)
Copying Firefox 18.0.2.dmg to /Users/Shared/munki_repo/pkgs/Firefox 18.0.2.dmg…
Saving pkginfo to /Users/Shared/munki_repo/pkgsinfo/Firefox-18.0.2…

Rebuild catalogs?[y/n]y
Rebuilding catalogs at /Users/Shared/munki_repo ….

After wards you can go to the munki_repo/pkgs folder and see that munki did actually copy the Firefox installer to the right folder.

munki-09

Step 7: Import first app into munki

_ _ _ _ _

Step 8: Creating a client manifest

The manifest is just the file that tells munki what software to offer. So now that we have Firefox in our repo we need to tell munki to offer it to our clients. First I need to create a manifest

run this command:

manifestutil

(again, my responses are in red, for a list of commands with manifestutil type help)

Entering interactive mode… (type “help” for commands)
> new-manifest test_munki
> add-catalog test –manifest test_munki
Added test to catalogs of manifest test_munki

add-pkg Firefox –manifest test_munki
Added Firefox to section managed_installs of manifest test_munki
> exit

munki-10

_ _ _ _ _

Step 9: Munki Client Configuration

In order for clients to see the munki server you need to install the munki tools on each client. Go here and download the munki tools and install them. This will install the Managed Software Updates app in the clients utility folder.

Now we need to tell ManagedInstalls where to find munki. Type this command.

sudo defaults write /Library/Preferences/ManagedInstalls SoftwareRepoURL "http://localhost/munki_repo"

This is just a test so I am using “http://localhost/munki_repo” , but if I really installed this on a different client I would have to change localhost to the IP of the Munki Server

sudo defaults write /Library/Preferences/ManagedInstalls ClientIdentifier "test"

“test” would be the name of your catalog you created.

To check your settings run this:

defaults read /Library/Preferences/ManagedInstalls

_ _ _ _ _

Step 10: Managed Software update

Now the moment of truth. Go to the Utility folder and double click Managed Software Updates. If everything was successful You should see the below.

munki-12

Create A BootCamp Partition From The Command Line

As a Mac admin in a mixed environment. Most of my users are being boot camped and running windows 7. While I have ways to image machines via Deploy Studio sometimes I just need to do a one off and Boot Camp a partition and then use winclone to install an image.

After Mac OS X 7.1 Boot Camp requires a physical CD to finish, you no longer have the options to “Quit and install later”. That just takes way to longer for administrators. So here’s a hand command for the terminal to partition the drive so you can reboot from an external and use winclone.

diskutil resizevolume /dev/disk0s2 xxG MS-DOS FAT xxG

– replace first xxG with size of the mac partition
– replace second xxG with size of windows partition
– any extra space goes to the windows partition ( 250G drive, 25g for mac, 200 for windows, add’s the left over 25G to windows)

Example:

diskutil resizevolume /dev/disk0s2 30G MS-DOS FAT 200G

– for a 250 GB SSD: creates a 30GB Mac partition, and 200GB Windows partition, anything left over will be added to the windows partition

After running the command, boot off a mac image with winclone installed and image the windows partition as normal.

How To Add Colors To Mac Terminal

As I spend more time in Terminal I find myself wishing it wasn’t so boring. luckily there is a way to add some color to that painfully dull screen.

Let’s create a .bash_profile by opening terminal and typing:

vim .bash_profile

This opens up the built in vim editor. Hit the “i’ key to inset text and type this:

# This command tells termical to add color
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad

# This command changes the terminal login colors
PS1=’\[\e[0;33m\]\h:\W \u\$\[\e[m\] ‘

Screen Shot 2013-02-01 at 4.18.31 PM copy 2

Then hit the “esc” key, this exits “insert” mode so you don’t add any more text to the actual file. To save and close the file type:

:wq

open a new terminal window and type:

ls

you should see that two parts now have color. The user of the session is highlighted before the prompt, and the output from the ls command is colored.

TERM02

To be honest thought the colors aren’t the best choose so lets install a better terminal them. Head over to here and install the peppermint theme.

Open terminal, select preferences and set the default to peppermint and check the colors by typing:

ls

TERM03

This looks better but, type this:

ping google.com

TERM04

Pretty boring standard output. Now lets get some color in the ping command.

Head over to Homebrew and copy this command from under INSTALL Homebrew or just paste it from below:

ruby -e “$(curl -fsSkL raw.github.com/mxcl/homebrew/go)”

TERM06

you should start to see some crazy things happen, that’s normal.

After that’s done run this command:

brew install grc

More crazy text things happening. Next run this command if you already setup a .bash_profile.

echo ‘source “`brew –prefix grc`/etc/grc.bashrc”‘ >> ~/.bash_profile

now the moment of truth. Open a new window in terminal and run this command:

ping google.com

TERM07

you should now see a colorful display of beauty. From here it’s just a matter of playing around with the ANSI colors of the peppermint theme in terminal preferences until you get something that you just love to look at.

TERM08

Support Links:
http://noiseandheat.com/blog/2011/12/os-x-lion-terminal-colours
http://mxcl.github.com/homebrew
http://noahfrederick.com/blog/2011/lion-terminal-theme-peppermint/

Increase the amount of RAM CrashPlan PROe can use

I run Crashplan PROe at work on 13 clients, backing up in the LAN and across the WAN. Occasionally I run into this issues where I open the client app on a workstation and it hangs on the splash screen and then crashes. At first I would unload and reload the engine until It eventually seemed to take. Then I ran into the instructions on how to increase the amount of RAM that Crashplan has action to. This seems to be especially important in my case because I’m running Crashplan on very old hardware. My Master and Storage servers are on PowerPC G5 Mac, stuck in time on 10.5.8. Even Crashplan has advised me to move to newer hardware as they are dropping support and I am currently maxed out as far as my Crashplan versions.

Editing the CrashPlan engine’s com.crashplan.engine.plist file allows java to use more memory. This seems to be more important for especially large file selections. Open the Terminal and follow these instructions

1. Stop the backup engine by typing this into the Terminal application:

sudo launchctl unload /Library/LaunchDaemons/com.crashplan.engine.plist

2. Run this command to edit the backup engine:

sudo nano /Library/LaunchDaemons/com.crashplan.engine.plist

3. Find this line: Xmx512m

4.Edit that line to something larger such as 640, 768, 896, or 1024. I went with 1024: Xmx1024m

This sets the maximum amount of memory that CrashPlan can use. CrashPlan will not use that much until it needs it.

5. Hold the Control key and tap the x key to exit. Choose “y” to confirm it.

6. You’ll see the prompt “File Name to Write.” Hit enter to save to the existing location.

7. Re-start the backup engine by typing:

sudo launchctl load /Library/LaunchDaemons/com.crashplan.engine.plist

You should know it works if you’re able to open the client app and the consistent crashing stops and normal backups resume.