#!/bin/bash function do_uninstall { set -x systemctl stop h804tun rm -rf /opt/h804tun systemctl disable h804tun rm /etc/systemd/system/h804tun.service systemctl daemon-reload } function do_build { echo "Building..." rm -rf build/ mkdir -p build/ pushd build/ cmake -DWITH_SYSTEMD=ON .. cmake --build . if [ -f /opt/h804tun/h804tun.conf ]; then head -n 2 /opt/h804tun/h804tun.conf > h804tun.conf else echo "INTERFACE_NAME" > h804tun.conf echo "STATIC_IP" >> h804tun.conf fi echo "" >> h804tun.conf echo "# Interfaces: " >> h804tun.conf ip link | sed 's/^/# /' >> h804tun.conf if [ -z "$EDITOR" ]; then EDITOR=ed fi $EDITOR h804tun.conf popd } function do_install { set -x systemctl stop h804tun mkdir -p /opt/h804tun cp build/h804tun /opt/h804tun/h804tun cp build/h804tun.conf /opt/h804tun/h804tun.conf cp h804tun.service /etc/systemd/system systemctl daemon-reload } if [ $# == 0 ] || [ $1 == "install" ]; then do_build sudo $0 do_install elif [ $1 == "uninstall" ]; then sudo $0 do_uninstall elif [ $1 == "do_install" ]; then do_install elif [ $1 == "do_uninstall" ]; then do_uninstall fi