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

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

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

parallel_pids=''

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

parallel_wait() {
    # 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)
    # 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 -e 'p' -e 's:^'"$rice_dir"':'"$dest_dir"':' |
        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"

################################################################################
# sync install
################################################################################

echo '---------------------------- SYNC FILE LINKS  ----------------------------'
mkdir -pv "$CLOUT_SYNC_PATH"
ln -svf "$CLOUT_SYNC_PATH/newsboat/urls" "$XDG_CONFIG_HOME/newsboat/urls"
ln -svf "$CLOUT_SYNC_PATH/qutebrowser/bookmarks/urls" "$XDG_CONFIG_HOME/qutebrowser/bookmarks/urls"

################################################################################
# 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"

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"
vim -c "PackerInstall" -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

[ $(uname) = Darwin ] && exit

###############################################################################
# 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' ]
    crontab crontab/user.crontab
fi

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

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

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