Thursday, July 16, 2009

Set up Cygwin Day 0

Day 0 instructions for setting up Cygwin on a fresh install.

Save this as a file, chmod 777 it and run it - or just c&p the code below into Cygwin. Important: make sure to take into account the two pre-requisites listed.

#!/bin/bash

# Pre-requisite 1. I have made a Windows HOME variable.
# right click on My Computer > select Properties
#   > select Advanced tab > click Environment Variables
#   > add new personal variable: HOME = "C:\rob\cygHome" for example

# Pre-requisite 2. Edit "mkpasswd options" to run one or the other.


# Make sure $USERNAME and $HOME are ok.
if [ ! -e "$HOME" ] ; then
    echo "Warning: HOME ($HOME) does not exist."
    exit 2
fi
if [ -z "$USERNAME" ] ; then
    echo "Warning: USERNAME ($USERNAME) is empty."
    exit 2
fi

# It is annoying always typing /cgydrive/
mount -s --change-cygdrive-prefix /

# Delete default home dir and replace as a link to HOME.
if [ -e /home/$USERNAME ] ; then
    rm -rf /home/$USERNAME
fi
ln -s $HOME /home/$USERNAME

# mkpasswd options
# Run this if in a corporate environment with domains.
# mkpasswd -l -c > /etc/passwd; mkgroup -l -d > /etc/group
# Otherwise..
# mkpasswd -l > /etc/passwd; mkgroup  -l > /etc/group

# Update passwd file with new home dir.
cat /etc/passwd | sed "s|:/home/$USERNAME:|:$HOME:|" > /etc/passwd

# Make links between Windows and Cygwin homes.
if [ -e $HOME/winHome ] ; then
    rm $HOME/winHome
fi
if [ -e /c/Documents\ and\ Settings/$USERNAME/cygHome ] ; then
    rm /c/Documents\ and\ Settings/$USERNAME/cygHome
fi
ln -s /c/Documents\ and\ Settings/$USERNAME $HOME/winHome
ln -s $HOME /c/Documents\ and\ Settings/$USERNAME/cygHome

Install PuttyCyg.