-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.sh
executable file
·156 lines (138 loc) · 3.63 KB
/
deploy.sh
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
#!/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
ln -snf "$link_src" "$link_dest"
}
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 "$HOME/.config/zsh/00-local.zsh"
fi
if [ ! -e "$HOME/.config/git/config-local" ]; then
cp local/gitconfig-local "$HOME/.config/git/config-local"
fi
if [ "$uname" = "linux" ]; then
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 custom fonts
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
}
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