-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-dotfiles
More file actions
executable file
·202 lines (175 loc) · 5.97 KB
/
deploy-dotfiles
File metadata and controls
executable file
·202 lines (175 loc) · 5.97 KB
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
#!/bin/bash
reponame=$(basename $(pwd))
tstamp=$(date +%Y%m%d%H%M%S)
# check that we are within the git repo
if [[ -d .git ]]; then
CWD=$(pwd)
elif [[ -d $(git rev-parse --git-dir 2>/dev/null) ]]; then
CWD=$(pwd)
fi
if [[ -z ${CWD} ]]; then
echo "Must run ${0} from dotfiles working directory"
exit 1
fi
# functions
check_link_and_backup () {
backupdir=$1
file=$2
# check that backupdir exists
if [[ ! -d ${backupdir} ]]; then
echo "Error, the backup directory '${backupdir}', does not exist"
exit 1
fi
# check to see if the file is a link, if not, backup
if [[ ! -L $1 ]]; then
mkdir -pv ${backupdir}/$(basename ${file}).${reponame}-${tstamp}
mv -v ${file} ${backupdir}/$(basename ${file}).${reponame}-${tstamp}
fi
}
############################# SCAFFOLDING ######################################
# test for the git command
git=$(which git)
if [[ $? -ne 0 ]]; then
echo "${0} needs the git command to run"
exit 1
fi
# set backup dir
BACKUP=${HOME}/.${reponame}-backup
if [[ ! -d ${BACKUP} ]]; then
echo "Creating backup dir: ${BACKUP}"
mkdir -pv ${BACKUP}
if [[ $? -ne 0 ]]; then
echo "Error, could not create backup dir"
exit 1
fi
fi
# set opt dir
OPT=${HOME}/opt
if [[ ! -d ${OPT} ]]; then
echo "Creating opt dir: ${OPT}"
mkdir -pv ${OPT}
if [[ $? -ne 0 ]]; then
echo "Error, could not create opt dir"
exit 1
fi
fi
############################## SUBMODULES ######################################
sub_status=$(git submodule status |grep -v -)
# Initialize top-level modules
if [[ $? -ne 0 ]]; then
echo "Initializing and updating submodules"
git submodule init && git submodule update
if [[ $? -ne 0 ]]; then
echo "Error initializing submodules"
exit 1
fi
fi
for sub in $(git submodule | awk '{ print $2 }'); do
echo "Initializing and updating the submodules FOR submodule '${sub}'"
cd ${CWD}/${sub}
git submodule init && git submodule update
cd ..
echo "Linking submodule '${sub}'"
link=${OPT}/${sub}
if [[ -L ${link} ]]; then
echo " Removing link for submodule: ${sub}"
rm -v ${link}
fi
ln -sv ${CWD}/${sub} ${link}
if [[ $? -ne 0 ]]; then
echo "Error linking submodule: ${sub}"
exit 1
fi
done
################################ CONFIG ########################################
CONFDIR=config
echo "Copying .${CONFDIR} files to ${HOME}/.${CONFDIR}"
if [[ ! -d ${BACKUP}/${CONFDIR} ]]; then
mkdir -v ${BACKUP}/${CONFDIR}.${reponame}-${tstamp}
fi
if [[ ! -d ${HOME}/.${CONFDIR} ]]; then
echo "Error! directory ${HOME}/.${CONFDIR} does not exist"
mkdir -v ${HOME}/.${CONFDIR}
fi
for dir in $(find ${CWD}/${CONFDIR} -mindepth 1 -maxdepth 1 -type d); do
dir=$(basename ${dir})
echo ${dir}
if [[ ! -L ${HOME}/.${CONFDIR}/${dir} ]]; then
mv -v ${HOME}/.${CONFDIR}/${dir} ${BACKUP}/${CONFDIR}.${reponame}-${tstamp}/${dir}
ln -sv ${CWD}/${CONFDIR}/${dir} ${HOME}/.${CONFDIR}/
fi
done
################################# BASH #########################################
echo "Copying bash dotfiles to ${HOME}"
dotfiles="bashrc bash_aliases bash_profile profile profile_methods"
for file in ${dotfiles};
do
if [[ -f ${CWD}/${file} ]]; then
if [[ -f ${HOME}/.${file} ]]; then
mv -v ${HOME}/.${file} ${BACKUP}/.${file}.${reponame}-${tstamp}
fi
cp -v ${CWD}/${file} ${HOME}/.${file}
fi
done
################################## VIM #########################################
dotfiles="vim vimrc"
for file in ${dotfiles};
do
if [[ -f ${HOME}/.${file} || -d ${HOME}/.${file} ]]; then
mv -v ${HOME}/.${file} ${BACKUP}/.${file}.${reponame}-${tstamp}
fi
## Special case for vimrc:
# vimrc has been broken up into several different files based on
# installed plugins, any new plugins that should be referenced in
# vimrc should be added to its own config file and "cat"-ed here.
if [[ ${file} == 'vimrc' && -f ${CWD}/vimrc-base ]]; then
echo "Writing out file: '${HOME}/.${file}'"
cat \
${CWD}/vimrc-base \
${CWD}/vimrc-ext-pathogen \
${CWD}/vimrc-ext-solarized \
${CWD}/vimrc-ext-powerline \
> ${HOME}/.${file}
else
if [[ -f ${CWD}/${file} || -d ${CWD}/${file} ]]; then
echo "Deploying file '${CWD}/${file}' to '${HOME}/.${file}'"
cp -rv ${CWD}/${file} ${HOME}/.${file}
fi
fi
done
if [[ ! -d ${HOME}/.vim/bundle ]]; then
mkdir -v ${HOME}/.vim/bundle
fi
# add solarized to pathogens path
if [[ -d ${OPT}/solarized/vim-colors-solarized && -d ${HOME}/.vim/bundle ]]; then
ln -sv ${OPT}/solarized/vim-colors-solarized ${HOME}/.vim/bundle/
fi
if [[ -d ${OPT}/powerline/powerline/bindings/vim && -d ${HOME}/.vim/bundle ]]; then
ln -sv ${OPT}/powerline/powerline/bindings/vim ${HOME}/.vim/bundle/vim-powerline
fi
################################# TMUX #########################################
file='tmux.conf'
tmuxdir='.tmux'
echo "Linking file '${file}' to '${HOME}'"
if [[ -f ${HOME}/.${file} ]]; then
mv -v ${HOME}/.${file} ${BACKUP}/.${file}.${reponame}-${tstamp}
ln -sv ${CWD}/${file} ${HOME}/.${file}
elif [[ -L ${HOME}/.${file} ]]; then
cp -v ${HOME}/.${file} ${BACKUP}/.${file}.${reponame}-${tstamp}
fi
# backup tmuxdir
if [[ -d ${HOME}/${tmuxdir} ]]; then
mv -v ${HOME}/${tmuxdir} ${BACKUP}/${tmuxdir}.${reponame}-${tstamp}
fi
if [[ ! -d ${HOME}/${tmuxdir} ]]; then
mkdir -v ${HOME}/${tmuxdir}
fi
tmuxcolordir='colors'
if [[ ! -d ${HOME}/${tmuxdir}/${tmuxcolordir} ]]; then
mkdir -v ${HOME}/${tmuxdir}/${tmuxcolordir}
fi
colors='tmuxcolors-256.conf'
echo "Copying tmux colorscheme '${file}' to '${HOME}'"
if [[ ! -f ${HOME}/${tmuxdir}/${tmuxcolordir}/${colors} ]]; then
cp -v ${CWD}/solarized/tmux/${colors} ${HOME}/${tmuxdir}/${tmuxcolordir}/.${colors}
fi