aboutsummaryrefslogtreecommitdiff
path: root/deploy.sh
blob: 4402a548c1252bba69e822fe8929c0afa5985ff7 (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash

set -eo pipefail

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

set -u

uname=$(uname | tr '[:upper:]' '[:lower:]')

# 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"
systemd="$xconfig/systemd/user"

mkdir -p "$xcache" "$xdata" "$xconfig" "$userbin"
mkdir -p "${xcache}/zsh"
mkdir -p "${xdata}/zsh"
if [ "linux" = "$uname" ]; then
  mkdir -p "$systemd"
fi

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

function deploy {
  deploy_src="$1"
  deploy_dest="$2"
  if [ -e "$deploy_src/all" ]; then
    cd "$deploy_src/all"
    for f in *
    do
        link "$(pwd)/${f}" "$deploy_dest/${f}"
    done
    cd ../..
  fi
  if [ -e "$deploy_src/$uname" ]; then
    cd "$deploy_src/$uname"
    for f in *
    do
        link "$(pwd)/${f}" "$deploy_dest/${f}"
    done
    cd ../..
  fi
}

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

# deploy to XDG dirs
deploy config "$xconfig"

# deploy user executables
deploy bin "$userbin"

# deploy systemd user units
deploy systemd "$systemd"

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

# deploy custom scripts to vim autoload
cd vim
for f in *
do
    link "$(pwd)/$f" "$autoload/$f"
done
cd ..

# 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
if [ "$uname" = "linux" ]; then
  if [ ! -e "$HOME/.config/kitty/local.conf" ]; then
      cp local/kitty-local.conf config/kitty/local.conf
  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
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

# download sway wallpaper
if command -v sway > /dev/null; then
  bg_dir="$xdata/backgrounds"
  if [ ! -d "$bg_dir" ] || [ -z "$(ls -A "$bg_dir" 2> /dev/null)" ]; then
    mkdir -p "$bg_dir"
  fi
  if [ ! -e "$bg_dir/sway.png" ]; then
    $DLCMD "$bg_dir/sway.png" "https://raw.githubusercontent.com/swaywm/sway/master/assets/Sway_Wallpaper_Blue_1366x768.png"
  fi
  if [ ! -e "$bg_dir/default" ]; then
    ln -s "$bg_dir/sway.png" "$bg_dir/default"
  fi
fi