aboutsummaryrefslogtreecommitdiff
path: root/install.sh
blob: f70d9d24dcfc54a9a848cf4b2127d64ce82d6233 (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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#!/bin/bash
set -efu

progpath="$0"
prog="${prog:-${0##*/}}"
prog_version="0.0.1"

pcmd=

show_help() {
    cat <<EOF
Usage: $prog [ options ]

Options:

  -v, --verbose          print additional information while running;

  -V, --version          show version and exit;

  -q, --quiet            toggle quiet (non-interactive) mode;

  -h, --help             print this page and exit.

EOF
    exit 0
}

show_usage() {
    echo
    show_help | head -1
    echo "Use \`$prog --help\` for more information."
}

print_version()
{
    cat <<EOF
$prog version $prog_version
EOF
}

write_error() {
    printf "$@" >&2
}

info() {
    [ -z "$verbose" ] || write_error "$@"
}

fatal() {
    write_error "$@"
    exit 1
}

realpath() {
  local realpath="$1"
  if [ -z "$realpath" ]; then
    info "realpath() required <path>\n"
    return
  fi

  readlink -f "$realpath"
}

install_dotfile() {
  if [ "$#" -ne 3 ]; then
    fatal "install_dotfiles() required <dependencies> <srcpath> <dstpath>\n\
e.g. install_dotfiles \"bash xterm\" \"/etc/profile\" \"\$HOME/.bashrc\"\n"
  fi

  local apps="$1"
  local srcpath="$2"
  local dstpath="$3"

  local dst=`basename "$dstpath"`
  local src=`basename "$srcpath"`

  local ret=0

  if [ -n "${apps}" ]; then
    for app in $apps; do
      command -v "$app" >/dev/null 2>&1 || ret=$?
      if [ $ret -ne 0 ]; then
        info ">> %s is not installed. Skipping %s...\n" \
                                                      "$app" "$srcpath"
        return
      fi
    done
  fi

  if [ -e "$srcpath" ]; then
    if [ -L $dstpath ]; then
      local curpath=`realpath $dstpath`
      if [ "$curpath" == "$srcpath" ]; then
        info "   %s is already installed.\n" "$src"
        return
      fi
    fi

    while true; do
      local yn=y

      if [ $quiet -eq 0 ]; then
        printf "Do you wish to install $src? [Y/n]: "

        read -n1 yn
        if [ "x$yn" == 'x' ]; then
          yn=y
        fi

        printf '\n'
      fi

      case $yn in
        [Yy]* )
           if [ -e "$dstpath" ] && [ ! -L "$dstpath" ]; then
              mv "$dstpath" "$dstpath.bak"
              info ">> %s has been backuped as %s.bak\n" "$dstpath" "$dstpath"
           fi

           mkdir -p `dirname "$dstpath"`
           ln -sf "$srcpath" "$dstpath"
           info ">> %s has been installed as link for %s\n" "$dst" "$srcpath"
           break;;
        [Nn]* )
        	return;;
        * ) echo "Please answer y or n.";;
      esac
    done

  fi
}

orig_opts="$@"
opts=`getopt -n $prog -o v,V,q,h -l verbose,version,quiet,help -- "$@"` ||
     ( ret=$?; show_usage; exit $ret ) >&2

eval set -- "$opts"

verbose=-v;
quiet=0;

while :; do
    case "$1" in
      -v|--verbose)
          #[ -z "$verbose" ] || set -x
          verbose=-v
          ;;
      -V|--version) print_version; exit 0;;
      -h|--help) show_help;;
      -q|--quiet) quiet=1;;
      --) shift; break;;
      *)
          fatal 'Unrecognized option: %s\n' "$1"
          ;;
    esac
    shift
done

scriptdir=`realpath "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"`
dotfilesdir=`realpath "$HOME/.dotfiles"`

if [ "$scriptdir" != "$dotfilesdir" ]; then
  fatal 'ERROR: install.sh must be located in %s!\n' +
        'Please move "%s" to "%s" and try again.\n'
        "$dotfilesdir" "$scriptdir" "$dotfilesdir"
fi

info "Installing dotfiles...\n"

install_dotfile "nvim"                                            \
                "$dotfilesdir/vimrc"                              \
                "$HOME/.config/nvim/init.vim"

install_dotfile "waybar"                                          \
                "$dotfilesdir/waybar-config"                      \
                "$HOME/.config/waybar/config"

install_dotfile "waybar"                                          \
                "$dotfilesdir/waybar-style"                       \
                "$HOME/.config/waybar/style.css"

install_dotfile "i3status"                                        \
                "$dotfilesdir/i3status-config"                    \
                "$HOME/.config/i3status/config"

# Don't create "Desktop" and "Downloads" directories
install_dotfile ""                                                \
                "$dotfilesdir/user-dirs.dirs"                     \
                "$HOME/.config/user-dirs.dirs"

install_dotfile "alacritty"                                       \
                "$dotfilesdir/alacritty.yml"                      \
                "$HOME/.config/alacritty/alacritty.yml"

install_dotfile "sway"                                            \
                "$dotfilesdir/sway-config"                        \
                "$HOME/.config/sway/config"

install_dotfile ""                                                \
                "$dotfilesdir/xkb-birman-ru"                      \
                "$HOME/.config/xkb/symbols/birman-ru"

install_dotfile ""                                                \
                "$dotfilesdir/xkb-birman-us"                      \
                "$HOME/.config/xkb/symbols/birman-us"

install_dotfile "htop"                                            \
                "$dotfilesdir/htoprc"                             \
                "$HOME/.config/htop/htoprc"

install_dotfile "foot"                                            \
                "$dotfilesdir/foot.ini"                           \
                "$HOME/.config/foot/foot.ini"

install_dotfile "dunst"                                           \
                "$dotfilesdir/dunstrc"                            \
                "$HOME/.config/dunstrc"

install_dotfile "bash"                                            \
                "$dotfilesdir/bashrc"                             \
                "$HOME/.bashrc"

install_dotfile "bash"                                            \
                "$dotfilesdir/bash_profile"                       \
                "$HOME/.bash_profile"

install_dotfile "bash"                                            \
                "$dotfilesdir/bash_history"                       \
                "$HOME/.bashrc.d/01-bash_history"

install_dotfile "bash"                                            \
                "$dotfilesdir/bash_env"                           \
                "$HOME/.bash_profile.d/02-bash_env"

install_dotfile "bash"                                            \
                "$dotfilesdir/bash_term"                          \
                "$HOME/.bashrc.d/02-bash_term"

install_dotfile "bash"                                            \
                "$dotfilesdir/bash_aliases"                       \
                "$HOME/.bashrc.d/02-bash_aliases"

install_dotfile "bash"                                            \
                "/etc/bash_completion"                            \
                "$HOME/.bashrc.d/01-bash_completion"

install_dotfile "bash"                                            \
                "/usr/share/bash-completion/bash_completion"      \
                "$HOME/.bashrc.d/01-bash_completion"

install_dotfile "bash sway"                                       \
                "$dotfilesdir/bash_wayland"                       \
                "$HOME/.bash_profile.d/99-wayland"

install_dotfile "sway mako"                                       \
                "$dotfilesdir/sway-mako"                          \
                "$HOME/.swayrc.d/03-mako"

install_dotfile "sway mako notify-send inotifywait neomutt"       \
                "$dotfilesdir/xinitrc-mailnotify"                 \
                "$HOME/.swayrc.d/00-mailnotify"

install_dotfile "bash"                                            \
                "/usr/share/doc/pkgfile/command-not-found.bash"   \
                "$HOME/.bashrc.d/02-command-not-found"

install_dotfile "bash dircolors"                                  \
                "$dotfilesdir/bash_dircolors"                     \
                "$HOME/.bash_profile.d/02-bash_dircolors"

install_dotfile "bash"                                            \
                "$dotfilesdir/bash_open"                          \
                "$HOME/.bashrc.d/04-bash_open"

install_dotfile "bash"                                            \
                "$dotfilesdir/inputrc"                            \
                "$HOME/.inputrc"

install_dotfile "tmux"                                            \
                "$dotfilesdir/tmux.conf"                          \
                "$HOME/.tmux.conf"

install_dotfile "Xorg"                                            \
                "$dotfilesdir/Xdefaults"                          \
                "$HOME/.Xdefaults"

install_dotfile "Xwayland"                                        \
                "$dotfilesdir/Xdefaults"                          \
                "$HOME/.Xdefaults"

install_dotfile "git"                                             \
                "$dotfilesdir/gitconfig"                          \
                "$HOME/.gitconfig"

install_dotfile "fc-cache"                                        \
                "$dotfilesdir/fonts"                              \
                "$HOME/.local/share/fonts"

install_dotfile "fc-cache"                                        \
                "$dotfilesdir/fonts.conf"                         \
                "$HOME/.fonts.conf"

install_dotfile "vim"                                             \
                "$dotfilesdir/vimrc"                              \
                "$HOME/.vimrc"

install_dotfile "i3"                                              \
                "$dotfilesdir/i3-config"                          \
                "$HOME/.i3/config"

install_dotfile "i3"                                              \
                "$dotfilesdir/xinitrc-i3"                         \
                "$HOME/.xinitrc"

install_dotfile "setxkbmap"                                       \
                "$dotfilesdir/xinitrc-xkbmap"                     \
                "$HOME/.xinitrc.d/00-xkbmap"

install_dotfile "dunst"                                           \
                "$dotfilesdir/xinitrc-dunst"                      \
                "$HOME/.xinitrc.d/03-dunst"

install_dotfile "dunst notify-send inotifywait mutt"              \
                "$dotfilesdir/xinitrc-mailnotify"                 \
                "$HOME/.xinitrc.d/00-mailnotify"

install_dotfile "xautolock i3lock"                                \
                "$dotfilesdir/xinitrc-xautolock"                  \
                "$HOME/.xinitrc.d/00-xautolock"

install_dotfile "feh"                                             \
                "$dotfilesdir/xinitrc-wallpaper"                  \
                "$HOME/.xinitrc.d/01-wallpaper"

install_dotfile "i3lock"                                          \
                "$dotfilesdir/lock"                               \
                "$HOME/.local/bin/lock"

install_dotfile "swaylock"                                        \
                "$dotfilesdir/sway-lock"                          \
                "$HOME/.local/bin/lock"

info "Installation completed successfully\n"