#!/bin/bash

# Installs the net-aranymp2p service
# Details in /etc/net-aranymp2p.conf

echo "
  Starting net-arnamyp2p installation....
"  

#check iptables
if [[ ! -f $(which iptables 2>/dev/null) ]];then
  echo "
  Need to install iptables...
  
  Is this ok?  y/n
  "
  read -n 1 anw
  if [ "$anw" = "y" ];then    
    apt update 
    apt -y install iptables 
  else
  	echo "
  net-aranymp2p installation aborted...
  
  "
    exit 0
  fi
fi


#chech netdev group
if id -nG $(logname) | grep -qw netdev; then
    echo "
  User $(logname) belongs to netdev group
    "
else
  echo "
  I add "$(logname)" to the netdev Group
  
  Is this ok? y/n
  "
  read -n 1 anw 
  if [ "$anw" = "y" ];then   
    echo
    adduser $(logname) netdev
  else
    echo "
    net-aranymp2p installation aborted...
  
    " 
    exit 0
   fi
fi

#install net-aranymp2p.service  
cp net-aranymp2p.conf /etc && chown root.root /etc/net-aranymp2p.conf && chmod 644 /etc/net-aranymp2p.conf
cp net-aranymp2p  /usr/bin && chown root.root /usr/bin/net-aranymp2p && chmod 755 /usr/bin/net-aranymp2p
cp net-aranymp2p.service /etc/systemd/system && chown root.root /etc/systemd/system/net-aranymp2p.service && chmod 644 /etc/systemd/system/net-aranymp2p.service

systemctl enable net-aranymp2p.service 2>/dev/null 

#Finally
echo "
  net-aranymp2p.service is installed.

  You must have a look in /etc/net-aranymp2p.conf,
 
  special for Firewall and IP's  !!!
 
  Note: that if a firewall is already active, you must enter the
  rules into the existing firewall yourself.
 
  After checking the /etc/net-aranymp2p.conf

  You need a Reboot of the System, for activating your Groups Rights new.
  
  Back from Reboot, you can setup aranym config Network (shell or GUI)

"
 
 exit 0
