#!/bin/bash


if [ ! -d /opt/script ]; then
	mkdir -p /opt/script
fi

mkdir -p /opt/npc
wget --no-check-certificate -P /opt/npc https://ftp.jingyi.fun/nps/linux_amd64_client.tar.gz  

tar -zxvf /opt/npc/linux_amd64_client.tar.gz -C /opt/npc
rm -f /opt/npc/linux_amd64_client.tar.gz


echo """#!/bin/bash

nohup /opt/npc/npc -server=119.3.177.170:8024 -vkey=$1 -type=tcp &
""" > /opt/script/npc.sh

echo """[Unit]
Description=npc
After=network.target

[Service]
Type=forking
ExecStart=/opt/script/npc.sh
ExecStop=/opt/script/npc.sh
PrivateTmp=true

[Install]
WantedBy=multi-user.target
""" > /lib/systemd/system/npc.service

chmod +x  /opt/script/npc.sh
systemctl daemon-reload
systemctl start npc.service
systemctl enable npc.service
