Environment Variables (without admin privileges) for Command Line

video_2016-12-23_145357
Standard

If you don’t have Admin rights to a machine and you need to add environment variables it can be a real pain in the neck to have to get Ops every time to do it. You can update the system PATH in a batch file, but it can be a hassle to have to source this file every time you open a command terminal. The following process allows you to automatically source any environment variables every time you open a terminal.

  1. Start the command prompt and ‘pin’ it to the taskbar.
  2. Right-click on it, edit properties, and append -cmd /K env.bat to the Target property.

2016-12-23_121217

%windir%\system32\cmd.exe -cmd /K env.bat

3. Create a batch file called env.bat and place it in your home folder. This file should include any environment variables you need set. For example:

@echo off

if "%ANT_HOME%"=="" (
 echo Setting environment...
) else (
 echo Environment already defined.
 exit /b
)

set ANT_HOME=C:\apps\apache-ant-1.9.6
set APACHE_HOME=C:\opt\apache2
set GIT_HOME=C:\Users\philip.murphy\AppData\Local\Programs\Git
set JAVA_HOME=C:\apps\jdk8u66
set JBOSS_HOME=C:\opt\jboss
set M2_HOME=C:\apps\apache-maven-3.0.3
set ONE_DRIVE="C:\Users\philip.murphy\OneDrive - Globoforce"
set ADB_PATH=C:\apps\android-sdk-windows\platform-tools
set CATALINA_HOME=C:\opt\tomcat
set ORACLE_HOME=C:\oraclexe\app\oracle\product\11.2.0\server
set ORACLE_SID=XE
set TNS_ADMIN=C:\oraclexe\app\oracle\product\11.2.0\server\network\ADMIN
set FFMPEG_HOME=C:\apps\ffmpeg
set SEVEN_ZIP="C:\Program Files\7-Zip"
set CHROME_HOME="C:\Program Files (x86)\Google\Chrome\Application"
set IMAGEMAGICK=C:\apps\imagemagick

set path=%ONE_DRIVE%\bin;%ANT_HOME%\bin;%APACHE_HOME%\bin;%GIT_HOME%\bin;%GIT_HOME%\usr\bin;%GIT_HOME%\mingw64\bin;%JAVA_HOME%\bin;%M2_HOME%\bin;C:\Ruby187\bin;C:\Python27;%ADB_PATH%;%FFMPEG_HOME%\bin;%SEVEN_ZIP%;%CHROME_HOME%;c:\apps;%IMAGEMAGICK%;%path%

Set and forget – you’re done.

Deploy from Windows to Linux using SSH

ssh
Standard

I generally develop on Windows and deploy to Linux servers where our Apache and Tomcat instances are running. The following single command is a bit of magic. It does the following:

  1. Tars up all the files for mywebapp
  2. Transfers them using ssh
  3. Extracts them to the correct location and as the correct user (builduser in this example) on the deployment machine.
tar -C c:/opt/apache2/htdocs/mywebapp -cvf - . | ssh philip.murphy@my-build-server.com "sudo -u builduser tar -C /var/www/html/mywebapp -xmf -"

GIT Commit Message Hook on Windows (without Admin Rights)

2016-05-30_231020
Standard

 

To get GIT to prevent a commit unless your commit message contains a certain format you need to use a GIT commit-msg hook.

To create the hook you need to create a hooks folder under your .git folder within each GIT repository. Within the .git/hooks folder place your commit-msg file.

The following commit-msg script makes sure that your commit message must start with the text “[Mobile]” – maybe Mobile¬†is your team name.

#!/bin/sh
commit_regex='^\[Mobile\]'

error_msg="Aborting commit. Your commit message is missing '[Mobile]' at beginning of comment."

if ! grep -iqE "$commit_regex" "$1"; then
 echo "$error_msg" >&2
 exit 1
fi

To have one central commit-msg file create a junction (if you don’t have Window’s Administrator Rights) or a symlink if you prefer, but you’ll need admin rights.

For example, if you have a repository called my-app and your central hooks folder is stored in your “OneDrive for Business” folder.

cd C:\Users\philip.murphy\Documentes\my-app\.git\
mklink /J /D hooks "C:\Users\philip.murphy\OneDrive for Business\hooks"

You should do this for each repository. Now when you update the central commit-msg file, all repositories will reflect your new commit message hook rules.

BTW, if you want to initially populate your commit comment with some text:

git config --global commit.template "C:\Users\philip.murphy\OneDrive for Business\committemplate.txt"

It may contain the text that you want to initially populate the comment message with:

[MOBILE]

Note for SourceTree users. The commit-msg hook works well, but the commit template doesn’t.

2016-05-30_231747

Example output of commit being prevented as comment doesn’t begin with [Mobile].