# Template file for 'inetutils'
pkgname=inetutils
version=2.0
revision=1
build_style=gnu-configure
configure_args="--without-wrap --with-pam"
makedepends="pam-devel readline-devel"
checkdepends="iana-etc net-tools"
short_desc="GNU network utilities"
maintainer="Orphaned <orphan@voidlinux.org>"
license="GPL-3.0-or-later"
homepage="http://www.gnu.org/software/inetutils"
distfiles="${GNU_SITE}/$pkgname/$pkgname-$version.tar.xz"
checksum=e573d566e55393940099862e7f8994164a0ed12f5a86c3345380842bdc124722

subpackages="inetutils-dnsdomainname inetutils-ftp inetutils-hostname
 inetutils-ifconfig inetutils-inetd inetutils-ping inetutils-rexec
 inetutils-syslog inetutils-telnet inetutils-tftp inetutils-traceroute
 inetutils-uucpd inetutils-whois"

CFLAGS="-fcommon"

# hostname test can't run in CI
make_check=ci-skip

case "$XBPS_TARGET_MACHINE" in
*-musl)
	# Some packages don't build on musl, so explicitly disable them
	configure_args+=" --disable-rcp --disable-rlogin --disable-rlogind --disable-rsh --disable-rshd --disable-talk --disable-talkd"
	;;
*)
	subpackages+=" inetutils-rcp inetutils-rlogin inetutils-rsh inetutils-talk"
	;;
esac
depends="${subpackages}"

pre_configure() {
	vsed -i 's|_GL_WARN_ON_USE (gets|//_GL_WARN_ON_USE (gets|' lib/stdio.in.h
	# Create a definition to allow the ifconfig program to build properly
	echo '#define PATH_PROCNET_DEV "/proc/net/dev"' >> ifconfig/system/linux.h
	# Use the standard name ("nicname") for the "whois" service.
	vsed -i 's|port : "whois"|port : "nicname"|' whois/whois.c
	# Changing the whois/whois.c triggers help2man invocation. This is not
	# necessary because no option has changed. Moreover, launching help2man
	# fails for the cross compilations. Let's make sure the build process
	# is not triggered to run it then.
	touch man/whois.1
}
post_install() {
	# Keep just usr/share/info/inetutils.info.gz
	rm -r ${DESTDIR}/usr/bin
	rm -r ${DESTDIR}/usr/share/man
	rm -r ${DESTDIR}/usr/libexec
}

inetutils-dnsdomainname_package() {
	short_desc+=" - dnsdomainname tool"
	pkg_install() {
		vbin src/dnsdomainname
		vman man/dnsdomainname.1
	}
}
inetutils-hostname_package() {
	short_desc+=" - hostname tool"
	alternatives="
	 hostname:hostname:/usr/bin/${pkgname}
	 hostname:hostname.1:/usr/share/man/man1/${pkgname}.1
	"
	pkg_install() {
		vbin src/hostname ${pkgname}
		vman man/hostname.1 ${pkgname}.1
	}
}
inetutils-ifconfig_package() {
	short_desc+=" - ifconfig tool"
	alternatives="
	 ifconfig:ifconfig:/usr/bin/${pkgname}
	 ifconfig:ifconfig.1:/usr/share/man/man1/${pkgname}.1
	"
	pkg_install() {
		vbin ifconfig/ifconfig ${pkgname}
		vman man/ifconfig.1 ${pkgname}.1
	}
}
inetutils-ftp_package() {
	short_desc+=" - ftp client and server (file transfer protocol)"
	alternatives="
	 ftp:ftp:/usr/bin/${pkgname}
	 ftp:ftp.1:/usr/share/man/man1/${pkgname}.1
	"
	pkg_install() {
		vbin ftp/ftp ${pkgname}
		vman man/ftp.1 ${pkgname}.1
		vbin ftpd/ftpd
		vman man/ftpd.8
		# TODO: write etc/inet.d/ftp.conf or add an etc/inetd.conf line
	}
}
inetutils-ping_package() {
	short_desc+=" - ping tool (IPv4 and IPv6)"
	alternatives="
	 ping:ping:/usr/bin/${pkgname}
	 ping:ping.1:/usr/share/man/man1/${pkgname}.1
	 ping6:ping6:/usr/bin/${pkgname}6
	 ping6:ping6.1:/usr/share/man/man1/${pkgname}6.1
	"
	pkg_install() {
		vbin ping/ping ${pkgname}
		vman man/ping.1 ${pkgname}.1
		vbin ping/ping6 ${pkgname}6
		vman man/ping6.1 ${pkgname}6.1
	}
}
inetutils-rcp_package() {
	short_desc+=" - rcp client (remote copy)"
	pkg_install() {
		vbin src/rcp
		vman man/rcp.1
	}
}
inetutils-rexec_package() {
	short_desc+=" - rexec client and server (remote exec)"
	conf_files="/etc/xinetd.d/rexec"
	pkg_install() {
		vbin src/rexec
		vman man/rexec.1
		vbin src/rexecd
		vman man/rexecd.8
		vinstall ${FILESDIR}/rexec.xinetd 644 etc/xinetd.d rexec
		# TODO: write etc/inet.d/rexec.conf or add an etc/inetd.conf line
	}
}
inetutils-rlogin_package() {
	short_desc+=" - rlogin client and server (remote login)"
	conf_files="/etc/xinetd.d/rlogin"
	pkg_install() {
		vbin src/rlogin
		vman man/rlogin.1
		vbin src/rlogind
		vman man/rlogind.8
		vinstall ${FILESDIR}/rlogin.xinetd 644 etc/xinetd.d rlogin
		# TODO: write etc/inet.d/rlogin.conf or add an etc/inetd.conf line
	}
}
inetutils-rsh_package() {
	short_desc+=" - rsh client and server (remote shell)"
	conf_files="/etc/xinetd.d/rsh"
	pkg_install() {
		vbin src/rsh
		vman man/rsh.1
		vbin src/rshd
		vman man/rshd.8
		vinstall ${FILESDIR}/rsh.xinetd 644 etc/xinetd.d rsh
		# TODO: write etc/inet.d/rsh.conf or add an etc/inetd.conf line
	}
}
inetutils-talk_package() {
	short_desc+=" - talk client and server"
	conf_files="/etc/xinetd.d/talk"
	pkg_install() {
		vbin talk/talk
		vman man/talk.1
		vbin talkd/talkd
		vman man/talkd.8
		vinstall ${FILESDIR}/talk.xinetd 644 etc/xinetd.d talk
		# TODO: write etc/inet.d/talk.conf or add an etc/inetd.conf line
	}
}
inetutils-telnet_package() {
	short_desc+=" - telnet client and server"
	conf_files="/etc/xinetd.d/telnet"
	pkg_install() {
		vbin telnet/telnet
		vman man/telnet.1
		vbin telnetd/telnetd
		vman man/telnetd.8
		vinstall ${FILESDIR}/telnet.xinetd 644 etc/xinetd.d telnet
		# TODO: write etc/inet.d/telnet.conf or add an etc/inetd.conf line
	}
}
inetutils-tftp_package() {
	short_desc+=" - tftp client and server (trivial file transfer protocol)"
	conf_files="/etc/xinetd.d/tftp"
	alternatives="
	 tftp:tftp:/usr/bin/${pkgname}
	 tftp:tftp.1:/usr/share/man/man1/${pkgname}.1
	 tftp:tftpd.8:/usr/share/man/man8/inetutils-tftpd.8
	"
	pkg_install() {
		vbin src/tftp ${pkgname}
		vman man/tftp.1 ${pkgname}.1
		vbin src/tftpd
		vman man/tftpd.8 inetutils-tftpd.8
		vinstall ${FILESDIR}/tftp.xinetd 644 etc/xinetd.d tftp
		# TODO: write etc/inet.d/tftp.conf or add an etc/inetd.conf line
	}
}
inetutils-traceroute_package() {
	short_desc+=" - traceroute tool"
	alternatives="
	 traceroute:traceroute:/usr/bin/${pkgname}
	 traceroute:traceroute.1:/usr/share/man/man1/${pkgname}.1
	"
	pkg_install() {
		vbin src/traceroute ${pkgname}
		vman man/traceroute.1 ${pkgname}.1
	}
}
inetutils-whois_package() {
	short_desc+=" - whois tool"
	alternatives="
	 whois:whois:/usr/bin/${pkgname}
	 whois:whois.1:/usr/share/man/man1/${pkgname}.1
	"
	pkg_install() {
		vbin whois/whois ${pkgname}
		vman man/whois.1 ${pkgname}.1
	}
}
inetutils-inetd_package() {
	short_desc+=" - inet daemon"
	pkg_install() {
		vbin src/inetd
		vman man/inetd.8
		# TODO: Install default config files with all services disabled?
		# Add config_files="/etc/inetd.conf /etc/hosts.deny /etc/hosts.allow"
	}
}
inetutils-syslog_package() {
	short_desc+=" - logger tool and syslog daemon"
	alternatives="
	 logger:logger:/usr/bin/inetutils-logger
	 logger:logger.1:/usr/share/man/man1/inetutils-logger.1
	"
	pkg_install() {
		vbin src/logger inetutils-logger
		vman man/logger.1 inetutils-logger.1
		vbin src/syslogd
		vman man/syslogd.8
	}
}
inetutils-uucpd_package() {
	short_desc+=" - uucpd daemon (unix to unix copy)"
	conf_files="/etc/xinetd.d/uucp"
	pkg_install() {
		vbin src/uucpd
		vman man/uucpd.8
		vinstall ${FILESDIR}/uucp.xinetd 644 etc/xinetd.d uucp
		# TODO: write etc/inet.d/uucp.conf or add an etc/inetd.conf line
	}
}
