summaryrefslogtreecommitdiffstats
path: root/godot.sh
blob: c335da0a6225d9217e76996d9b7c20c70fb6bece (plain) (blame)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash

# target dir of dotfiles (relative to $HOME)
TARGET=".dotfiles"

if [[ ! -e "${HOME}/${TARGET}" ]]; then
    if hash git > /dev/null 2>&1 ; then
	git clone git://git.animux.de/dotfiles.git "${HOME}/${TARGET}"
    else
	echo -e "\033[31m*\033[0m git is not available! This script will NOT work! Exiting..."
	exit
    fi
fi

pushd $HOME >/dev/null

# create new symlinks as specified in dotfiles mapping file:
grep -ve "^#" -e "^$" "${TARGET}/symlink-mapping" | \
    grep -E "[^ ]+ -> [^ ]+" | \
    awk -F " -> " '{ print $1 ; print "'$TARGET'/"$2; }' | \
    while read target ; read source ; do 
    	if [[ -e "${target}" && ! -f "${target}" && ! -L "${target}" ]];  then
	    echo "!!! ~/${target}/ exists and is not a symlink."
	else
	    # remove folder (only if they are symlinks) and regular files
	    # (all other actions could be dangerouse: e.g. lost private keys)
	    [[ -L "${target}" || -f "${target}" ]] && rm -f "${target}"
	    
	    # create ne symlink
	    ln -s "${source}" "${target}"
	fi
    done

popd >/dev/null

pushd "${HOME}/${TARGET}" >/dev/null
       
# update hash of current symlink mapping
if hash md5sum 2> /dev/null ; then
    md5sum "symlink-mapping" > "./management/symlinks.md5"
else
    if hash md5 2> /dev/null ; then
	md5 "symlink-mapping" > "./management/symlinks.md5"
    fi
fi
       
popd >/dev/null

echo
echo "All done. Happy hacking ;)"
echo