00873025b1cf54f6289b1535191180fd919ee827
[src/xds/xds-cli.git] / scripts / install.sh
1 #!/bin/bash
2
3 ###########################################################################
4 # Copyright 2017-2018 IoT.bzh
5 #
6 # author: Sebastien Douheret <sebastien@iot.bzh>
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 #     http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20 # Script used to install XDS cli tool.
21 #
22 ###########################################################################
23
24
25 DESTDIR=${DESTDIR:-/opt/AGL/xds/cli}
26
27 ROOT_SRCDIR=$(cd $(dirname "$0")/.. && pwd)
28
29 install() {
30     mkdir -p "${DESTDIR}" && cp "${ROOT_SRCDIR}/bin/"* "${DESTDIR}" || exit 1
31
32     FILE=/etc/profile.d/xds-cli.sh
33     sed -e "s;%%XDS_INSTALL_BIN_DIR%%;${DESTDIR};g" "${ROOT_SRCDIR}/conf.d/${FILE}" > ${FILE} || exit 1
34 }
35
36 uninstall() {
37     rm -rf "${DESTDIR}"
38     rm -f /etc/profile.d/xds-cli.sh
39 }
40
41 if [ "$1" == "uninstall" ]; then
42     echo -n "Are-you sure you want to remove ${DESTDIR} [y/n]? "
43     read answer
44     if [ "${answer}" = "y" ]; then
45         uninstall
46         echo "xds-cli sucessfully uninstalled."
47     else
48         echo "Uninstall canceled."
49     fi
50 else
51     install
52 fi