Tuesday, May 24, 2016

Dead Icons on Mac OS X

Having used a Mac for the last 6 months again (how annoying), I went through the process of clearing it up ready for the next person to use (as I'd never personally own an Apple Mac, since I was the person who coined the term "Crapple Mac").

However, in the process of working out how to remove applications that were not installed through iTunes (I have no intention of putting my credit card details into a laptop I don't own, or to Apple), most of my applications were installed via brew.

I had the following shell script to install, search or delete my applications;
#!/bin/bash

if (( $# < 2 ))
then
echo "SYNTAX: $0 action package" >&2
echo "Where action is one of (search|install|uninstall)" >&2
exit 1
fi

action=$1
shift
package="$@"

case $action in
'install')
brew cask $action $package --force
;;
        remove|erase)
                brew cask uninstall $package
;;
*)
brew cask $action $package
;;

esac

So when coming to delete the applications were not always easy to remove with brew, as some were downloaded over the Internet.

So if brew odes not remove the application you can try one of the following 3 options;
  1. The simple method of clicking on Launchpad and then click and hold on the application to remove.  All the icons will then wobble.  If you can remove the application here then an X will appear against the application.  Clicking it will allow you to remove it.
  2. Open the application.  Then bring up the menu for the application in the dock so that you can "show in finder".  Then quit the application (don't just close, you need to quit it) and then drag the .app from Finder into the waste basket and then empty trash.
  3. This final one will help remove application Icons where the application has gone, but the icon refuses to budge from Launchpad.  The following describes how to do this.
To remove an icon or application still showing in Launchpad that could not be remove using steps 1 or 2 do the following;

1. To find the application and see if it is in Launchpad run the following command
for x in $(find /private/var/folders -name *launchpad*)
do
  sqlite3 $x/db/db "SELECT * FROM apps;"
done | grep -i appName

2. In the 2nd column is the title.  This next command requires you to type the title in in the exact case.  So if for example you have an application called Thunderbird you would delete it as follows;

for x in $(find /private/var/folders -name *launchpad*)
do
  sqlite3 $x/db/db "DELETE FROM apps WHERE title='Thunderbird';"
done
Replacing Thunderbird with the title you got from Step 1.

Your launchpad will now start to look cleaner.

Monday, April 4, 2016

GPG Sharing encrypted files

Occasionally you want to share a secret file, be it a password, or some credentials, or even somethings else with colleague(s) over the unsecure internet or via Email.

gpg is a useful program for achieving this but it does require you to have the public key of the person you are intending to encrypt the file for, or a shared public key to which everyone has the private one.


You ENCRYPT: gpg -z0 --output message.gpg --encrypt --recipient “Person-B" message.txt
Colleague DECRYPT: gpg --output message --decrypt message.gpg

Sunday, March 20, 2016

Making Live CDs with latest updates

Not too long back I bought a new laptop, and as always needed to put my favourite Linux OS on it to keep ahead of the enterprise version.  If you haven't guessed I'm referring to Fedora.  Being about 3 years ahead of what is about to hit RedHat is extremely useful.

However the laptop that I decided to buy, from pcspecialist looked like a Mac Airbook, or whatever they call their slimest one, but with the latest and greatest faster i7 6th Gen processor, etc.  So in short far superior to the Apple, but less than 1/2 the price at £620.

When it arrived, it was excellent - F23 installed, but after a short while it started to hang if it was stressed, so diverted over to Elementary OS, which although pretty, was a little old from a Kernel perspective and lacking some features.

Last weekend I had some time to sit down, since F23 wouldn't run as a Live USB stick from download I decided to build my own spin.  I've been building kickstart systems for a very long time, especially over networks and also on DVDs, however in recent times the process has changed a little since you can't get the entire OS DVD, but have to create a live one.

So using some useful sites around livecd-tools decided to install it and create F23 spin with all of the latest updates taken from rpmfusion.  Here is how it is done on a Fedora system;

1.Install livecd-tools
    1. sudo dnf -y install livecd-tools fedora-kickstarts
      1. The fedora-kickstarts will provide the basis for your files to build the livecd
2. Create a directory to perform the work and store your final ISO image
    1. mkdir -p $HOME/livecds/fc23
      1. I've added fc23 so that I can build different versions
    2. I also created a script called $HOME/livecds/livecd so that I don't have to remember the options;

#!/bin/bash

# URL location
# https://fedoraproject.org/wiki/How_to_create_and_use_a_Live_CD
if (( $# < 3 ))
then
  echo "Syntax: $0 " >&2
  exit 1
fi

pathToKickstartFileks="$1"
tmpcacheLocation="$2"
cdLabel="$3"

livecd-creator --verbose --config="$pathToKickstartFileks" --fslabel="CDLabel" \
--cache="$tmpcacheLocation"

3. The main element to creating a live CD with the latest kernel, etc is to include the repositories of rpmfusion, and to add the necessary packages to the kickstart file.
  1. Copy the example kickstart base file for Fedora 23 so that you can modify it;
    1. cp /usr/share/spin-kickstarts/fedora-live-workstation.ks $HOME/livecds/fc23
  2. Modify the kickstart file, changing the following to make it fit on an 8GB USB
    1. part / --size 8192  --fstype ext4 --grow
      1. The original only allows for a 4GB and doesn't have grow
    2. Under the %packages section you can add your extra Groups or individual packages that you need.  Note if you are adding a group then something like "Development tools" should be written as development-tools
    3. If you don't want a package then precede it with a hyphen (-)
      1. e.g. -shotwell
    4. You will also notice in this file the line;
      1. %include fedora-repo.ks
      2. Create this file with the following for F23, change version based on OS
repo --name=fedora --mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=fedora-23&arch=$basearch
repo --name=fedora-updates --mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=updates-released-f23&arch=$basearch
repo --name=fpmfusionfreerawhide --mirrorlist=http://mirrors.rpmfusion.org/mirrorlist?repo=free-fedora-rawhide&arch=$basearch
repo --name=rpmfusionnonfreerawhide --mirrorlist=http://mirrors.rpmfusion.org/mirrorlist?repo=nonfree-fedora-rawhide&arch=$basearch
repo --name=rpmfusionfree --mirrorlist=http://mirrors.rpmfusion.org/mirrorlist?repo=free-fedora-23&arch=$basearch
repo --name=rpmfusionfreeupdates --mirrorlist=http://mirrors.rpmfusion.org/mirrorlist?repo=free-fedora-updates-released-23&arch=$basearch
repo --name=rpmfusionnonfree --mirrorlist=http://mirrors.rpmfusion.org/mirrorlist?repo=nonfree-fedora-23&arch=$basearch
repo --name=rpmfusionnonfreeupdate --mirrorlist=http://mirrors.rpmfusion.org/mirrorlist?repo=nonfree-fedora-updates-released-23&arch=$basearch
repo --name=google --baseurl=http://dl.google.com/linux/chrome/rpm/stable/x86_64

You'll note that I've also included Chrome.  Each repo is one complete line.  The key ones are the rpmfusion and the updates so that we get the latest and greatest software installed.

4. To build the ISO image simply run your livecd script from within the F23 directory;
  1. $HOME/livecds/livecd ../fedora-live-base.ks ../cache F23-livecd
    1. This command then connects with the relevant repositories to download the rpms and builds the DVD ISO image
    2. You should watch the early output since it will tell you if you have any mistakes with package names or groups
5. Finally put the image on to you USB stick with;
  1. dd if=F23-livecd.iso of=/dev/sdd
    1. Where /dev/sdd should be changed to your USB drive
    2. If you don't know how to find out then;
      1. df -h
        1. Get a list of all the Filesystems
      2. Insert the USB stick
        1. df -h
        2. Look for the Filesystems that was not their previously
      3. Unmount the USB stick so you can write to it with dd
        1. sudo umount /dev/sdd

Troubleshooting

In most cases you are likely to see the following error if the partition size in the kickstart file is not large enough for the image.  If this is the case you will see;
Error creating Live CD : Unable to install: Could not run transaction.
Unmounting directory /var/tmp/imgcreate-vo3YLW/install_root
Losetup remove /dev/loop1
In the above case you should increase the part --size until the error no longer appears.

If you have an incorrect package you will see something like;
Retrieving http://www.mirrorservice.org/sites/download1.rpmfusion.org/nonfree/fedora/updates/testing/23/x86_64/repodata/d5d34f8bad2e14babefd4ff808715d34cdd5637475759a76c58852f211892340-primary.sqlite.xz ...OK
Skipping missing group 'Web Server'
Edit the fedora-live-base.ks file and modify the name in the %package section.