-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·173 lines (150 loc) · 4.8 KB
/
setup.sh
File metadata and controls
executable file
·173 lines (150 loc) · 4.8 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
#! /bin/bash
## Setup script links in all configs found in ~/.peteches_configs to their
## expected locations. deleted any existing configs found.
# usage()
# prints usage
#
# inputs -
# outputs - usage message
# return value - 0 if successfull
# side effects -
usage()
{
echo "Usage: $0 [ install | uninstall | update ]"
}
if ! [[ -x $( type -P readlink ) ]]; then
echo "Must install readlink for setup to work" >&2
exit 1
fi
if [[ $# -ne 1 ]]; then
usage
exit 1
fi
case $1 in
install )
;&
update )
;&
uninstall )
_action=$1
;;
* )
usage
exit 1
;;
esac
config_dir=$(dirname $(readlink -e $0))
# create backup directory for existing files
backup_dir=${config_dir}/backups
function install_config {
target=$1
dest=$2
case $_action in
update )
if [[ -L ${dest} ]]; then
return
fi
;& # execute the install code block as well
install )
if [[ -e ${dest} ]]; then
[[ -d ${backup_dir} ]] || mkdir -p ${backup_dir}
mv --backup=numbered ${dest} ${backup_dir}
fi
# ensure target dir exists.
[[ -d $( dirname ${dest} ) ]] || mkdir --parents $( dirname ${dest} )
if [[ $SETUP_V ]]; then
echo "linking ${target} to ${dest}"
fi
ln -s ${target} ${dest}
;;
uninstall )
if [[ ! -L ${dest} ]]; then
read -p "${dest} is not a symlink really delete? [y/N]: " delete
fi
if [[ ${delete^^} == 'N' ]]; then
echo "exiting"
exit 0
fi
rm -f ${dest}
mv ${backup_dir}/$( basename ${dest} ) ${dest}
;;
esac
}
config_matrix=(
"${config_dir}/X-configs/Xdefaults ${HOME}/.Xdefaults"
"${config_dir}/X-configs/xsession ${HOME}/.xsession"
"${config_dir}/awesome ${HOME}/.config/awesome"
"${config_dir}/bash ${HOME}/.bash"
"${config_dir}/bash/bashrc ${HOME}/.bashrc"
"${config_dir}/misc/mailcap ${HOME}/.mailcap"
"${config_dir}/mutt ${HOME}/.mutt"
"${config_dir}/mutt/muttrc ${HOME}/.muttrc"
"${config_dir}/tmux ${HOME}/.tmux"
"${config_dir}/tmux/tmux.conf ${HOME}/.tmux.conf"
"${config_dir}/vim ${HOME}/.vim"
"${config_dir}/vim/vimrc ${HOME}/.vimrc"
"${config_dir}/vim/gvimrc ${HOME}/.gvimrc"
"${config_dir}/vimperator ${HOME}/.vimperator"
"${config_dir}/vimperator/vimperatorrc ${HOME}/.vimperatorrc"
"${config_dir}/gitconfig ${HOME}/.gitconfig"
"${config_dir}/gitignore ${HOME}/.gitignore"
)
# add scripts individually so as to keep locally generated scripts.
for script in ${config_dir}/scripts/*; do
config_matrix+=( "${script} ${HOME}/bin/$( basename ${script} )" )
done
for x in ${config_dir}/zsh/*; do
config_matrix+=( "$x $HOME/.$(basename $x)" )
done
# Also add kde things seperately to keep local scripts in tact.
for file in $( find ${config_dir}/kde -type f -printf "%P "); do
config_matrix+=( "${config_dir}/kde/${file} ${HOME}/.kde/${file}")
done
# and the same for firefox things, although more complicated as the
# profile directory will have a random 8 character string infrom of the
# profile name.
for file in $( find "${config_dir}/firefox" -type f -printf "%P "); do
# potentially this could match multiple paths, old profiles backups etc.
profile=$( echo $file | cut -d/ -f1)
dst_paths=($(find "${HOME}/.mozilla/firefox" \
-maxdepth 1 \
-type d -name \*.${profile} \
-print))
if [[ ${#dst_paths[@]} -gt 1 ]]; then
# we did find multiple profiles
for i in ${!dst_paths[@]}; do
if [[ $i -eq ${#dst_paths[@]} ]];then
break # no element i+1 now, need to vamoose before we error.
fi
# here we chaeck to see which is newer and assume that the most
# recent is the correct one.
if [[ ${dst_paths[$i]} -nt ${dst_paths[$i+1]} ]]; then
dst=${dst_paths[$i]}
else
dst=${dst_paths[$i+1]}
fi
done
else
dst=${dst_paths[0]}
fi
dst_path=${dst}/${file#*/} #strip profile name
config_matrix+=("${config_dir}/firefox/${file} ${dst_path}")
done
for args in "${config_matrix[@]}"; do
install_config $args
done
# install fonts
if [[ -x ${config_dir}/fonts/install.sh ]]; then
# subshell used to auto return to cwd.
(
cd ${config_dir}/fonts
${config_dir}/fonts/install.sh
)
fi
if [[ $_action == install ]]; then
echo "initialising submodules"
cd ${config_dir} && git submodule init && git submodule update
elif [[ $_action == update ]]; then
cd ${config_dir} && git submodule update
fi
exit $?