set -eu

APP_DIR='/data/soft/frp'
ARCH=$(uname -m)
screenNum=$(lib::getScreenNum "$CONFIG_FILE")

bin='frpc'
if [ "${ARCH}" = 'aarch64' ]; then
  bin="frpc-${ARCH}"
fi

mkdir -p $APP_DIR || true

lib::rsyncDownload /frp/$bin "${APP_DIR}/"
if [ "${bin}" != 'frpc' ]; then
  mv $APP_DIR/$bin $APP_DIR/frpc
fi
lib::rsyncDownload /frp/frpc.toml "${APP_DIR}/"
lib::rsyncDownload /frp/frpc.service /etc/systemd/system/

sed -i "s/screen-000/screen-$screenNum/g" "${APP_DIR}/frpc.toml"

chmod +x $APP_DIR/frpc
systemctl daemon-reload
chmod +x /etc/systemd/system/frpc.service

systemctl enable frpc
systemctl restart frpc
systemctl --no-pager status frpc
