forked from thonixx/.dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·210 lines (170 loc) · 5.64 KB
/
install.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
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
#!/bin/bash
################################################################################
##### CONFIG
# define directory where all files are stored
SCRIPT_NAME="${0##*/}"
SCRIPT_PWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# check for env var HOME or assume /home/USER
if [ "${HOME}" ]
then
home="${HOME}"
else
home="/home/${USER}"
fi
################################################################################
##### PREPARATIONS (backup, move, etc)
function backup(){
# backup config if file exists or unlink it
config="${1}"
path="${home}/${config}"
# do the magic
if [ -h "${path}" ]
then
# remove symlink
rm "${path}" && echo "${config}: symlink removed"
elif [ -e "${path}" ]
then
# backup config
mv "${path}" "${path}.bak" && echo "${config}: backup done"
else
# do nothing
echo "${config}: no previous config, continuing"
fi
}
backup .irssi
backup .zshrc
backup .tmux.conf
backup .vimrc
backup .vim
backup .ssh/config
backup .ssh/ssh.local
# backup .gitconfig # should be removed/backed up
backup .config/zathura
backup .gnupg/gpg-agent.conf
backup .gnupg/gpg.conf
backup .config/redshift
backup .xscreensaver
backup .xsessionrc
backup .Xresources
backup .themes/Ambiant-MATE-Dark
backup .icons/Ambiant-MATE
################################################################################
##### INSTALL CONFIGS
function putconfig(){
# arguments
source="${SCRIPT_PWD}/${1}"
target="${2}"
# link it
config="$(basename "${target}")"
test -e "${source}" && ln -s "${source}" "${target}" && echo "${config}: linked"
}
# irssi if installed
dpkg -l irssi 2> /dev/null | grep -qE '^ii' && {
putconfig irssi "${home}/.irssi"
}
# tmux
putconfig tmux/tmux.conf "${home}/.tmux.conf"
# link zshrc
putconfig zsh/zshrc "${home}/.zshrc"
# link vim
putconfig vim "${home}/.vim"
# link vimrc
putconfig vim/vimrc "${home}/.vimrc"
# link ssh config
putconfig ssh/ssh_default_config "${home}/.ssh/config"
putconfig ssh.local "${home}/.ssh/ssh.local"
# link zathura config
dpkg -l zathura 2> /dev/null | grep -qE '^ii' && {
putconfig zathura "${home}/.config/zathura"
}
# link gpg-agent config
putconfig gpg/gpg-agent.conf "${home}/.gnupg/gpg-agent.conf"
# create gpg.conf
echo
gpg -K
echo
read -p 'Provide your main GPG key id for gpg conf for hidden-ecrypt-to (format 0x...) for GPG config: ' gpg
echo "hidden-encrypt-to $gpg" > $HOME/.gnupg/gpg.conf
# link redshift config if installed
dpkg -l redshift 2> /dev/null | grep -qE '^ii' && {
putconfig redshift "${home}/.config/redshift"
}
# link xscreensaver config if installed
dpkg -l xscreensaver 2> /dev/null | grep -qE '^ii' && {
putconfig xscreensaver/xscreensaver "${home}/.xscreensaver"
putconfig xscreensaver/xsessionrc "${home}/.xsessionrc"
putconfig xscreensaver/Xresources "${home}/.Xresources"
}
# themes/icons
putconfig themes/Ambiant-MATE-Dark "${home}/.themes/Ambiant-MATE-Dark"
putconfig icons/Ambiant-MATE "${home}/.icons/Ambiant-MATE"
################################################################################
##### POST INSTALL STUFF
# modify tlib dir option
if [[ -z "$(grep -A 3 'tlib.git' .git/config | grep 'ignore = dirty')" ]]
then
sed -i.bak 's/tlib.git$/tlib.git\
ignore = dirty/g' .git/config && echo 'added ignore option to tlib submodule'
fi
# link dotfiles folder
if [ ! -d "${home}/.dotfiles" ]
then
ln -s "${SCRIPT_PWD}" "${home}/.dotfiles" && echo '.dotfiles folder linked'
fi
################################################################################
##### GIT INSTALL
# find out git version before doing git configuration
gitversion="$(git --version | grep -Eo '\ [1-9]\.[0-9]' | sed 's/\ //')"
# only append gpg encrypted content if not already there
if [[ -z "$(grep -s 'email' ~/.gitconfig)" ]]
then
# ask whether use personal or work settings
echo -n 'type "personal" or "work" and press enter: '
read env
# check for input
if [ -z "${env}" ]
then
echo .no input given. skipping gitconfig..
else
# copy type specific git config
case ${env} in
'work')
type='work'
;;
'personal'|*)
type='personal'
;;
esac
# add header
cat "${SCRIPT_PWD}/git/gitconfig_head" > "${home}/.gitconfig" && echo ..gitconfig head is now installed.
# decrypt and save it
gpg < "${SCRIPT_PWD}/git/gitconfig.${type}.gpg" >> "${home}/.gitconfig" && echo ".gitconfig ${type} appended"
# append gitconfig content
cat "${SCRIPT_PWD}/git/gitconfig_body" >> "${home}/.gitconfig" && echo ..gitconfig body appended.
fi
else
# config is there already, displaying a diff if there are changed settings from dotfiles repo
echo
echo 'Diffing git config file...'
# create a temporary git config for diffing
tempfile="$(mktemp)"
# add head & body
cat "${SCRIPT_PWD}/git/gitconfig_head" "${SCRIPT_PWD}/git/gitconfig_body" > ${tempfile}
# do the diff
vimdiff ${tempfile} "${home}/.gitconfig"
fi
# remove push setting for older git versions
if [ "$(echo "${gitversion}" | sed 's/\ //' | egrep '1\.[1-7]')" ] && [ -e "${home}/.gitconfig" ]
then
# push setting not supported, so removing it
sed -i '/\[push\]/d;/default\ =\ /d;' ~/.gitconfig
echo 'removed push default setting due to low version'
fi
# notify about packages to be installed
echo "For syntax highlighting, don't forget to install:"
echo 'yamllint puppet-lint jsonlint'
echo
# hint about cronjob
echo "How about adding a cronjob to stay in sync?"
echo "*/5 * * * * bash -c 'git -C ${SCRIPT_PWD} pull'"
echo