Showing posts with label brew. Show all posts
Showing posts with label brew. Show all posts

Friday, June 16, 2017

Brew afsctool on your own for Mac OS Sierra

Recently, I came across an error message while compressing the document with HFS+ compression using open source tool afsctool. The repository on Homebrew project is still on version 1.6.4.

Message comes up every time: "Unable to compress file."

Someone on Github has figured out what's happening and has a solution. The Github user has pointed out that the filesystem on Sierra returns a different value of file type than its predecessor. This renders afsctool useless and return error message at all time. But the suggested change has never been updated on the original source repository of afsctool.

With a little patience for not using this tool, I made up my mind. I think it's time to homebrew our software tool before the Author patches the source code for this.

Here's the recipe:

Before your own compiling work, you might want to uninstall the outdated brew formula for afsctool:

$
$ brew uninstall afsctool

Make sure gcc is installed properly on your Mac.

Take a look at the Hombrew formulas for afsctool via http://brewformulas.org/Afsctool

Take a look at the source file from there: https://github.com/Homebrew/homebrew-core/tree/master/Formula/afsctool.rb

We found a URL from there: https://docs.google.com/uc?export=download&id=0BwQlnXqL939ZQjBQNEhRQUo0aUk

Also, take a look at the parameters called from the def() function call. Highlighted parameters will be useful for compiling:
def install
    cd "afsctool_34" do
      system ENV.cc, ENV.cflags, "-lz",
         "-framework", "CoreServices", "-o", "afsctool", "afsctool.c"

      bin.install "afsctool"
    end
end

Grab the source code ZIP of afsctool from the above URL.

Extract the ZIP file to a temporary location.

Find afsctool.c and amend the file according to this Github post.

Try compiling the .c file afsctool.c with GCC compiler using the aforementioned parameters from brew formula:

$
$ gcc -lz -framework CoreServices -o afsctool afsctool.c

Copy the compile file afsctool to the common bin folder for easy access:

$
$ cp ./afsctool /usr/local/bin/afsctool

Well, it's time to have a try on our new compiled tool:

$ afsctool -cv ./afsctool.c
/afsctool_34/afsctool.c:
File content type: public.c-source
File size (uncompressed data fork; reported size by Mac OS 10.6+ Finder): 79339 bytes / 79 KB (kilobytes) / 77 KiB (kibibytes)
File size (compressed data fork - decmpfs xattr; reported size by Mac OS 10.0-10.5 Finder): 13396 bytes / 16 KB (kilobytes) / 16 KiB (kibibytes)
File size (compressed data fork): 13412 bytes / 16 KB (kilobytes) / 16 KiB (kibibytes)
Compression savings: 83.1%
Number of extended attributes: 4
Total size of extended attribute data: 50 bytes
Approximate overhead of extended attributes: 1608 bytes
Approximate total file size (compressed data fork + EA + EA overhead + file overhead): 18306 bytes / 18 KB (kilobytes) / 18 KiB (kibibytes)

Finally, the compression works again.

By the way, we may need to keep watching until one day an updated brew formula is available to tackle this problem for Sierra.



Tuesday, December 20, 2016

Solution to Homebrew upgrade issue after MacOS Sierra 12.12.x Upgrade

For anyone who has problems in upgrading Homebrew repository after upgrading to MacOS Sierra 12.12.

$
$ cd "$(brew --repo)" && git fetch && git reset --hard origin/master && brew update
$ brew update
$ brew upgrade
$ brew cleanup
$ brew cask install --force $(brew cask list)
$ brew cask cleanup
$

If you have changed permissions on folder /usr/local while installing Homebrew previously on El Capitan 10.11, you might want to run the following command to revert that change whereas new Homebrew doesn't need special permission over this folder:

$
$ sudo chown root:wheel /usr/local
$


Friday, October 3, 2014

Installing Composer on OS X Mavericks with XAMPP for Mac installed

Composer is a popular tool for the dependency management in PHP. It lets you declare dependent libraries for each particular project.

Let's have a quick look on what have installed so far on the development machine:

OS X Mavericks
XAMPP for Mac installed and configured properly (A running instance)
Hombrew installed and configured (Try brew doctor to tackle any problem before you start)

Steps as follows:

Assuming default installation path of XAMPP for Mac package installed as usual, please change into the directory where PHP executable resides:
$ cd /Applications/XAMPP/bin/


Check the version of PHP:

$ php --version
PHP 5.4.30 (cli) (built: Jul 29 2014 23:43:29) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies

Now we know PHP version is 5.4. Let's remember this for use in next couple of steps.

If you try to install Composer with brew command now, you may end up with an error like this:
composer: Missing PHP53, PHP54, PHP55 or PHP56 from homebrew-php. Please install one of them before continuing
Error: An unsatisfied requirement failed this build.

The likely cause is that we are using PHP within XAMPP package whereas brew cannot detect its presence without installing its own PHP engine.
Supposing XAMPP package is installed properly, we can simply add the path /Applications/XAMPP/bin/ to $PATH environment variable to the end of the file ~/.bash_profile . If it doesn't work then another to get around this would be installing a new version of PHP package using brew command.

[OPTIONAL] So which version of brew's PHP engine to install? It's better match the version of PHP within XAMPP, i.e., 5.5.

[OPTIONAL] Let's install PHP54 package by using brew command:
$ brew install php55

Once finished, start installing Composer with brew commands like these:
$brew update;brew tap homebrew/dupes;brew tap homebrew/php;brew install composer

It includes the actions of updating and tapping the right repository for downloading Composer's source.

When brew's package for Composer is installed successfully, we can carry out next step to create composer.phar file within XAMPP's bin directory.

$ sudo php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"

We must execute the command as root privilege to avoid permission denied error.

When done, we can try composer command within /Applications/XAMPP/bin/ directory.
$ php composer.phar
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 1e4229e22aefe50582734964d027fc1bfec16b1d 2014-10-02 11:34:17

Usage:
  [options] command [arguments]...


Then it should be ready for us to checkout new dependent packages within a new or existing PHP project directory.