Fix build release and packaging
[src/xds/xds-agent.git] / scripts / install.sh
1 #!/bin/bash
2
3 # Install XDS agent as a user systemd service
4
5 DESTDIR=${DESTDIR:-/opt/AGL/xds/agent}
6
7 ROOT_SRCDIR=$(cd $(dirname "$0")/.. && pwd)
8
9 install() {
10     mkdir -p ${DESTDIR} && cp ${ROOT_SRCDIR}/bin/* ${DESTDIR} || exit 1
11
12     cp ${ROOT_SRCDIR}/conf.d/etc/xds-agent /etc/ || exit 1
13     cp ${ROOT_SRCDIR}/conf.d/etc/default/xds-agent /etc/default/ || exit 1
14
15     FILE=/etc/profile.d/xds-agent.sh
16     sed -e "s;%%XDS_INSTALL_BIN_DIR%%;${DESTDIR};g" ${ROOT_SRCDIR}/conf.d/${FILE} > ${FILE} || exit 1
17
18     FILE=/usr/lib/systemd/user/xds-agent.service
19     sed -e "s;/opt/AGL/xds/agent;${DESTDIR};g" ${ROOT_SRCDIR}/conf.d/${FILE} > ${FILE} || exit 1
20
21     echo ""
22     echo "To enable xds-agent service, execute:      systemctl --user enable xds-agent"
23     echo "and to start xds-agent service, execute:   systemctl --user start xds-agent"
24 }
25
26 uninstall() {
27     rm -rf "${DESTDIR}"
28     rm -f /etc/xds-agent /etc/profile.d/xds-agent.sh /usr/lib/systemd/user/xds-agent.service
29 }
30
31 if [ "$1" == "uninstall" ]; then
32     echo -n "Are-you sure you want to remove ${DESTDIR} [y/n]? "
33     read answer
34     if [ "${answer}" = "y" ]; then
35         uninstall
36         echo "xds-agent sucessfully uninstalled."
37     else
38         echo "Uninstall canceled."
39     fi
40 else
41     install
42 fi