-
Notifications
You must be signed in to change notification settings - Fork 74
/
install.sh
executable file
·218 lines (149 loc) · 5.09 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
211
212
213
214
215
216
217
218
#!/bin/bash
# This script installs Atomsk on the local computer.
# If run with super-user rights (su or sudo), then the
# program and documentation are installed in /usr/local/.
# Otherwise they are installed in the user's home directory.
web="https://atomsk.univ-lille.fr"
BINPATH=/usr/local/bin/
DOCPATH=/usr/local/share/doc/
MPATH=/usr/local/share/man/man1/
clear
printf "___________________________________________________________\n"
printf "\e[1m Atomsk Installation Setup\e[0m\n"
printf "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _\n"
# Check if executable is present; otherwise, try to compile it
if [ ! -e 'atomsk' ] ; then
if [ -e "src/atomsk" ] ; then
cp src/atomsk .
else
echo "<i> INFO: the executable 'atomsk' does not exist in current directory."
if [ ! -d "src" ] ; then
printf "<?> Do you wish to download Atomsk from the Web site? (y/n) "
read answer
if [ "${answer}" = "y" ] ; then
wget ${web}/version.txt
if [ -e "version.txt" ] ; then
ver=$(more version.txt)
wget ${web}/code/atomsk_b${ver}.tar.gz
rm version.txt
if [ -e "atomsk_b${ver}.tar.gz" ] ; then
tar -xzf atomsk_b${ver}.tar.gz
cd atomsk_b${ver}
else
echo "X!X ERROR: unable to reach ${web} , aborting."
exit
fi
else
echo "X!X ERROR: unable to reach ${web} , aborting."
exit
fi
else
echo ">>> Installation cancelled."
exit
fi
fi
if [ -d "src" ] ; then
printf "<?> Do you wish to compile Atomsk from the source code? (y/n) "
read answer
if [ "${answer}" = "y" ] ; then
cd src
make -j3 atomsk
cd ..
if [ -e "src/atomsk" ] ; then
cp src/atomsk .
else
echo "X!X ERROR: compilation failed. Please read the documentation before compiling again,"
echo " or download a binary version from ${web}."
fi
else
echo ">>> Installation cancelled."
exit
fi
else
echo "X!X ERROR: impossible to install Atomsk. Please download the program from ${web}"
exit
fi
fi
fi
# Check if we have super-user rights
if [ ! "$UID" -eq 0 ] ; then
echo "<!> INFO: I must have super-user rights (su) to install Atomsk in your system (${BINPATH})."
echo "<!> If you choose no, then Atomsk will be installed in the /bin/ directory in your home (${HOME}/bin)."
printf "<?> Do you wish to activate super-user rights to install Atomsk system-wide? (y/n) "
read answer
if [ "${answer}" = "y" ] ; then
exec sudo "$0" "$@"
fi
fi
# Copy program and files into user's computer
if [ "$UID" -eq 0 ] ; then
printf "<?> Atomsk will be installed in ${BINPATH}. Continue? (y/n) "
read answer
if [ "${answer}" = "y" ] ; then
# System configuration file
cp -rf ./etc/atomsk.conf /etc/
# Atomsk binary
chmod +x atomsk
cp atomsk ${BINPATH}
# Atomsk tools
chmod +x ./tools/*.sh
cp ./tools/* ${BINPATH}
echo ""
echo ">>> The program was successfuly installed in ${BINPATH}"
echo " To run it, enter 'atomsk' in a terminal."
# Atomsk documentation
mkdir -p ${DOCPATH}/atomsk
rm -rf ${DOCPATH}/atomsk/*
cp -rf ./doc/* ${DOCPATH}/atomsk/
chmod -R a+r ${DOCPATH}/atomsk/
echo ""
echo ">>> The html documentation was installed. You may read it by entering the"
echo " following address in your Web browser: ${DOCPATH}atomsk/index.html"
# Atomsk man page
mkdir -p ${MPATH}
gzip -c ./man/atomsk >${MPATH}/atomsk.1.gz
else
echo ">>> Installation cancelled."
fi
else
# Install program in user's home directory
BINPATH=~/bin/atomsk/
DOCPATH=~/bin/atomsk/doc/
echo ""
printf "<?> Atomsk will be installed in ${BINPATH}. Continue? (y/n) "
read answer
if [ "${answer}" = "y" ] ; then
# Create the target folder
mkdir -p ${BINPATH}
# System configuration file
cp -rf ./etc/atomsk.conf ~/.config/
# Atomsk binary
chmod +x atomsk
cp atomsk ${BINPATH}
# Atomsk tools
chmod +x ./tools/*.sh
cp ./tools/* ${BINPATH}
echo ""
echo ">>> The program was successfuly installed in ${BINPATH}"
echo " To run it, enter 'atomsk' in a terminal."
# Atomsk documentation
mkdir -p ${DOCPATH}
rm -rf ${DOCPATH}/*
cp -rf ./doc/* ${DOCPATH}
chmod -R a+r ${DOCPATH}
echo ""
echo ">>> The html documentation was installed. You may read it by entering the"
echo " following address in your Web browser: ${DOCPATH}index.html"
# Create alias
n=$(grep "atomsk" ~/.bashrc | wc -l)
if [ $n -eq 0 ] ; then
echo "export PATH=\"\$PATH:${BINPATH}\"" >> ~/.bashrc
source ~/.bashrc
echo ""
echo ">>> ${BINPATH} was added to your PATH environment variable."
fi
else
echo ">>> Installation cancelled."
fi
fi
printf "___________________________________________________________\n"