Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Friday, 15 February 2019

Pivotal Cloud Foundry - "access denied" for custom buildpacks written on Windows

Writing custom buildpacks on Windows can lead to some unnecessary frustrations. Today I would like to cover one of those frustrations: buildpack scripts not being executable on PCF. Creating buildpack scripts on windows can lead to cryptic errors during buildpack execution like "access denied" or "permission denied".

The problem is caused by the fact that any new file created on Windows is automatically set to mode 644 aka rw-r--r-- (linux standards), but at the same type is automatically executable (-rwxr-xr-x) by windows standards.

Result? Listing your buildpack scripts using git bash on windows you see:

drwxr-xr-x 1 Piotr_Justyna 1049089    0 Feb 13 20:46 ./
drwxr-xr-x 1 Piotr_Justyna 1049089    0 Feb 13 20:44 ../
-rwxr-xr-x 1 Piotr_Justyna 1049089  137 Feb 13 20:44 detect*
-rwxr-xr-x 1 Piotr_Justyna 1049089   40 Feb 13 20:46 finalize*
-rwxr-xr-x 1 Piotr_Justyna 1049089  102 Feb 13 20:44 release*
-rwxr-xr-x 1 Piotr_Justyna 1049089  135 Feb 13 20:46 supply*

While in fact all of them are by default mode 644 (rw-r--r--). Trying to execute those scripts on PCF will result in "access denied" errors. It is pretty annoying, so I prepared a little cheat sheet for those of you who work with custom buildpacks, windows and git bash:

Executable files:

  • DON'T:
    chmod +x file
    
  • DO:
    git update-index --chmod=+x file
    

List files with their access modes:

  • DON'T:
    ls -la
    
  • DO:
    git ls-files -s
    

Copying files:

  • DON'T:
    cp file file_copy (that defaults the access mode of the copy to 644 even if the file is e.g. 755)
    
  • DO:
    cp file file_copy *and then* git update-index --chmod=+x file_copy
    

chmod-calculator.com is a very handy tool, especially for those who don't work with linux too often.

Sunday, 14 October 2018

Linux: permanently update your PATH.

To permanent change your PATH:

  1. Locate your profile file. This is your user-specific initialization file for your shell and you can find it in the root of your home directory (~). It can be named slightly differently depending on your distribution and the type of shell you are using (.bash_profile, .zprofile, etc.), but it's really not easy to miss. In my case (Fedora & bash), my profile file is named .bash_profile.
  2. Make desired changes to your PATH. There's a good chance the file already has some PATH changes, so just append yours.

    # .bash_profile
    
    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
     . ~/.bashrc
    fi
    
    # User specific environment and startup programs
    
    PATH=$PATH:$HOME/.local/bin:$HOME/bin
    PATH=$PATH:~/Documents/rebar3
    
    export PATH
    

  3. Now for the changes to take effect you can either simply log out and log back in or run:

    source ~/.bash_profile
    

    That will basically execute the command defined in ~/.bash_profile using your current shell.
And that's it.

Thank you and happy hacking!

Piotr