50 lines
951 B
Bash
50 lines
951 B
Bash
#!/bin/bash
|
|
|
|
if [ $# -ne 2 ]; then
|
|
echo "wrong argument count"
|
|
fi
|
|
|
|
# Set variables
|
|
homedir="$1"
|
|
dotfilesdir="$2"
|
|
|
|
# Change directory to home dir
|
|
cd "$homedir"
|
|
|
|
# Define a function that create a link unless it already exists
|
|
makelink() {
|
|
test $# -eq 2 || { echo "makelink: invalid function call"; exit 1; }
|
|
|
|
if [ ! -e "$1" ]; then
|
|
echo "can't create link '$2': target '$1' does not exist"
|
|
return
|
|
fi
|
|
|
|
if [ ! -e "$2" ]; then
|
|
# Create link
|
|
ln -sr "$1" "$2"
|
|
elif [ ! -L "$2" ]; then
|
|
# A file with the same name exists and it's not a link
|
|
# -> warn user!
|
|
echo "can't create link '$2': file already exists"
|
|
fi
|
|
}
|
|
|
|
makelink_simple() {
|
|
test $# -eq 1 || { echo "makelink_simple: invalid function call"; exit 1; }
|
|
|
|
makelink "$dotfilesdir/$1" "$1"
|
|
}
|
|
|
|
# -- CREATE THE LINKS HERE --
|
|
|
|
# ~/bin
|
|
makelink "$dotfiles/bin/" bin
|
|
|
|
# dotfiles
|
|
makelink_simple .profile
|
|
makelink_simple .bashrc
|
|
makelink_simple .bash_profile
|
|
makelink_simple .bash_logout
|
|
|