summaryrefslogtreecommitdiff
path: root/install.sh
blob: f679a42dc9d1d3811490a8857488b74b9df01f5d (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash

home=/home/urbain
dir=~/dotfiles
olddir=~/dotfiles_old

install_dotfiles=0
install_repos=0
install_aux=0

while [[ $# > 0 ]]
do
    key="$1"
    echo $key
    case $key in
        -d|--dotfiles)
            install_dotfiles=1
            ;;
        -r|--repositories)
            install_repos=1
            ;;
        -l|--lib)
            install_aux=1
            ;;
        *)
            ;;
    esac
    shift
done

if [[ "$install_dotfiles" -eq "1"  ]]; then

    echo -e "\n*** Installing dotfiles ***"


    rm -rf $olddir
    mkdir -p $olddir

    listFiles=`ls --ignore="make" --ignore="tex" --ignore="README.md"`

    cd $dir
    for file in $listFiles; do
        if [ -e ~/.$file ]; then
            mv ~/.$file $olddir
            printf '~/.%-15s exists. ' $file
            echo -n "Moving it to $olddir. "
        fi
        ln -s $dir/$file ~/.$file
        echo "(Re)-creating symbolic link of $file."
    done

    cd $dir
    mkdir -p nvim/vimundo
    mkdir -p mutt/temp
    mkdir -p mutt/cache
    mkdir -p mutt/cache/bodies
fi

if [[ "$install_repos" -eq "1" ]]; then
    echo -e "\n *** Updating/Creating git repositories ***"

    declare -A repos
    repos[altercation]=$home/.solarized/mutt-colors-solarized
    repos[Anthony25]=$home/.solarized/gnome-terminal-colors-solarized
    repos[seebi]=$home/.solarized/dircolors-solarized
    repos[gmarik]=$home/.vim/bundle/vundle
    repos[junegunn]=$home/.nvim/vim-plug
    repos[tmux-plugins]=$home/.tmux/plugins/tpm
    repos[uvaes]=$home/git/fuzzy-zsh-marks
    repos[alols]=$home/xcape

    for author in "${!repos[@]}"; do
        thisDir=${repos[$author]}
        if [ ! -d $thisDir ]; then
            parentDir=`echo $thisDir | sed 's/\/[^\/]\+$//g'`
            githubDir=https://github.com/$author`echo $thisDir | sed 's/.*\(\/[^\/]\+\)$/\1/g'`
            mkdir -p $parentDir; cd $parentDir
            echo "Cloning $githubDir in $parentDir..."
            git clone -q $githubDir >> /dev/null
        else
            cd $thisDir
            echo "Updating git repository stored in $thisDir"
            git pull -q origin master >> /dev/null
            cat <(git log --pretty=format:"-- %h %s (%cr)" "ORIG_HEAD...HEAD")
        fi
    done

    # Installing vim-plug vim package manager
    cd $dir/nvim
    if [ -e autoload ]; then
        rm -rf autoload
    fi
    mkdir -p autoload
    ln -s $dir/nvim/vim-plug/plug.vim $dir/nvim/autoload/plug.vim
fi

# Creating auxiliary files
if [[ "$install_aux" -eq "1" ]]; then
    echo "Nothing to do for -a"
fi

echo -e "\n*** Installation successful *** \n"