aboutsummaryrefslogtreecommitdiff
path: root/deploy.sh
blob: f3d5e157e348b6aaf31f4b7131aa97f9fd341448 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash

set -eo pipefail

mkdir -p dotfiles-backup

if command -v unzip > /dev/null; then
    UNZIPCMD="unzip"
fi
if command -v vim > /dev/null; then
    VIMCMD="vim"
fi
if command -v wget > /dev/null; then
    DLCMD="wget -O"
elif command -v curl > /dev/null; then
    DLCMD="curl -Lo"
fi
if [ -z "$UNZIPCMD" ] || [ -z "$VIMCMD" ] || [ -z "$DLCMD" ]; then
    echo "requires 'unzip', 'vim', and either 'wget' or 'curl'"
    exit 1
fi

# XDG layout
xcache="${XDG_CACHE_HOME:-${HOME}/.cache}"
xdata="${XDG_DATA_HOME:-${HOME}/.local/share}"
xconfig="${XDG_CONFIG_HOME:-${HOME}/.config}"

userbin="$HOME/.local/bin"

mkdir -p "$xcache" "$xdata" "$xconfig" "$userbin"

function link {
    src="$1"
    dest="$2"
    if [ -e "$dest" ] && [ ! -L "$dest" ]; then
        mv "$dest" "../dotfiles-backup/."
    fi
    if [ ! -e "$dest" ]; then
        ln -sf "$src" "$dest"
    fi
}

# deploy to XDG dirs
mkdir -p "${xcache}/zsh"
mkdir -p "${xdata}/zsh"
cd config
for d in *
do
    link "$(pwd)/$d" "${xconfig}/$d"
done
cd ..

# deploy to home
cd home
for f in *
do
    link "$(pwd)/${f}" "$HOME/.${f}"
done
cd ..

# deploy to user binaries
mkdir -p "$userbin"
cd bin
for f in *
do
    link "$(pwd)/${f}" "$userbin/${f}"
done
cd ..

# install vim-plug
if [ ! -e "$HOME/.vim/autoload/plug.vim" ]; then
    mkdir -p "$HOME/.vim/autoload"
    $DLCMD "$HOME/.vim/autoload/plug.vim" \
        https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
    $VIMCMD +PlugInstall +qall
fi

# create local files
if [ ! -e "$HOME/.config/zsh/00-local.zsh" ]; then
    cp local/local.zsh config/zsh/00-local.zsh
fi
if [ ! -e "$HOME/.config/git/config-local" ]; then
    cp local/gitconfig-local config/git/config-local
fi
dconfig="$xconfig/duplicity"
mkdir -p "$dconfig"
if [ ! -e "$dconfig/config" ]; then
    cp local/duplicity-config "$dconfig/config"
fi
if [ ! -e "$dconfig/excludes" ]; then
    cp local/duplicity-excludes "$dconfig/excludes"
fi

# download nerdfonts
if command -v fc-cache > /dev/null; then
    new_font=0
    function get_font {
        local font_name="$1"
        local font_url="$2"
        shift 2
        local font_dir="$HOME/.local/share/fonts/$font_name"
        mkdir -p "$font_dir"
        if [ ! -d "$font_dir" ] || [ -z "$(ls -A "$font_dir" 2> /dev/null)" ]; then
            $DLCMD "$font_dir/font.zip" "$font_url"
            $UNZIPCMD "$font_dir/font.zip" "$@" -d "$font_dir"
            rm "$font_dir/font.zip"
            new_font=1
        fi
    }
    get_font sourcecodepro-nerd \
        https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/SourceCodePro.zip \
        "Sauce Code Pro Medium Nerd Font Complete.ttf" \
        "Sauce Code Pro Bold Nerd Font Complete.ttf" \
        "Sauce Code Pro Medium Italic Nerd Font Complete.ttf" \
        "Sauce Code Pro Bold Italic Nerd Font Complete.ttf"
    get_font jetbrainsmono-nerd \
        https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/JetBrainsMono.zip \
    "JetBrains Mono Regular Nerd Font Complete Mono.ttf" \
    "JetBrains Mono Italic Nerd Font Complete Mono.ttf" \
    "JetBrains Mono Bold Nerd Font Complete Mono.ttf" \
    "JetBrains Mono Bold Italic Nerd Font Complete Mono.ttf" \
    "JetBrains Mono Regular Nerd Font Complete.ttf" \
    "JetBrains Mono Italic Nerd Font Complete.ttf" \
    "JetBrains Mono Bold Nerd Font Complete.ttf" \
    "JetBrains Mono Bold Italic Nerd Font Complete.ttf"
    if [ "$new_font" = "1" ]; then
        echo "Hint: Run 'fc-cache -v' to rebuild your font cache"
    fi
fi