aboutsummaryrefslogtreecommitdiff
path: root/install
blob: bbcf8ac18375d79b527d68558f629edcfe1b4c82 (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
#!/bin/sh

# zprofile isn't installed yet on new machine
# shellcheck source=/dev/null
. config/zsh/.zshenv

if [ "$USER" = 'root' ]
then
    crontab crontab/root.crontab
    pkgfile --update
    exit
fi

parallel_pids=''

parallel_start() {
    "$@" & parallel_pids="$parallel_pids $!"
}

parallel_wait() {
    echo 'Waiting for processes'
    # shellcheck disable=SC2086
    wait $parallel_pids
    parallel_pids=''
}

mkdir -pv "$XDG_CONFIG_HOME"
mkdir -pv "$XDG_DATA_HOME"
mkdir -pv "$XDG_CACHE_HOME"
# xmonad uses ~/.xmonad if those directories don't already exists
if [ "$(uname)" = Linux ]
then
    mkdir -pv "$XMONAD_CONFIG_HOME"
    mkdir -pv "$XMONAD_DATA_HOME"
    mkdir -pv "$XMONAD_CACHE_HOME"
fi

echo '---------------------------- CONFIG FILE LINKS ---------------------------'

link_home_files() {
    rice_dir="$1"
    dest_dir="$2"
    paths=$(mktemp)
    platform="$(uname | tr '[:upper:]' '[:lower:]')"
    other_platform="$([ "$platform" = 'linux' ] && echo darwin || echo linux)"
    # generate a file with the file path in this repo and the link for the real path
    # each line is in the format: TARGET LINKNAME
    find "$rice_dir" -type f |
        sed "/\.$other_platform/ d" |
        sed -e 'p' -e "s:^$rice_dir:$dest_dir:" -e "s/\.$platform//" |
        awk '{ if (NR % 2 == 1) { print "'"$(pwd)"'" "/" $0 } else print }' |
        xargs -L 2 > "$paths"
    < "$paths" cut -d ' ' -f 2 | xargs -L 1 dirname | xargs -L 1 mkdir -pv
    < "$paths" xargs -L 1 ln -svf
}

link_home_files 'config' "$XDG_CONFIG_HOME"
link_home_files 'local'  "$HOME/.local"

# ln -svf "$(pwd)/config/zsh/zprofile" "$HOME/.zprofile"


################################################################################
# vim plug
################################################################################

echo '---------------------------- INSTALL VIM PLUG ----------------------------'
PLUGFILE="$XDG_DATA_HOME/vim/autoload/plug.vim"
PLUGURL='https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
[ ! -f "$PLUGFILE" ] && curl -fLo "$PLUGFILE" --create-dirs "$PLUGURL"
vim -c 'PlugInstall' -c 'qa'

echo '---------------------------- INSTALL NVIM PACKER -------------------------'
PACKERDIR="$XDG_DATA_HOME/nvim/site/pack/packer/start/packer.nvim"
PACKERURL='https://github.com/wbthomason/packer.nvim'
[ ! -d "$PACKERDIR" ] && git clone --depth 1 "$PACKERURL" "$PACKERDIR"
nvim -c 'PackerInstall' -c 'PackerSync' -c "qa"

###############################################################################
# zsh pluggins
###############################################################################

echo '---------------------------- INSTALL ZSH PLUGGINS ------------------------'
update_zsh_plugin()
{
    url="$1"
    path="$XDG_DATA_HOME/zsh/$(basename "$url")"
    if [ ! -d "$path" ] || [ -z "$(ls -A "$path")" ]
    then git clone "$url" "$path"
    else git -C "$path" pull
    fi
}

mkdir -p "$XDG_DATA_HOME/zsh"
parallel_start update_zsh_plugin 'https://github.com/sindresorhus/pure'
parallel_start update_zsh_plugin 'https://github.com/zsh-users/zsh-syntax-highlighting'
parallel_start update_zsh_plugin 'https://github.com/MichaelAquilina/zsh-you-should-use'
parallel_wait

if [ "$(uname)" = Darwin ]
then
    # xdg vars not defined for qutebrowser
    ln -svfF "$XDG_CONFIG_HOME/qutebrowser" "$HOME/.qutebrowser"
    exit
fi

###############################################################################
# fish pluggins
###############################################################################

fish -c 'fisher install pure-fish/pure'
fish -c 'fisher install PatrickF1/fzf.fish'
fish -c 'fisher install decors/fish-colored-man'

###############################################################################
# Linux specific
###############################################################################

###############################################################################
# crontab
###############################################################################

echo '---------------------------- INSTALL CRONTAB -----------------------------'

if [ "$(cat /etc/hostname)" = 'charleslaptopcarbon' ]
then
    cat crontab/user.crontab crontab/laptop.crontab | crontab -
elif [ "$(cat /etc/hostname)" = 'cacharle-main' ]
then
    crontab crontab/user.crontab
fi

echo 'INFO: Run this script as root if you want to install the root contab'

###############################################################################
# dictionaries
###############################################################################

# command is sdcv
echo '---------------------------- INSTALL DICTIONARY --------------------------'
install_dict() {
    url="$1"
    archive_name="$(basename "$url")"
    dir_name="${archive_name%%.tar.bz2}"
    install_dir="${STARDICT_DATA_DIR:-/usr/share/stardict}/dic"
    [ ! -d "$install_dir" ]  && mkdir -pv "$install_dir"
    [ -d "$install_dir/$dir_name" ] && return
    echo "----------------------------- Installing dictionary: $dir_name"
    curl "$url" | tar -xjvf - -C "$install_dir" &
}
# other dictionaries at: http://download.huzheng.org/
#parallel_start install_dict 'http://download.huzheng.org/dict.org/stardict-dictd_www.dict.org_gcide-2.4.2.tar.bz2'  # english
#parallel_start install_dict 'http://download.huzheng.org/fr/stardict-xmlittre-2.4.2.tar.bz2'                        # french
#parallel_wait