-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·217 lines (181 loc) · 5.08 KB
/
setup.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
211
212
213
214
215
216
217
#!/bin/bash
trap exit INT
banner()
{
echo '#######################################################'
echo '# ________ .___ #'
echo '# / _____/_ _ __ ____ ____ __| _/_______ __ #'
echo '# / \ __\ \/ \/ // __ \/ _ \ / __ |/ __ \ \/ / #'
echo '# \ \_\ \ /\ ___( <_> ) /_/ \ ___/\ / #'
echo '# \______ /\/\_/ \___ >____/\____ |\___ >\_/ #'
echo '# \/ \/ \/ \/ #'
echo '# #'
echo '#######################################################'
}
help_menu()
{
echo '#### MAIN OPTIONS: #'
echo ' -[-]i[nstall]=<path> The installation path #'
echo '#######################################################'
}
show_config()
{
echo "#### CONFIGURATION: "
echo " - SRC = $GD_SRC "
echo " - INSTALL = $GD_INSTALL "
echo " - TMP = $GD_TMP "
echo " - CACHE = $GD_CACHE "
echo "#######################################################"
}
convert_absolute_path()
{
test -z "`echo "$1" | grep -E "^/.*$"`" && printf "$2/"
printf "$1"
}
error()
{
printf "Error: $@\n" 1>&2
exit 42
}
warn()
{
printf "Warn: $@\n" 1>&2
}
read_arg()
{
echo "$1" | sed -re "s@^$2@@"
}
create_symlinks()
{
for link in `cat $GD_SRC/.links`
do
src=`echo $link | cut -f1 -d":"`
target=`echo $link | cut -f2 -d":" | sed -e "s,HOME,${HOME},g"`
test -e "${target}" -a ! -L "$target" && warn "Don't want to erase the regular file $target !" && continue
test -f "$src" && ln -sf $GD_SRC/$src $target || warn "Trouble to create $target link !"
done
}
build_packages()
{
if test -d $GD_SRC/spack/ -a ! -e $GD_SRC/spack/share/spack/setup-env.sh; then
warn "Spack not present. Cloning it first"
(git submodule update --remote) || error "Can't download Spack !"
fi
. $GD_SRC/spack/share/spack/setup-env.sh || error "Can't source Spack environment !"
type module > /dev/null 2>&1
if test "$?" != "0"; then
warn "Environment-modules not present. Installing first"
spack bootstrap || error "Unable to deploy Spack Bootstrap"
fi
test -f "$GD_SRC/spack_recipes" && git submodule update --remote
spack repo add $GD_SRC/spack_recipes
grep -v '^ *#' < $GD_SRC/.defprogs |
while read package
do
test -z "$package" && continue
spack install $package || error "Unable to install $package"
done
}
deploy_vim()
{
echo "Deploying VIM environment"
mkdir -p ~/.vim/bundle
if test -d ~/.vim/bundle/vundle.vim; then
cd ~/.vim/bundle/vundle.vim && git pull
else
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/vundle.vim || error "Can't clone vundle.vim from Github !"
fi
}
list_installs()
{
test -f ~/.gd_install || echo "No previous installation"
while read conf
do
install="`echo "$conf" | cut -f1 -d":"`"
cache="`echo "$conf" | cut -f2 -d":"`"
echo "* Install: $install (cache: $cache)"
done < ~/.gd_install
}
check_install()
{
test -f ~/.gd_install || return
while read conf
do
install="`echo "$conf" | cut -f1 -d":"`"
cache="`echo "$conf" | cut -f2 -d":"`"
if test "$install" != "$GD_INSTALL"; then
error "You re-install while you already have an install in $install"
elif test "$cache" != "$GD_CACHE"; then
error "I do not handle Cache path moving yet !"
fi
done < ~/.gd_install
}
register_new_install()
{
echo "$GD_INSTALL:$GD_CACHE" >> ~/.gd_install
}
GD_PWD="$PWD"
GD_SRC="`dirname $0`"
GD_INSTALL=
GD_TMP=
GD_CACHE=
GD_GCC=6.2.0
banner
for arg in $@
do
case $arg in
--list)
list_installs
exit 0
;;
--install=*|-i=*)
GD_INSTALL="`read_arg "$arg" "--*i(nstall)*="`"
;;
--tmp=*|-t=*)
GD_TMP="`read_arg "$arg" "--*t(mp)*="`"
;;
--cache=*|-c=*)
GD_CACHE="`read_arg "$arg" "--*c(ache)*="`"
;;
--help|-help|-h|-H)
help_menu
exit 0
;;
--cc_ver=*)
GD_GCC="`read_arg "$arg" "--cc_ver="`"
;;
*)
help_menu
error "Unknown argument '$arg'"
;;
esac
done
GD_SRC="`convert_absolute_path "$GD_SRC" "$GD_PWD"`"
test -z "$GD_INSTALL" && GD_INSTALL=$GD_SRC/spack/opt/spack
test -z "$GD_TMP" && GD_TMP=$GD_SRC/spack/var/spack/stage
test -z "$GD_CACHE" && GD_CACHE=$GD_SRC/spack/var/spack/cache
GD_INSTALL="`convert_absolute_path "$GD_INSTALL" "$GD_PWD"`"
GD_TMP="`convert_absolute_path "$GD_TMP" "$GD_PWD"`"
GD_CACHE="`convert_absolute_path "$GD_CACHE" "$GD_PWD"`"
show_config
check_install
create_symlinks
mkdir -p $HOME/.spack
cat<<EOF > $HOME/.spack/config.yaml
config:
install_tree: $GD_INSTALL
build_stage: $GD_TMP/spack
source_cache: $GD_CACHE
EOF
build_packages
deploy_vim
register_new_install
rm -rf $GD_TMP/spack
echo "#######################################################"
echo "# Installation complete ! Just few more steps:"
echo "# 1. $GD_SRC/resources/update_bashrc.sh"
echo " 2. . ~/.bashrc"
echo " 3. spack load vim"
echo "# 4. $GD_SRC/resources/install_vimplugins.sh"
echo "###### THANKS FOR USING IT ! ##########################"
exit 0