Showing posts with label Mac OS X. Show all posts
Showing posts with label Mac OS X. Show all posts

Monday, November 14, 2016

Mac OS X Sierra and self signed certificates

For some reason after upgrading to Sierra some of self signed certificates stopped being trusted.
Keychain Access was hanging and guru meditating while trying to delete/reinstall certificate.

this helps to reinstall self signed certificate:


0. find your certificate among installed

security find-certificate -a -Z|grep -e "SHA\|alis"

1. remove cert with

security delete-certificate -Z certSha

2. install cert via command line

sudo security add-trusted-cert -d -r trustAsRoot -p ssl myCoolSelfSigned.cer

3. in Keychain Access in system keychain open certificate and select "Always Trust"


as well this tool does magick


sudo certtool i myCert.crt

Monday, August 25, 2014

Why libimobiledevice are good. or List all iDevices connected to a host.

a note to meself

for i in `idevice_id --list`;
do 
  ideviceinfo -u $i |grep "^SerialNumber\|^DeviceName"; 
done;

Tuesday, August 5, 2014

Purging disk cache to see mor free RAM on Mac OS X

It is frightening when there is little amount of free RAM displayed by top command.

Most of time on an idle mac it can be fixed by purge command (to force disk cache to be purged).

sudo purge # do not use. see important note below

On GNU/Linux there is another way round (as usual).

sudo -s
echo 3 > /proc/sys/vm/drop_caches



Important update!!
Do not use sudo purge  on Mac OS X!
it turned out it is dangerous. Just reboot the Mac.

Wednesday, October 16, 2013

Enable VNC Server on Mac OS X remotely

Thanks Apple, they use shell.

ssh to Mac OS X

sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -configure -clientopts -setvnclegacy -vnclegacy yes -setvncpw -vncpw YOUR_PASSWORD  -access -on -users admin -privs -all -restart -agent -menu

Src: don't rememmber

Saturday, October 12, 2013

Install libimobiledevice on Mac OS X

So you'd like to manage your iOS devices by command line?
You can use libimobiledevice tools for that.
Easy on Linux. Let's see how it is on Mac OS X.

You'll need to:
1. install Xcode
2. start Xcode and agree to it's license
3. install Xcode command line tools (Start Xcode, Go to Preferences -> Downloads tab)
4. install homebrew by this command (sudo password will be prompted)

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

5. run following


brew install -s --HEAD libimobiledevice ideviceinstaller

6. ready to go


That's all, folks. Just a little more steps than in GNU/Linux.
So Mac OS X can really be of use by people.

Enable VNC Server on Mac remotely

Thanks, Apple! You've made life of many Unix admins easier by integrating some necessary stuff in OS X out of box.

To enable VNC Server on Mac when you have only SSH, fire this command.

sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -configure -clientopts -setvnclegacy -vnclegacy yes -setvncpw -vncpw YOUR_PASSWORD  -access -on -users admin -privs -all -restart -agent -menu 


Src - don't rememmber. If i'll find it, I'll add.

Uninstall MacPorts from Mac


"Uninstalling MacPorts can be a drastic step" so they say. That's why my choice is HomeBrew!

So here it is. Might be your's will be with a little deviation.

%% sudo port -fp uninstall installed

%% sudo rm -rf \
    /opt/local \
    /Applications/DarwinPorts \
    /Applications/MacPorts \
    /Library/LaunchDaemons/org.macports.* \
    /Library/Receipts/DarwinPorts*.pkg \
    /Library/Receipts/MacPorts*.pkg \
    /Library/StartupItems/DarwinPortsStartup \
    /Library/Tcl/darwinports1.0 \
    /Library/Tcl/macports1.0 \
    ~/.macports




Tuesday, September 17, 2013

Use perl to edit multiple lines XML

Ok, here is a strange request - to edit some xml file over ssh on Mac OS X.

One needs to change false to true in following

<key>system.privilege.taskport</key> <dict> <key>allow-root</key> <false/>

Luckily, Mac OS X has perl (not sure if it was installed along with XCode). So let's use perl for that:

ssh user@192.168.1.2 "set -x; \
echo 'Password' | sudo -S \
perl -p -0777 -i -e 's@<key>system.privilege.taskport</key>.*?<dict>.*?<key>allow-root</key>.*?<false/>@<key>system.privilege.taskport</key>\n\t\t<dict>\n\t\t\t<key>allow-root</key>\n\t\t\t<true/>@sg' /etc/authorization"

Breaking this down:
  • -p tells it to loop through the input and print
  • -0777 tells it to use the end of file as the input separator, so that it gets the whole thing in in one slurp
  • -e means here comes the stuff I want you to do

And the substitution itself:
  • use @ as a delimiter so you don't have to escape /
  • use *?, the non-greedy version, to match as little as possible, so we don't go all the way to the last occurrence of </xyz> in the file
  • use the s modifier to let . match newlines (to get the multiple-line tag values)
  • use the g modifier to match the pattern multiple times
Perl expression was constructed with help of this answer from stackoverflow.

Friday, August 30, 2013

HomeBrew: Installing right software to Mac OS X

Mac OS X can behave polite - one can install required software using HomeBrew http://brew.sh/

Homebrew installs the stuff you need that Apple didn't.
brew install wget

For example, let's prepare our Mac OS X for Jenkins CI

brew install  -v --devel --build-from-source --fresh wget automake autoconf libtool libzip pkg-config libimobiledevice



Start process, get PID of just started process, and terminate the process by PID later

Ok, let's say we have a usecase - a job on Jenkins CI that needs to start a background process, remember PID of the process, pass the PID to some later cleanup. And we need something that will work on Linux and on Mac OS X (yes, even this OS can behave polite).

So 1st, let's start a process and remember it's PID. This is done via $! shell environment variable. The $! variable will have PID of latest started process. So here is an example:

nohup tail -f /var/log/syslog > /tmp/$BUILD_TAG.log & export LOGGER_PID=$! 
# $BUILD_TAG - is an environment variable provided by Jenkins CI, it has unique job execution identifier

2nd, let's remember the PID

echo -e "LOGGER_PID=$LOGGER_PID" > /tmp/$BUILD_TAG

3rd, let's use the PID and send SIGTERM to the process if it is still alive. We'll wrap it to a shell script.

#!/bin/bash
. /tmp/$BUILD_TAG  # read to LOGGER_PID env variable

kill_proc(){

  local pid_alive=`ps ax| awk '{print $1}' | grep -e "^$LOGGER_PID$" >>/dev/null; echo $?`;
   # ps ax| awk '{print $1}' - will print to stdout PIDs without surrounding spaces
   # grep -e "^$LOGGER_PID$" >>/dev/null; - will search for the PID, ^ and $ are important, just in case our PID is a substring of some other PID on system
   # echo $? - will echo exit code of last command
  if [ $pid_alive -eq 0 ]; then 
    kill $LOGGER_PID; # sending  SIGTERM to the process
    sleep 10;
  else
    echo "Proc with PID $LOGGER_PID already terminated" 
  fi;  
}

kill_proc;