summaryrefslogtreecommitdiff
path: root/bin/setup.sh
blob: 6d1620d58c896203ea9f4a1d27e6c9c6b82baf20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash

red='\e[0;31m'
green='\e[0;32m'
none='\e[0m'

cd
# Check that things are in their right places.
if [[ ! -f dotfiles/bin/setup.sh ]]; then
 echo -e "${red}[FAIL]${none} expected to find myself"
 exit 1
fi

# Creates a symlink with target $1 at location $2.
# Does nothing and prints an error message if $2 exists and is not a symlink.
create_symlink() {
  if [[ -e "$2" && ! -h "$2" ]]; then
    echo -e "${red}[WARNING]${none} '$2' exists and is not a symlink. Skipped."
  else
    if ln -sf "$1" "$2"; then
      echo -e "${green}[OK]${none} '$2' → '$1'"
    else
      echo -e "${red}[WARNING] Could not create '$2'"
    fi
  fi
}

create_symlink dotfiles/gitconfig .gitconfig